I have some photon devices which are located in areas with poor wifi stability. I have attempted to make the devices resilient by detecting if the server is no longer available, entering listen mode (in case this was a deliberate change to the wifi credentials which could happen when devices are moved between locations) and exit after a minute, re-trying server access again. This works very well for most of the devices. All except one which sometimes enters listening mode e.g. flashing blue but no softAP is present or if it is present it does not allow a connection to it.
Relevant code snippets:
SYSTEM_MODE(MANUAL);
SYSTEM_THREAD(ENABLED);
TCPClient client;
byte server[] = { 192, 168, 0, 1 };
void setup() {
WiFi.connect();
waitFor(WiFi.ready, 10000);
WiFi.selectAntenna(ANT_EXTERNAL);
}
void loop() {
unsigned long time;
if (client.connect(server, 80)) {
.......
} else {
WiFi.disconnect();
WiFi.listen();
time = millis();
while (WiFi.listening() && time + 60000 > millis() && time <= millis()) {
}
WiFi.listen(false);
WiFi.connect();
waitFor(WiFi.ready, 10000);
}
}
I have tried it on different firmware versions from 0.7.0 to the latest 0.8.0-rc.10 but all show this kind of behaviour e.g. either crashing on entry or exit to listening mode. Do I have a dodgy device or is there something I can do with the code?
Thanks
Andy