multiple networks
pbljung opened this issue · 1 comments
I am trying to read from both ANT+ devices and non-ANT+ (PUBLIC) devices. (I can successfully read from both individually using 2 separate programs.) I added the PUBLIC and ANTPLUS network keys as network 0x00 and 0x01. I created 2 channels using each of the networks. However I can only successfully read from network 0x00 (PUBLIC). How can I also read from network 0x01 (ANTPLUS)?
Here is my test code
`from ant.easy.node import Node
from ant.easy.channel import Channel
from ant.base.message import Message
import logging
import struct
import threading
import sys
ANTPLUS_NETWORK_KEY = [0xB9, 0xA5, 0x21, 0xFB, 0xBD, 0x72, 0xC3, 0x45]
PUBLIC_NETWORK_KEY = [0xE8, 0xE4, 0x21, 0x3B, 0x55, 0x7A, 0x67, 0xC1]
def on_data(data):
hx = list(map(hex, data.tolist()))
if len(data) > 8:
deviceNumberLSB = data[9]
deviceNumberMSB = data[10]
deviceNumber = "{}".format(deviceNumberLSB + (deviceNumberMSB << 8))
deviceType = "{}".format(data[11])
else:
deviceNumber = 0
deviceType = 0
print("DeviceNr: {} DeviceType: {} Data: {}".format(deviceNumber, deviceType, hx))
sys.stdout.flush()
def main():
logging.basicConfig(filename="example.log", level=logging.DEBUG)
node = Node()
node.set_network_key(0x00, PUBLIC_NETWORK_KEY)
node.set_network_key(0x01, ANTPLUS_NETWORK_KEY)
# PUBLIC sensor
channel0 = node.new_channel(Channel.Type.BIDIRECTIONAL_RECEIVE, 0x00, 0x00) # network 0x00 PUBLIC
channel0.on_broadcast_data = on_data
channel0.on_burst_data = on_data
channel0.on_acknowledge = on_data
channel0.set_id(0, 0, 0) # wildcards
channel0.enable_extended_messages(1)
channel0.set_search_timeout(12)
channel0.set_period(3895)
channel0.set_rf_freq(67)
ANTPLUS heartrate
channel1 = node.new_channel(Channel.Type.BIDIRECTIONAL_RECEIVE, 0x00, 0x01) # network 0x01 ANTPLUS
channel1.on_broadcast_data = on_data
channel1.on_burst_data = on_data
channel1.on_acknowledge = on_data
channel1.set_id(0, 0, 0) # wildcards
channel1.enable_extended_messages(1)
channel1.set_search_timeout(0xFF)
channel1.set_period(8070)
channel1.set_rf_freq(57)
try:
channel1.open()
channel0.open()
node.start()
finally:
channel1.close()
channel0.close()
node.stop()
if name == "main":
main()
`
The output is only from the 0x00 PUBLIC network. There is no output from the ANT+ heart rate sensor.
DeviceNr: 18192 DeviceType: 112 Data: ['0xe4', '0xf3', '0xd9', '0x2', '0xf3', '0x0', '0x6b', '0x21', '0x80', '0x10', '0x47', '0x70', '0x5'] DeviceNr: 18192 DeviceType: 112 Data: ['0xe4', '0xf4', '0xdb', '0x2', '0xf4', '0x0', '0x6b', '0x21', '0x80', '0x10', '0x47', '0x70', '0x5'] ...
The question is outside the scope of this repository.
It should be asked in the openant+ repository.