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 <WiFi.h>
|
||||||
#include <WiFiMulti.h>
|
#include <WiFiMulti.h>
|
||||||
#include <NTPClient.h>
|
#include <NTPClient.h>
|
||||||
|
#include <HTTPClient.h>
|
||||||
|
|
||||||
#include <LittleFS.h>
|
#include <LittleFS.h>
|
||||||
|
|
||||||
|
@ -310,6 +311,32 @@ static void draw_epaper_callback(GxEPD2_DISPLAY_CLASS<GxEPD2_DRIVER_CLASS, MAX_H
|
||||||
display->print(" UTC");
|
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)
|
void loop(void)
|
||||||
{
|
{
|
||||||
static bool first_scd30_readout = true;
|
static bool first_scd30_readout = true;
|
||||||
|
@ -345,9 +372,14 @@ void loop(void)
|
||||||
Serial.println(" %");
|
Serial.println(" %");
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
|
|
||||||
|
Serial.println("\nUploading...");
|
||||||
|
upload_data();
|
||||||
|
|
||||||
if((now - lastEPaperRefresh) >= 60000) {
|
if((now - lastEPaperRefresh) >= 60000) {
|
||||||
|
Serial.println("Rendering display...");
|
||||||
lastEPaperRefresh = now;
|
lastEPaperRefresh = now;
|
||||||
epaper_draw_and_hibernate(draw_epaper_callback, false);
|
epaper_draw_and_hibernate(draw_epaper_callback, false);
|
||||||
|
Serial.println("Display updated.");
|
||||||
|
|
||||||
timeseries_prune(&ts_scd30_humidity, 3600); // keep the last hour
|
timeseries_prune(&ts_scd30_humidity, 3600); // keep the last hour
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue