From 308dc064fee41ea85d7c706e6dc7d438d39356c2 Mon Sep 17 00:00:00 2001 From: lumapu Date: Wed, 19 Jul 2023 23:56:07 +0200 Subject: [PATCH] 0.7.13 * add date, time and version to export json #1024 --- src/CHANGES.md | 1 + src/app.cpp | 2 +- src/platformio.ini | 2 +- src/utils/helper.cpp | 9 +++++++++ src/utils/helper.h | 1 + src/web/RestApi.h | 5 ++++- 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/CHANGES.md b/src/CHANGES.md index affdc71e..ca360a36 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -2,6 +2,7 @@ ## 0.7.13 - 2023-07-19 * merged display PR #1027 +* add date, time and version to export json #1024 ## 0.7.12 - 2023-07-09 * added inverter status - state-machine #1016 diff --git a/src/app.cpp b/src/app.cpp index 535af4c8..bf647f23 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -330,7 +330,7 @@ void app::tickMinute(void) { // only triggered if 'reset values on no avail is enabled' zeroIvValues(true); - } +} //----------------------------------------------------------------------------- void app::tickMidnight(void) { diff --git a/src/platformio.ini b/src/platformio.ini index e6980552..c05908f0 100644 --- a/src/platformio.ini +++ b/src/platformio.ini @@ -26,7 +26,7 @@ lib_deps = https://github.com/yubox-node-org/ESPAsyncWebServer nrf24/RF24 @ 1.4.5 paulstoffregen/Time @ ^1.6.1 - https://github.com/bertmelis/espMqttClient#v1.4.4 + https://github.com/bertmelis/espMqttClient#v1.4.2 bblanchon/ArduinoJson @ ^6.21.2 https://github.com/JChristensen/Timezone @ ^1.2.4 olikraus/U8g2 @ ^2.34.17 diff --git a/src/utils/helper.cpp b/src/utils/helper.cpp index 95f330e9..26cbdad2 100644 --- a/src/utils/helper.cpp +++ b/src/utils/helper.cpp @@ -41,6 +41,15 @@ namespace ah { return String(str); } + String getDateTimeStrFile(time_t t) { + char str[20]; + if(0 == t) + sprintf(str, "na"); + else + sprintf(str, "%04d-%02d-%02d_%02d-%02d-%02d", year(t), month(t), day(t), hour(t), minute(t), second(t)); + return String(str); + } + String getTimeStr(time_t t) { char str[9]; if(0 == t) diff --git a/src/utils/helper.h b/src/utils/helper.h index 3112ffd3..054ae0c3 100644 --- a/src/utils/helper.h +++ b/src/utils/helper.h @@ -41,6 +41,7 @@ namespace ah { void ip2Char(uint8_t ip[], char *str); double round3(double value); String getDateTimeStr(time_t t); + String getDateTimeStrFile(time_t t); String getTimeStr(time_t t); uint64_t Serial2u64(const char *val); void dumpBuf(uint8_t buf[], uint8_t len); diff --git a/src/web/RestApi.h b/src/web/RestApi.h index d88e8db8..29a70d85 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -184,9 +184,12 @@ class RestApi { response = request->beginResponse(200, F("application/json; charset=utf-8"), tmp); } + String filename = ah::getDateTimeStrFile(mApp->getTimezoneOffset()); + filename += "_v" + String(mApp->getVersion()); + response->addHeader("Content-Type", "application/octet-stream"); response->addHeader("Content-Description", "File Transfer"); - response->addHeader("Content-Disposition", "attachment; filename=ahoy_setup.json"); + response->addHeader("Content-Disposition", "attachment; filename=" + filename + "_ahoy_setup.json"); request->send(response); fp.close(); }