MKR1000 WiFi101.h and WiFi.disconnect()

Can’t seem to disconnect…

void loop() {
while ( status != WL_CONNECTED )
Serial.println(“Obviously not connected…”);
status = WiFi.begin(ssid);
Serial.println(“Connected. Trying to disconnect”);

11:14:19.204 → Obviously not connected…
11:14:21.742 → Connected. Trying to disconnect
11:14:51.757 → Connected. Trying to disconnect

ad infinitum

The first time the loop runs, status is set to WL_CONNECTED. After that, there is no way in your code for status to ever get set to anything other than WL_CONNECTED since status is only updated in the while loop and the while loop can only run if status != WL_CONNECTED. So even though it was disconnected by the call to WiFi.disconnect(), the while loop will never run again.

In order to run as you expect, you would want to change the while loop to look like this:

 while (WiFi.status() != WL_CONNECTED )
    Serial.println("Obviously not connected...");