- Notifications
You must be signed in to change notification settings - Fork14
A minimal library for binary data logging in ESP8266 systems
License
bitmario/SPIFFSLogger
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A minimal library for binary data logging in ESP8266 systems.
- Easy to use
- Stores data in binary along with a UTC timestamp
- Results in about 50% space spavings when compared to logging the same data in CSV
- Splits data into daily files, allowing for efficient search
- Automatically rotates files, deleting the ones that exceed the specified age
- Uses built-in ESP/newlib time functions
- Download thelatest release
- Extract it into your libraries folder
- Rename the folder from
SPIFFSLogger-x.x.x
toSPIFFSLogger
See the summary below and try theexample. You may also want to take a peek at ourdocumentation.
#include<SPIFFSLogger.h>
This struct represents the data as stored in SPIFFS (including the timestamp). It is returned in any logger read operations.
Definition:
template<classT>structSPIFFSLogData{time_t timestampUTC;/** creation time in UTC*/ T data;/** data of type T*/};
This is the core of the library. You can create your logger like so:
// store ints, saving files in /log/ and keeping today + 7 days of historySPIFFSLogger<int>logger("/log",7);
We can also store a struct (which is probably more useful!):
structEnvData {float temperature;float humidity;uint16_t pressure;};SPIFFSLogger<EnvData>logger("/log",7);
This library uses the ESP8266 SPIFFS and built-in time functions so you must initialize those components and then calllogger.init()
.
Yoursetup()
should look something like this:
voidsetup() {// configure time however you like, we use NTP herewifiSetup();// ommitted for brevityconfigTime(0,0,"pool.ntp.org");// initialize SPIFFS SPIFFS.begin();// initialize our logger logger.init();}
You must calllogger.process()
in your loop to run the required operations (file updates and rotation). E.g.:
voidloop() {// your code is here logger.process();}
Simply calllogger.write()
and the data will be logged with the current timestamp:
structEnvData data = {23.54,50.67,1020 };logger.write(data);
Reading the first row of today's logfile:
SPIFFSLogData<EnvData> data;logger.readRows(&data, time(nullptr),0,1);Serial.printf("TS: %d, T: %.2f, H: %.2f, %u\n", data.timestampUTC, data.data.temperature, data.data.humidity, data.data.pressure);
Or the last row:
consttime_t now = time(nullptr);constsize_t rowCount = logger.rowCount(now);logger.readRows(&data, now, rowCount -1,1);
Or 25 rows starting at the 50th:
SPIFFSLogData<EnvData> data[25];logger.readRows(data, time(nullptr),49,25);
Retrieving data from the last 20 minutes:
SPIFFSLogData<EnvData> data[25];size_t count = logger.readRowsBetween( &data,// output now - (60 *20),// time start (inclusive) now,// time end (inclusive)0,// start index within results25// max number of rows to fetch);for (int i=0; i<count; i++) { Serial.printf("TS: %d, T: %.2f, H: %.2f, %u\n", data[i].timestampUTC, data[i].data.temperature, data[i].data.humidity, data[i].data.pressure);}
Licensed under the GNU LGPLv3, see theLICENSE file.
About
A minimal library for binary data logging in ESP8266 systems
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Contributors2
Uh oh!
There was an error while loading.Please reload this page.