Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.DS_Store
.pio/
platformio-local-override.ini
.vscode/
65 changes: 24 additions & 41 deletions esp32-web-interface.ino
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,6 @@
#include <Ticker.h>
#include <StreamString.h>

#ifndef ENABLE_SDCARD
#define ENABLE_SDCARD 1
#endif

#ifndef ENABLE_RTC
#define ENABLE_RTC 1
#endif

#include <SD_MMC.h>
#include "RTClib.h"
#include <ESP32Time.h>
Expand All @@ -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);
Expand All @@ -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];
Expand Down Expand Up @@ -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\"}");

Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 0 additions & 5 deletions platformio-local-override.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 3 additions & 9 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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/> -<src/flashloader>
upload_port = /dev/ttyUSB0
upload_speed = 921600
Expand Down
Loading