Commit a047b520 authored by 957dd's avatar 957dd

Merge branch 'feature/add_post' into 'master'

Feature/add post See merge request !12
parents 707c309d 0ae069ac
......@@ -1205,6 +1205,7 @@ CMakeFiles/main.dir/src/mqtt.c.o
/usr/include/cjson/cJSON.h
/home/orangepi/car/master/system/sensor/warm.h
/home/orangepi/car/master/include/fileopen.h
/home/orangepi/car/master/device_judg/judg/judg.h
CMakeFiles/main.dir/src/opensh.c.o
/home/orangepi/car/master/src/opensh.c
......@@ -1319,6 +1320,7 @@ CMakeFiles/main.dir/src/opensh.c.o
/usr/include/mosquitto.h
/usr/include/cjson/cJSON.h
/home/orangepi/car/master/include/opensh.h
/home/orangepi/car/master/device_judg/judg/judg.h
CMakeFiles/main.dir/src/pthrpoll.c.o
/home/orangepi/car/master/src/pthrpoll.c
......@@ -1577,6 +1579,7 @@ CMakeFiles/main.dir/src/request.c.o
/usr/lib/gcc/aarch64-linux-gnu/11/include/stdbool.h
/home/orangepi/car/master/include/mqtt.h
/usr/include/mosquitto.h
/home/orangepi/car/master/device_judg/judg/judg.h
CMakeFiles/main.dir/src/thread_main.c.o
/home/orangepi/car/master/src/thread_main.c
......
......@@ -1194,7 +1194,8 @@ CMakeFiles/main.dir/src/mqtt.c.o: ../src/mqtt.c \
/usr/include/mosquitto.h \
/usr/include/cjson/cJSON.h \
../system/sensor/warm.h \
../include/fileopen.h
../include/fileopen.h \
../device_judg/judg/judg.h
CMakeFiles/main.dir/src/opensh.c.o: ../src/opensh.c \
/usr/include/stdc-predef.h \
......@@ -1307,7 +1308,8 @@ CMakeFiles/main.dir/src/opensh.c.o: ../src/opensh.c \
../include/mqtt.h \
/usr/include/mosquitto.h \
/usr/include/cjson/cJSON.h \
../include/opensh.h
../include/opensh.h \
../device_judg/judg/judg.h
CMakeFiles/main.dir/src/pthrpoll.c.o: ../src/pthrpoll.c \
/usr/include/stdc-predef.h \
......@@ -1563,7 +1565,8 @@ CMakeFiles/main.dir/src/request.c.o: ../src/request.c \
/usr/include/wiringPi.h \
/usr/lib/gcc/aarch64-linux-gnu/11/include/stdbool.h \
../include/mqtt.h \
/usr/include/mosquitto.h
/usr/include/mosquitto.h \
../device_judg/judg/judg.h
CMakeFiles/main.dir/src/thread_main.c.o: ../src/thread_main.c \
/usr/include/stdc-predef.h \
......
......@@ -116,4 +116,5 @@ CMakeFiles/main.dir/src/mqtt.c.o: /home/orangepi/car/master/src/mqtt.c \
/home/orangepi/car/master/include/mqtt.h /usr/include/mosquitto.h \
/usr/include/cjson/cJSON.h \
/home/orangepi/car/master/system/sensor/warm.h \
/home/orangepi/car/master/include/fileopen.h
/home/orangepi/car/master/include/fileopen.h \
/home/orangepi/car/master/device_judg/judg/judg.h
......@@ -92,4 +92,5 @@ CMakeFiles/main.dir/src/opensh.c.o: \
/usr/include/wiringPi.h \
/usr/lib/gcc/aarch64-linux-gnu/11/include/stdbool.h \
/home/orangepi/car/master/include/mqtt.h /usr/include/mosquitto.h \
/usr/include/cjson/cJSON.h /home/orangepi/car/master/include/opensh.h
/usr/include/cjson/cJSON.h /home/orangepi/car/master/include/opensh.h \
/home/orangepi/car/master/device_judg/judg/judg.h
......@@ -123,4 +123,5 @@ CMakeFiles/main.dir/src/request.c.o: \
/usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \
/usr/include/wiringPi.h \
/usr/lib/gcc/aarch64-linux-gnu/11/include/stdbool.h \
/home/orangepi/car/master/include/mqtt.h /usr/include/mosquitto.h
/home/orangepi/car/master/include/mqtt.h /usr/include/mosquitto.h \
/home/orangepi/car/master/device_judg/judg/judg.h
#define PROJECT_VERSION_MAJOR 1
#define PROJECT_VERSION_MINOR 0
#define PROJECT_VERSION_PATCH 1
#define GIT_HASH "b76a578"
#define BUILD_TIMESTAMP "2025-04-10T13:20:57"
#define GIT_HASH "4110c15"
#define BUILD_TIMESTAMP "2025-04-10T16:16:30"
#define BUILD_USER "orangepi"
No preview for this file type
......@@ -9,9 +9,23 @@
#include "tank.h"
#include "ship.h"
#include "pao.h"
#include "fileopen.h"
char TOPIC_middle[23];
char TOPIC2_middle[23];
char TOPIC3_middle[15];
void topic_middle_value() {
TOPIC=TOPIC_middle;
TOPIC2=TOPIC2_middle;
TOPIC3=TOPIC3_middle;
}
int Device_File_Init() {
const char *readbuf=device_inspect();
const char *readbuf=device_inspect();
//将第3个和第4个字符提取出来
char *sub_str=malloc(5);
sub_str[0]=readbuf[2];
......@@ -39,12 +53,14 @@ int Device_File_Init() {
free(sub_str);
}
Delay_Ms(20,0);
TOPIC=malloc(24);
TOPIC2=malloc(24);
TOPIC3= malloc(16);
sprintf(TOPIC2,"dev2app/%s",readbuf);
sprintf(TOPIC,"app2dev/%s",readbuf);
sprintf(TOPIC3,"%s",readbuf);
sprintf(TOPIC2_middle,"dev2app/%s",readbuf);
sprintf(TOPIC_middle,"app2dev/%s",readbuf);
sprintf(TOPIC3_middle,"%s",readbuf);
topic_middle_value();//指针传值声明
printf("1:%s,2:%s,3:%s\n",TOPIC,TOPIC2,TOPIC3);
return 0;
}
#ifndef __JUDG_H__
#define __JUDG_H__
int Device_File_Init();
int Device_File_Init();//指针传值声明
#endif
\ No newline at end of file
#ifndef __FILEOPEN_H__
#define __FILEOPEN_H__
#define filename "/home/orangepi/car/master/Deviceld.txt"//设备名存放文件
#define file_version "/home/orangepi/car/master/version.conf"
char *device_inspect() ;//打开设备号文件
char *program_version() ;//打开版本文件
#endif
\ No newline at end of file
#ifndef __THREAD_MAIN_H__
#define __THREAD_MAIN_H__
#define filename "/home/orangepi/car/master/Deviceld.txt"
int thread_start(void *AppExit(void *arg),void *Mqttbeat(void *arg),void *opensh(void *arg),void *Mqtt_onnect(void *arg)) ;
void *AppExit(void *arg) ;
void *Mqttbeat(void *arg) ;
void *opensh(void *arg) ;
void *Mqtt_onnect(void *arg) ;
char *device_inspect() ;
void thread_end() ;
#endif
\ No newline at end of file
#include "fileopen.h"
#include "common.h"
#include "delay.h"
char buffer_device[30]; // 用于存储文件内容
char buffer_version[30];// 用于存储版本号内容
char *device_inspect() {//读出文件函数
FILE *file;
while (1) {
file = fopen(filename, "r"); // 以只读模式打开文件
if (file == NULL) {
printf("文件 %s 打开失败,等待中...\n", filename);
}
else {
// 尝试读取文件内容
if (fgets(buffer_device, sizeof(buffer_device), file) != NULL) {
// 如果文件内容不为空
fclose(file);
printf("读取到文件内容: %s\n", buffer_device);
return buffer_device;
} else {
printf("文件为空,等待中...\n");
}
fclose(file);
}
Delay_Ms(1,0); // 等待1秒后再次检查
}
}
char *program_version() {//打开版本文件
FILE *file;
file = fopen(file_version, "r"); // 以只读模式打开文件
if (file == NULL) {
printf("文件无");
} else {
// 尝试读取文件内容
if (fgets(buffer_version, sizeof(buffer_version), file) != NULL) {
// 如果文件内容不为空
fclose(file);
printf("读取到文件内容: %s\n", buffer_version);
return buffer_version;
} else {
printf("文件为空,等待中...\n");
}
fclose(file);
}
}
\ No newline at end of file
......@@ -7,12 +7,16 @@
#include "heat.h"
#include "mqtt.h"
#include "warm.h"
#include "fileopen.h"
#include "judg.h"
struct mosquitto *mosq;
char* TOPIC;
char* TOPIC2;
char* TOPIC3;
char* TOPIC = NULL;
char* TOPIC2 = NULL;
char* TOPIC3 = NULL;
char *version_num;//版本号指针
int gPwmCount = 0; // 计数
int gmessage_type=10086;
......@@ -53,7 +57,7 @@ int mqtt_init() {
void on_connect(struct mosquitto *mosq, void *obj, int rc) {//回调函数
if (rc == 0) {
printf("Connected to broker\n");
topic_middle_value();
mosquitto_subscribe(mosq, NULL, TOPIC, 0);
} else {
......@@ -61,7 +65,7 @@ void on_connect(struct mosquitto *mosq, void *obj, int rc) {//回调函数
}
}
void mqtt_wirte(){//心跳格式
void mqtt_wirte(){//心跳格式,每5s一次心跳
float voltage = INA226_readBusVoltage(sda_pin, scl_pin);
float current = INA226_readCurrent(sda_pin, scl_pin);
......@@ -72,11 +76,17 @@ void mqtt_wirte(){//心跳格式
sprintf(current_str, "%.2f", current);
if(AppExit_pin_pwm/100 != 2) alarm_control(voltage);//判断电压警报
/*读取程序版本号*/
version_num = malloc(16);
version_num = program_version();
heat_tem();//获取CPU温度
message=1;
topic_middle_value();
cJSON *root = cJSON_CreateObject();
cJSON *body = cJSON_CreateObject();
cJSON *head = cJSON_CreateObject();
......@@ -88,6 +98,7 @@ void mqtt_wirte(){//心跳格式
cJSON_AddStringToObject(body,"Tem:",temperature);//发送温度
cJSON_AddStringToObject(body, "N", glat);//gps
cJSON_AddStringToObject(body, "E", glon);//gps
cJSON_AddStringToObject(body, "version", version_num);//gps
cJSON_AddNumberToObject(head, "message_type",message);
......@@ -97,7 +108,11 @@ void mqtt_wirte(){//心跳格式
char *payload = cJSON_PrintUnformatted(root);
printf("%s\n",payload);
mosquitto_publish(mosq, NULL, TOPIC2, strlen(payload), payload, 0, false);
mosquitto_publish(mosq, NULL, TOPIC3, strlen(payload), payload, 0, false);
mosquitto_publish(mosq, NULL, TOPIC3, strlen(payload), payload, 0, false);
cJSON_Delete(root); // 释放 cJSON 对象
return ;
}
void message_3(cJSON *body,cJSON *pwm_ctrl){//message_type为3,控制pwm
......
#include "common.h"
#include "mqtt.h"
#include "opensh.h"
#include "judg.h"
char gwebcam[254];//存放启动火狐网站命令
int opencamsh(){
const char* url = "https://jywy.yd-ss.com?dev=";
char urls[50];
topic_middle_value();
sprintf(urls,"%s%s",url,TOPIC3);
//setenv("DISPLAY", ":0", 1);//设置环境变量https://jywy.yd-ss.com?dev=controcar0004 --new-window sudo
......
......@@ -2,6 +2,8 @@
#include <cjson/cJSON.h>
#include "request.h"
#include "mqtt.h"
#include "judg.h"
const char *post = "http://47.119.190.60/api/v1/device/config";
int errCodeValue;
......@@ -82,6 +84,8 @@ int analysis_request_json(char *payload_str) {
char *wirte_json() {
cJSON *body = cJSON_CreateObject();
topic_middle_value();
cJSON_AddStringToObject(body, "device_id", TOPIC3); // 发送设备id
char *payload = cJSON_PrintUnformatted(body);
......
......@@ -10,7 +10,6 @@
#include "common.h"
#include "thread_main.h"
char buffer[30]; // 用于存储文件内容
pthread_t thread[4];
//开启线程
int thread_start(void *AppExit(void *arg),void *Mqttbeat(void *arg),void *opensh(void *arg),void *Mqtt_onnect(void *arg)){
......@@ -89,30 +88,6 @@ void *Mqtt_onnect(void *arg) {//mqtt异常处理,断开自动重连,简单
return NULL;
}
char *device_inspect() {//读出文件函数
FILE *file;
while (1) {
file = fopen(filename, "r"); // 以只读模式打开文件
if (file == NULL) {
printf("文件 %s 打开失败,等待中...\n", filename);
}
else {
// 尝试读取文件内容
if (fgets(buffer, sizeof(buffer), file) != NULL) {
// 如果文件内容不为空
fclose(file);
printf("读取到文件内容: %s\n", buffer);
return buffer;
} else {
printf("文件为空,等待中...\n");
}
fclose(file);
}
Delay_Ms(1,0); // 等待1秒后再次检查
}
}
// 等待线程结束
void thread_end() {
......
......@@ -7,7 +7,10 @@
int alarm_highest(int index) {//最高警报,最低电压报警
if(index == 1) {
pin_value(20,1);//紫灯
pin_value(22,1);//蜂鸣器
if(enable_buzzer_value)
{
pin_value(22,1);//蜂鸣器
}
}else if(index == 0) {
pin_value(20,0);//紫灯
pin_value(22,0);//蜂鸣器
......
......@@ -14,5 +14,6 @@
#include "thread_main.h"
#include "judg.h"
#include "request.h"
#include "fileopen.h"
#endif
\ No newline at end of file
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