Upload the data
This commit is contained in:
parent
a83bac914e
commit
b417554444
32
src/main.cpp
32
src/main.cpp
|
@ -4,6 +4,7 @@
|
|||
#include <WiFi.h>
|
||||
#include <WiFiMulti.h>
|
||||
#include <NTPClient.h>
|
||||
#include <HTTPClient.h>
|
||||
|
||||
#include <LittleFS.h>
|
||||
|
||||
|
@ -310,6 +311,32 @@ static void draw_epaper_callback(GxEPD2_DISPLAY_CLASS<GxEPD2_DRIVER_CLASS, MAX_H
|
|||
display->print(" 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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue