IMP stuck - my bad code?

My IMP is stuck in a loop. It’s online, I can push new code and the build number increments and the asterisk disappears but the device keeps looping and not accepting the new code. The IMP is a drive away so I can power cycle it tomorrow evening.

It’s the first time I’ve used a while loop and the very first time I’ve locked myself out of an IMP.

The question: Which bit of my code below is bad enough to lock me out?


//*** I should have put these two lines AFTER the debug section ***
hardware.pin1.configure(DIGITAL_IN, pin1changed);
hardware.pin2.configure(DIGITAL_IN_PULLDOWN, pin2changed);

debug <- true
while (debug = true)
server.log(“pin1:” + + " pin2:" +
imp.sleep (1.0)

I don’t know why it would be stuck but the compare operator is “==”

while (debug == true)

Either way it’s equivalent to while(1), as “debug” can never get back to being false again. This is a power-cycle job I’m afraid, although at some point we hope to implement a sort of “dead man’s handle” for imps in this situation. (The hard part of that, of course, is working out whether you’ve accidentally written an infinite loop, or deliberately written a loop that takes a long but not infinite time. But after, say, an hour it’d be pretty clear.)


Remember that Squirrel can never interrupt other Squirrel, and can’t interrupt imp.sleep(). Even if you’ve got an event-handler (on a button maybe) that sets “debug” back to false again, that event-handler will not run while the imp is stuck in an infinite while loop.


imp.sleep() is a blocking call, so although you are building new code in the IDE your imp is not processing any messages from the server.

Instead of while/sleep, try imp.wakeup():

`debug <- true
function debugFunction() {
   if(debug == true) {
      server.log("pin1:" + + " pin2:" +
      imp.wakeup(1, debugFunction)