Unable to connect after adding wi-fi code to Device

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() {

function changeWiFi() {
    server.log("Device disconnecting from " + imp.getssid());
    // Wait for the WiFi buffer to empty before disconnecting
    // Change the WiFI configuration with the passed parameters
    imp.setwificonfiguration(ssid, password);
    // Attempt to reconnect asynchronously

// 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

Yes, you’re right, the angle brackets in the example code should also have been substituted out.

Unfortunately that means your imp is unable to join either wifi network and therefore unable to contact EI servers, so it’s not possible to recover the device remotely. You’ll need to blink it up again locally, sorry.

Great. Thanks. I renamed my router for a few minutes and the device got right online. Probably annoyed a few people, but that’s life.

Obviously the server.log() in the callback that notes that the device is disconnected will never be seen (because you’re not online).

Strongly recommend you hook up an FTDI cable to a UART when debugging code like this, so you can see what the imp is up to when offline: https://electricimp.com/docs/resources/disconnecteddebugging/

1 Like