Browse Source

Update ahoy.py channel hopping and logging

* Improve channel hopping
   by rotating rx start channel for each transaction
 * Set autoack True
   gives nearly 100% transmission success rate
 * Cleanup unused lines
pull/1/head
Jan-Jonas Sämann 3 years ago
parent
commit
030af13c96
  1. 51
      tools/rpi/ahoy.py

51
tools/rpi/ahoy.py

@ -226,35 +226,40 @@ def main_loop():
print_addr(dtu_ser) print_addr(dtu_ser)
ctr = 1 ctr = 1
last_tx_message = ''
ts = int(time.time()) # see what happens if we always send one and the same (constant) time!
rx_channels = [3,23,61,75] rx_channels = [3,23,61,75]
chn_id = 0 rx_channel_id = 0
rx_channel = rx_channels[chn_id] rx_channel = rx_channels[rx_channel_id]
tx_channels = [40]
tx_channel_id = 0
tx_channel = tx_channels[tx_channel_id]
while True: while True:
# Sweep receive start channel
rx_channel_id = ctr % len(rx_channels)
rx_channel = rx_channels[rx_channel_id]
radio.setChannel(rx_channel) radio.setChannel(rx_channel)
radio.enableDynamicPayloads() radio.enableDynamicPayloads()
radio.setAutoAck(False) radio.setAutoAck(True)
radio.setPALevel(RF24_PA_MAX) radio.setPALevel(RF24_PA_MAX)
radio.setDataRate(RF24_250KBPS) radio.setDataRate(RF24_250KBPS)
radio.openWritingPipe(ser_to_esb_addr(inv_ser)) radio.openWritingPipe(ser_to_esb_addr(inv_ser))
radio.flush_rx() radio.flush_rx()
radio.flush_tx() radio.flush_tx()
radio.openReadingPipe(1,ser_to_esb_addr(dtu_ser)) radio.openReadingPipe(1,ser_to_esb_addr(dtu_ser))
#radio.openReadingPipe(1,ser_to_esb_addr(inv_ser))
radio.startListening() radio.startListening()
if ctr<3:
pass
# radio.printPrettyDetails()
t_end = time.monotonic_ns()+1e9 t_end = time.monotonic_ns()+1e9
while time.monotonic_ns() < t_end: while time.monotonic_ns() < t_end:
has_payload, pipe_number = radio.available_pipe() has_payload, pipe_number = radio.available_pipe()
if has_payload: if has_payload:
size = radio.getDynamicPayloadSize() size = radio.getDynamicPayloadSize()
payload = radio.read(size) payload = radio.read(size)
print(last_tx_message, end='')
last_tx_message = ''
dt = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f") dt = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")
print(f"{dt} Received {size} bytes on channel {rx_channel} pipe {pipe_number}: " + print(f"{dt} Received {size} bytes on channel {rx_channel} pipe {pipe_number}: " +
" ".join([f"{b:02x}" for b in payload])) " ".join([f"{b:02x}" for b in payload]))
@ -263,27 +268,31 @@ def main_loop():
radio.stopListening() radio.stopListening()
radio.setChannel(rx_channel) radio.setChannel(rx_channel)
radio.startListening() radio.startListening()
chn_id = chn_id + 1 rx_channel_id = rx_channel_id + 1
if chn_id >= len(rx_channels): if rx_channel_id >= len(rx_channels):
chn_id = 0 rx_channel_id = 0
rx_channel = rx_channels[chn_id] rx_channel = rx_channels[rx_channel_id]
time.sleep(0.01) time.sleep(0.01)
tx_channel_id = tx_channel_id + 1
if tx_channel_id >= len(tx_channels):
tx_channel_id = 0
tx_channel = tx_channels[tx_channel_id]
radio.stopListening() # put radio in TX mode radio.stopListening() # put radio in TX mode
radio.setChannel(40) radio.setChannel(tx_channel)
radio.openWritingPipe(ser_to_esb_addr(inv_ser)) radio.openWritingPipe(ser_to_esb_addr(inv_ser))
if ctr<3: ts = int(time.time())
pass
# radio.printPrettyDetails()
# ts = int(time.time())
payload = compose_0x80_msg(src_ser_no=dtu_ser, dst_ser_no=inv_ser, ts=ts) payload = compose_0x80_msg(src_ser_no=dtu_ser, dst_ser_no=inv_ser, ts=ts)
print(f"{ctr:5d}: len={len(payload)} | " + " ".join([f"{b:02x}" for b in payload]), dt = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")
flush=True) last_tx_message = f"{dt} Transmit {ctr:5d}: channel={tx_channel} len={len(payload)} | " + \
" ".join([f"{b:02x}" for b in payload]) + "\n"
radio.write(payload) # will always yield 'True' because auto-ack is disabled radio.write(payload) # will always yield 'True' because auto-ack is disabled
ctr = ctr + 1 ctr = ctr + 1
print(flush=True, end='')

Loading…
Cancel
Save