diff --git a/src/main.cpp b/src/main.cpp index 47cbb10..2788b50 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -310,6 +311,32 @@ static void draw_epaper_callback(GxEPD2_DISPLAY_CLASSprint(" UTC"); } +static void upload_data(void) +{ + String json_string = String("{" + "\"scd30_co2\":") + scd30.CO2 + + ", \"scd30_temperature\":" + scd30.temperature + + ", \"scd30_humidity\":" + scd30.relative_humidity + "}"; + + // send the data to graphite + HTTPClient client; + client.begin("http://stats.tkolb.de/sensor/sensorcube.php"); + client.addHeader("Content-Type", "application/json"); + + int httpResponseCode = client.POST(json_string); + + if(httpResponseCode>0) { + Serial.print("HTTP request result: "); + Serial.println(httpResponseCode); //Print return code + + //String response = http.getString(); //Get the response to the request + //Serial.println(response); //Print request answer + } else { + Serial.print("Error on sending POST: "); + Serial.println(httpResponseCode); + } +} + void loop(void) { static bool first_scd30_readout = true; @@ -345,9 +372,14 @@ void loop(void) Serial.println(" %"); Serial.println(""); + Serial.println("\nUploading..."); + upload_data(); + if((now - lastEPaperRefresh) >= 60000) { + Serial.println("Rendering display..."); lastEPaperRefresh = now; epaper_draw_and_hibernate(draw_epaper_callback, false); + Serial.println("Display updated."); timeseries_prune(&ts_scd30_humidity, 3600); // keep the last hour }