Wakeup from deep sleep fails
Posted: Wed May 22, 2019 6:23 pm
Hi
I have a problem with external wakup (ext1) where the Esp32 (rarely) does not wake up. It has happened two times - both times I had to pull the reset pin in order to wake it.
Anyone knows what might be wrong?
Here is my code:
I have a problem with external wakup (ext1) where the Esp32 (rarely) does not wake up. It has happened two times - both times I had to pull the reset pin in order to wake it.
Anyone knows what might be wrong?
Here is my code:
Code: Select all
#include <driver/rtc_io.h>
#include <WiFi.h>
#include <WiFiUdp.h>
#define PIN_LED 5
const char* ssid = "xxxx";
const char* password = "xxxx";
IPAddress local_IP(192, 168, 0, 200);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
const char * udpAddress = "192.168.0.255";
const int udpPort = 5000;
WiFiUDP udp;
#define BUTTON_PIN_BITMASK (1 << 4) | (1 << 2)
RTC_DATA_ATTR bool gulvShow = false;
RTC_DATA_ATTR bool loftShow = false;
bool gulvActivated = false;
bool loftActivated = false;
void setup(){
pinMode(2, INPUT);
pinMode(4, INPUT);
if (digitalRead(2) == HIGH) {
gulvShow = !gulvShow;
gulvActivated = true;
}
if (digitalRead(4) == HIGH) {
loftShow = !loftShow;
loftActivated = true;
}
esp_sleep_enable_ext1_wakeup(BUTTON_PIN_BITMASK, ESP_EXT1_WAKEUP_ANY_HIGH);
pinMode(PIN_LED, OUTPUT);
digitalWrite(PIN_LED, HIGH);
Serial.begin(115200);
delay(1000); //Take some time to open up the Serial Monitor
if (!WiFi.config(local_IP, gateway, subnet)) {
Serial.println("STA Failed to configure");
}
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
if (millis() > 10000) {
Serial.print("timeout.");
Serial.flush();
esp_deep_sleep_start();
}
}
Serial.println("");
Serial.println("WiFi connected!");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("ESP Mac Address: ");
Serial.println(WiFi.macAddress());
Serial.print("Subnet Mask: ");
Serial.println(WiFi.subnetMask());
Serial.print("Gateway IP: ");
Serial.println(WiFi.gatewayIP());
if (gulvActivated) {
for (int i=0; i<3; i++) {
udp.beginPacket(udpAddress,udpPort);
udp.print(gulvShow ? "SHOW_GULV" : "HIDE_GULV");
udp.endPacket();
}
Serial.println(gulvShow ? "SHOW_GULV" : "HIDE_GULV");
}
if (loftActivated) {
for (int i=0; i<3; i++) {
udp.beginPacket(udpAddress,udpPort);
udp.print(loftShow ? "SHOW_LOFT" : "HIDE_LOFT");
udp.endPacket();
}
Serial.println(loftShow ? "SHOW_LOFT" : "HIDE_LOFT");
}
delay(1000);
//If you were to use ext1, you would use it like
//esp_sleep_enable_ext1_wakeup(BUTTON_PIN_BITMASK,ESP_EXT1_WAKEUP_ANY_HIGH);
//Go to sleep now
Serial.println("Going to sleep now");
Serial.flush();
esp_deep_sleep_start();
Serial.println("This will never be printed");
}
void loop(){
//This is not going to be called
}