Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Raspberry Monitor using ThingSpeak
## Installation: sudo bash -c "wget -P /usr/local/bin && chmod +x /usr/local/bin/"
echo() { :; } # comment line to enable debugging
apiKey=XXXXXXXX # ThingSpeak channel write API key, put your own
freeram=$(free -m | awk '/Mem:/ { print $4 }')
freeroot=$(df -BM | awk '/rootfs/ { print substr($4, 1, length($4)-1) }')
freependrive=$(df -BM | awk '/sda1/ { print substr($4, 1, length($4)-1) }')
temp=$(cat /sys/class/thermal/thermal_zone0/temp | awk '{ print $1/1000 }')
processes=$(ps ax | wc -l | tr -d " ")
load=$(cat /proc/loadavg | awk '{ print $2 }')
echo "## Raspberry Monitor -> ThingSpeak ##"
echo "Temp: $temp C"
echo "Load: $load"
echo "Processes: $processes"
echo "Free RAM: $freeram MB"
echo "Free rootfs: $freeroot MB"
echo "Free pendrive: $freependrive MB"
# Send values to ThingSpeak
update=$(curl --silent --request POST --header "X-THINGSPEAKAPIKEY: $apiKey" --data "field1=$temp&field2=$load&field3=$processes&field4=$freeram&field5=$freeroot&field6=$freependrive" "")
echo "Update #$update"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.