首页 > 其他 > 详细

将树莓派的CPU温度和GPU温度上传到yeelink

时间:2014-04-24 07:02:31      阅读:441      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
#coding=utf-8
import commands
import requests
import json
from time import strftime

headers = {"U-ApiKey": "aae39f7225ba04*******c545bbc9d7"}
DEVICE_ID = "9311"
CPU_SENSOR_ID = "14695"
GPU_SENSOR_ID = "14696"


def upload_temp(sensor_type, temp):
    if sensor_type == "cpu":
        sensor_id = CPU_SENSOR_ID
    else:
        sensor_id = GPU_SENSOR_ID
    url = r"http://api.yeelink.net/v1.0/device/%s/sensor/%s/datapoints" % (DEVICE_ID, sensor_id)
    data = {"timestamp": strftime("%Y-%m-%dT%H:%M:%S"), "value": temp}
    r = requests.post(url, data=json.dumps(data), headers=headers)
    print r.content
    
def get_cpu_temp():
    tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
    cpu_temp = tempFile.read()
    tempFile.close()
    return float(cpu_temp)/1000

def get_gpu_temp():
    gpu_temp = commands.getoutput( /opt/vc/bin/vcgencmd measure_temp ).replace( temp=, ‘‘ ).replace( \‘C, ‘‘ )
    return  float(gpu_temp)

upload_temp("cpu", get_cpu_temp())
upload(temp("gpu", get_gpu_temp())
    
    
bubuko.com,布布扣

关于获取CPU和GPU的温度

http://www.geekfan.net/6317/

yeelink开发文档

http://www.yeelink.net/developer

将树莓派的CPU温度和GPU温度上传到yeelink,布布扣,bubuko.com

将树莓派的CPU温度和GPU温度上传到yeelink

原文:http://www.cnblogs.com/virusdefender/p/3683658.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!