From 9b928cb11b62b3065b7b6e23f48e2bd90fd522fd Mon Sep 17 00:00:00 2001 From: mattbk Date: Wed, 30 Aug 2023 22:26:23 -0500 Subject: [PATCH 1/2] Combine forms and remove elses in form processing. --- vulpes/src/main.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/vulpes/src/main.cpp b/vulpes/src/main.cpp index 922f2e5..3a7a81e 100644 --- a/vulpes/src/main.cpp +++ b/vulpes/src/main.cpp @@ -49,15 +49,19 @@ const char index_html[] PROGMEM = R"rawliteral( }
- inputString (current value %inputString%): + inputString (current value %inputString%):
+ + Seconds between flash (current value %inputInt%):
+ + inputFloat (current value %inputFloat%):
@@ -304,18 +308,18 @@ void setup() { writeFile(SPIFFS, "/inputString.txt", inputMessage.c_str()); } // GET inputInt value on /get?inputInt= - else if (request->hasParam(PARAM_INT)) { + if (request->hasParam(PARAM_INT)) { inputMessage = request->getParam(PARAM_INT)->value(); writeFile(SPIFFS, "/inputInt.txt", inputMessage.c_str()); } // GET inputFloat value on /get?inputFloat= - else if (request->hasParam(PARAM_FLOAT)) { + if (request->hasParam(PARAM_FLOAT)) { inputMessage = request->getParam(PARAM_FLOAT)->value(); writeFile(SPIFFS, "/inputFloat.txt", inputMessage.c_str()); } - else { - inputMessage = "No message sent"; - } + // else { + // inputMessage = "No message sent"; + // } Serial.println(inputMessage); request->send(200, "text/plain", inputMessage); @@ -353,14 +357,14 @@ void loop() { // float yourInputFloat = readFile(SPIFFS, "/inputFloat.txt").toFloat(); // if you want to send code, and it's not sending, then start it up - if(yourInputInt != 0 & morseLed.IsRunning() == false){ + if((yourInputInt != 0) & (morseLed.IsRunning() == false)){ //jled morseLed.Reset().Update(); //morse.send("CQ CQ CQ DE W1CDN K"); //etherkit morse //telegraph26.send("CQ CQ CQ DE W1CDN K"); //telegraph // if you want to send code, and it is sending, keep sending - } else if(yourInputInt != 0 & morseLed.IsRunning() == true){ + } else if((yourInputInt != 0) & (morseLed.IsRunning() == true)){ morseLed.Update(); // if you don't want to send code } else { -- 2.30.2 From 6552d9034f415ea620c048ec7779742ba97a55d5 Mon Sep 17 00:00:00 2001 From: mattbk Date: Thu, 31 Aug 2023 09:10:30 -0500 Subject: [PATCH 2/2] Refer to global variables rather than reading files. --- vulpes/src/main.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/vulpes/src/main.cpp b/vulpes/src/main.cpp index 3a7a81e..b840c45 100644 --- a/vulpes/src/main.cpp +++ b/vulpes/src/main.cpp @@ -37,6 +37,11 @@ const char* PARAM_STRING = "inputString"; const char* PARAM_INT = "inputInt"; const char* PARAM_FLOAT = "inputFloat"; +// Global variables +String yourInputString; +int yourInputInt; +float yourInputFloat; + // HTML web page to handle 3 input fields (inputString, inputInt, inputFloat) const char index_html[] PROGMEM = R"rawliteral( @@ -267,22 +272,23 @@ void setup() { digitalWrite(output27, LOW); // Initialize SPIFFS - #ifdef ESP32 + SPIFFS.begin(true); + //#ifdef ESP32 if(!SPIFFS.begin(true)){ Serial.println("An Error has occurred while mounting SPIFFS"); return; } - #else + //#else if(!SPIFFS.begin()){ Serial.println("An Error has occurred while mounting SPIFFS"); return; } - #endif + //#endif // Read in existing data -// String yourInputString = readFile(SPIFFS, "/inputString.txt"); -// int yourInputInt = readFile(SPIFFS, "/inputInt.txt").toInt(); -// float yourInputFloat = readFile(SPIFFS, "/inputFloat.txt").toFloat(); + yourInputString = readFile(SPIFFS, "/inputString.txt"); + yourInputInt = readFile(SPIFFS, "/inputInt.txt").toInt(); + yourInputFloat = readFile(SPIFFS, "/inputFloat.txt").toFloat(); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); @@ -306,21 +312,23 @@ void setup() { if (request->hasParam(PARAM_STRING)) { inputMessage = request->getParam(PARAM_STRING)->value(); writeFile(SPIFFS, "/inputString.txt", inputMessage.c_str()); + yourInputString = inputMessage; } // GET inputInt value on /get?inputInt= if (request->hasParam(PARAM_INT)) { inputMessage = request->getParam(PARAM_INT)->value(); writeFile(SPIFFS, "/inputInt.txt", inputMessage.c_str()); + yourInputInt = inputMessage.toInt(); } // GET inputFloat value on /get?inputFloat= if (request->hasParam(PARAM_FLOAT)) { inputMessage = request->getParam(PARAM_FLOAT)->value(); writeFile(SPIFFS, "/inputFloat.txt", inputMessage.c_str()); + yourInputFloat = inputMessage.toFloat(); } // else { // inputMessage = "No message sent"; // } - Serial.println(inputMessage); request->send(200, "text/plain", inputMessage); // // Update data from files @@ -352,8 +360,8 @@ void loop() { //arduinomorse //sender.continueSending(); - String yourInputString = readFile(SPIFFS, "/inputString.txt"); - int yourInputInt = readFile(SPIFFS, "/inputInt.txt").toInt(); + //String yourInputString = readFile(SPIFFS, "/inputString.txt"); + //int yourInputInt = readFile(SPIFFS, "/inputInt.txt").toInt(); // float yourInputFloat = readFile(SPIFFS, "/inputFloat.txt").toFloat(); // if you want to send code, and it's not sending, then start it up @@ -371,6 +379,7 @@ void loop() { // stop sending and make sure the pin is off morseLed.Stop(JLed::eStopMode::FULL_OFF).Update(); } + morseLed.Update(); -- 2.30.2