Commit c7c7206a authored by 957dd's avatar 957dd

加入了拉取mqtt服务器,还需等后端完成后再修改

parent 060cf3b1
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#define FILE_VERSION "/home/orangepi/car/master/version.conf" #define FILE_VERSION "/home/orangepi/car/master/version.conf"
char *g_device_id = NULL; char *g_device_id = NULL;//设备的类型的id
/*读出文件函数,读取设备号函数,获得设备号id*/ /*读出文件函数,读取设备号函数,获得设备号id*/
char *device_inspect() { char *device_inspect() {
......
...@@ -25,9 +25,14 @@ int main(){ ...@@ -25,9 +25,14 @@ int main(){
return -5; return -5;
} }
if(http_mqtt_video_init() !=0){
my_zlog_error("请求mqtt服务器和video数据失败");
return -6;
}
if(softiic_init()!=0){ if(softiic_init()!=0){
my_zlog_error("软件iic初始化失败"); my_zlog_error("软件iic初始化失败");
return -6; return -7;
} }
if(ina225_init()!=0){ if(ina225_init()!=0){
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "INA226.h" #include "INA226.h"
#include "devcontrol_common.h" #include "devcontrol_common.h"
#include "gpio_init.h" #include "gpio_init.h"
#include "http_config_mqtt.h"
/*设备id读取初始化*/ /*设备id读取初始化*/
int device_id_file_init(); int device_id_file_init();
...@@ -41,6 +42,9 @@ int thread_start_init(ThreadFunc thread_exit_time, ThreadFunc thread_mqtt_beat, ...@@ -41,6 +42,9 @@ int thread_start_init(ThreadFunc thread_exit_time, ThreadFunc thread_mqtt_beat,
/*像服务器请求*/ /*像服务器请求*/
int request_date(); int request_date();
/*mqtt服务器和视频流地址初始化*/
int http_mqtt_video_init();
/*线程关闭函数*/ /*线程关闭函数*/
void thread_end_close() ; void thread_end_close() ;
......
...@@ -18,7 +18,7 @@ pthread_t g_thread[PTHREAD_MAX]; // 全局线程句柄数组(或传参) ...@@ -18,7 +18,7 @@ pthread_t g_thread[PTHREAD_MAX]; // 全局线程句柄数组(或传参)
int g_webrtc_index=0;//判断游览器是否打开 int g_webrtc_index=0;//判断游览器是否打开
int g_mqtt_grc=0; int g_mqtt_grc=0;//mqtt连接状态机
void* g_args[PTHREAD_MAX] = { NULL}; void* g_args[PTHREAD_MAX] = { NULL};
...@@ -83,8 +83,6 @@ void *thread_mqtt_beat(void *arg) { ...@@ -83,8 +83,6 @@ void *thread_mqtt_beat(void *arg) {
} }
while(1) { while(1) {
// if( g_device_type >= 200 && g_device_type<=205) delay_ms(45);
// if( g_device_type != 202)delay_ms(100);
delay_ms(100); delay_ms(100);
g_heartbeat_count++; g_heartbeat_count++;
......
...@@ -1158,6 +1158,30 @@ modules/delay/delay.c.s: ...@@ -1158,6 +1158,30 @@ modules/delay/delay.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/delay/delay.c.s $(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/delay/delay.c.s
.PHONY : modules/delay/delay.c.s .PHONY : modules/delay/delay.c.s
modules/http/http_config_mqtt.o: modules/http/http_config_mqtt.c.o
.PHONY : modules/http/http_config_mqtt.o
# target to build an object file
modules/http/http_config_mqtt.c.o:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/http/http_config_mqtt.c.o
.PHONY : modules/http/http_config_mqtt.c.o
modules/http/http_config_mqtt.i: modules/http/http_config_mqtt.c.i
.PHONY : modules/http/http_config_mqtt.i
# target to preprocess a source file
modules/http/http_config_mqtt.c.i:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/http/http_config_mqtt.c.i
.PHONY : modules/http/http_config_mqtt.c.i
modules/http/http_config_mqtt.s: modules/http/http_config_mqtt.c.s
.PHONY : modules/http/http_config_mqtt.s
# target to generate assembly for a file
modules/http/http_config_mqtt.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/http/http_config_mqtt.c.s
.PHONY : modules/http/http_config_mqtt.c.s
modules/http/http_consolepush.o: modules/http/http_consolepush.c.o modules/http/http_consolepush.o: modules/http/http_consolepush.c.o
.PHONY : modules/http/http_consolepush.o .PHONY : modules/http/http_consolepush.o
...@@ -1981,6 +2005,9 @@ help: ...@@ -1981,6 +2005,9 @@ help:
@echo "... modules/delay/delay.o" @echo "... modules/delay/delay.o"
@echo "... modules/delay/delay.i" @echo "... modules/delay/delay.i"
@echo "... modules/delay/delay.s" @echo "... modules/delay/delay.s"
@echo "... modules/http/http_config_mqtt.o"
@echo "... modules/http/http_config_mqtt.i"
@echo "... modules/http/http_config_mqtt.s"
@echo "... modules/http/http_consolepush.o" @echo "... modules/http/http_consolepush.o"
@echo "... modules/http/http_consolepush.i" @echo "... modules/http/http_consolepush.i"
@echo "... modules/http/http_consolepush.s" @echo "... modules/http/http_consolepush.s"
......
#define PROJECT_VERSION_MAJOR 1 #define PROJECT_VERSION_MAJOR 1
#define PROJECT_VERSION_MINOR 2 #define PROJECT_VERSION_MINOR 2
#define PROJECT_VERSION_PATCH 12 #define PROJECT_VERSION_PATCH 13
#define GIT_HASH "" #define GIT_HASH ""
#define BUILD_TIMESTAMP "" #define BUILD_TIMESTAMP ""
#define BUILD_USER "" #define BUILD_USER ""
No preview for this file type
...@@ -2,8 +2,8 @@ CMAKE_PROGRESS_1 = ...@@ -2,8 +2,8 @@ CMAKE_PROGRESS_1 =
CMAKE_PROGRESS_2 = CMAKE_PROGRESS_2 =
CMAKE_PROGRESS_3 = 81 CMAKE_PROGRESS_3 = 81
CMAKE_PROGRESS_4 = CMAKE_PROGRESS_4 =
CMAKE_PROGRESS_5 = CMAKE_PROGRESS_5 = 82
CMAKE_PROGRESS_6 = 82 CMAKE_PROGRESS_6 =
CMAKE_PROGRESS_7 = CMAKE_PROGRESS_7 =
CMAKE_PROGRESS_8 = 83 CMAKE_PROGRESS_8 = 83
CMAKE_PROGRESS_9 = CMAKE_PROGRESS_9 =
......
CMAKE_PROGRESS_1 = 93 CMAKE_PROGRESS_1 = 93
CMAKE_PROGRESS_2 = CMAKE_PROGRESS_2 =
CMAKE_PROGRESS_3 = CMAKE_PROGRESS_3 = 94
CMAKE_PROGRESS_4 = 94 CMAKE_PROGRESS_4 =
CMAKE_PROGRESS_5 = CMAKE_PROGRESS_5 =
...@@ -12,8 +12,8 @@ CMAKE_PROGRESS_11 = ...@@ -12,8 +12,8 @@ CMAKE_PROGRESS_11 =
CMAKE_PROGRESS_12 = CMAKE_PROGRESS_12 =
CMAKE_PROGRESS_13 = 5 CMAKE_PROGRESS_13 = 5
CMAKE_PROGRESS_14 = CMAKE_PROGRESS_14 =
CMAKE_PROGRESS_15 = 6 CMAKE_PROGRESS_15 =
CMAKE_PROGRESS_16 = CMAKE_PROGRESS_16 = 6
CMAKE_PROGRESS_17 = CMAKE_PROGRESS_17 =
CMAKE_PROGRESS_18 = 7 CMAKE_PROGRESS_18 = 7
CMAKE_PROGRESS_19 = CMAKE_PROGRESS_19 =
...@@ -29,8 +29,8 @@ CMAKE_PROGRESS_28 = ...@@ -29,8 +29,8 @@ CMAKE_PROGRESS_28 =
CMAKE_PROGRESS_29 = CMAKE_PROGRESS_29 =
CMAKE_PROGRESS_30 = 11 CMAKE_PROGRESS_30 = 11
CMAKE_PROGRESS_31 = CMAKE_PROGRESS_31 =
CMAKE_PROGRESS_32 = 12 CMAKE_PROGRESS_32 =
CMAKE_PROGRESS_33 = CMAKE_PROGRESS_33 = 12
CMAKE_PROGRESS_34 = CMAKE_PROGRESS_34 =
CMAKE_PROGRESS_35 = 13 CMAKE_PROGRESS_35 = 13
CMAKE_PROGRESS_36 = CMAKE_PROGRESS_36 =
......
...@@ -2,8 +2,8 @@ CMAKE_PROGRESS_1 = ...@@ -2,8 +2,8 @@ CMAKE_PROGRESS_1 =
CMAKE_PROGRESS_2 = CMAKE_PROGRESS_2 =
CMAKE_PROGRESS_3 = 17 CMAKE_PROGRESS_3 = 17
CMAKE_PROGRESS_4 = CMAKE_PROGRESS_4 =
CMAKE_PROGRESS_5 = 18 CMAKE_PROGRESS_5 =
CMAKE_PROGRESS_6 = CMAKE_PROGRESS_6 = 18
CMAKE_PROGRESS_7 = CMAKE_PROGRESS_7 =
CMAKE_PROGRESS_8 = 19 CMAKE_PROGRESS_8 = 19
CMAKE_PROGRESS_9 = CMAKE_PROGRESS_9 =
...@@ -19,8 +19,8 @@ CMAKE_PROGRESS_18 = ...@@ -19,8 +19,8 @@ CMAKE_PROGRESS_18 =
CMAKE_PROGRESS_19 = CMAKE_PROGRESS_19 =
CMAKE_PROGRESS_20 = 23 CMAKE_PROGRESS_20 = 23
CMAKE_PROGRESS_21 = CMAKE_PROGRESS_21 =
CMAKE_PROGRESS_22 = 24 CMAKE_PROGRESS_22 =
CMAKE_PROGRESS_23 = CMAKE_PROGRESS_23 = 24
CMAKE_PROGRESS_24 = CMAKE_PROGRESS_24 =
CMAKE_PROGRESS_25 = 25 CMAKE_PROGRESS_25 = 25
CMAKE_PROGRESS_26 = CMAKE_PROGRESS_26 =
...@@ -36,10 +36,10 @@ CMAKE_PROGRESS_35 = ...@@ -36,10 +36,10 @@ CMAKE_PROGRESS_35 =
CMAKE_PROGRESS_36 = CMAKE_PROGRESS_36 =
CMAKE_PROGRESS_37 = 29 CMAKE_PROGRESS_37 = 29
CMAKE_PROGRESS_38 = CMAKE_PROGRESS_38 =
CMAKE_PROGRESS_39 = 30 CMAKE_PROGRESS_39 =
CMAKE_PROGRESS_40 = CMAKE_PROGRESS_40 = 30
CMAKE_PROGRESS_41 = CMAKE_PROGRESS_41 =
CMAKE_PROGRESS_42 = 31 CMAKE_PROGRESS_42 =
CMAKE_PROGRESS_43 = CMAKE_PROGRESS_43 = 31
CMAKE_PROGRESS_44 = CMAKE_PROGRESS_44 =
...@@ -6,8 +6,8 @@ CMAKE_PROGRESS_5 = ...@@ -6,8 +6,8 @@ CMAKE_PROGRESS_5 =
CMAKE_PROGRESS_6 = CMAKE_PROGRESS_6 =
CMAKE_PROGRESS_7 = 87 CMAKE_PROGRESS_7 = 87
CMAKE_PROGRESS_8 = CMAKE_PROGRESS_8 =
CMAKE_PROGRESS_9 = CMAKE_PROGRESS_9 = 88
CMAKE_PROGRESS_10 = 88 CMAKE_PROGRESS_10 =
CMAKE_PROGRESS_11 = CMAKE_PROGRESS_11 =
CMAKE_PROGRESS_12 = 89 CMAKE_PROGRESS_12 = 89
...@@ -6,11 +6,11 @@ CMAKE_PROGRESS_5 = ...@@ -6,11 +6,11 @@ CMAKE_PROGRESS_5 =
CMAKE_PROGRESS_6 = CMAKE_PROGRESS_6 =
CMAKE_PROGRESS_7 = 56 CMAKE_PROGRESS_7 = 56
CMAKE_PROGRESS_8 = CMAKE_PROGRESS_8 =
CMAKE_PROGRESS_9 = CMAKE_PROGRESS_9 = 57
CMAKE_PROGRESS_10 = 57 CMAKE_PROGRESS_10 =
CMAKE_PROGRESS_11 = CMAKE_PROGRESS_11 =
CMAKE_PROGRESS_12 = CMAKE_PROGRESS_12 = 58
CMAKE_PROGRESS_13 = 58 CMAKE_PROGRESS_13 =
CMAKE_PROGRESS_14 = CMAKE_PROGRESS_14 =
CMAKE_PROGRESS_15 = 59 CMAKE_PROGRESS_15 = 59
CMAKE_PROGRESS_16 = CMAKE_PROGRESS_16 =
...@@ -23,11 +23,11 @@ CMAKE_PROGRESS_22 = ...@@ -23,11 +23,11 @@ CMAKE_PROGRESS_22 =
CMAKE_PROGRESS_23 = CMAKE_PROGRESS_23 =
CMAKE_PROGRESS_24 = 62 CMAKE_PROGRESS_24 = 62
CMAKE_PROGRESS_25 = CMAKE_PROGRESS_25 =
CMAKE_PROGRESS_26 = CMAKE_PROGRESS_26 = 63
CMAKE_PROGRESS_27 = 63 CMAKE_PROGRESS_27 =
CMAKE_PROGRESS_28 = CMAKE_PROGRESS_28 =
CMAKE_PROGRESS_29 = CMAKE_PROGRESS_29 = 64
CMAKE_PROGRESS_30 = 64 CMAKE_PROGRESS_30 =
CMAKE_PROGRESS_31 = CMAKE_PROGRESS_31 =
CMAKE_PROGRESS_32 = 65 CMAKE_PROGRESS_32 = 65
CMAKE_PROGRESS_33 = CMAKE_PROGRESS_33 =
...@@ -40,11 +40,11 @@ CMAKE_PROGRESS_39 = ...@@ -40,11 +40,11 @@ CMAKE_PROGRESS_39 =
CMAKE_PROGRESS_40 = CMAKE_PROGRESS_40 =
CMAKE_PROGRESS_41 = 68 CMAKE_PROGRESS_41 = 68
CMAKE_PROGRESS_42 = CMAKE_PROGRESS_42 =
CMAKE_PROGRESS_43 = CMAKE_PROGRESS_43 = 69
CMAKE_PROGRESS_44 = 69 CMAKE_PROGRESS_44 =
CMAKE_PROGRESS_45 = CMAKE_PROGRESS_45 =
CMAKE_PROGRESS_46 = CMAKE_PROGRESS_46 = 70
CMAKE_PROGRESS_47 = 70 CMAKE_PROGRESS_47 =
CMAKE_PROGRESS_48 = CMAKE_PROGRESS_48 =
CMAKE_PROGRESS_49 = 71 CMAKE_PROGRESS_49 = 71
CMAKE_PROGRESS_50 = CMAKE_PROGRESS_50 =
...@@ -57,11 +57,11 @@ CMAKE_PROGRESS_56 = ...@@ -57,11 +57,11 @@ CMAKE_PROGRESS_56 =
CMAKE_PROGRESS_57 = CMAKE_PROGRESS_57 =
CMAKE_PROGRESS_58 = 74 CMAKE_PROGRESS_58 = 74
CMAKE_PROGRESS_59 = CMAKE_PROGRESS_59 =
CMAKE_PROGRESS_60 = CMAKE_PROGRESS_60 = 75
CMAKE_PROGRESS_61 = 75 CMAKE_PROGRESS_61 =
CMAKE_PROGRESS_62 = CMAKE_PROGRESS_62 =
CMAKE_PROGRESS_63 = CMAKE_PROGRESS_63 = 76
CMAKE_PROGRESS_64 = 76 CMAKE_PROGRESS_64 =
CMAKE_PROGRESS_65 = CMAKE_PROGRESS_65 =
CMAKE_PROGRESS_66 = 77 CMAKE_PROGRESS_66 = 77
CMAKE_PROGRESS_67 = CMAKE_PROGRESS_67 =
......
...@@ -5,9 +5,7 @@ ...@@ -5,9 +5,7 @@
int g_device_delay_back_count =0;//设备计时,比如坦克打击倒退逻辑 int g_device_delay_back_count =0;//设备计时,比如坦克打击倒退逻辑
int abnormal_pin_pwm_stop=0; int g_device_type =0; //设备详细类型,让其他地方判断,比如tank0202、car0101
int g_device_type =0; //设备详细类型,比如tank0202、car0101
const deviceconfig_t device_configs[] = { const deviceconfig_t device_configs[] = {
// car0101配置 // car0101配置
...@@ -90,8 +88,8 @@ const deviceconfig_t device_configs[] = { ...@@ -90,8 +88,8 @@ const deviceconfig_t device_configs[] = {
{ {
.device_id = DEVICE_SHIP0301, .device_id = DEVICE_SHIP0301,
.device_name = "ship0301", .device_name = "ship0301",
.gpio_pins = {5, 6, 7, 10, 16, 20, 22, 23, 24, 25, 26,-1},/* 补充GPIO引脚 */ .gpio_pins = {6, 16, 20, 22, 23,-1},/* 补充GPIO引脚 */
.gpio_pwms = {27,-1}, .gpio_pwms = {5 , 7 ,24,26, 27,-1},
.device_pwm_init = physics_pwm_init, .device_pwm_init = physics_pwm_init,
.device_control_stop = ship0301_stop,/* 补充速度控制函数 */ .device_control_stop = ship0301_stop,/* 补充速度控制函数 */
.emergency_code = 301 .emergency_code = 301
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "browser_open.h" #include "browser_open.h"
#include "device_fileopen.h" #include "device_fileopen.h"
#include "device_identity.h" #include "device_identity.h"
#include "http_config_mqtt.h"
char gwebcam[2048];//存放启动火狐网站命令 char gwebcam[2048];//存放启动火狐网站命令
......
#include "device_identity.h"
#include "http_config_mqtt.h"
#include<curl/curl.h>
#include "cjson/cJSON.h"
#include "http_request.h"
DEVICE_MQTTCONFIG g_mqtt_cam_config;
DEVICE_MQTTCONFIG *g_mqtt_cam_config_t = &g_mqtt_cam_config;
int parse_device_config(const char *json_str) {
// 解析 JSON
cJSON *root = cJSON_Parse(json_str);
if (!root) {
fprintf(stderr, "JSON 解析失败: %s\n", cJSON_GetErrorPtr());
return -1;
}
// 1. 提取顶层字段
cJSON *message = cJSON_GetObjectItemCaseSensitive(root, "message");
cJSON *code = cJSON_GetObjectItemCaseSensitive(root, "code");
if (cJSON_IsString(message) && cJSON_IsNumber(code)) {
my_zlog_debug("状态: %s", message->valuestring);
my_zlog_debug("状态码: %d", code->valueint);
if(code->valueint!=200){
my_zlog_error("code error");
return -1;
}
}
// 2. 提取 data 对象
cJSON *data = cJSON_GetObjectItemCaseSensitive(root, "data");
if (data) {
// 3. 提取 mqtt 服务器列表
cJSON *mqtt = cJSON_GetObjectItemCaseSensitive(data, "mqtt");
if (cJSON_IsArray(mqtt)) {
my_zlog_info("MQTT 服务器:");
cJSON *item;
int i = 0;
cJSON_ArrayForEach(item, mqtt) {
if (cJSON_IsString(item)) {
my_zlog_debug(" [%d] %s", i++, item->valuestring);
strncpy(g_mqtt_cam_config_t->mqtt_servers[i], item->valuestring, sizeof(g_mqtt_cam_config_t->mqtt_servers[i]) - 1);
g_mqtt_cam_config_t->mqtt_servers[i][sizeof(g_mqtt_cam_config_t->mqtt_servers[i]) - 1] = '\0';
}
g_mqtt_cam_config_t->mqtt_count = i;
}
}
// 4. 提取 api 和 videoUrl
cJSON *videoUrl = cJSON_GetObjectItemCaseSensitive(data, "videoUrl");
if (cJSON_IsString(videoUrl)) {
my_zlog_debug("视频地址: %s", videoUrl->valuestring);
strncpy(g_mqtt_cam_config_t->videourl, videoUrl->valuestring, sizeof(g_mqtt_cam_config_t->videourl) - 1);
g_mqtt_cam_config_t->videourl[sizeof(g_mqtt_cam_config_t->videourl) - 1] = '\0';
}
}
// 释放内存
cJSON_Delete(root);
}
// 拉取并解析 JSON 数据的函数
int deviceconfig_mqtt_video_init() {
CURL *curl;
CURLcode res;
struct MemoryStruct chunk = {NULL, 0};
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if (!curl) {
fprintf(stderr, "Failed to initialize CURL\n");
my_zlog_error("Failed to initialize CURL");
return -1;
}
// 构造请求 URL
char url[512];
snprintf(url, sizeof(url), "http://192.168.0.112:8111/device/getConfig?deviceNo=%s", mqtt_topic_pure_number());
my_zlog_info("url:%s",url);
// 设置 CURL 选项
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writememorycallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");
// 执行 HTTP 请求
res = curl_easy_perform(curl);
if (res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
my_zlog_error("curl_easy_perform() failed");
return -1;
} else {
// 解析返回的 JSON 数据
cJSON *root = cJSON_Parse(chunk.memory);
if (!root) {
fprintf(stderr, "JSON parse error: %s\n", cJSON_GetErrorPtr());
my_zlog_error("JSON parse error");
} else {
parse_device_config(chunk.memory);
}
}
// 清理资源
free(chunk.memory);
curl_easy_cleanup(curl);
curl_global_cleanup();
return 0;
}
/*mqtt服务器和视频流地址初始化*/
int http_mqtt_video_init(){
for(int i =0; i<3;i++){
if(deviceconfig_mqtt_video_init()==0){
my_zlog_info("http_mqtt_video_init success");
return 0;
}else {
my_zlog_info("http_mqtt_video_init reconnect");
}
}
my_zlog_error("http_mqtt_video_init failure");
return -1;
}
\ No newline at end of file
#ifndef _HTTP_CONFIG_MQTT_H
#define _HTTP_CONFIG_MQTT_H
#include "common.h"
typedef struct{
char videourl[512];
char mqtt_servers[10][256];
int mqtt_count;
}DEVICE_MQTTCONFIG;
extern DEVICE_MQTTCONFIG *g_mqtt_cam_config_t ;
/*mqtt服务器和视频流地址初始化*/
int http_mqtt_video_init();
#endif
\ No newline at end of file
...@@ -15,7 +15,7 @@ double g_err_voltage_value=9.7; ...@@ -15,7 +15,7 @@ double g_err_voltage_value=9.7;
double g_shot_speed_value=0.5; double g_shot_speed_value=0.5;
// 回调函数,用于处理接收到的数据 // 回调函数,用于处理接收到的数据
static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) { size_t writememorycallback(void *contents, size_t size, size_t nmemb, void *userp) {
size_t realsize = size * nmemb; size_t realsize = size * nmemb;
struct MemoryStruct *mem = (struct MemoryStruct *)userp; struct MemoryStruct *mem = (struct MemoryStruct *)userp;
...@@ -145,7 +145,7 @@ int request_date_open() {//请求数据 ...@@ -145,7 +145,7 @@ int request_date_open() {//请求数据
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
// 设置接收数据的回调函数 // 设置接收数据的回调函数
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writememorycallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
// 执行请求 // 执行请求
......
...@@ -18,4 +18,7 @@ extern double g_warn_voltage_value;//警告电压 ...@@ -18,4 +18,7 @@ extern double g_warn_voltage_value;//警告电压
extern double g_err_voltage_value;//错误电压 extern double g_err_voltage_value;//错误电压
int request_date();//请求数据 int request_date();//请求数据
size_t writememorycallback(void *contents, size_t size, size_t nmemb, void *userp);
#endif #endif
...@@ -4,11 +4,12 @@ ...@@ -4,11 +4,12 @@
#include "device_identity.h" #include "device_identity.h"
#include "mqtt_infor_handle.h" #include "mqtt_infor_handle.h"
#include "mylog.h" #include "mylog.h"
#include "http_config_mqtt.h"
struct mosquitto *mosq; struct mosquitto *mosq;
//struct mosquitto *mosq1;
uint16_t AppExit_pin_pwm=0;//判断坦克或者车的退出 //struct mosquitto *mosq2;
//mqtt初始化 //mqtt初始化
int mqtt_init() { int mqtt_init() {
...@@ -21,6 +22,8 @@ int mqtt_init() { ...@@ -21,6 +22,8 @@ int mqtt_init() {
return -1; return -1;
} }
mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5); mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5);
//mosquitto_int_option(mosq1, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5);
//mosquitto_int_option(mosq2, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5);
return 0; return 0;
} }
......
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