Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float getActiveSensorTemperature(String serverName)
- {
- WiFiClient wclient;
- HTTPClient http;
- String json, timestamp, uname = "";
- float temp = -1;
- char result[64];
- DynamicJsonDocument document(1024);
- http.begin(wclient, serverName);
- http.addHeader("Content-Type", "application/text");
- int httpResponseCode = http.GET();
- if (httpResponseCode > 0) {
- json = http.getString();
- deserializeJson(document, json);
- JsonArray array = document.as<JsonArray>();
- temp = document[0]["temperature"].as<float>();
- timestamp = document[0]["timestamp"].as<String>();
- uname = document[0]["uname"].as<String>();
- Serial.print(getTimestamp() + " : Room temperature (from database): "); Serial.print(temp); Serial.println(" °C - (" + uname + " - " + timestamp + ")");
- } else
- Serial.println(getTimestamp() + " : No response " + httpResponseCode);
- http.end();
- return temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement