照说前两天已经搞定SHT2x的温度采集,可以来做上传了,不过以前一直没搞定的CPU温度也希望再尝试一下
这个是小伙伴的帖子,不过一直没有sensons可以安装
http://forum.banana-pi.org.cn/thread-742-1-1.html
尝试用C操作
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define TEMP_PATH "/sys/class/thermal/thermal_zone0/temp"
#define MAX_SIZE 32
int main(void)
{
int fd;
double temp = 0;
char buf[MAX_SIZE];
// 打开/sys/class/thermal/thermal_zone0/temp
fd = open(TEMP_PATH, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "failed to open thermal_zone0/temp\n");
return -1;
}
// 读取内容
if (read(fd, buf, MAX_SIZE) < 0) {
fprintf(stderr, "failed to read temp\n");
return -1;
}
// 转换为浮点数打印
temp = atoi(buf);
printf("temp: %.2f\n", temp);
// 关闭文件
close(fd);
}
既然不能除1000了,所以要有一些小修改
提交到yeelink的代码
# -*- coding: utf-8 -*-
import requests
import json
# 打开文件
file = open("/sys/class/thermal/thermal_zone0/temp")
# 读取结果,并转换为浮点数
temp = float(file.read())
# 关闭文件
file.close()
# 向控制台打印结果
print "temp : %.1f" %temp
# 设备URI
apiurl = 'http://api.yeelink.net/v1.0/device/344832/sensor/383501/datapoints'
# 用户密码, 指定上传编码为JSON格式
apiheaders = {'U-ApiKey': 'a0ff0c16029821a7b8f7a75e', '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
| 有奖活动 | |
|---|---|
| 2026年“我要开发板活动”第三季,开始了! | |
| 硬核工程师专属补给计划——填盲盒 | |
| “我踩过的那些坑”主题活动——第002期 | |
| 【EEPW电子工程师创研计划】技术变现通道已开启~ | |
| 发原创文章 【每月瓜分千元赏金 凭实力攒钱买好礼~】 | |
| 【EEPW在线】E起听工程师的声音! | |
| 高校联络员开始招募啦!有惊喜!! | |
| 【工程师专属福利】每天30秒,积分轻松拿!EEPW宠粉打卡计划启动! | |
我要赚赏金打赏帖 |
|
|---|---|
| window下生成compilecommands.json的的方法被打赏¥22元 | |
| 【S32K3XX】GPIO中断配置被打赏¥26元 | |
| 【分享开发笔记,赚取电动螺丝刀】WS2812B的RGB灯介绍以及驱动方法被打赏¥25元 | |
| PTC与NTC功能常规对比被打赏¥14元 | |
| 【S32K3XX】核间通信MU使用被打赏¥27元 | |
| 【分享开发笔记,赚取电动螺丝刀】关于3pin锂电池接口的介绍/使用被打赏¥16元 | |
| 以启明云端ESP32P4开发板实现TF卡读写功能被打赏¥28元 | |
| 【分享开发笔记,赚取电动螺丝刀】树莓派5串口UART0配置被打赏¥25元 | |
| 【STM32F103ZET6】17:分享在Rtos项目中断管理的使用经验被打赏¥23元 | |
| 【STM32F103ZET6】16:分享在中断中恢复串口任务,遇到的问题被打赏¥31元 | |