 
 unsigned long lastConnectionTime = 0;            
 const unsigned long pollingInterval = 5L * 1000L; // 5 sec polling delay, in milliseconds
-
 
 int status = WL_IDLE_STATUS;
 

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
	Serial.println("wait 10 seconds for connection");
    delay(10000);
  }
  Serial.println("connection succeeded");
}

void azureMessageloop() 

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

void loop(){
  val = digitalRead(MKR1000_PINPIR1);   // read input value
  if (val == HIGH) {                    // check if the input is HIGH
    digitalWrite(MKR1000_LED, HIGH);    // turn LED ON
    //delay(150);

    if (lockLow) {           
         lockLow = false;               //makes sure we wait for a transition to LOW before any further output is made:
         duration = millis()/1000;
         Serial.println("---");
         Serial.print("motion detected at ");
         Serial.print(duration);
         Serial.println(" sec");                 
         
         azureHttpPost("{deviceId:NeshMKR100Dev1, motion:1,elapsed:"+ duration + "}");
    }
    
    takeLowTime = true;
  } 
  else {
      digitalWrite(MKR1000_LED, LOW);   // turn LED OFF
      //delay(150);    

       if(takeLowTime){
          lowIn = millis();             //save the time of the transition from high to LOW
          takeLowTime = false;          //make sure this is only done at the start of a LOW phase
        }    

       //if the sensor is low for more than the given pause, we assume that no more motion is going to happen
       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;              
           Serial.print("motion ended at ");      //output
           Serial.print(duration);
           Serial.println(" sec");    
           
          azureHttpPost("{deviceId:NeshMKR100Dev1, motion:0,elapsed:"+ duration + "}");  
    }
  }
}