[Exit Code] imp restarted, reason: wifi error

I have an imp that I am experimenting with, it wasn’t meant to be an experiment but it’s turned out that way. It is simply measuring and reporting a frequency from the Pulse counter on Pin1. It is deployed so I don’t really have access to it (without getting on an airplane) and I have started to get “[Exit Code] imp restarted, reason: wifi error” in my log “file”. Reading around I want to say that maybe there are other devices around producing RF that is causing the WIFI chip to croak but the RSSI is coming back as -65, which seems to be an acceptable value. Does anyone have ideas?

A little more info about the installation:
*Battery powered with a transformer nearby
*Very close to a router
*May be warm (from the sun)


yes, -65 is a good number.

Does the imp come back up and run correctly after that?

If so, could this be as simple as the ISP losing service for a bit? It does not happen often but I have seen temporary disruptions on my devices in the middle of the night - as you said - “wifi error”. I cannot recall if I had to re-launch the code or if the device kept on running, but I think the latter.

“wifi error” is usually a wifi error. Seems obvious, but errors upstream of the router (ISP losing service) will usually be reported appropriately (subject to your server disconnect action being configured).

It doesn’t necessarily mean that there was a glitch in the RF signal, it can also be caused (for example) when the periodic wifi key renegotiation happens, and if there’s a bug/misfeature in your router (which is more common than you might expect).

If it only happens occasionally and the imp recovers, then I wouldn’t worry too much about it. If it happens a lot, or if the imp doesn’t recover, then we’d like more details about which router or AP (including firmware version) you’re using.

My experience with that error is different with different code, sometimes I get them and sometimes with other code I don’t. I didn’t find out what the trigger is, but it has nothing to do with my wifi connection (in my case).

“wifi outage” is generally an outage (upstream, etc). “wifi error” is actually the broadcom chip stopping talking to us for unknown reasons; this happens more often with some routers than others for reasons broadcom can’t explain. It happens less than it used to (broadcom software updates) but still does happen.

The next release detects this and silently recovers rather than going bang and rebooting - ie, it should be invisible for pretty much every user.

EDIT: All below is lies - sorry. Further trimming of code shows that the WiFi error happens each time an imp.wakeup() executes the handler. Removing all of the handler code still causes the error, and the reboot event is “Reason for waking/reboot: An event timer fired” (following the WiFi error). Have to admit I’m a little baffled!

Just wanted to chime in and add my voice to this. I’ve been developing against an imp to create a simple clock and the device code aspects all work fine, code uploads, executes and is stable. However, the second I include ‘agent.on(…)’ the imp becomes unstable, albeit when the agent first ‘sends’ to the device. The code is based on the example from the electric imp site (it’s at this stage switching an LED on/off), but even with the core of the handler removed, the device will reboot at random intervals, sometimes before the handler can be executed - and from there on in the imp reboots become continuous, but at random intervals. I’ve tried it with two different routers, varied the distance etc. and the same problem… I understand that there could be issues with RF errors, but how come the code will deploy with no glitches (that I can see anyway?)

Yeah, that’s very strange. If you could send your code to us we can see if it can replicate it. I’m not sure how any VM level code could cause the wifi chip to stop talking to us, but if you have an example that does it regularly then that would definitely help find any issues!

How big are the messages you’re sending to the device?

Hi Hugo,

Thanks for the rapid response. :slight_smile:

Sadly real work has got in the way of my extra-curricular activities, but as soon as I can get back I’ll trim some code down to replicate the problem and get it posted. Regarding the message size, its just an integer as per the device.send example.

All very odd, and I fear there’s going to be something smelly with my WiFi at the end of all this…



I’ve trimmed everything back to basics, and the following is the code I’m running:

`function wakeUp()
imp.wakeup(10, wakeUp);


function logDeviceOnline()
local reasonString = “Unknown”;
reasonString = “The power was turned on”;

        reasonString = "A software reset took place";
        reasonString = "An event timer fired";
        reasonString = "Pulse detected on Wakeup Pin";
        reasonString = "New Squirrel code downloaded";

server.log("Reason for waking/reboot: " + reasonString);

if ("getsoftwareversion" in imp)
    server.log("Device firmware version: " + imp.getsoftwareversion());
    server.log("Sorry - my firmware doesn't include imp.getsoftwareversion() yet.");




And the log shows (with the initial event being the code being pushed down to the imp):

2014-06-28 19:54:47 UTC+1 [Status] Device disconnected
2014-06-28 19:54:48 UTC+1 [Exit Code] imp restarted, reason: wifi error
2014-06-28 19:54:48 UTC+1 [Status] Downloading new code; 2.93% program storage used
2014-06-28 19:54:48 UTC+1 [Device] Reason for waking/reboot: An event timer fired
2014-06-28 19:54:48 UTC+1 [Device] Device firmware version: af0f28a - release-27.10 - Fri Dec 13 11:08:38 2013
2014-06-28 19:54:48 UTC+1 [Device] Awake.
2014-06-28 19:54:59 UTC+1 [Device] Awake.
2014-06-28 19:55:08 UTC+1 [Device] Awake.
2014-06-28 19:55:18 UTC+1 [Device] Awake.
2014-06-28 19:55:29 UTC+1 [Device] Awake.
2014-06-28 19:55:48 UTC+1 [Status] Device disconnected
2014-06-28 19:55:49 UTC+1 [Exit Code] imp restarted, reason: wifi error
2014-06-28 19:55:49 UTC+1 [Status] Device Booting; 2.93% program storage used
2014-06-28 19:55:49 UTC+1 [Device] Reason for waking/reboot: An event timer fired
2014-06-28 19:55:49 UTC+1 [Device] Device firmware version: af0f28a - release-27.10 - Fri Dec 13 11:08:38 2013
2014-06-28 19:55:49 UTC+1 [Device] Awake.
2014-06-28 19:56:03 UTC+1 [Status] Device disconnected
2014-06-28 19:56:04 UTC+1 [Exit Code] imp restarted, reason: wifi error
2014-06-28 19:56:04 UTC+1 [Status] Device Booting; 2.93% program storage used
2014-06-28 19:56:04 UTC+1 [Device] Reason for waking/reboot: An event timer fired
2014-06-28 19:56:04 UTC+1 [Device] Device firmware version: af0f28a - release-27.10 - Fri Dec 13 11:08:38 2013
2014-06-28 19:56:04 UTC+1 [Device] Awake.

… and so it continues.

I’m at a loss unless there’s a problem with my imp, or WiFi? Or I’m just doing something dumb (more likely)? Any advice would be gratefully received! ~O)

Many Thanks,

What’s your signal strength? (add a server.log(imp.rssi()) to your code).

Nothing wrong with your code that I can see. The only time we’ve seen regular wifi errors is with very strong signals (generally greater than -20dBm).

Well, initially, I was getting -73dBm, a little tweaking later and I’m getting -67dBm. Things seem more stable and the restarts are a lot less frequent.

So, brilliant advice, thank you! I can now get back to seeing what I can get my imp doing!

One final question, though, occasionally the imp.rssi() call logs ‘7’ rather than a negative value? Is this normal?

Anyway, thanks again - brilliant product, and brilliant support :slight_smile:

Logging 7 is not normal. This could be related to your repeated wifi unhappy logs. -67 or -73 is just fine for wifi signal.

What router are you using?

Hmm, odd? It’s a Netgear WNR2200 serving the wifi, hooked to Virgin Media (UK) cable modem, we get a steady 50Mb/s downstream, 10 Mb/s up. Nothing too contentious? It’s setup in a domestic setting as I’m just a hobbyist (can you tell ;-)). Wifi channel selection is automatic. I’m going to pick up a further imp to check that I’ve not abused the current one in some way, plus it’s a good excuse for another! Also, I’ll try it on a different setup at a friends house and see if that helps.

Can you give more details on the router, eg exact model number (any revision, picture of label, etc?) and software version? Can you see many other wifi networks near you? (in case the issue is your router fighting another one it can hear).

Trying it on another AP would be good. If the problem is seen on multiple imps with that router then we’ll try and replicate the environment here.