Cool stuff for Raspberry Pi, Arduino and all electronics hobby projects
Clear all

[Solved / Archived] CLI access to api?

3 Posts
2 Users
Posts: 8
Active Member
Topic starter

I'm looking at the wittypi4 and I kind of get how the index.html invokes some javascript but is there a way to just call an API from the command line to get, for example, temp, vin, vout?

Thanks for any tips.

Posted : 23/06/2024 11:03 pm
Posts: 371
Member Admin

All those information are stored in I2C registers. At the end of the user manual there is a table that lists all registers, and you may access them via "i2cget" command with their indices.

However the data stored in those I2C registers are raw data and you usually need to do some calculation to convert them to human-readable data. A good way to learn how to do it, is to review the source code in For example, you may checkout this get_input_voltage() function, or this get_temperature() function, or this get_output_voltage() function etc.


Posted : 24/06/2024 9:34 am
Posts: 8
Active Member
Topic starter

Here is the code where I am using the set of functions for my function, witty_stats().  Seems to be working fine.  Thank you.

The check_undervolt is another function where I look at entries in syslog for undervolt issues, and lumped them into this output.


# get wittypi4 stats
witty_stats() {

# determine correct I2C bus, 0 or 1?
if [ -e /dev/i2c-1 ]; then
elif [ -e /dev/i2c-0 ]; then
echo "No I2C bus found. Exiting."
exit 1

export I2C_BUS

# source the file

# is microcontroller connected
if [ $(is_mc_connected) -eq 1 ]; then
# Get values using utility functions
local temp=$(get_temperature)
local vin=$(get_input_voltage)
local vout=$(get_output_voltage)
local iout=$(get_output_current)
local voltages=""

# Check power mode and add Vin if applicable
if [ $(get_power_mode) -ne 0 ]; then
voltages+=" Voltage in: $(printf %.02f $vin)V (6V - 30V)<br> "

# add Vout and Iout
voltages+="Voltage out: $(printf %.02f $vout)V (best @ 4.9V - 5.1V) <br> Amps out: $(printf %.02f $iout)A<br>"

# echo the content
echo "$voltages"
echo " Temperature: $temp (normal < 50°C, extreme > 80°C)"
echo " "
echo "Witty is not available."
This post was modified 3 weeks ago by cjefferies
Posted : 25/06/2024 7:11 pm
Join Waitlist We will inform you when the product arrives in stock. Please leave your valid email address below.