From abe751d30ccafeba30237513bbf7c802beb255b0 Mon Sep 17 00:00:00 2001 From: mattbk Date: Sat, 2 Sep 2023 22:11:51 -0500 Subject: [PATCH] Get form submission time from webform and update RTC. --- vulpes/platformio.ini | 9 ++++++--- vulpes/src/main.cpp | 33 ++++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/vulpes/platformio.ini b/vulpes/platformio.ini index 14981de..1a2242f 100644 --- a/vulpes/platformio.ini +++ b/vulpes/platformio.ini @@ -10,10 +10,12 @@ [env:esp32doit-devkit-v1] platform = espressif32 -build_flags = - -std=gnu++11 +;build_flags = +; -std=c++11 +; -std=gnu++11 board = esp32doit-devkit-v1 framework = arduino +upload_speed = 921600 monitor_speed = 115200 lib_deps = me-no-dev/AsyncTCP@^1.1.1 @@ -21,6 +23,7 @@ lib_deps = contrem/arduino-timer@^3.0.1 kj7rrv/Telegraph@^1.0.0 jandelgado/JLed@^4.13.0 - adafruit/RTClib@^2.1.1 + ;adafruit/RTClib@^2.1.1 + https://github.com/adafruit/RTClib.git ; >=2.1.2 adafruit/Adafruit BusIO@^1.14.3 ;jchristensen/DS3232RTC@^2.0.1 diff --git a/vulpes/src/main.cpp b/vulpes/src/main.cpp index d49f0ea..063cdfa 100644 --- a/vulpes/src/main.cpp +++ b/vulpes/src/main.cpp @@ -25,14 +25,14 @@ #include // for DS3231 #include // for DS3231 //#include //for DS3231 -#include +//#include // download zip from https://github.com/me-no-dev/ESPAsyncWebServer and install. #include AsyncWebServer server(80); -RTC_DS3231 rtc; +RTC_DS3231 rtc; // set up RTC // Read from config.h const char* ssid = WIFI_SSID; @@ -52,7 +52,7 @@ int yourInputWPM; int yourInputMsg; int yourInputMsg_old; // to save previous state and check changes float yourInputFloat; -long yourInputTime; //to keep time +uint32_t yourInputTime; //to keep time // HTML web page to handle 3 input fields (inputString, inputSend, inputFloat) const char index_html[] PROGMEM = R"rawliteral( @@ -65,7 +65,7 @@ const char index_html[] PROGMEM = R"rawliteral( setTimeout(function(){ document.location.reload(false); }, 500); } var putDate = function(form) { - form.inputTimeUnix.value = Date.now(); + form.inputTimeUnix.value = Math.floor(Date.now() / 1000); };
@@ -90,7 +90,7 @@ const char index_html[] PROGMEM = R"rawliteral( WPM (current value %inputWPM%): (doesn't work yet)
-
+ @@ -461,10 +461,29 @@ void setup() { // GET inputTimeUnix value on /get?inputTimeUnix= if (request->hasParam(PARAM_TIME)) { inputMessage = request->getParam(PARAM_TIME)->value(); - yourInputTime = std::stol(inputMessage); + Serial.println(inputMessage); + //https://stackoverflow.com/a/22733127/2152245 + yourInputTime = atol(inputMessage.c_str()); Serial.println(yourInputTime); // update the RTC time rtc.adjust(DateTime(yourInputTime)); +; + DateTime now = rtc.now(); + Serial.print("UTC time from browser: "); + Serial.print(now.year(), DEC); + Serial.print('/'); + Serial.print(now.month(), DEC); + Serial.print('/'); + Serial.print(now.day(), DEC); + Serial.print(" ("); + Serial.print(now.dayOfTheWeek()); + Serial.print(") "); + Serial.print(now.hour(), DEC); + Serial.print(':'); + Serial.print(now.minute(), DEC); + Serial.print(':'); + Serial.print(now.second(), DEC); + Serial.println(); } // GET inputFloat value on /get?inputFloat= if (request->hasParam(PARAM_FLOAT)) { @@ -499,7 +518,7 @@ void loop() { time_until_start.tick(); timer.tick(); - DateTime now = rtc.now(); + // DateTime now = rtc.now(); // Serial.print(now.year(), DEC); // Serial.print('/'); // Serial.print(now.month(), DEC);