Help Using An Application to Change Sleep State & Period

Hello All,

We’ve got a product that measures the changing density of alcohol as it ferments.

We want to change the periods of time which our Imp awakes and sends & receives data from the web/database and mobile application. Right now we are achieving this thru altering the Device code in our IDE. We change the Device code, power cycle the Imp, then clicking Check and Run. However, we want to allow ourselves and ultimately our users/customers to achieve this via their mobile application.

For a large portion of the time our product will be in use, we will be gathering and sending data every 10 minutes. There isn’t much change from one reading to the next, 10 minutes later. This period allows us to put the Imp into deep sleep and allows our product to live for quite a long time. However, on command, sometimes we want to send and receive data much more often, something like every 5 seconds.

How can we change the Imp sleep/wake period with the web or mobile app?

  • Upon Setup - For a short period of time we want to send and receive data frequently ~5s (calibration and testing)
  • During Fermentation - Most of the time we want a deep sleep (power cycling in necessary to awake and receive commands)

Any communication has to be via HTTPS requests right?

All help or suggestions are very welcomed!


Yep, all HTTP. Here is the non-blocking example code that you would use in your Imp to receive HTTP requests:


The issue is your imp is in deep sleep you can’t change it’s sleep time unit it wakes again so cmd to speed up logging will have to be sent aprox 10mins before it’s needed. Assume it’s battery powered hence deep sleep? At 5sec you will want to be shallow sleeping. Something I do when pin wake triggers from deep sleep.

Thank you @jwehr.

We are okay with it being in deep sleep and unavailable until wakeup. If necessary, we power cycle the imp.

The issue is changing the sleep state/period with HTTP requests. ie. Press a button to enter “Calibration State” on your phone, power cycle the Imp, and now rather than waking every 600s the Imp wakes every 5s. After we are done calibrating we will select “Fermentation State”, next time the Imp wakes up it returns back to waking every 600s.

Make sense?

The imp would just need to stay awake long enough to receive the HTTP commands. You wouldn’t need to power cycle it, just wake it with Pin 1, though technically, that does reboot it.

Yep but you only need to deep sleep if your trying to conserve battery power.
How would you power cycle the imp? if your have to do it physically why not a
"Calibrate" button connected to pin1 as jwehr says?

This should be pretty easy:

  1. implement an http request to the agent that saves the desired sleep/wake time in an agent variable (ideally in a table which is saved with to ensure this persists if the agent gets restarted)

  2. implement a device.on() handler in the agent which then sends, with device.send() the current sleep time.

  3. on the device, at every connect (before it sleeps, ie after all the other work has been done) it should then use agent.send() to the handler in (2) to request the new sleep duration. You’d then have an agent.on() handler which received the sleep time and did an imp.onidle(function() { server.sleepfor(newsleeptime); });