Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
car-controlserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenzhongjian
car-controlserver
Commits
f386b8c5
Commit
f386b8c5
authored
Apr 03, 2025
by
957dd
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/orangepi-T' into 'master'
将温度加入了心跳 See merge request
!5
parents
54c45d9e
03c67e1c
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
51 additions
and
7 deletions
+51
-7
heat.h
lib/heat.h
+12
-0
main.h
lib/main.h
+1
-1
mqtt.h
lib/mqtt.h
+1
-0
main
main
+0
-0
heat.c
src/heat.c
+25
-0
mqtt.c
src/mqtt.c
+8
-6
main.c
usr/main.c
+4
-0
No files found.
lib/heat.h
0 → 100755
View file @
f386b8c5
#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
lib/main.h
View file @
f386b8c5
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
#include "opensh.h"
#include "opensh.h"
#include "INA226.h"
#include "INA226.h"
#include "pthrpoll.h"
#include "pthrpoll.h"
#include "heat.h"
...
...
lib/mqtt.h
View file @
f386b8c5
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
#include "INA226.h"
#include "INA226.h"
#include "pthrpoll.h"
#include "pthrpoll.h"
#include "gpio_pwm_2.h"
#include "gpio_pwm_2.h"
#include "heat.h"
extern
char
*
TOPIC
;
//="app2dev/controlcar0004"
extern
char
*
TOPIC
;
//="app2dev/controlcar0004"
extern
char
*
TOPIC2
;
//="dev2app/controlcar0004"
extern
char
*
TOPIC2
;
//="dev2app/controlcar0004"
...
...
main
View file @
f386b8c5
No preview for this file type
src/heat.c
0 → 100755
View file @
f386b8c5
#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
src/mqtt.c
View file @
f386b8c5
...
@@ -60,16 +60,18 @@ void mqtt_wirte(){//心跳格式
...
@@ -60,16 +60,18 @@ void mqtt_wirte(){//心跳格式
sprintf
(
voltage_str
,
"%.2f"
,
voltage
);
sprintf
(
voltage_str
,
"%.2f"
,
voltage
);
char
current_str
[
20
];
// 足够存储转换后的字符串的缓冲区
char
current_str
[
20
];
// 足够存储转换后的字符串的缓冲区
sprintf
(
current_str
,
"%.2f"
,
current
);
sprintf
(
current_str
,
"%.2f"
,
current
);
heat_tem
();
//获取CPU温度
message
=
1
;
message
=
1
;
cJSON
*
root
=
cJSON_CreateObject
();
cJSON
*
root
=
cJSON_CreateObject
();
cJSON
*
body
=
cJSON_CreateObject
();
cJSON
*
body
=
cJSON_CreateObject
();
cJSON
*
head
=
cJSON_CreateObject
();
cJSON
*
head
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
body
,
"ip"
,
ip_address
);
cJSON_AddStringToObject
(
body
,
"ip"
,
ip_address
);
//发送设备id
cJSON_AddStringToObject
(
body
,
"ID"
,
TOPIC
);
cJSON_AddStringToObject
(
body
,
"ID"
,
TOPIC
);
//发送设备号
cJSON_AddStringToObject
(
body
,
"V:"
,
voltage_str
);
cJSON_AddStringToObject
(
body
,
"V:"
,
voltage_str
);
//心跳发送电压
cJSON_AddStringToObject
(
body
,
"I:"
,
current_str
);
cJSON_AddStringToObject
(
body
,
"I:"
,
current_str
);
//心跳发送电流
cJSON_AddStringToObject
(
body
,
"N"
,
glat
);
cJSON_AddStringToObject
(
body
,
"Tem:"
,
temperature
);
//发送温度
cJSON_AddStringToObject
(
body
,
"E"
,
glon
);
cJSON_AddStringToObject
(
body
,
"N"
,
glat
);
//gps
cJSON_AddStringToObject
(
body
,
"E"
,
glon
);
//gps
cJSON_AddNumberToObject
(
head
,
"message_type"
,
message
);
cJSON_AddNumberToObject
(
head
,
"message_type"
,
message
);
cJSON_AddItemToObject
(
root
,
"body"
,
body
);
cJSON_AddItemToObject
(
root
,
"body"
,
body
);
cJSON_AddItemToObject
(
root
,
"head"
,
head
);
cJSON_AddItemToObject
(
root
,
"head"
,
head
);
...
...
usr/main.c
View file @
f386b8c5
...
@@ -9,6 +9,10 @@ int Device_File_Init() {
...
@@ -9,6 +9,10 @@ int Device_File_Init() {
sub_str
[
2
]
=
'\0'
;
sub_str
[
2
]
=
'\0'
;
printf
(
"开始初始化了"
);
printf
(
"开始初始化了"
);
if
(
strcmp
(
sub_str
,
"01"
)
==
0
){
//车的编码
if
(
strcmp
(
sub_str
,
"01"
)
==
0
){
//车的编码
pwm_speed
();
//pwm初始化,车为停止
pwm_speed
();
//pwm初始化,车为停止
pin_init
();
pin_init
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment