Commit 03c67e1c authored by orangepi's avatar orangepi

将温度加入了心跳

parent 54c45d9e
#ifndef __HEAT_H__
#define __HEAT_H__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int heat_tem();//获取CPU温度
extern char temperature[];//温度存储
#endif
\ No newline at end of file
......@@ -18,7 +18,7 @@
#include "opensh.h"
#include "INA226.h"
#include "pthrpoll.h"
#include "heat.h"
......
......@@ -17,6 +17,7 @@
#include "INA226.h"
#include "pthrpoll.h"
#include "gpio_pwm_2.h"
#include "heat.h"
extern char* TOPIC ;//="app2dev/controlcar0004"
extern char* TOPIC2 ;//="dev2app/controlcar0004"
......
No preview for this file type
#include "heat.h"
#define MAX_LINE_LENGTH 20
char temperature[20];
float temp_str;
int heat_tem() {
FILE *file;
char line[MAX_LINE_LENGTH];
file = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
if (file == NULL) {
perror("无法打开温度文件");
return 1;
}
if (fgets(line, sizeof(line), file) != NULL) {
temp_str = (float)atof(line) / 1000.0;
sprintf(temperature, "%.2f°C", temp_str);
printf("CPU 温度: %.2f°C\n", temp_str);
}
fclose(file);
return 0;
}
\ No newline at end of file
......@@ -60,16 +60,18 @@ void mqtt_wirte(){//心跳格式
sprintf(voltage_str, "%.2f", voltage);
char current_str[20]; // 足够存储转换后的字符串的缓冲区
sprintf(current_str, "%.2f", current);
heat_tem();//获取CPU温度
message=1;
cJSON *root = cJSON_CreateObject();
cJSON *body = cJSON_CreateObject();
cJSON *head = cJSON_CreateObject();
cJSON_AddStringToObject(body, "ip", ip_address);
cJSON_AddStringToObject(body, "ID", TOPIC);
cJSON_AddStringToObject(body, "V:", voltage_str);
cJSON_AddStringToObject(body, "I:", current_str);
cJSON_AddStringToObject(body, "N", glat);
cJSON_AddStringToObject(body, "E", glon);
cJSON_AddStringToObject(body, "ip", ip_address);//发送设备id
cJSON_AddStringToObject(body, "ID", TOPIC);//发送设备号
cJSON_AddStringToObject(body, "V:", voltage_str);//心跳发送电压
cJSON_AddStringToObject(body, "I:", current_str);//心跳发送电流
cJSON_AddStringToObject(body,"Tem:",temperature);//发送温度
cJSON_AddStringToObject(body, "N", glat);//gps
cJSON_AddStringToObject(body, "E", glon);//gps
cJSON_AddNumberToObject(head, "message_type",message);
cJSON_AddItemToObject(root, "body", body);
cJSON_AddItemToObject(root, "head",head);
......
......@@ -9,6 +9,10 @@ int Device_File_Init() {
sub_str[2]='\0';
printf("开始初始化了");
if(strcmp(sub_str,"01")==0){//车的编码
pwm_speed(); //pwm初始化,车为停止
pin_init();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment