Stay Hungry, Stay Foolish.
树莓派3 定时上传CUP温度到 yeelink 代码
CPUtemperature.py 代码
#!/usr/bin/env python
import requests
import json
import time
file = open("/sys/class/thermal/thermal_zone0/temp")
CPUtemperature = float(file.read()) / 1000
file.close
print "CPU Temperature :", CPUtemperature
topost_CPUtemperature_payload={'value':CPUtemperature}
url_CPUtemperature='你的传感器URL'
header={'U-ApiKey':'你的Apikey', 'content-type': 'application/json'}
post_CPUtemperature = requests.post(url_CPUtemperature,headers=header,data=json.dumps(topost_CPUtemperature_payload))
yeelink.sh 代码
sudo python /home/pi/yeelink.py
运行
sudo chmod +x /home/pi/yeelink.sh
设置定时5分钟运行一次
sudo crontab -e
加入
*/5 * * * * /home/pi/yeelink.sh