From a0b04aad095dcf9ee030ed120c37331ffd077755 Mon Sep 17 00:00:00 2001 From: zhangsheng Date: Tue, 27 Aug 2024 12:15:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96mqtt=20client=20ID=EF=BC=8C?= =?UTF-8?q?=E5=9C=A8=E7=9C=8B=E9=97=A8=E7=8B=97=E5=8A=A0=E4=BA=86=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E7=BA=BF=E7=A8=8B=E7=8A=B6=E6=80=81=E5=88=A4=E6=96=AD?= =?UTF-8?q?=EF=BC=8C3.2.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/SH_global.h | 3 ++- main.cpp | 12 +++++++++++- mqttclient/SH_MqttClient.cpp | 3 ++- platform/SH_PlatformInit.cpp | 1 + threadfunc/SH_ThreadFunc.cpp | 1 + 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/common/SH_global.h b/common/SH_global.h index e893d95..c67b7d6 100644 --- a/common/SH_global.h +++ b/common/SH_global.h @@ -20,7 +20,7 @@ enum enumZigBeeTransmitStatus { //#define NR5G_MODULE -//#define Q4G_MODULE +#define Q4G_MODULE //#define WIFI_MODULE //#define NR5G_MEIGE //#define G2UL_GATEWAY @@ -47,6 +47,7 @@ public : static std::string Config_G; //配置文件 static std::string ServerIP; //服务器地址 static int ServerPort; //服务器端口 + static int threadStatus; static std::string UartName_G; static TopicList Topic_G; //发布的主题 static ZigbeeInfo ZigbeeInfo_G; //gateway zigbee info diff --git a/main.cpp b/main.cpp index 1618a43..05a71ff 100644 --- a/main.cpp +++ b/main.cpp @@ -138,7 +138,7 @@ int main(int argc, char *argv[]) startHeart.detach(); int fd = OpenWatchDog(); - + int count = 0; while (GlobalConfig::QuitFlag_G) { #ifdef G2UL_GATEWAY gpio_set(GlobalConfig::GPIO_G.hardWatchDog,1); @@ -147,6 +147,16 @@ int main(int argc, char *argv[]) #endif WriteWatchDog(fd); sleep(20); + if(GlobalConfig::threadStatus == 0){ + count ++; + }else if(GlobalConfig::threadStatus == 1){ + GlobalConfig::threadStatus = 0; + count = 0; + } + if(count >= 180){ + LOG_ERROR("===========threadStatus ========failed \n"); + break; + } // data_publish(senddata.c_str(), GlobalConfig::Topic_G.mPubData.c_str()); } diff --git a/mqttclient/SH_MqttClient.cpp b/mqttclient/SH_MqttClient.cpp index 830d5d0..3a24cc4 100644 --- a/mqttclient/SH_MqttClient.cpp +++ b/mqttclient/SH_MqttClient.cpp @@ -247,7 +247,8 @@ int start_client(const char *boardname, const char *gwid, const char* gwip, cons mosquitto_lib_cleanup(); return 1; } - snprintf(id, len, "mosqsub/%d-%s", getpid(), hostname); + + snprintf(id, len, "mosqsub/%s-%s", GlobalConfig::ZigbeeInfo_G.PanID.c_str(), hostname); if (strlen(id) > MOSQ_MQTT_ID_MAX_LENGTH){ /* Enforce maximum client id length of 23 characters */ id[MOSQ_MQTT_ID_MAX_LENGTH] = '\0'; diff --git a/platform/SH_PlatformInit.cpp b/platform/SH_PlatformInit.cpp index 9201d51..a1be577 100644 --- a/platform/SH_PlatformInit.cpp +++ b/platform/SH_PlatformInit.cpp @@ -23,6 +23,7 @@ std::string GlobalConfig::NR5GTemp = ""; int GlobalConfig::serverStatus = 0; int GlobalConfig::NetSignal = 0; int GlobalConfig::ServerPort = 0; +int GlobalConfig::threadStatus = 1; TopicList GlobalConfig::Topic_G; diff --git a/threadfunc/SH_ThreadFunc.cpp b/threadfunc/SH_ThreadFunc.cpp index 27d2044..fa1ecef 100644 --- a/threadfunc/SH_ThreadFunc.cpp +++ b/threadfunc/SH_ThreadFunc.cpp @@ -50,6 +50,7 @@ void CheckThread() int connectCount = 0; while (GlobalConfig::QuitFlag_G) { + GlobalConfig::threadStatus = 1; if (10 == heart_count) { // StatusPub(); if (GlobalConfig::LinkCount > 30) {