Added timeout when running as initializer and not receiving an pong answer
when running as a responder, no timeout is needed - it should just sit there waiting till a request (ping) arrives - that't why the ToDo there got removed
This commit is contained in:
parent
517db51909
commit
45ee016126
@ -53,13 +53,27 @@ def as_initializer(lora, lcd, lcd_connected, interrupt_pin):
|
||||
ping_to_send = False
|
||||
if not ping_to_send:
|
||||
print("[LoRaPingPong] Now waiting for a response")
|
||||
time_now = time()
|
||||
while not lora.received_packet():
|
||||
sleep(0.01)
|
||||
if interrupted(): return # if interrupt btn is pressed, stop listening
|
||||
# TODO: implement a timeout
|
||||
if (time() - time_now) > 15:
|
||||
# timeout if waiting too long for a response
|
||||
# possible causes of triggering this could be e.g. lost connection
|
||||
print("[LoRaPingPong] Timeout reached. Sending ping again.")
|
||||
if lcd:
|
||||
lcd.move_to(0,1)
|
||||
lcd.putstr("Reached timeout!")
|
||||
break
|
||||
|
||||
# NOW got a response!
|
||||
blink_led(receive_led)
|
||||
payload = lora.read_payload()
|
||||
|
||||
if not payload: # if empty because of timeout
|
||||
ping_to_send = True
|
||||
continue
|
||||
|
||||
try:
|
||||
payload_dict = loads(payload)
|
||||
TX_POWER_REQ = payload_dict["tx_power"]
|
||||
@ -116,7 +130,6 @@ def as_responder(lora, lcd, lcd_connected, interrupt_pin):
|
||||
while not lora.received_packet():
|
||||
sleep(0.01)
|
||||
if interrupted(): return # if interrupt btn is pressed, stop listening
|
||||
# TODO: implement a timeout
|
||||
# NOW got a response!
|
||||
blink_led(receive_led)
|
||||
payload = lora.read_payload()
|
||||
|
Loading…
Reference in New Issue
Block a user