# Problem with Wifi.setCredentials on new network

**URL:** <https://community.particle.io/t/problem-with-wifi-setcredentials-on-new-network/53493>\
**Category:** Troubleshooting\
**Tags:** argon\
**Created:** [November 26, 2019, 9:52pm UTC](https://community.particle.io/t/problem-with-wifi-setcredentials-on-new-network/53493 "2019-11-26T21:52:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cbrake](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/cbrake/32/22538_2.png) [@cbrake](https://community.particle.io/u/cbrake)\
**Post date:** [November 26, 2019, 9:52pm UTC](https://community.particle.io/t/problem-with-wifi-setcredentials-on-new-network/53493/1 "2019-11-26T21:52:52Z")

</div>

Running on an Argon with deviceOS@1.4.1 …

Trying to configure WiFI settings via BLE:

> <https://github.com/simpleiot/firmware/blob/master/siot-fw/src/siot-fw.ino#L63>

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?

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [November 26, 2019, 9:57pm UTC](https://community.particle.io/t/problem-with-wifi-setcredentials-on-new-network/53493/2 "2019-11-26T21:57:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cbrake](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/cbrake/32/22538_2.png) [@cbrake](https://community.particle.io/u/cbrake)\
**Post date:** [November 26, 2019, 10:18pm UTC](https://community.particle.io/t/problem-with-wifi-setcredentials-on-new-network/53493/3 "2019-11-26T22:18:24Z")

</div>

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

```auto
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();
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![shanevanj](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/shanevanj/32/21186_2.png) [@shanevanj](https://community.particle.io/u/shanevanj)\
**Post date:** [November 27, 2019, 10:30am UTC](https://community.particle.io/t/problem-with-wifi-setcredentials-on-new-network/53493/4 "2019-11-27T10:30:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![armor](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/armor/32/18398_2.png) [@armor](https://community.particle.io/u/armor)\
**Post date:** [November 27, 2019, 2:23pm UTC](https://community.particle.io/t/problem-with-wifi-setcredentials-on-new-network/53493/5 "2019-11-27T14:23:37Z")

</div>

> Start with a 2s value and test.

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

```auto
        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().

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/3/2/3291e3c9351789fe8620ae5bcec8d3fec67ff221.png) [@system](https://community.particle.io/u/system)\
**Post date:** [January 26, 2020, 2:23pm UTC](https://community.particle.io/t/problem-with-wifi-setcredentials-on-new-network/53493/6 "2020-01-26T14:23:39Z")

</div>

Closed on January 26, 2020, 2:23pm UTC

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