PS:全志h2+的发热真是好严重
shell版
需要curl支持

1
2
3
4
5
6
7
#!/bin/sh
YL_ApiKey='0dc1415a229d00b57a9a0353bffd5f2d'
YL_URL=http://api.yeelink.net/v1.0/device/352542/sensor/398633/datapoints
temp=$(cat /sys/class/thermal/thermal_zone0/temp)
echo {\"value\":$temp} >> /tmp/tmp
curl --request POST --data @/tmp/tmp --header U-ApiKey:$YL_ApiKey $YL_URL
> /tmp/tmp

Python版
需要安装pip以及requests

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# -*- coding: utf-8 -*-
import requests
import json
# 打开文件
file = open("/sys/class/thermal/thermal_zone0/temp")
# 读取结果,并转换为浮点数
temp = float(file.read()) / 1000
# 关闭文件
file.close()
# 向控制台打印结果
print "temp : %.1f" %temp
# 设备URI
apiurl = 'http://api.yeelink.net/v1.0/device/352542/sensor/398633/datapoints'
# 用户密码, 指定上传编码为JSON格式
apiheaders = {'U-ApiKey': '0dc1415a229d00b57a9a0353bffd5f2d', '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