Sleep

Hello,

I have a ping_sensor() function that reads data from a sensor and I need to use imp.sleep every time I ping the sensor.

function ping_sensor()
{

trigPin.write(0);
imp.sleep(0.01);
trigPin.write(1);

}

Then I have an imp.onidle function that is activated by any imp.sleep call, but I also have an imp.sleep call in my loop function that will trigger a call to imp.onidle. I only want the imp.onidle function to be called from the loop function, not from the ping_sensor() function. Is there a way to accomplish that?

function loop()
{
// Doing something…
imp.sleep(1);
}

imp.onidle(function() {
loop();
server.sleepfor(3600);
});

Thank you

As I said in the other thread, imp.sleep() is a busy sleep. onidle() handlers do not get trigged during any code execution, including imp.sleep’s. See the other thread for info on how to run repeated tasks at intervals.