M5.Power.getBatteryLevel() returns 0 when using Power.lightSleep etc.
-
I would appreciate any thoughts on this.
M5.Power.getBatteryLevel() works fine on Capsule. But when I use power saving, such as Power.lightSleep(6000000), M5.Power.getBatteryLevel() returns 0. Same results with .deepSleep(6000000).
The Sleep works as expected, but M5.Power.getBatteryLevel() always returns zero when any "Sleep" is used.Full code I use is below:
/*
Using M5Capsule to gather ENVIII sensor data. Then send via to Paper S3 via
WiFi.
*/
#include <M5Capsule.h>
#include <esp_now.h>
#include <WiFi.h>
#include <M5UnitENV.h>
SHT3X sht3x;
QMP6988 qmp;uint8_t broadcastAddress[] = {0xa0, 0x85, 0xe3, 0xef, 0xf4, 0x48};
// Structure example to send data
// Must match the receiver structure
typedef struct struct_message {
//char a[32];
float Mytemp;
int Myhum;
int Mypres;
float Myalt;
int Mysendbat;//bool d;
} struct_message;// Create a struct_message called myData
struct_message myData;esp_now_peer_info_t peerInfo;
// callback when data is sent
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
Serial.print("\r\nLast Packet Send Status:\t");
Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}void setup() {
auto cfg = M5.config();
M5Capsule.begin(cfg);
M5.Power.begin();
Serial.begin(115200);//Config the ENVIII Sensor
if (!qmp.begin(&Wire, QMP6988_SLAVE_ADDRESS_L, 13, 15, 400000U)) {
Serial.println("Couldn't find QMP6988");
while (1) delay(1);
}if (!sht3x.begin(&Wire, SHT3X_I2C_ADDR, 13, 15, 400000U)) { Serial.println("Couldn't find SHT3X"); while (1) delay(1); }
// Set device as a Wi-Fi Station
WiFi.mode(WIFI_STA);// Init ESP-NOW
if (esp_now_init() != ESP_OK) {
Serial.println("Error initializing ESP-NOW");
return;
}// Once ESPNow is successfully Init, we will register for Send CB to
// get the status of Trasnmitted packet
esp_now_register_send_cb(OnDataSent);// Register peer
memcpy(peerInfo.peer_addr, broadcastAddress, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;// Add peer
if (esp_now_add_peer(&peerInfo) != ESP_OK){
Serial.println("Failed to add peer");
return;
}
}void loop() {
// Set values to send
//============================================
if (sht3x.update()) {
Serial.println("-----SHT3X-----");
Serial.print("Temperature: ");
Serial.print(sht3x.cTemp);
Serial.println(" degrees C");
Serial.print("Humidity: ");
Serial.print(sht3x.humidity);
Serial.println("% rH");
Serial.println("-------------\r\n");
}if (qmp.update()) { Serial.println("-----QMP6988-----"); Serial.print(F("Temperature: ")); Serial.print(((qmp.cTemp *(9/5)) + 32)); Serial.println(" *C"); Serial.print(F("Pressure: ")); Serial.print(qmp.pressure); Serial.println(" Pa"); Serial.print(F("Approx altitude: ")); Serial.print(qmp.altitude); Serial.println(" m"); Serial.println("-------------\r\n"); }
myData.Mysendbat = M5.Power.getBatteryLevel();
myData.Mytemp = sht3x.fTemp;
myData.Myhum = sht3x.humidity;
myData.Mypres = qmp.pressure;
myData.Myalt = qmp.altitude;// Send message via ESP-NOW
esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData));if (result == ESP_OK) {
Serial.println("Sent with success");
Serial.println(myData.Mytemp);
Serial.println(myData.Mysendbat);
}
else {
Serial.println("Error sending the data");
}M5.Power.lightSleep(10000000);
}