Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zigbee: Improve the sleep sketch with regard to energy requirements #10746

Open
1 task done
michapr opened this issue Dec 17, 2024 · 8 comments
Open
1 task done

Zigbee: Improve the sleep sketch with regard to energy requirements #10746

michapr opened this issue Dec 17, 2024 · 8 comments
Assignees
Labels
Area: Libraries Issue is related to Library support. Area: Zigbee Issues and Feature Request about Zigbee

Comments

@michapr
Copy link

michapr commented Dec 17, 2024

Board

ESP32H2

Device Description

Devboard, Supermini

Hardware Configuration

nothing connected

Version

latest development Release Candidate (RC-X)

IDE Name

Arduino IDE

Operating System

Windows 11

Flash frequency

80MHz

PSRAM enabled

no

Upload speed

921600

Description

The device require too much energy in active and sleeping mode.
ppk-20241217T194851

  1. not clear, why there are so many peaks with 100mA
  2. sleeping current is in my case about 450uA - too much. Any idea how to minimize it for ESP32H2?
    • maybe other request - provide a light sleep example without needed rejoin

Sketch

A bit modified sleeping sketch:
----------------------------------

#ifndef ZIGBEE_MODE_ED
#error "Zigbee end device mode is not selected in Tools->Zigbee mode"
#endif

#include "Zigbee.h"
#include <rom/rtc.h>

#define BOOT_PIN                  9  //Boot button for C6/H2
/* Zigbee temperature + humidity sensor configuration */
#define TEMP_SENSOR_ENDPOINT_NUMBER 10

#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP  55         /* Sleep for 55s will + 5s delay for establishing connection => data reported every 1 minute */

uint8_t button = BOOT_PIN;

ZigbeeTempSensor zbTempSensor = ZigbeeTempSensor(TEMP_SENSOR_ENDPOINT_NUMBER);

/********************* Arduino functions **************************/
void setup() {
  Serial.begin(115200);

  // Init button switch
  pinMode(button, INPUT_PULLUP);

  // Configure the wake up source and set to wake up every 5 seconds
  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);

  // Optional: set Zigbee device name and model
  zbTempSensor.setManufacturerAndModel("Espressif", "SleepyZigbeeTempSensorTest");

  // Set minimum and maximum temperature measurement value (10-50°C is default range for chip temperature measurement)
  zbTempSensor.setMinMaxValue(10, 50);

  // Set tolerance for temperature measurement in °C (lowest possible value is 0.01°C)
  zbTempSensor.setTolerance(1);

  // Set power source to battery and set battery percentage to measured value (now 100% for demonstration)
  // The value can be also updated by calling zbTempSensor.setBatteryPercentage(percentage) anytime
  zbTempSensor.setPowerSource(ZB_POWER_SOURCE_BATTERY, 100);

  // Add humidity cluster to the temperature sensor device with min, max and tolerance values
  zbTempSensor.addHumiditySensor(0, 100, 1);

  // Add endpoint to Zigbee Core
  Zigbee.addEndpoint(&zbTempSensor);

  // Create a custom Zigbee configuration for End Device with keep alive 10s to avoid interference with reporting data
  esp_zb_cfg_t zigbeeConfig = ZIGBEE_DEFAULT_ED_CONFIG();
  zigbeeConfig.nwk_cfg.zed_cfg.keep_alive = 10000;

  // When all EPs are registered, start Zigbee in End Device mode
  if (!Zigbee.begin(&zigbeeConfig, false)) {
    Serial.println("Zigbee failed to start!");
    Serial.println("Rebooting...");
    ESP.restart();
  }
  Serial.println("Connecting to network");
  while (!Zigbee.connected()) {
    Serial.print(".");
    delay(100);
  }
  Serial.println();
  Serial.println("Successfully connected to Zigbee network");

  // Delay approx 1s (may be adjusted) to allow establishing proper connection with coordinator, needed for sleepy devices
   if ( (int)rtc_get_reset_reason(0) != 5 )  { // =  SW_CPU_RESET=12  // POWERON_RESET=1 //DEEPSLEEP_RESET=5
     delay(20000);
   }
}

void loop() {
  // Checking button for factory reset
  if (digitalRead(button) == LOW) {  // Push button pressed
    // Key debounce handling
    delay(100);
    int startTime = millis();
    while (digitalRead(button) == LOW) {
      delay(50);
      if ((millis() - startTime) > 3000) {
        // If key pressed for more than 3secs, factory reset Zigbee and reboot
        Serial.println("Resetting Zigbee to factory and rebooting in 1s.");
        delay(1000);
        Zigbee.factoryReset();
      }
    }
  }

  // Call the function to measure temperature and put the device to sleep
  meausureAndSleep();
}

Debug Message

No errors in debug

Other Steps to Reproduce

disabled USB CDC, debugging for saving energy.
Have removed the internal temperature procedure and replaced with random value.

Have used Nordic Power Profiler Kit II for measurements with 3.3V power

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@michapr michapr added the Status: Awaiting triage Issue is waiting for triage label Dec 17, 2024
@michapr
Copy link
Author

michapr commented Dec 18, 2024

Have added before Zigbee.begin (because was thinking about scanning):
Zigbee.setPrimaryChannelMask(0x800);
but no change. (channel 11 in my case)

@P-R-O-C-H-Y
Copy link
Member

I will be able to test the consumption at the start of new year again to check if there is anything that can help.
But I can tell that if you are willing to do the LightSleep you have to switch to use the esp-zigbee-sdk directly. They have the light sleep example there. For Arduino it's not possible now, as there need to be a tickles RTOS config set, which we won't have anytime soon, as it may bring unexpected behavior.

@P-R-O-C-H-Y
Copy link
Member

Have added before Zigbee.begin (because was thinking about scanning): Zigbee.setPrimaryChannelMask(0x800); but no change. (channel 11 in my case)

What you can do that can help with optimizing stuff is to provide a pcap file from Wireshark, to see what is happening at that time. If there are some transmissions going on in the peaks. Otherwise for now there is nothing you can set/select to make it more power efficient.

@P-R-O-C-H-Y P-R-O-C-H-Y added Area: Libraries Issue is related to Library support. and removed Status: Awaiting triage Issue is waiting for triage labels Dec 18, 2024
@P-R-O-C-H-Y
Copy link
Member

Btw the energy consumption in the deep sleep is probably related to the board design. I can't tell what board I used if it was C6 or H2 Espressifs devout, but in deep sleep the power consumption was 9,8 uA. That's a big difference.

@michapr
Copy link
Author

michapr commented Dec 18, 2024

My Wireshark setup is not working, haven't found time to find out what happen...

About spikes: what I see in the Gateway logs is, that looks like a routing problem after rejoin (get messages like ezspIncomingNetworkStatusHandler(): callback called with: [errorCode=ROUTE_ERROR_TREE_LINK_FAILURE], [target=12084] ).
Same effect in ZHA (other log lines in debug mode) and in Zigbee2MQTT

Otherwise for now there is nothing you can set/select to make it more power efficient.

Why it is not possible to save all session information in RTC RAM and use it after reboot from deep sleep mode (if valid)?
Same was realized for ESP32 Lora modules and is working fine.

I can't tell what board I used if it was C6 or H2 Espressifs devout, but in deep sleep the power consumption was 9,8 uA. That's a big difference.

without any additional settings? like pin setting to analog input or disable anything?
Something like Zigbee.end() is not needed to switch off the modem part?

@P-R-O-C-H-Y
Copy link
Member

without any additional settings? like pin setting to analog input or disable anything?
Something like Zigbee.end() is not needed to switch off the modem part?

No additional settings, I am just using the sleepy example how its written.
In Deep-sleep mode, the CPUs, most of the RAM, and all digital peripherals that are clocked from APB_CLK are powered off. The only parts of the chip that remain powered on are:

  • RTC controller
  • ULP coprocessor
  • RTC FAST memory

So there is no need for Zigbee.end()

Why it is not possible to save all session information in RTC RAM and use it after reboot from deep sleep mode (if valid)?
Same was realized for ESP32 Lora modules and is working fine.

I will need to investigate this, if there is anything that can help. But the stuff is saved in Zigbee partitions, and it should be recalled. But the device still has to reconnect to the network.

My Wireshark setup is not working, haven't found time to find out what happen...

If you have some time, would b nice to have the logs from the Wireshark.

About spikes: what I see in the Gateway logs is, that looks like a routing problem after rejoin (get messages like ezspIncomingNetworkStatusHandler(): callback called with: [errorCode=ROUTE_ERROR_TREE_LINK_FAILURE], [target=12084] ).
Same effect in ZHA (other log lines in debug mode) and in Zigbee2MQTT

I can ask about this, but for sure more informations would be needed (WireShark traffic).

@michapr
Copy link
Author

michapr commented Dec 18, 2024

I will need to investigate this, if there is anything that can help. But the stuff is saved in Zigbee partitions, and it should be recalled. But the device still has to reconnect to the network.

But the "rejoin process" should be other and much faster.
If you compare with commercial temperature sensors - the online time is here < 1second (if taken the logs from Zigbee gateway to compare it)
Device will be recognized without a real rejoin.

@michapr
Copy link
Author

michapr commented Dec 21, 2024

About spikes: what I see in the Gateway logs is, that looks like a routing problem after rejoin (get messages like ezspIncomingNetworkStatusHandler(): callback called with: [errorCode=ROUTE_ERROR_TREE_LINK_FAILURE], [target=12084] ).
Same effect in ZHA (other log lines in debug mode) and in Zigbee2MQTT

I can ask about this, but for sure more informations would be needed (WireShark traffic).

Cannot confirm my thoughts.... the routing errors was something else...

In Wireshark see only short Zigbee time. So the other code before need so much time for "something"...

grafik
and
grafik

This difference is interesting, but not the top important thing....

@SuGlider SuGlider added the Area: Zigbee Issues and Feature Request about Zigbee label Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Libraries Issue is related to Library support. Area: Zigbee Issues and Feature Request about Zigbee
Projects
None yet
Development

No branches or pull requests

3 participants