文章标题
来源:互联网 发布:ubuntu怎么进入文件夹 编辑:程序博客网 时间:2024/05/30 02:26
检测树莓派温度
树莓派内部有温度传感器,所以只需要调用传感器来实现。
检测树莓派温度代码部分:
import requests import json import time while 1: try: file = open("/sys/class/thermal/thermal_zone0/temp") temp = float(file.read()) / 1000 file.close() #print "response status: %d" %r.status_code with open("cpu_result.txt","a") as f: strTime = time.strftime('%Y-%m-%d:%H-%M-%S',time.localtime(time.time())) f.write(strTime + " %.1f" %temp + " %d" %r.status_code + "\n") time.sleep(5*60) except Exception,e: with open("cpu_result.txt","a") as f: f.write("error!\n")
实现后,检测到的温度无法实时查看,需要物联网控制平台yeelink来查看。
综合实现代码如下:
#!/usr/bin/env python # -*- coding: utf-8 -*- import requests import json import time while 1: try: file = open("/sys/class/thermal/thermal_zone0/temp") temp = float(file.read()) / 1000 file.close() # 设备URI apiurl = 'http://api.yeelink.net/v1.1/device//sensor/406330/datapoints' apiheaders = {'U-ApiKey': 'f0f605d2d279ba74edaf0b7a5', 'content-type': 'application/json'} # 字典类型数据,在post过程中被json.dumps转换为JSON格式字符串 {"value": 48.123} payload = {'value': temp} r = requests.post(apiurl, headers=apiheaders, data=json.dumps(payload)) #print "response status: %d" %r.status_code with open("cpu_result.txt","a") as f: strTime = time.strftime('%Y-%m-%d:%H-%M-%S',time.localtime(time.time())) f.write(strTime + " %.1f" %temp + " %d" %r.status_code + "\n") time.sleep(5*60) except Exception,e: with open("cpu_result.txt","a") as f: f.write("error!\n")
上传成功后,既可以在物联网平台查看。
阅读全文
0 0
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- Gradle for Android-高级Build和自定义
- ★实验9-3 1.用不同的方案实现两个命令的连接,例如 “who|sort”、“ps aux | grep init” 源程序: #include <stdio.h> #include <sys
- 【Nginx】Nginx优秀特点
- 【spring MVC】数据校验
- H
- 文章标题
- 黑阔的win10--把win10打造成kali(记录帖)
- Linux-视频监控系统(5)-TCP传输子系统实现
- 折叠ToolBar
- ★实验10-1 1.编写程序测试函数setitimer(int)和getitimer()。 2.安装信号, 使信号SIGALRM、SIGVTALRM、SIGPROF可以被捕获。 #include
- Python的逻辑运算
- 【我的总结——思想篇】
- 字符串操作函数的使用及其实现
- ★实验10-2 1.编写程序测试sigaction()函数。 2.sa_flags 设置为以下标志时,程序的行为有何不同。 对比程序运行情况予以说明。 SA_SIGINFO SA_NOCLDST