Problem with Wifi.setCredentials on new network

Running on an Argon with deviceOS@1.4.1 …

Trying to configure WiFI settings via BLE:

WiFi.clearCredentials() always returns false, but it seems like the credentials are cleared.

When I run the method to change the wifi settings, the device is stuck on fast blink green, or may be fast blink cyan.

Once I reset the device, it connects fine to the new network.

Is there any way I can force the wifi to connect to a new network without restarting?

Have you tried WiFi.off() after storing the new settings and then WiFi.on() again?

I tried adding Wifi.off/on (see below). It still stays on fast blinking green LED, so no change. After reset, connects fine.

static void onSetWifiPass(const uint8_t* data, size_t len, const BlePeerDevice& peer, void* context)
{
    char buf[100];
    if (len > sizeof(buf)) {
        Serial.println("ssid is too long");
        return;
    }

    strncpy(buf, (char*)data, len);
    buf[len] = 0;
    Serial.printf("set wifi pass: %s\n", buf);
    if (PLATFORM_ID == PLATFORM_ARGON) {
        WiFi.disconnect();
        if (!WiFi.clearCredentials()) {
            Serial.println("Failed to clear Wifi credentials");
        }
        if (!WiFi.setCredentials(setSSID.c_str(), buf)) {
            Serial.println("Failed to set Wifi credentials");
        } else {
            Serial.println("WiFi credentials set");
            wifiSSIDCharacteristic.setValue(setSSID);
            WiFi.off();
            WiFi.on();
            Particle.connect();
            //System.reset();
        }
    }
}

Try using a delay() after the WIFi.off() - I suspect that the module is not completing the off process before trying to set it on again. Start with a 2s value and test.

1 Like

Start with a 2s value and test.

In my experience with the Photon the following delay periods work well after WiFi.clearCredentials()

        WiFi.off();
        delay(20);
        WiFi.on();
        delay(100);

Not so sure with the Argon but certainly longer than no delay. Generally I have found it a good idea to insert a delay after WiFi.on(); and calling WiFi.connect() which I would do before checking for wifi.ready and calling Particle.connect().

2 Likes

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