To sleep or not to sleep?

To sleep or not to sleep?

lastrun_1 = 0 lastrun_2 = 0

while True: now = time.time()

if (lastrun_1 == 0) or (now - lastrun_1 >= 60):
    read_sensor_1()
    lastrun_1 = now
if (lastrun_2 == 0) or (now - lastrun_2 >= 300):
    read_sensor_2()
    lastrun_2 = now

machine.idle()

If we were only reading a single sensor (or multiple sensors at the same interval), we could drop the loop and juse use the ESP8266’s deep sleep mode (assuming we have wired things properly):

read more →