sdcard: timestamp in iso8601 format
This commit is contained in:
1 parent
76c465ccb7
commit
854480a051
4 files changed
+26
-32
No files matched your search
+9
-12
@@ -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)
|
||||
|
||||
+10
-13
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user