Get form submission time from webform and update RTC.

This commit is contained in:
mattbk 2023-09-02 22:11:51 -05:00
parent 0317a93d38
commit abe751d30c
2 changed files with 32 additions and 10 deletions

View File

@ -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

View File

@ -25,14 +25,14 @@
#include <Adafruit_BusIO_Register.h> // for DS3231
#include <RTClib.h> // for DS3231
//#include <DS3232RTC.h> //for DS3231
#include <sstream>
//#include <sstream>
// download zip from https://github.com/me-no-dev/ESPAsyncWebServer and install.
#include <ESPAsyncWebServer.h>
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);
};
</script></head><body>
<form action="/get" target="hidden-form" onsubmit="putDate(this);">
@ -90,7 +90,7 @@ const char index_html[] PROGMEM = R"rawliteral(
WPM (current value %inputWPM%): <input type="number " name="inputWPM" value = %inputWPM%> (doesn't work yet)<br>
<input type="hidden" name="inputTimeUnix" id="js_time_unix"><br>
<input type="hidden" name="inputTimeUnix" id="js_time_unix">
<script>
<!-- document.write(Date.now()); -->
</script>
@ -461,10 +461,29 @@ void setup() {
// GET inputTimeUnix value on <ESP_IP>/get?inputTimeUnix=<inputMessage>
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 <ESP_IP>/get?inputFloat=<inputMessage>
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);