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

[Solved / Archived] CLI access to api?

3 Posts
2 Users
0 Likes
139 Views
(@cjefferies)
Posts: 8
Active Member
Topic starter
 

I'm looking at the wittypi4 api.sh 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
(@admin)
Posts: 421
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 utilities.sh. 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
(@cjefferies)
Posts: 8
Active Member
Topic starter
 

Here is the code where I am using the utilities.sh 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.

WITTYUTIL_PATH="/home/pi/wittypi/utilities.sh"

# get wittypi4 stats
witty_stats() {


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

export I2C_BUS

# source the utilities.sh file
source "$WITTYUTIL_PATH"


# 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> "
fi


# 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 " "
check_undervolt
else
echo "Witty is not available."
fi
}
This post was modified 2 months 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.