                 if(Record!="@"){
                   Record.toCharArray(msg, Record.length()+1);
                   Serial.println(msg);
-
-                  mqttPublishRoutine(0);
-                  
-                  LastPostTime = currentTime;
-
-                  //mqttClient.publish(mqttTopic, msg);
-                  //sent the same msg to partner which may monitor this topic, current work around
-                  //these delay msg may cause problem to partner, not send it now.
-                  //mqttClient.publish(mqttTopicSelf, msg);
-                  Serial.print(".");
-                  dotCnt++;
-                  if((dotCnt % 1) ==0){
-                    Serial.println(".");
+                  if(checkWifiConnected()==1){
+                    mqttPublishRoutine(0);
+                    
+                    LastPostTime = currentTime;
+  
+                    //mqttClient.publish(mqttTopic, msg);
+                    //sent the same msg to partner which may monitor this topic, current work around
+                    //these delay msg may cause problem to partner, not send it now.
+                    //mqttClient.publish(mqttTopicSelf, msg);
+                    Serial.print(".");
+                    dotCnt++;
+                    if((dotCnt % 1) ==0){
+                      Serial.println(".");
+                    }
+                  }else{
+                    upload_fail=1; 
+                    break; 
                   }
                   
                 }

void logSend(){
  int dotCnt=0;
  boolean bConnected;

  //Drv.remove((char*)LOG_FILENAME); // for debug
  // upload log only when wifi ready

      mqttClient.disconnect();
    }*/
    wifistatus = LWiFi.status();
    
    if (wifistatus!=LWIFI_STATUS_DISABLED && failedCounter>3){
        Serial.println("before LWiFi.end()...");
        LWiFi.end();
