Adafruit_Learning_System_Guides
Adafruit_Learning_System_Guides copied to clipboard
bug in retry code for Star Fragment Lamp
I believe there is a bug in the retry code used get_request()
in the Star Fragment Lamp code.
The retry code at line 65 (https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/a2a29163d12ccf8db341462c93c9b74deb0c3e08/Star_Fragment_Lamp/code.py#L65) is:
n = ping
This simply assigns the value of ping to the variable n. It does not invoke ping. It should be:
n = ping()
The reason the code appears to work is that the retry code is called like this (on line 78 and at least one other location):
now = get_request(5, io.receive_time())
Specifically, io.recieve_time()
is being invoked before get_request()
. The result of io.recieve_time()
is then being passed into get_request()
as the value for ping
, which as shown above simply copies that value into n
, which it then returns as the result of get_request()
. So io.recieve_time()
is being invoked outside of the retry code in get_request()
, which mean it doesn't benefit from any retries. Instead, get_request()
should be invoked like this:
now = get_request(5, io.receive_time)
This passes a reference to the io.recieve_time()
as the value of ping
, which with the change I suggest above, will then be invoked inside the retry loop in get_request
.
(Edit: formatting typo)