读取 raspberrypi 的cpu和gpu温度
2015-03-25 19:13
561 查看
#!/usr/bin/env python # -*- coding: utf-8 -*- import requests import json import time import commands def main(): # fileRecord = open("result.txt", "w") # fileRecord.write("connect to yeelink\n"); # fileRecord.close() while True: # 打开文件 apiheaders = {'U-ApiKey': 'a96bbccdd8f5e6e24fd3b2358d6cbc45', 'content-type': 'application/json'} gpu = commands.getoutput( '/opt/vc/bin/vcgencmd measure_temp' ).replace( 'temp=', '' ).replace( '\'C', '' ) gpu = float(gpu) #print('gpu value:%.2f' % gpu) # GPU设备URI apiurl_gpu = 'http://api.yeelink.net/v1.0/device/13926/sensor/23125/datapoints' #YEELINK 用户密码, 指定上传编码为JSON格式i #apiheaders = {'U-ApiKey': 'a96bbccdd8f5e6e24fd3b2358d6cbc45', 'content-type': 'application/json'} payload_gpu = {'value': gpu} r = requests.post(apiurl_gpu, headers=apiheaders, data=json.dumps(payload_gpu)) file = open("/sys/class/thermal/thermal_zone0/temp") # 读取结果,并转换为浮点数 cpu = float(file.read()) / 1000 # 关闭文件 file.close() #print('cpu value:%.2f' % cpu) # CPU设备URI apiurl_cpu = 'http://api.yeelink.net/v1.0/device/13926/sensor/23121/datapoints' #YEELINK 用户密码, 指定上传编码为JSON格式 #apiheaders = {'U-ApiKey': 'a96bbccdd8f5e6e24fd3b2358d6cbc45', 'content-type': 'application/json'} # 字典类型数据,在post过程中被json.dumps转换为JSON格式字符串 {"value": 48.123} payload_cpu = {'value': cpu} #发送请求 r = requests.post(apiurl_cpu, headers=apiheaders, data=json.dumps(payload_cpu)) # 向控制台打印结果 # fileRecord = open("result.txt", "a") # strTime = time.strftime('%Y-%m-%d:%H-%M-%S',time.localtime(time.time())) #fileRecord.writelines(strTime + "\n") #strTemp = "temp : %.1f" %temp + "\n" #fileRecord.writelines(strTemp) #fileRecord.writelines(str(r.status_code) + "\n") #fileRecord.close() time.sleep(1*60) if __name__ == '__main__': main()
源代码摘自:http://www.geekfan.net/6317/
相关文章推荐
- python C语言文件IO读取树莓派CPU、GPU温度
- 读取树莓派CPU/GPU温度,内存,硬盘使用率
- 读取树莓派的CPU和GPU温度
- Ubuntu 14.04 下读取CPU温度
- 读取CPU核心温度
- imx6 读取CPU温度
- 温度读取vc++获取cpu温度
- 树莓派查看CPU和GPU温度
- i.MX6(D-Chip)读取CPU内部温度的方法
- linux下读取cpu核温度。
- Linux下如何通过编程读取cpu温度?
- 转载:c# 获取CPU温度(非WMI,直接读取硬件)
- c# 获取CPU温度(非WMI,直接读取硬件)
- 树莓派-获取CPU和GPU温度
- Raspberry Pi B+ 定时向物联网yeelink上传CPU GPU温度
- Raspberry Pi B+ 定时向物联网yeelink上传CPU GPU温度
- 笔记本CPU正常温度控制技巧
- CPU和GPU双低效,摩尔定律之后一万倍 ——写于TPU版AlphaGo重出江湖之际
- CPU和GPU的区别、工作原理、及如何tensorflow-GPU安装等操作
- tensorflow对比AlexNet的CPU和GPU运算效率