ESP32-C3 Modem sleep for always connected application.

Status
Not open for further replies.

papaisou11

Member level 2
Joined
Aug 2, 2016
Messages
50
Helped
0
Reputation
0
Reaction score
1
Trophy points
1,288
Activity points
1,785
Hello...
I have developed a custom ESP32-C3 board for my home lock. I am using a lithium battery 18650 with 2200mAH. I am poor in coding and started to code from past 2 months.

Well, I need to connected with the WiFi always, as if I press unlock on the blynk app, the motor should rotate to anticlockwise and unlock the door.

My problem is the battery consumption. I am using ESP32-C3-MINI-N4 and for the coding Arduino IDE framework on the VS code studio.

How can I achieve lowest Power consumption on the ESP32 to achieve the low current consumption on the ESP32-C3?

I have already having options to turn off the 5V regulator for motor, having proper hardware structure to lower the consumption.

I am using the WiFimanager and achieved 17-20mA continuous while connected with WiFi.

Here is my code -
Code:
#include <Arduino.h>
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
#include <WiFiClientSecure.h>
#include <DNSServer.h>
#include <BlynkSimpleEsp32.h>
#include <Wire.h>
#define debug_en 1
//#define threshold 1000
#define PRINTF_BUF 50
#define StartWordCount 32
#define reconnect_try 1 // How many times the wifi will try to reconenct
#define dooropen_thresshold 3 // not required as of now.
#define batt_sw 22
#define batt_sense_pin 32
#define BATT_VOLT_DIV_R1  10  //kohm
#define BATT_VOLT_DIV_R2  10  //kohm
#define BATT_VOLT_OFFSET  2.25906
#define BATT_AVG_COUNT  60
char auth[] = "##############"; //Sourav Token
//char auth[] = "##########"; //
int reconnect_count = 0;
boolean doorOPEN = false;   // to figure out who woke up the board
boolean firealarm = false;  // to figure out who woke up the board
boolean con_status = false; // to figure out connection establishment
WiFiManager wifiManager;    // for provisioning
char door_State = 0;
int fire_State = 0;
unsigned long previousMillis = 0;
const long interval = 6000; // milli seconds, wait after detecting door is opened.
float voltage = 0; // Variable to keep track of LiPo voltage
void start_wifi_blynk(void);
void release_power(void);
void checkdoor(void);
void check_door_state(void);
void setup()
{ 
  setCpuFrequencyMhz(60);
  Serial.begin(115200);
  start_wifi_blynk(); //Starting the WiFi Facility
  Blynk.run();
  Serial.println("Applciation Started . . . ");
}
void loop(){
 
}
void start_wifi_blynk(void)
{
  wifiManager.setDebugOutput(false);
  wifiManager.setTimeout(60); //1min, if can't get connected just go back to sleep
                              // WiFiManager wifiManager;
  //wifiManager.startConfigPortal("dumadum-dum-dum");
  Serial.println("connected...yeey :)");
  Serial.println("WiFi Process started");
  if (!wifiManager.autoConnect("dumadum-dum-dum"))
  { // SSID you connect to from browser
#if debug_en
    Serial.println("failed to connect WiFiand hit timeout");
#endif
  }
#if debug_en
  Serial.println(""); // WiFi info
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
#endif
  Blynk.config(auth);
  //Blynk.run();
  while (!(con_status = Blynk.connect()))
  {
#if debug_en
    Serial.println("connecting to Blynk Server");
    Serial.println("Reconnecting try -");
#endif
    reconnect_count++;
#if debug_en
    Serial.println(reconnect_count);
#endif
    if (reconnect_count == reconnect_try)
    {
#if debug_en
      Serial.println("Failed to connect Internet. Power is turing OFF");
      Serial.println("Releasing Power");
#endif
    }
  }
#if debug_en
  if (con_status)
  {
    Serial.println(" Blynk Connected!");
    Blynk.notify("I am on...");
    //Blynk.email("#########@gmail.com", "ESP32 Alert", "Connected");
  }
#endif
}
(code tags added by moderator)
 
Last edited by a moderator:

I think you can try the low power modes (active/light sleep/deep sleep) of ESP32 depending on your application.
 

I'm doing the same thing but with the ESP-IDF framework.
The biggest issue is that the WiFi does wake up every so often (depending on how you set up the type of sleep and other power save settings) but it does still draw in the low mA region on average.
Susan
 

Maybe Aussie Susan can comment on this. I find with ESP8266 designs that the
time to perform the network association with the router limits how long you can sleep
w/o ignoring user loss of command servicing.

And the ESP32 itself takes 200 - 300 ms startup. Guess is internal clock PLL startup
problems.

So "classic" low power designs that achieve the 1 mA or better class of power down
more difficult with this type of design. However the following link does show some
sub mA kinds of sleep performance for some boards designed for that purpose.



Regards, Dana.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…