melkati / CO2-Gadget

An advanced CO2 Monitor/Meter firmware for ESP32 with Android and iOS App for real time visualization and charting of air data, data logger, a variety of communication options (BLE, WIFI, MQTT, ESP-Now) and many supported sensors.
https://emariete.com/medidor-co2-gadget/
GNU General Public License v3.0
68 stars 14 forks source link

Issues with Unreliable Battery and External Power Detection #222

Open melkati opened 6 months ago

melkati commented 6 months ago

Description: The current implementation of battery and external power detection in the "CO2 Gadget" meter is encountering reliability issues. This affects various aspects of the device's functionality, including CPU frequency fluctuation and inconsistent behavior in screen activation and deactivation.

Additional Clarification:

When the battery charge is low, the charger built into the ESP32 board initiates recharging, causing a drop in battery voltage. The extent of this drop varies based on hardware specifics. It takes time for the voltage to recover and surpass a threshold (approximately 4.45V), which the CO2 Gadget uses to determine external power usage. Consequently, there might be a delay in the battery icon reflecting the switch to external power. Voltage fluctuations occur during CO2 sensor measurements, such as with an SCD30 sensor, where current spikes during measurements, potentially leading to voltage dips below the 4.45V threshold. This can cause the CO2 Gadget to incorrectly assume battery power, toggling between battery and external power modes. Configuration settings, like keeping the display on when connected to external power and off on battery, can exacerbate the issue. Voltage drops when switching to battery mode may trigger the display to turn off. Subsequently, reduced power consumption can cause voltage to rise, resulting in a cycle of on/off states, reflected by the battery icon. It's important to acknowledge that hardware variations contribute to these issues. While hardware control is limited, using quality wires, reliable power adapters, and good-quality batteries can mitigate these issues. Proposed Resolution: Implement a more robust detection mechanism tailored to each specific board, considering voltage thresholds and fluctuations during sensor measurements. Additionally, optimize functionalities dependent on power state to handle detection errors more effectively.

Impact Assessment: Addressing these issues will enhance the stability and performance of the "CO2 Gadget" meter, ensuring a more consistent user experience.