diff --git a/examples/basicDB/basicDB.ino b/examples/basicDB/basicDB.ino index 3f212bc..ee7e7a4 100644 --- a/examples/basicDB/basicDB.ino +++ b/examples/basicDB/basicDB.ino @@ -7,7 +7,7 @@ * json format. Internet access is necessary in order to sync network time. * Updates are entered into the database every minute through a ticker. ******************************************************************************************/ -#include // You must use FAT for rrdtool +#include // rrdtool will not work on SPIFFS/LITTLEFS! #include #include #include @@ -15,8 +15,8 @@ #define BUILD_TEST_DATA -const char* myssid = "myssid"; -const char* mypasswd = "mypasswd"; +const char* myssid = "wifiname"; +const char* mypasswd = "wifipassword"; const char ntpSrv[] = "pool.ntp.org"; const char* rrd_files[] = {"/ffat/rrd_0.rrd", "/ffat/rrd_1.rrd"}; // Must use full vfs path @@ -91,31 +91,40 @@ void handleStatus() { void fakeData(uint8_t rrd_mask) { if (!rrd_mask) return; - Serial.println("Generating fake data. This will take ~10 minutes"); - uint32_t first_update = time(NULL) - 120000; - uint16_t rrd_step = 60; + Serial.println("Generating fake data. This will take ~90 seconds"); + const uint32_t range = 140000; + const uint32_t now = time(NULL); + const uint32_t first_update = now - range; + const uint16_t rrd_step = 60; + const uint8_t chunk = 100; uint32_t counter0 = 0; - size_t counter1 = 0; - for (uint32_t x=first_update; x now) c_time = now; + counter0 += random(100000); + filler0[y] = (char*) malloc(24); + snprintf(filler0[y], 23, "%10u:%u", c_time, counter0); + log_v("filler0[%d]: %s", x*chunk+y, filler0[y]); + filler1[y] = (char*) malloc(18); + snprintf(filler1[y], 17, "%10u:%5.2f", c_time, sin(c_time/600.0*2*M_PI)*50+50); + log_v("filler1[%d]: %s", x*chunk+y, filler1[y]); + } + if (rrd_mask & 1) rrd_update_r(rrd_files[0], NULL, chunk, (const char**)&filler0); + if (rrd_mask & 2) rrd_update_r(rrd_files[1], NULL, chunk, (const char**)&filler1); + for (uint16_t y=0; y // https://github.com/tobozo/ESP32-PsRamFS/ +#include // https://github.com/lorol/LITTLEFS +#include +#include +#include +#include + +#define BUILD_TEST_DATA + +const char* myssid = "wifiname"; +const char* mypasswd = "wifipassword"; +const char ntpSrv[] = "pool.ntp.org"; + +const char* rrd_files[] = {"/psram/rrd_0.rrd", "/psram/rrd_1.rrd"}; // Must use full vfs path +const char* backup_files[] = {"/littlefs/rrd_0.rrd", "/littlefs/rrd_1.rrd"}; +const char* rrd_0 = "-s60 -b1600000000 /psram/rrd_0.rrd DS:bytesin:COUNTER:180:0:100000 RRA:AVERAGE:0.5:1:60 RRA:AVERAGE:0.5:10:2016 RRA:AVERAGE:0.5:360:2924"; +const int argc = 10; +const char* rrd_1[argc] = {"rrd_create", //Argv[0] will be ignored + rrd_files[1], + "--step", "60", //seconds + "--start", "1600000000", // Sep 13, 2020 + "DS:wave:GAUGE:120:0:100", // range is 0-100, expected every 2 mins + "RRA:AVERAGE:0.5:1:60", // 1 hour @ 1 minute + "RRA:AVERAGE:0.5:10:2016", // 2 weeks @ 10 minutes + "RRA:AVERAGE:0.5:360:2924" }; // 2 years @ 6 hours + +const char* indexHtml = R"rrdJ( + + + RRD Example on ESP32 + +

RRD Example on ESP32

+ + +
Javascript needed for this page to work
+
+
+
+ + + +)rrdJ"; + +Ticker tkFillData; +WebServer server(80); + +size_t lastStr(const char* rrdFile, String &returnStr, uint8_t ds=0) { + char* argv[2] = {(char*)"a", (char*)rrdFile}; + time_t last_update; + unsigned long ds_cnt; + char **ds_namv, **last_ds; + if (rrd_lastupdate(2, (char**)&argv, &last_update, &ds_cnt, &ds_namv, &last_ds) == 0) { + returnStr = "{\"data_store\":\"" + String(ds_namv[ds]); + returnStr += "\",\"last_update\":" + String(last_update); + returnStr += ",\"value\":" + String(last_ds[ds]) + "}"; + for (int x=0; x now) c_time = now; + counter0 += random(100000); + filler0[y] = (char*) malloc(24); + snprintf(filler0[y], 23, "%10u:%u", c_time, counter0); + log_v("filler0[%d]: %s", x*chunk+y, filler0[y]); + filler1[y] = (char*) malloc(18); + snprintf(filler1[y], 17, "%10u:%5.2f", c_time, sin(c_time/600.0*2*M_PI)*50+50); + log_v("filler1[%d]: %s", x*chunk+y, filler1[y]); + } + if (rrd_mask & 1) rrd_update_r(rrd_files[0], NULL, chunk, (const char**)&filler0); + if (rrd_mask & 2) rrd_update_r(rrd_files[1], NULL, chunk, (const char**)&filler1); + for (uint16_t y=0; y