sensor.ino aktualisiert

This commit is contained in:
Julian Kiedaisch 2025-06-05 08:14:39 +00:00
parent 85670b839a
commit d361e4c380

View File

@ -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();
}
}