diff --git a/sensor.ino b/sensor.ino index 6859b44..2e99c1d 100644 --- a/sensor.ino +++ b/sensor.ino @@ -117,6 +117,7 @@ void setup() { void loop() { if ((millis() - lastTime) > timerDelay) { + lastTime = millis(); //timeClient.update(); //Get a time structure //time_t epochTime = timeClient.getEpochTime(); @@ -140,34 +141,35 @@ void loop() { Serial.printf("TVOC = %d \n", tvoc); Serial.println(); - if(WiFi.status()== WL_CONNECTED){ - WiFiClientSecure client; - client.setInsecure(); - HTTPClient http; - // Your Domain name with URL path or IP address with path - http.begin(client, serverName); - // Specify content-type header - http.addHeader("Content-Type", "application/json"); - // Data to send with HTTP POST - String httpRequestData = "{\"sender\":\"" + String(sender) + "\",\"data\":[" + String(temperature) + "," + String(temperature_2) + "," + String(pressure) + "," + String(humidity) + "," + String(co2) + "," + String(tvoc) + "]}"; - // Send HTTP POST request - Serial.println(httpRequestData); - int httpResponseCode = http.POST(httpRequestData); - - Serial.print("HTTP Response code: "); - Serial.println(httpResponseCode); - - // Free resources - http.end(); - } - else { + if(WiFi.status()!= WL_CONNECTED){ Serial.println("WiFi Disconnected"); WiFi.begin(WIFI_SSID, WIFI_PASS); + while (WiFi.status() != WL_CONNECTED) + { + delay(100); + Serial.print(".1."); + } } + WiFiClientSecure client; + client.setInsecure(); + HTTPClient http; + // Your Domain name with URL path or IP address with path + http.begin(client, serverName); + // Specify content-type header + http.addHeader("Content-Type", "application/json"); + // Data to send with HTTP POST + String httpRequestData = "{\"sender\":\"" + String(sender) + "\",\"data\":[" + String(temperature) + "," + String(temperature_2) + "," + String(pressure) + "," + String(humidity) + "," + String(co2) + "," + String(tvoc) + "]}"; + // Send HTTP POST request + Serial.println(httpRequestData); + int httpResponseCode = http.POST(httpRequestData); + + Serial.print("HTTP Response code: "); + Serial.println(httpResponseCode); + + // Free resources + http.end(); - - lastTime = millis(); - + } } \ No newline at end of file