Deep sleep - not wake up

blackjack
Posts: 1
Joined: Fri Jul 24, 2020 9:54 am

Deep sleep - not wake up

Postby blackjack » Fri Jul 24, 2020 10:30 am

Hello.

I have a problem with deep sleep mode in the ESP32-WROOM-32U module.

My program is very simple:
1) after wake up the WiFi connection is established
2) temperature is read from sensor
3) data are sent to the server via WiFi
4) deep sleep mode is entered (10 min)

Everything works great, but after several successfully wake ups it don't wake up any more. The last time it was after 2 weeks. I need to restart the board using the reset button. Also nothing is written to the console when it is in this fail state.

I'm using the DOIT ESP32 development board (Chinese clone I think, from Alliexpress), but I change the main module with a module with antenna connector (ESP32-WROOM-32U, also Alliexpress).

My code:

Code: Select all

#include <WiFi.h>
#include <HTTPClient.h>

#define TIME_TO_SLEEP  600*1000000 // 10 min

// Network login
const char ssid[] = "ASUS";
const char password[] = "xxxx";

// Server data
const char* serverName = "http://192.168.1.99/post-esp-data.php";
String apiKeyValue = "xxxx";

// Status inputs
const int pinS1 = 27;
const int pinS2 = 26;
const int pinS3 = 25;

// NTC sensor constants
const float c0 = -2.4688e+01;
const float c1 = 5.7712e-02;
const float c2 = -1.9700e-05;
const float c3 = 3.7013e-09;
const int adcOffset = 200;

const String status_desc[] = {
  "Temperature/Timer fault",
  "Unknown",
  "Charging",
  "Low battery output",
  "Charge complete",
  "Unknown",
  "Shutdown/No battery present",
  "No input power"
};

String read_status()
{
  int stat1 = digitalRead(pinS1);
  int stat2 = digitalRead(pinS2);
  int stat3 = digitalRead(pinS3);
  int stat = (stat1 << 2 | stat2 << 1 | stat3);
  
  return status_desc[stat];
}

String read_temp()
{
  int x = analogRead(36) + adcOffset;
  float temp = c3*x*x*x + c2*x*x + c1*x + c0;
  
  return String(int(temp));
}

void print_mac()
{
  byte mac[6] = {0};
  char out[23];
  
  WiFi.macAddress(mac);
  sprintf(out, "MAC: %02X:%02X:%02X:%02X:%02X:%02X",
               mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
  Serial.println(out);
}

void setup()
{
  Serial.begin(115200);
  Serial.println();

  pinMode(pinS1, INPUT);
  pinMode(pinS2, INPUT);
  pinMode(pinS3, INPUT);

  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP);

  // Connect to Wi-Fi
  print_mac();
  WiFi.begin(ssid, password);
  Serial.println("Connecting to WiFi");
  int fail_count = 0;
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    ++fail_count;
    if (fail_count >= 20) {
      Serial.println();
      Serial.println("Too many login attempts. Restarting ESP32.");
      ESP.restart();
    }
  }
  Serial.println();
  Serial.println(WiFi.localIP());

  HTTPClient http;
    
  http.begin(serverName);
  http.addHeader("Content-Type", "application/x-www-form-urlencoded");  // "'text_plain' can be here"
  
  String httpRequestData = "api_key=" + apiKeyValue + "&value1=" + read_temp() + "&status=" + read_status() + "";
  Serial.print("httpRequestData: ");
  Serial.println(httpRequestData);

  int httpResponseCode = http.POST(httpRequestData);
      
  if (httpResponseCode>0) {
    Serial.print("HTTP Response code: ");
    Serial.println(httpResponseCode);
  }
  else {
    Serial.print("Error code: ");
    Serial.println(httpResponseCode);
  }
  
  http.end();

  Serial.println("Entering deep sleep");
  esp_deep_sleep_start();
}

void loop()
{
  // nothing here
}
Do you have any idea what's wrong with it?

Thank you.

Who is online

Users browsing this forum: No registered users and 43 guests