Check RTC Battery Voltage through SSH/Terminal

Just wondering if this is possible. On a PR1 with shell access, is there any command I can use to pull the RTC battery voltage? I snooped around /sys/class/rtc but did not see anything that exposed the voltage.

I see that it is accessible through the REST API, but configuring the REST API for our application is not practical. I also cannot download any packages to the devices, so any command would have to be ‘built in’ or part of the base distribution.

Thanks,

-Peter

On my PR1, calling the sensors command shows the battery voltage at input 4 on the ads1015-i2c chip.

You can get the voltage in mV:

cat /sys/devices/soc0/soc/2100000.aips-bus/21a0000.i2c/i2c-0/0-0048/in4_input

Opto may use different chips on different hardware, so this may not work for you, but you should be able to find yours by calling the sensors command.

Yeah, it does look like different hardware configurations.

It also does not look like the sensors application is guaranteed to be installed depending on firmware release. The command worked on an older firmware (3.6.0) but not on the unit I originally checked (4.0.3). Very possible that the 4.0 firmware release that updated the Linux kernel no longer supports that command.

It is obviously available to be polled somewhere… as it is shown on the groov Manage System Status page on firmware 4.0.3. I did not see anything in the hardware monitoring (hwmon) besides thermals or other obvious places.

-Peter

Go to /sys/bus/i2c/driver and see if the ads1015 driver is there. The directory will have a link to the loaded device you can run a cat on.

2 Likes

Looking through the IC2 devices helped, and I was able to find the voltages. There are noticeable differences between my PR1’s and what is listed in these directories though. Must be either differences in hardware or the Linux distribution/version installed.

I was hoping for one easy command to run and check (sensors would have been perfect…), but this is probably going to be more difficult to standardize across our fleet of hundreds of PR1’s with different hardware releases and varying firmware versions.

-Peter

Here is the command the API calls: /usr/bin/battery-voltage-read.sh

It has 700 permissions so:

sudo /usr/bin/battery-voltage-read.sh

It is calling the following command (on a PR1 with 3.4.4 firmware):

echo "scale=3; $(cat /sys/bus/i2c/devices/0-0048/in4_input)/1000" | bc

2 Likes

Yeah, looks like all of that changed somewhere around firmware 4.0. If I could call the same script Opto uses would also have been a great solution…

Doing some searches that script does not exist in any directory I have access to on the latest firmware. How did you figure out that script is being called from the API command? I can make a REST API request if there is a way to see the routing.

The (4) voltages I can see at the IC2 bus below (and the only voltages I can find) also do not match the value I get from the REST API. I feel like I am blindly looking around when this is probably a permissions issue.

/sys/devices/platform/soc/2100000.bus/21a0000.i2c/i2c-0/0-0048/iio:device0

To be clear on my original request - I want my application running on the EPIC to request the voltage. It is significantly easier if I can make an MMP read or invoke an operating system command in C++.

I am trying to deal with some headache from older units in harsher environments all suddenly having issues with the real time clock because of the batteries being dead.

I appreciate the help so far.

-Peter

1 Like

It looks as of firmware 4.0 groov Manage is reading the battery voltage directly instead of using a script.

The new raw voltage location appears to be:
/sys/bus/i2c/devices/0-0048/iio:device0/in_voltage0_raw

Fair warning, reading the battery voltage drains it a little. So reading the voltage infrequently helps the battery last longer. The ADC pin needs to be enabled when reading the battery so you might want to disable that after reading the voltage to prevent battery drainage. groov Manage only updates its reading every 15 minutes and caches the result.

That being said, Gemini helped me put the attached shell script together to read the battery voltage on EPIC as of 4.0. Use it at your own risk.

battery_check.zip (825 Bytes)

Usage: sudo ./battery_check.sh

It returns the scaled voltage, or -1 if it encounters a read error.

2 Likes

Thanks! With the confirmation that voltage0 is the RTC battery voltage, I can make this work. Easy enough to check the firmware version and run a different command for units running older firmware.

Thanks again for the help @ccaldwell and @philip

I wanted to offer another option, especially as some might find it useful for other rest api calls.

You can make any rest call to query the Epic from a shell script using “curl” and you can process the json result easily using “jq”. Both are available on the Epic. For example, to get the battery voltage, put this in a script.

#!/bin/bash
curl -s -k -H apiKey:YourApiKeyHere \
    https://127.0.0.1/manage/api/v1/system/battery-voltage | \
    jq -r '.voltage'> /home/dev/unsecured/voltage.txt

Your API key is shown in the groov Manage accounts/users page, and the documentation for available rest api calls is under the info/help page.

The above will dump to a text file in the unsecured file storage, accessible from PacControl or other utilities for processing.

Google “man jq” to learn how to parse more complex json responses.

2 Likes

This is absolutely a valid approach! I highly recommend using the REST API to get the voltage if you need it for a local strategy. This also has no potential to break on future firmware releases.

This just did not work for my scenario because I have a thousand of PR1’s I would have to go through and configure API keys. Way easier for me to send out a new version installer to my team than have people go through each controller individually.