         mqttClient.connect(clientID);
         mqttSubscribeRoutine();
       }
-      mqttClient.publish((char*)mqttTopic, msg);
-      delay(10);
-      //sent the same msg to partner which may monitor this topic, current work around
-      mqttClient.publish((char*)mqttTopicSelf, msg); 
-      Serial.println("MQTT sending");
+      mqttPublishRoutine(1);      
+      mqttClient.disconnect();
       LastPostTime = currentTime;
       // example:
       // Sensors/DustSensor |device_id=LASD-wuulong|time=20645|device=LinkItONE|values=0|gps=$GPGGA,235959.000,2448.0338,N,12059.5733,E,0,0,,160.1,M,15.0,M,,*4F
-      mqttClient.loop();
+      
       
       if(LWiFi.status()!=LWIFI_STATUS_CONNECTED){
         wifi_ready=0;

  
  Serial.print("-----Loop ID: ");
  Serial.print(loop_cnt);
  loop_cnt++;
  Serial.println(" -----");
  // GPS  

void mqttSubscribeRoutine(){
  mqttClient.subscribe((char*)mqttTopicSelf);
  mqttClient.subscribe((char*)mqttTopicPartner);

  Serial.print("Subscribing ");
  Serial.println(mqttTopicSelf);
  Serial.print("Subscribing ");
  Serial.println(mqttTopicPartner);
}
#else
void mqttSubscribeRoutine(){}
#endif

void mqttPublishRoutine(int bPartner){
      mqttClient.publish((char*)mqttTopic, msg);
      //delay(100);
#if ALARM_ENABLE == 1
      //sent the same msg to partner which may monitor this topic, current work around
      if(bPartner){
        mqttClient.publish((char*)mqttTopicSelf, msg); 
      }
#endif
      mqttClient.loop();
      Serial.println("MQTT sending");
  
}
String stringTopicCmp = "";
// callback to handle incomming MQTT messages
void msgCallback(char* topic, byte* payload, unsigned int len) { 
