Raspbery pi
Jump to navigation
Jump to search
General notes on some of my Pis
Prep work for power monitoring using lechacal Hats....
Run the raspi-config tool $ sudo raspi-config Then disable the login uart 3 Interface Options <<-- Use option 5 Interfacing Options instead if using the image before 12 DEC 2020 P6 Serial Would you like a login shell to be accessible over serial? Select No to the login shell question. Would you like the serial port hardware to be enabled? Select Yes to the serial port hardware to be enabled question. Select Ok at the summary. Back at the menu select finish. Would you like to reboot now? Select No to the reboot question (we will do that later). sudo nano /boot/config.txt At the end of the file add the following line: dtoverlay=disable-bt sudo systemctl disable hciuart sudo reboot & exit
Testing that it works
chubbard@power01:~$ cat /dev/ttyAMA0 11 1129.3 62.6 206.0 79.3 2583.9 986.6 246.9 92.4 11 1142.2 60.3 207.3 78.5 2576.7 1028.9 244.9 91.0 11 1134.1 66.0 208.5 75.3 2595.9 1014.4 244.8 90.8 11 1134.4 62.8 206.0 76.7 2566.3 987.1 248.9 91.8 ^C
Script currently in use:
#!/bin/bash # Output from serial port: # 11 125.7 54.2 51.2 54.5 260.2 58.8 1447.0 53.0 getdata() { stty -F /dev/ttyAMA0 raw speed 38400 >/dev/null read ID < /dev/ttyAMA0 echo "${ID}" # Create array of values: IFS=$' \r' read -r -a PROBES <<< "${ID}" unset IFS } pushgraphite() { local G_HOST="192.168.15.193" local G_PORT=2003 # This is fast so only get the date once local DAT=$(date +%s --utc) # Iterate over array of values for element in "${!PROBES[@]}"; do # Suppress the noise floor on the 100A RPICT8 (~59w or so) if [[ $( echo "${PROBES[element]} >= 71.9" | bc) -ne 1 ]];then VALUE=0.0 else VALUE="${PROBES[element]}" fi # 0 element is actually the ID of the hat, NOT a valid value if [[ ${element} -eq 0 ]]; then JUNK=0 else # Send data to Graphite if [[ ${UDP} = 'true' ]];then echo " monitor.power.probe${element} ${VALUE} ${DAT}" | nc -u -q 1 -C ${G_HOST} ${G_PORT} echo "Sent: monitor.power.probe${element} REAL: ${PROBES[element]} SENT: ${VALUE} ${DAT} | nc -u -q 1 -C ${G_HOST} ${G_PORT}" else echo " monitor.power.probe${element} ${VALUE} ${DAT}" | nc -N -C ${G_HOST} ${G_PORT} echo "Sent: monitor.power.probe${element} REAL: ${PROBES[element]} SENT: ${VALUE} ${DAT} | nc -N -C ${G_HOST} ${G_PORT}" fi fi done } #------------------------------------------------------------------------------- # Set our defaults #------------------------------------------------------------------------------- UDP='false' # Get any command args for the script while getopts "hxU" OPTION do case ${OPTION} in h) usage; exit 0 ;; x) export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'; set -x ;; U) UDP="true" ;; *) echo "Status WARNING - Unexpected argument given $@"; exit 1 ;; esac done RES='none' while [ "${RES}" != 'good' ]; do getdata # https://www.cyberciti.biz/faq/finding-bash-shell-array-length-elements/ if [[ ${#PROBES[@]} -ne 9 ]] ; then echo "PROBE count ${#PROBES[@]} serial bug detected." RES='bad' sleep 5 else # echo "PROBE count ${#PROBES[@]}" RES='good' fi done pushgraphite exit 0