SSID and passcode not updating

Hello there. I am having an issue with the secret tab in the Arduino Editor. Using the D1mini ESP8266 to control a couple of relays through the cloud. I am testing it at home with my WiFi (SSID and passcode). After successful test, I am going to give it to a friend who has a different SSID and passcode. After updating the SSID and passcode in the secret tab to my friend's, I flash and let the code run one more time to be sure. In the serial monitor I can see, that it claims to be connected to my friend's WiFi (I see the updates SSID) and it actually also connects to the IOT cloud! I can see and control everything. I am still on my WiFi!
That tells me, that the data I updated in the secret tab are not taken over, it still uses my WiFi credentials. I hacked the thingProperties.h files but this doesn't change this behaviour.
Now: this is not always happening! Have you had such a behavior? Any idea how to get around this annoying issue?

ESP8266 WiFi stack will save WiFi configuration to flash memory, and automatically reconnect to the same network on restart. This happens even if you aren't using WiFi functions. You can disable persistence by adding WiFi.persistent(false); in the beginning of your WiFi initialization code.

You might want to use WiFiManager. I've never tried it, but here is a tutorial you could try.

Thanks! Seems to be the problem. I ran the following after it connected to the cloud. Now it isn't connecting anymore to my WiFi. But it also isn't connecting to another WiFi (using my phone hotspot to test) :frowning:

void doThisOnConnect() {
    delay(1000);
    WiFi.disconnect();
    delay(1000);
    WiFi.persistent(false);
    delay(1000);
    WiFi.begin();
}

Looks like the following solves the issue. I added code right before initProperties();

This is what I added:

    WiFi.disconnect(); 
    delay(1000); 
    WiFi.mode(WIFI_STA); 
    delay(1000);
    WiFi.begin(SSID,PASS);

 // Defined in thingProperties.h
  initProperties();
    
  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  ArduinoCloud.addCallback(ArduinoIoTCloudEvent::CONNECT, doThisOnConnect);// allows to subscribe to cloud events

FYI: my iPhone 12 hotspot was set to 5G hence it never worked. Set it to 2G (Maximize Compatibility to on) and the ESP will connect.

Now I can switch between WiFi networks :slight_smile: Thanks again.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.