Prolonged severe weather across the U.S. is causing delays including the ability to transport and deliver packages in certain cities. Please see here for more details. Thank you for your continued support and patience.


Please see all COVID-19 updates here as some shipments may be delayed due to CDC safety and staffing guidelines. If you have an order or shipping question please refer to our Customer Support page. For technical questions please check out our Forums. Thank you for your continued support.

Member #754448

Member Since: December 22, 2015

Country: United States

  • Thanks for the post. It is really helpful.

    Regarding ESP8266 code: I didnt quite understand the purpose of using the attach function and calling it every 250ms and putting the device to deep sleep for 60secs.

    My understanding is: On the first iteration, attach function gets called , led blinks for 20 times, then the uC goes to deep sleep for 60 secs. Then wakes up in default mode which means (as per datasheet) it would run the program from void setup() and reach attach function. Then again it will do the blinking and go back to sleep. Now, where is the role of 250ms in the attach function here? What happens to the interrupt which is generated after 250ms, when the device would be sleeping. Will it be considered dont care or will it wake up the device ?

    One other point, the deepsleep function automatically wakes up the device after 60s, so why bother giving an interrupt every 250ms? Any particular reason?

    Will the power performance in the following code and your code be the same?

    int ledPin = 5; // LED is attached to ESP8266 pin 5.
    uint8_t ledStatus = 0; // Flag to keep track of LED on/off status
    int counter = 0; // Count how many times we've blinked
    void setup() 
     pinMode(ledPin, OUTPUT); // Set LED pin (5) as an output
    void loop() 
      if (ledStatus)
      digitalWrite(ledPin, HIGH);
       digitalWrite(ledPin, LOW);
        ledStatus = (ledStatus + 1) % 2; // Flip ledStatus
        if (counter++ > 20) // If we've blinked 20 times
        ESP.deepSleep(60000000, WAKE_RF_DEFAULT); // Sleep for 60 seconds

    Please let me know. Thanks!

No public wish lists :(