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.
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.
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 }