Back in December last year, my router, that served also as DHCP server, died. It took me a day or two to replace it and it was powered on with identical configuration as the one that passed away (thanks to Edgerouters using USB stick). After the new router booted, I was surprised that none of my IoT devices around the house, particularly the QtPy's come up in terms of IP connectivity. Had to go and restart them by hand one by one.
They were using simple code that basically connected to WiFi, acquired some sensor metrics and sent them to the MQTT broker. The WiFi part looked like this:
Code: Select all
wifi.radio.connect(secrets["ssid"], secrets["password"], timeout=10)
I did a small experiment to see what happens in terms of DHCP traffic and CircuitPython behavior if the DHCP server goes down. After killing the DHCP server daemon on the router, I noticed that the DHCP client uses some sort of exponential backoff algotithm for sending the DHCP requests. I let it run for some 15 minutes and the clients kept sending the DHCP requests. The connect() on the client I was observing with console was still running. So, perhaps I would need to wait more for the failure to come up, or it had different nature and I'd need to do something else to replicate the scenario.
Since this hickup, I modified the code on all the IoT devices to start using watchdog, so that sort of solves the problem, however I wonder about two things:
- Even though the timeout=10 argument was used for the connect(), it happily continued after the 10 seconds (assuming it is specified in seconds). This does not sound right. My expectation is that after 10 seconds of not receiving any DHCP reply, it should throw an exception or something. In fact, the documentation on https://docs.circuitpython.org/en/lates ... io.connect is mum about the timeout argument.
- Speaking of connect() documentation, it does not even mention that DHCP is used at all.
It makes me wonder how and where is the DHCP client functionality implemented. Is this within some generic layer in CircuitPython or is it perhaps specific to the hardware platform (ESP32-S2 in my case) ? Source code pointers are welcome.