sdcard: timestamp in iso8601 format

This commit is contained in:
cyberman54 2022-01-28 20:57:31 +01:00
parent 76c465ccb7
commit 854480a051
4 changed files with 26 additions and 32 deletions

View File

@ -256,12 +256,12 @@ The data is written to the card and after 3 write-operations the data is flushed
And finally: this is the data written to the disk:
date, time, wifi, bluet
00.00.1970,00:01:09,2,0
00.00.1970,00:02:09,1,0
00.00.1970,00:03:09,2,0
Format of the data is CSV, which can easily imported into LibreOffice, Excel, .....
timestamp, wifi, ble
2022-01-28T19:36:35Z,17,48
2022-01-28T19:37:35Z,21,52
2022-01-28T19:38:35Z,14,49
Format of the data is CSV, timestamp is ISO8601, which can easily imported into LibreOffice, Excel, Influx, etc.
If you want to change this please look into src/sdcard.cpp and include/sdcard.h.

View File

@ -55,7 +55,7 @@
#endif
#define SDCARD_FILE_NAME "/paxcount.%02d"
#define SDCARD_FILE_HEADER "date, time, wifi, bluet"
#define SDCARD_FILE_HEADER "timestamp, wifi, ble"
#if (COUNT_ENS)
#define SDCARD_FILE_HEADER_CWA ",cwa"

View File

@ -42,11 +42,10 @@ bool sdcard_init() {
void sdcardWriteData(uint16_t noWifi, uint16_t noBle,
__attribute__((unused)) uint16_t noBleCWA) {
static int counterWrites = 0;
char tempBuffer[12 + 1];
char tempBuffer[20 + 1];
time_t t = time(NULL);
struct tm tt;
localtime_r(&t, &tt);
mktime(&tt);
gmtime_r(&t, &tt); // make UTC timestamp
#if (HAS_SDS011)
sdsStatus_t sds;
@ -56,19 +55,17 @@ void sdcardWriteData(uint16_t noWifi, uint16_t noBle,
return;
ESP_LOGD(TAG, "writing to SD-card");
strftime(tempBuffer, sizeof(tempBuffer), "%d.%m.%Y", &tt);
strftime(tempBuffer, sizeof(tempBuffer), "%FT%TZ", &tt);
fileSDCard.print(tempBuffer);
strftime(tempBuffer, sizeof(tempBuffer), "%H.%M.%S", &tt);
fileSDCard.print(tempBuffer);
sprintf(tempBuffer, "%d,%d", noWifi, noBle);
snprintf(tempBuffer, sizeof(tempBuffer), ",%d,%d", noWifi, noBle);
fileSDCard.print(tempBuffer);
#if (COUNT_ENS)
sprintf(tempBuffer, ",%d", noBleCWA);
snprintf(tempBuffer, sizeof(tempBuffer), ",%d", noBleCWA);
fileSDCard.print(tempBuffer);
#endif
#if (HAS_SDS011)
sds011_store(&sds);
sprintf(tempBuffer, ",%5.1f,%4.1f", sds.pm10, sds.pm25);
snprintf(tempBuffer, sizeof(tempBuffer), ",%5.1f,%4.1f", sds.pm10, sds.pm25);
fileSDCard.print(tempBuffer);
#endif
fileSDCard.println();
@ -88,7 +85,7 @@ void createFile(void) {
for (int i = 0; i < 100; i++) {
sprintf(bufferFilename, SDCARD_FILE_NAME, i);
// ESP_LOGD(TAG, "SD: looking for file <%s>", bufferFilename);
ESP_LOGD(TAG, "SD: looking for file <%s>", bufferFilename);
#if HAS_SDCARD == 1
bool fileExists = SD.exists(bufferFilename);
@ -97,7 +94,7 @@ void createFile(void) {
#endif
if (!fileExists) {
// ESP_LOGD(TAG, "SD: file does not exist: opening");
ESP_LOGD(TAG, "SD: file does not exist: creating");
#if HAS_SDCARD == 1
fileSDCard = SD.open(bufferFilename, FILE_WRITE);
@ -106,7 +103,7 @@ void createFile(void) {
#endif
if (fileSDCard) {
ESP_LOGD(TAG, "SD: name opened: <%s>", bufferFilename);
ESP_LOGD(TAG, "SD: file opened: <%s>", bufferFilename);
fileSDCard.print(SDCARD_FILE_HEADER);
#if (COUNT_ENS)
fileSDCard.print(SDCARD_FILE_HEADER_CWA); // for Corona-data (CWA)

View File

@ -65,18 +65,6 @@ void SendPayload(uint8_t port) {
mqtt_enqueuedata(&SendBuffer);
#endif
// write data to sdcard, if present
#if (HAS_SDCARD)
if (port == COUNTERPORT) {
sdcardWriteData(libpax_macs_wifi, libpax_macs_ble
#if (COUNT_ENS)
,
cwa_report()
#endif
);
}
#endif
} // SendPayload
// interrupt triggered function to prepare payload to send
@ -130,7 +118,16 @@ void sendData() {
#ifdef HAS_DISPLAY
dp_plotCurve(libpax_macs_ble + libpax_macs_wifi, true);
#endif
break;
#if (HAS_SDCARD)
sdcardWriteData(libpax_macs_wifi, libpax_macs_ble
#if (COUNT_ENS)
,
cwa_report()
#endif
);
#endif // HAS_SDCARD
break; // case COUNTDATA
#endif
#if (HAS_BME)