Skip to content

drv_battery: Fix for incorrect log messages#1918

Open
protectivedad wants to merge 7 commits intoopenshwprojects:mainfrom
protectivedad:drv_battery-fix
Open

drv_battery: Fix for incorrect log messages#1918
protectivedad wants to merge 7 commits intoopenshwprojects:mainfrom
protectivedad:drv_battery-fix

Conversation

@protectivedad
Copy link
Copy Markdown
Contributor

@protectivedad protectivedad commented Dec 26, 2025

Removed unused reading of ADC which caused incorrect log messages saying device wasn't on battery.
Changed "DEBUG" message after correct ADC reading to "INFO" so the battery information is still in the log.

Removed unused reading of ADC which caused incorrect log messages
saying device wasn't on battery.
@protectivedad
Copy link
Copy Markdown
Contributor Author

protectivedad commented Dec 26, 2025

The documentation says setting Battery_Cycle 0 should stop polling battery sensor, but it actually makes it poll every second. I've fixed that also and will add it as a second commit on this PR. It will poll once on boot (as it did before) and if Battery_Cycle 0 is run it will do the last poll and then stop polling.

@protectivedad protectivedad force-pushed the drv_battery-fix branch 3 times, most recently from 36719fa to aae31c4 Compare December 26, 2025 15:00
Battery_Cycle 0 - caused polling every second. Now it will poll one
last time and then stop polling. This ensures at least one poll on the
device boot though without waiting the first reading might be invalid.
@protectivedad
Copy link
Copy Markdown
Contributor Author

I experimented with increasing the timing of the first reading, because with my device the reading is only valid after the device finishes the boot. It didn't really make a difference unless I increased it above 5 cycles, so I left it the way it was 1 cycle. At one cycle the web page gets the first value (maybe invalid), but it never gets published. If anyone has a suggestion on how to ensure the first reading is good (in the driver) let me know.

I use waitFor MQTT 1 and then set the Battery_Cycle 0 to poll and publish one value.

 Readings below half of the minimum expected voltage are invalid and
 ignored. Only after a valid reading is the battery cycle set to a
 new battery cycle reference. This will ensure at least one good
 reading before turning off or changing the reading cycle.
@protectivedad
Copy link
Copy Markdown
Contributor Author

protectivedad commented Jan 1, 2026

Made the battery driver more resilient. Invalid readings (anything less than half the expected voltage) are ignored. Effectively this means the command Battery_Cycle 0 can be run to stop reading the ADC at any time during the boot process and at least one valid value will be read. Removing the reliance on waitFor MQTT 1.

@divadiow
Copy link
Copy Markdown
Contributor

should this be merged? seems sad not to make use of your work

@protectivedad
Copy link
Copy Markdown
Contributor Author

Has there been any other changes to the drv_battery anyone working on it? If not then I think it should be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants