        if(!lockLow && millis() - lowIn > pause){  
            //makes sure this block of code is only executed again after a new motion sequence has been detected
            lockLow = true;        
-           duration = (millis() - pause)/1000;              
+           duration = (millis() - pause)/1000;   
+           Serial.println("---");           
            Serial.print("motion ended at ");      //output
            Serial.print(duration);
            Serial.println(" sec");    
-           delay(50);
-          webServiceSucceeded = azureHttpPost("{deviceId:NeshMKR100Dev1, motion:0,timestamp:" + getTimeStamp() + "}");
-          //webServiceSucceeded = httpRequest("POST", senduri,"text/plain","{deviceId:NeshMKR100Dev1, motion:0,timestamp:" + getTimeStamp() + "}");
-          if(webServiceSucceeded == false)
-         {
-            Serial.println("retrying webservice call ");
-            azureHttpPost("{deviceId:NeshMKR100Dev1, motion:0,timestamp:" + getTimeStamp() + "}");
-            //webServiceSucceeded = httpRequest("POST", senduri,"text/plain","{deviceId:NeshMKR100Dev1, motion:0,timestamp:" + getTimeStamp() + "}");
-         }
+           delay(150);
+           
+           if (! String(rtc.getYear()).equals("0"))
+           {
+             timeStamp = getTimeStamp();
+             Serial.println(timeStamp);
+             webServiceSucceeded = azureHttpPost("{deviceId:NeshMKR100Dev1, motion:0,timestamp:" + timeStamp + "}");
+             //webServiceSucceeded = httpRequest("POST", senduri,"text/plain","{deviceId:NeshMKR100Dev1, motion:0,timestamp:" + timeStamp + "}");
+             if(webServiceSucceeded == false)
+             {
+                delay(150);
+                Serial.println("retrying webservice call ");
+                azureHttpPost("{deviceId:NeshMKR100Dev1, motion:0,timestamp:" + timeStamp + "}");
+                //webServiceSucceeded = httpRequest("POST", senduri,"text/plain","{deviceId:NeshMKR100Dev1, motion:0,timestamp:" + timeStamp + "}");
+             }
+             else
+             {
+               delay(1000);//delay at least 1 sec to allow web service to finish
+             }    
+           }       
     }
   }
 
   /* ------Poling for Cloud-to-Device messages------*/
-  
+  delay(150);
   String response = "";
   char c;
   ///read response if WiFi Client is available

      {
          client.println();
      }

      return true;
    }
  else {
    // if you couldn't make a connection:
    Serial.println("connection to azure webservice failed");
    reconnetWifi();
    return false;
  }    


void syncRTCReceived(String resp)
{
  //String resp = "SyncRTC:"2016-4-10T21:00";
  int idxStart=10;  
  int idxEnd = resp.indexOf("-", idxStart);
  year = resp.substring(idxStart,idxEnd).toInt();  

