sdcard: timestamp in iso8601 format
This commit is contained in:
parent
76c465ccb7
commit
854480a051
12
README.md
12
README.md
@ -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:
|
And finally: this is the data written to the disk:
|
||||||
|
|
||||||
date, time, wifi, bluet
|
timestamp, wifi, ble
|
||||||
00.00.1970,00:01:09,2,0
|
2022-01-28T19:36:35Z,17,48
|
||||||
00.00.1970,00:02:09,1,0
|
2022-01-28T19:37:35Z,21,52
|
||||||
00.00.1970,00:03:09,2,0
|
2022-01-28T19:38:35Z,14,49
|
||||||
|
|
||||||
Format of the data is CSV, which can easily imported into LibreOffice, Excel, .....
|
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.
|
If you want to change this please look into src/sdcard.cpp and include/sdcard.h.
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SDCARD_FILE_NAME "/paxcount.%02d"
|
#define SDCARD_FILE_NAME "/paxcount.%02d"
|
||||||
#define SDCARD_FILE_HEADER "date, time, wifi, bluet"
|
#define SDCARD_FILE_HEADER "timestamp, wifi, ble"
|
||||||
|
|
||||||
#if (COUNT_ENS)
|
#if (COUNT_ENS)
|
||||||
#define SDCARD_FILE_HEADER_CWA ",cwa"
|
#define SDCARD_FILE_HEADER_CWA ",cwa"
|
||||||
|
@ -42,11 +42,10 @@ bool sdcard_init() {
|
|||||||
void sdcardWriteData(uint16_t noWifi, uint16_t noBle,
|
void sdcardWriteData(uint16_t noWifi, uint16_t noBle,
|
||||||
__attribute__((unused)) uint16_t noBleCWA) {
|
__attribute__((unused)) uint16_t noBleCWA) {
|
||||||
static int counterWrites = 0;
|
static int counterWrites = 0;
|
||||||
char tempBuffer[12 + 1];
|
char tempBuffer[20 + 1];
|
||||||
time_t t = time(NULL);
|
time_t t = time(NULL);
|
||||||
struct tm tt;
|
struct tm tt;
|
||||||
localtime_r(&t, &tt);
|
gmtime_r(&t, &tt); // make UTC timestamp
|
||||||
mktime(&tt);
|
|
||||||
|
|
||||||
#if (HAS_SDS011)
|
#if (HAS_SDS011)
|
||||||
sdsStatus_t sds;
|
sdsStatus_t sds;
|
||||||
@ -56,19 +55,17 @@ void sdcardWriteData(uint16_t noWifi, uint16_t noBle,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
ESP_LOGD(TAG, "writing to SD-card");
|
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);
|
fileSDCard.print(tempBuffer);
|
||||||
strftime(tempBuffer, sizeof(tempBuffer), "%H.%M.%S", &tt);
|
snprintf(tempBuffer, sizeof(tempBuffer), ",%d,%d", noWifi, noBle);
|
||||||
fileSDCard.print(tempBuffer);
|
|
||||||
sprintf(tempBuffer, "%d,%d", noWifi, noBle);
|
|
||||||
fileSDCard.print(tempBuffer);
|
fileSDCard.print(tempBuffer);
|
||||||
#if (COUNT_ENS)
|
#if (COUNT_ENS)
|
||||||
sprintf(tempBuffer, ",%d", noBleCWA);
|
snprintf(tempBuffer, sizeof(tempBuffer), ",%d", noBleCWA);
|
||||||
fileSDCard.print(tempBuffer);
|
fileSDCard.print(tempBuffer);
|
||||||
#endif
|
#endif
|
||||||
#if (HAS_SDS011)
|
#if (HAS_SDS011)
|
||||||
sds011_store(&sds);
|
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);
|
fileSDCard.print(tempBuffer);
|
||||||
#endif
|
#endif
|
||||||
fileSDCard.println();
|
fileSDCard.println();
|
||||||
@ -88,7 +85,7 @@ void createFile(void) {
|
|||||||
|
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
sprintf(bufferFilename, SDCARD_FILE_NAME, 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
|
#if HAS_SDCARD == 1
|
||||||
bool fileExists = SD.exists(bufferFilename);
|
bool fileExists = SD.exists(bufferFilename);
|
||||||
@ -97,7 +94,7 @@ void createFile(void) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!fileExists) {
|
if (!fileExists) {
|
||||||
// ESP_LOGD(TAG, "SD: file does not exist: opening");
|
ESP_LOGD(TAG, "SD: file does not exist: creating");
|
||||||
|
|
||||||
#if HAS_SDCARD == 1
|
#if HAS_SDCARD == 1
|
||||||
fileSDCard = SD.open(bufferFilename, FILE_WRITE);
|
fileSDCard = SD.open(bufferFilename, FILE_WRITE);
|
||||||
@ -106,7 +103,7 @@ void createFile(void) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fileSDCard) {
|
if (fileSDCard) {
|
||||||
ESP_LOGD(TAG, "SD: name opened: <%s>", bufferFilename);
|
ESP_LOGD(TAG, "SD: file opened: <%s>", bufferFilename);
|
||||||
fileSDCard.print(SDCARD_FILE_HEADER);
|
fileSDCard.print(SDCARD_FILE_HEADER);
|
||||||
#if (COUNT_ENS)
|
#if (COUNT_ENS)
|
||||||
fileSDCard.print(SDCARD_FILE_HEADER_CWA); // for Corona-data (CWA)
|
fileSDCard.print(SDCARD_FILE_HEADER_CWA); // for Corona-data (CWA)
|
||||||
|
@ -65,18 +65,6 @@ void SendPayload(uint8_t port) {
|
|||||||
mqtt_enqueuedata(&SendBuffer);
|
mqtt_enqueuedata(&SendBuffer);
|
||||||
#endif
|
#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
|
} // SendPayload
|
||||||
|
|
||||||
// interrupt triggered function to prepare payload to send
|
// interrupt triggered function to prepare payload to send
|
||||||
@ -130,7 +118,16 @@ void sendData() {
|
|||||||
#ifdef HAS_DISPLAY
|
#ifdef HAS_DISPLAY
|
||||||
dp_plotCurve(libpax_macs_ble + libpax_macs_wifi, true);
|
dp_plotCurve(libpax_macs_ble + libpax_macs_wifi, true);
|
||||||
#endif
|
#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
|
#endif
|
||||||
|
|
||||||
#if (HAS_BME)
|
#if (HAS_BME)
|
||||||
|
Loading…
Reference in New Issue
Block a user