Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By torntrousers
#16182
torntrousers wrote:Does anyone have deep sleep working well on an ESP-01? ... it always ends up in the zombie mode


Just as FYI - this seems to have been resolved by soldering a 100uF capacitor directly to the power pins of the ESP-01
User avatar
By schufti
#55875 I use it like this and it works for months now
Code: Select all  client.stop();
  WiFi.disconnect();
  WiFi.mode(WIFI_OFF);
  ESP.deepSleep(30000000ul);
  delay(100);
User avatar
By barsznica
#56351 Hi all.
If I use system_deep_sleep, it doesn't sleep and no UDP is sent? It does seem to reset.
If I use ESP.deepSleep, it sleeps, gets the time, but no UDP data is sent?
Either way, UDP is not sent even once (before deep sleep).

If I don't use any deep-sleep, everything works.
Any ideas?

I'm not ready to set-up a MTTQ broker.
MTTQ seems more common and I haven't seen any problems with deep sleep.

IDE 1.6.10, esptool.exe 0.4.9, Win10 x64

Code: Select all//extern "C" { // For 'system_deep_sleep()'
//#include "user_interface.h"
//}

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

#include "TimeClient.h"
float utcOffset = 9.5; // enter your UTC
TimeClient timeClient(utcOffset);

const char* ssid     = "SSID";
const char* password = "Password";
IPAddress ipBroadCast(192, 168, 1, 200); // Destination IP
const unsigned int udpRemotePort = 8889; // Destination Port

const int sleepTimeS = 3; // Deep sleep time (s)

const int UDP_PACKET_SIZE = 10; // excluding NL character
char udpBuffer[UDP_PACKET_SIZE];
WiFiUDP udp; // setup UDP object


//////////////// SETUP ///////////////
void setup() {
  delay(500);
  Serial.begin(57600);
  delay(100);
// We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.print("Destination IP address: ");
  Serial.println(ipBroadCast);
  Serial.print("Port: ");
  Serial.println(udpRemotePort);
  Serial.println("Starting UDP");

}

void loop() {

  timeClient.updateTime();
  //String time = timeClient.getFormattedTime();

  strcpy(udpBuffer, "abcdefghij"); // Debug message
  udp.beginPacket(ipBroadCast, udpRemotePort);
  delay(10);
  udp.write(udpBuffer, sizeof(udpBuffer));
  delay(10);
  udp.endPacket();
  udp.flush(); // not required (doesn't help)

  Serial.print("Sent: ");
  Serial.println(udpBuffer);

  //// SLEEP ////
  Serial.println("Entering sleep mode...");
  Serial.println("");
  //WiFi.forceSleepBegin();
  //ESP.deepSleep(sleepTimeS * 1000*1000, WAKE_RF_DEFAULT); // or WAKE_RFCAL or WAKE_NO_RFCAL or WAKE_RF_DISABLED or WAKE_RF_DEFAULT
  //ESP.deepSleep(3 * 1000*1000);
  //system_deep_sleep(3 * 1000*1000);
  Serial.println("Exiting sleep mode...");

  delay(1*1000);
}