diff --git a/.gitignore b/.gitignore index b70f5ca..8a990cc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ .DS_Store .pio/ platformio-local-override.ini -.vscode/ diff --git a/esp32-web-interface.ino b/esp32-web-interface.ino index b0387e6..8516b2b 100644 --- a/esp32-web-interface.ino +++ b/esp32-web-interface.ino @@ -51,14 +51,6 @@ #include #include -#ifndef ENABLE_SDCARD -#define ENABLE_SDCARD 1 -#endif - -#ifndef ENABLE_RTC -#define ENABLE_RTC 1 -#endif - #include #include "RTClib.h" #include @@ -77,10 +69,12 @@ #define LED_BUILTIN 5 #endif -#define SDIO_BUFFER_SIZE 16384 #define RESERVED_SD_SPACE 2000000000 +#define SDIO_BUFFER_SIZE 16384 #define FLUSH_WRITES 60 //flush file every 60 blocks + #define MAX_SD_FILES 200 + #define LOG_DELAY_VAL 10000 //HardwareSerial Inverter(INVERTER_PORT); @@ -100,8 +94,8 @@ Ticker sta_tick; RTC_PCF8523 ext_rtc; ESP32Time int_rtc; -bool haveRTC = ENABLE_RTC != 0; -bool haveSDCard = ENABLE_SDCARD != 0; +bool haveRTC = false; +bool haveSDCard = false; bool fastLoggingEnabled = true; bool fastLoggingActive = false; uint8_t SDIObuffer[SDIO_BUFFER_SIZE]; @@ -338,15 +332,14 @@ void handleRTCNow() { } void handleRTCSet() { - if (haveRTC && server.hasArg("timestamp")) { + + if (server.hasArg("timestamp")) { String timestamp = server.arg("timestamp"); server.send(200, "text/json", "{\"result\":\"" + timestamp + "\"}"); DateTime now = DateTime(timestamp.toInt()); ext_rtc.adjust(now); int_rtc.setTime(now.unixtime()); handleRTCNow(); - } else if (!haveRTC) { - server.send(500, "text/json", "{\"result\":\"No RTC\"}"); } else { server.send(500, "text/json", "{\"result\":\"timestamp missing\"}"); @@ -366,8 +359,10 @@ void handleSdCardDeleteAll() { } server.send(200, "text/json", "{\"result\": \"done\"}"); + } void handleSdCardList() { + if (!haveSDCard) { server.send(200, "text/json", "{\"error\": \"No SD Card\"}"); return; @@ -727,43 +722,31 @@ void setup(void){ pinMode(LED_BUILTIN, OUTPUT); //check for external RTC and if present use to initialise on-chip RTC - if (haveRTC) + if (ext_rtc.begin()) { - if (ext_rtc.begin()) + haveRTC = true; + DBG_OUTPUT_PORT.println("External RTC found"); + if (! ext_rtc.initialized() || ext_rtc.lostPower()) { - DBG_OUTPUT_PORT.println("External RTC found"); - if (! ext_rtc.initialized() || ext_rtc.lostPower()) - { - DBG_OUTPUT_PORT.println("RTC is NOT initialized, setting to build time"); - ext_rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); - } - - ext_rtc.start(); - DateTime now = ext_rtc.now(); - int_rtc.setTime(now.unixtime()); - } - else - { - haveRTC = false; - DBG_OUTPUT_PORT.println("No RTC found, defaulting to sequential file names"); + DBG_OUTPUT_PORT.println("RTC is NOT initialized, setting to build time"); + ext_rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); } + + ext_rtc.start(); + DateTime now = ext_rtc.now(); + int_rtc.setTime(now.unixtime()); } else - DBG_OUTPUT_PORT.println("RTC support disabled at compile time"); + DBG_OUTPUT_PORT.println("No RTC found, defaulting to sequential file names"); //initialise SD card in SDIO mode //if (SD_MMC.begin("/sdcard", true, false, 40000, 5U)) { - if (haveSDCard) { - if (SD_MMC.begin()) { - DBG_OUTPUT_PORT.println("Started SD_MMC"); - } - else { - haveSDCard = false; - DBG_OUTPUT_PORT.println("Couldn't start SD_MMC"); - } + if (SD_MMC.begin()) { + DBG_OUTPUT_PORT.println("Started SD_MMC"); + haveSDCard = true; } else - DBG_OUTPUT_PORT.println("SD card support disabled at compile time"); + DBG_OUTPUT_PORT.println("Couldn't start SD_MMC"); //Start SPI Flash file system SPIFFS.begin(); diff --git a/platformio-local-override.ini.example b/platformio-local-override.ini.example index bdce7d3..4112110 100644 --- a/platformio-local-override.ini.example +++ b/platformio-local-override.ini.example @@ -4,8 +4,3 @@ upload_port = /dev/cu.usbserial-DGAJb113318 upload_speed = 921600 monitor_port = /dev/cu.usbserial-DGAJb113318 monitor_speed = 115200 - -; Optional local feature overrides -; [features] -; enable_rtc = -D ENABLE_RTC=0 -; enable_sdcard = -D ENABLE_SDCARD=0 diff --git a/platformio.ini b/platformio.ini index eb9c17e..e8bb52e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -18,19 +18,13 @@ extra_configs = platformio-local-override.ini [common] monitor_speed = 115200 -[features] -enable_rtc = -D ENABLE_RTC=1 -enable_sdcard = -D ENABLE_SDCARD=1 - [env] -platform = espressif32@6.12.0 +platform = espressif32 framework = arduino +platform_packages = platformio/tool-esptoolpy board = esp32dev board_build.filesystem = spiffs -board_build.flash_mode = dio -build_flags = - ${features.enable_rtc} - ${features.enable_sdcard} +board_build.flash_mode = qout build_src_filter = +<*> -<.git/> -<.svn/> - upload_port = /dev/ttyUSB0 upload_speed = 921600