Skip to content

Instantly share code, notes, and snippets.

@Sean-Bradley
Created August 17, 2019 12:44
Show Gist options
  • Save Sean-Bradley/2261a0da87261b56984c610766887202 to your computer and use it in GitHub Desktop.
Save Sean-Bradley/2261a0da87261b56984c610766887202 to your computer and use it in GitHub Desktop.
import subprocess
import time
cmd = '/opt/vc/bin/vcgencmd measure_temp'
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
output, error = process.communicate()
#print(output)
tempC = output.split("=")[1].replace("'C", "").strip()
#print(tempC)
cmd = 'zabbix_sender -z 127.0.0.1 -s "raspberrypi" -k "pitemp" -o "%s" ' % (tempC)
print(cmd)
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
output, error = process.communicate()
print(output)
@Sean-Bradley
Copy link
Author

Sean-Bradley commented Aug 17, 2019

I copy this file to /home/pi/gettemp_cron.py
and create a cron job with settings,
*/1 * * * * python /home/pi/gettemp_cron.py

Provided, I have a Zabbix trapper item in my raspberrypi host settings in Zabbix Server, with key = pitemp
I will see the temperature of my raspberry pi logged every minute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment