Created
February 1, 2017 18:15
-
-
Save LarsBergqvist/e27ab8f47c2575e4f6cd64b1324998b3 to your computer and use it in GitHub Desktop.
Measure the CPU temperature on a Raspberry Pi and publish the data with MQTT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import paho.mqtt.publish as publish | |
from subprocess import check_output | |
from re import findall | |
def get_temp(): | |
temp = check_output(["vcgencmd","measure_temp"]).decode("UTF-8") | |
return(findall("\d+\.\d+",temp)[0]) | |
def publish_message(topic, message): | |
print("Publishing to MQTT topic: " + topic) | |
print("Message: " + message) | |
publish.single(topic, message, hostname="192.168.1.16") | |
temp = get_temp() | |
publish_message("Home/RPI3/Temp", temp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment