Snapshot.

This commit is contained in:
mattbk 2023-09-05 20:41:55 -05:00
parent 458232f08f
commit 8a95413224

View File

@ -25,7 +25,7 @@
#include <Adafruit_BusIO_Register.h> // for DS3231 #include <Adafruit_BusIO_Register.h> // for DS3231
#include <RTClib.h> // for DS3231 #include <RTClib.h> // for DS3231
//#include <DS3232RTC.h> //for DS3231 //#include <DS3232RTC.h> //for DS3231
//#include <sstream> #include <string>
// download zip from https://github.com/me-no-dev/ESPAsyncWebServer and install. // download zip from https://github.com/me-no-dev/ESPAsyncWebServer and install.
#include <ESPAsyncWebServer.h> #include <ESPAsyncWebServer.h>
@ -45,6 +45,7 @@ const char* PARAM_MSG = "inputMsg";
const char* PARAM_FLOAT = "inputFloat"; const char* PARAM_FLOAT = "inputFloat";
const char* PARAM_TIME = "inputTimeUnix"; const char* PARAM_TIME = "inputTimeUnix";
const char* PARAM_START = "inputStartTimeUnix"; const char* PARAM_START = "inputStartTimeUnix";
const char* PARAM_RUNNING = "programRunning";
// Global variables // Global variables
String yourInputString; String yourInputString;
@ -55,6 +56,7 @@ int yourInputMsg_old; // to save previous state and check changes
float yourInputFloat; float yourInputFloat;
uint32_t yourInputTime; //to keep time uint32_t yourInputTime; //to keep time
uint32_t yourInputStartTimeUnix; uint32_t yourInputStartTimeUnix;
int yourProgramRunning;
// HTML web page to handle 3 input fields (inputString, inputSend, inputFloat) // HTML web page to handle 3 input fields (inputString, inputSend, inputFloat)
const char index_html[] PROGMEM = R"rawliteral( const char index_html[] PROGMEM = R"rawliteral(
@ -83,11 +85,11 @@ const char index_html[] PROGMEM = R"rawliteral(
</script></head><body> </script></head><body>
<form action="/get" target="hidden-form" onsubmit="putDate(this);" accept-charset=utf-8> <form action="/get" target="hidden-form" onsubmit="putDate(this);" accept-charset=utf-8>
Sending program (cycle doesn't work yet) (current value: <b>%inputSend%</b>): <p>Sending program (cycle doesn't work yet) (current value: <b>%inputSend%</b>):
<select name="inputSend" id="send-program"> <select name="inputSend" id="send-program">
<option value="0">0 -Off</option> <option value="0">0 -Off</option>
<option value="1">1 - Continuous</option> <option value="1">1 - Continuous</option>
<option value="2">2 - Cycle</option> <option value="2">2 - Cycle Program</option>
</select><br> </select><br>
Message (current value <b>%inputMsg%</b>): Message (current value <b>%inputMsg%</b>):
@ -98,19 +100,24 @@ const char index_html[] PROGMEM = R"rawliteral(
<option value="3">3 - MOS</option> <option value="3">3 - MOS</option>
<option value="4">4 - MOH</option> <option value="4">4 - MOH</option>
<option value="5">5 - MO5</option> <option value="5">5 - MO5</option>
</select><br> </select></p>
Program start time (current value <b><span id = current-start></span></b>): <input type="datetime-local" id="js_start_time_unix_entry" /><br> <p>Current time (UTC): <b>%inputTimeUnix%</b><br>
<input type="hidden" name="inputStartTimeUnix" id="js_start_time_unix" />
Current time (UTC): %inputTimeUnix% Program start time (current value <b><span id = current-start></span></b>): <input type="datetime-local" id="js_start_time_unix_entry" />
<!-- This field is hidden so people don't change it (it will be wrong) --> <!-- JS converts the entered start time to a unix timestamp, and copies that value
<input type="hidden" name="inputTimeUnix" id="js_time_unix"><br> to this hidden field so the user doesn't have to see it. -->
<input type="hidden" name="inputStartTimeUnix" id="js_start_time_unix" /></p>
<!-- This field is hidden so people don't change the submit time (it will be wrong).
The value is automatically filled in with JS. -->
<input type="hidden" name="inputTimeUnix" id="js_time_unix">
<!-- Extra fields just in case I need them --> <!-- Extra fields just in case I need them -->
<input type="hidden" name="inputWPM" value = %inputWPM%><br> <input type="hidden" name="inputWPM" value = %inputWPM%>
<input type="hidden" name="inputString" value=%inputString%><br> <input type="hidden" name="inputString" value=%inputString%>
<input type="hidden" name="inputFloat" value = %inputFloat%><br> <input type="hidden" name="inputFloat" value = %inputFloat%>
<input type="submit" value="Submit""> <input type="submit" value="Submit"">
</form> </form>
@ -350,6 +357,15 @@ auto morseToSend_blink = morseTEST_blink; // set this up to overwrite later
// Serial.println(buf); // Serial.println(buf);
// } // }
//================================================================================
// start_program(): a function to start the planned program at the planned time
//================================================================================
bool start_program(){
Serial.println("The scheduled program has started.");
yourProgramRunning = 1;
return false;
}
//================================================================================ //================================================================================
// setup(): stuff that only gets done once, after power up (KB1OIQ's description) // setup(): stuff that only gets done once, after power up (KB1OIQ's description)
//================================================================================ //================================================================================
@ -485,6 +501,10 @@ void setup() {
inputMessage = request->getParam(PARAM_SEND)->value(); inputMessage = request->getParam(PARAM_SEND)->value();
writeFile(SPIFFS, "/inputSend.txt", inputMessage.c_str()); writeFile(SPIFFS, "/inputSend.txt", inputMessage.c_str());
yourInputSend = inputMessage.toInt(); yourInputSend = inputMessage.toInt();
// if not running a program, set the program running off
if(yourInputSend != 2){
yourProgramRunning = 0;
}
} }
// GET inputWPM value on <ESP_IP>/get?inputWPM=<inputMessage> // GET inputWPM value on <ESP_IP>/get?inputWPM=<inputMessage>
if (request->hasParam(PARAM_WPM)) { if (request->hasParam(PARAM_WPM)) {
@ -503,7 +523,6 @@ void setup() {
// GET inputTimeUnix value on <ESP_IP>/get?inputTimeUnix=<inputMessage> // GET inputTimeUnix value on <ESP_IP>/get?inputTimeUnix=<inputMessage>
if (request->hasParam(PARAM_TIME)) { if (request->hasParam(PARAM_TIME)) {
inputMessage = request->getParam(PARAM_TIME)->value(); inputMessage = request->getParam(PARAM_TIME)->value();
Serial.println(inputMessage);
//https://stackoverflow.com/a/22733127/2152245 //https://stackoverflow.com/a/22733127/2152245
yourInputTime = atol(inputMessage.c_str()); yourInputTime = atol(inputMessage.c_str());
Serial.println(yourInputTime); Serial.println(yourInputTime);
@ -536,8 +555,12 @@ void setup() {
// GET inputStartTimeUnix value on <ESP_IP>/get?inputStartTimeUnix=<inputMessage> // GET inputStartTimeUnix value on <ESP_IP>/get?inputStartTimeUnix=<inputMessage>
if (request->hasParam(PARAM_START)) { if (request->hasParam(PARAM_START)) {
inputMessage = request->getParam(PARAM_START)->value(); inputMessage = request->getParam(PARAM_START)->value();
Serial.println(inputMessage);
// if a start time isn't entered, don't overwrite the old one
//if(!(inputMessage != NULL && inputMessage[0] == '\0')){
writeFile(SPIFFS, "/inputStartTimeUnix.txt", inputMessage.c_str()); writeFile(SPIFFS, "/inputStartTimeUnix.txt", inputMessage.c_str());
yourInputStartTimeUnix = atol(inputMessage.c_str()); yourInputStartTimeUnix = atol(inputMessage.c_str());
//}
Serial.println(yourInputStartTimeUnix); Serial.println(yourInputStartTimeUnix);
} }
// else { // else {