diff --git a/src/commser.cpp b/src/commser.cpp index 8f9b51d..3a89935 100644 --- a/src/commser.cpp +++ b/src/commser.cpp @@ -16,10 +16,10 @@ static const char *MOUDLENAME = "COMMSER"; /*项目对象*/ // char* ssid = "szdot"; //wifi帐号 // char* password = "Ttaj@#*.com"; //wifi密码 -// char *ssid = "flicube"; // wifi帐号 -// char *password = "fxmf0622"; // wifi密码 -char *ssid = "fxmf_sc01"; // 4g wifi帐号 -char *password = "12345678"; // 4g wifi密码 +char *ssid = "flicube"; // wifi帐号 +char *password = "fxmf0622"; // wifi密码 +// char *ssid = "fxmf_sc01"; // 4g wifi帐号 +// char *password = "12345678"; // 4g wifi密码 char *mqttServer = "szdot.top"; // mqtt地址 int mqttPort = 1883; // mqtt端口 char *mqttName = "admin"; // mqtt帐号 @@ -628,24 +628,27 @@ void pubThread() // 遍历 有更新的数据 组成一个json对象 for (int i = 0; i < topicPubCount; i++) { - if (topicPubMsg[i] != oldMsg[i]) + if (i == 0) + { // 心跳包 每每向心跳主题发布信息 + // 启动飞控 第一次心跳 ps:防止飞控 滞后启动 拿不到数据 + if (fc.getIsInit()) + { + fc.setIsInit(false); + fc.mav_request_data(); // 再向飞控请求一次 设定飞控输出数据流内容 + } + // 设置对象成员 ps:心跳 + doc[topicPub[0]] = topicPubMsg[0]; + } + else if (i == 10) { - if (i == 0) - { // 心跳包 每每向心跳主题发布信息 - // 启动飞控 第一次心跳 ps:防止飞控 滞后启动 拿不到数据 - if (fc.getIsInit()) - { - fc.setIsInit(false); - fc.mav_request_data(); // 再向飞控请求一次 设定飞控输出数据流内容 - } - // 设置对象成员 ps:心跳 - doc[topicPub[0]] = topicPubMsg[0]; - } - else - { // 非心跳 有更新 录入成员 - doc[topicPub[i]] = topicPubMsg[i]; - oldMsg[i] = topicPubMsg[i]; - } + // 设置对象成员 ps:飞机状态 state + doc[topicPub[10]] = topicPubMsg[10]; + } + else if (topicPubMsg[i] != oldMsg[i]) + { + // 非心跳 非飞机状态 有更新 录入成员 + doc[topicPub[i]] = topicPubMsg[i]; + oldMsg[i] = topicPubMsg[i]; } } // 将JSON对象序列化为JSON字符串