Hi All,
I’m currently struggling with a design decision to handle a bug brought up by an alpha tester of my product.
The end user received a device with the Photon inside and attempted to connect the device to his wifi. Before sending him the device, I had cleared the memory and the wifi credentials, so that he would have a brand new device. I have set up SoftAP for easy wifi setup from a mobile device; basically when the user first opens the device, the external LEDs start blinking a certain color pattern to let the user know to set up wifi before using the product. **The problem was that he accidentally put in the wrong wifi credentials through SoftAP and now “his device is stuck.” ** I replicated this issue with my test device; to clarify what he meant, if the user enters the incorrect wifi credentials, upon resetting the device, the Photon blinks green indefinitely. It’s unable to connect to the network, as it has stored incorrect credentials, but it tries to connect anyways with the incorrect credentials.
What’s weird is that this also prevents the user from interacting from the device in any other way. The buttons aren’t registering, which makes me think the application code isn’t running. For context, I have system thread enabled, and it’s in semi-automatic mode. In setup(), the Photon attempts connecting to wifi if it scans a network in the area for which it has stored credentials.
Here’s some code:
void begin_listening() {
// If the device has one set of incorrect credentials, after reset, it will try to connect to WiFi with those credentials
WiFi.on();
attachInterrupt(btn2, exit_listening_isr, RISING);
WiFi.listen();
// Let the user know the device is in listening mode
while(WiFi.listening()) { flash_lights(1, 0, 20, 20); flash_lights(1, 20, 20, 0); }
// Let the user know the device is attempting to connect
while(WiFi.connecting()) { flash_lights(1, 0, 20, 20); flash_lights(1, 0, 20, 0); }
detachInterrupt(btn2);
if(WiFi.ready()) {
flash_lights(5, 0, 20, 0); // Let the user know the connection was successful
} else { flash_lights(5, 20, 0, 0); } // Let the user know the connection was not successful
}
// In case the photon attempts to connect to the new network for a long time
void exit_listening_isr() {
detachInterrupt(btn2);
WiFi.listen(false);
System.reset();
}
bool is_wifi_available() {
WiFiAccessPoint my_aps[5];
int num_ap = 0;
num_ap = WiFi.getCredentials(my_aps, 5);
WiFiAccessPoint scanned_aps[20];
int found_aps = WiFi.scan(scanned_aps, 20);
for(int i = 0; i < num_ap; i++) {
for(int j = 0; j < found_aps; j++) {
if(String(my_aps[i].ssid) == String(scanned_aps[j].ssid)) return true;
}
}
WiFi.off();
return false;
}
If the device is “new,” begin_listening is called in setup. After entering the incorrect wifi credentials, the user said his device blinked red, which was expected. The device went to sleep after 10 seconds, which was also expected. However, after waking it back up, the device attempted to connect to the only network it had credentials for, which were incorrect. This caused the Photon to be “stuck” flashing green, attempting to connect to the network.
I apologize if this has been addressed before. I looked through the forums for quite a bit, but I couldn’t find anything that directly addressed this problem.
Thanks in advance for your help.
Best,
Rishub