A few months ago I found the code below and uploaded to an 002. After that the device went offline and has been since. I have some time today so I thought I’d resolve this.
Just curious, is the problem obvious? I’m assuming it is. Like should have been just “virtual2” and “yan3kees”?
And, do I now need someone at Electric Imp to clear the device so I can start from scratch?
local ssid = "<virtual2>";
local password = "<yan3kees>";
function connected(reason) {
if (reason == SERVER_CONNECTED) {
server.log("Device now connected to " + imp.getssid());
} else {
server.log("Device disconnected - attempting to reconnect in 15s");
imp.wakeup(15, function() {
server.connect(connected);
});
}
}
function changeWiFi() {
server.log("Device disconnecting from " + imp.getssid());
// Wait for the WiFi buffer to empty before disconnecting
server.flush(60.0);
server.disconnect();
// Change the WiFI configuration with the passed parameters
imp.setwificonfiguration(ssid, password);
// Attempt to reconnect asynchronously
server.connect(connected);
}
// Set the server connection behavior policy (makes server.connect() asynchronous)
server.setsendtimeoutpolicy(RETURN_ON_ERROR, WAIT_TIL_SENT, 10);
// Device connected to the WLAN set during BlinkUp
server.log("Device connected to its inital WiFi hotspot");
// Change to backup network
changeWiFi();