Add option for cycle send and clean up a bit.

This commit is contained in:
mattbk 2023-08-31 20:41:24 -05:00
parent 13ddf853ed
commit b0be20087c

View File

@ -34,15 +34,15 @@ const char* ssid = WIFI_SSID;
const char* password = WIFI_PASSWORD; const char* password = WIFI_PASSWORD;
const char* PARAM_STRING = "inputString"; const char* PARAM_STRING = "inputString";
const char* PARAM_INT = "inputInt"; const char* PARAM_SEND = "inputSend";
const char* PARAM_FLOAT = "inputFloat"; const char* PARAM_FLOAT = "inputFloat";
// Global variables // Global variables
String yourInputString; String yourInputString;
int yourInputInt; int yourInputSend;
float yourInputFloat; float yourInputFloat;
// HTML web page to handle 3 input fields (inputString, inputInt, 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(
<!DOCTYPE HTML><html><head> <!DOCTYPE HTML><html><head>
<title>ESP Input Form</title> <title>ESP Input Form</title>
@ -57,9 +57,10 @@ const char index_html[] PROGMEM = R"rawliteral(
inputString (current value %inputString%): <input type="text" name="inputString" value=%inputString%><br> inputString (current value %inputString%): <input type="text" name="inputString" value=%inputString%><br>
Sending program: Sending program:
<select name="inputInt" id="send-program"> <select name="inputSend" id="send-program">
<option value="0">Off</option>
<option value="1">Continuous</option> <option value="1">Continuous</option>
<option value="0">Cycle</option> <option value="2">Cycle</option>
</select><br> </select><br>
inputFloat (current value %inputFloat%): <input type="number " name="inputFloat" value = %inputFloat%><br> inputFloat (current value %inputFloat%): <input type="number " name="inputFloat" value = %inputFloat%><br>
@ -101,7 +102,7 @@ bool toggle_gpio_26(void *) {
// defaults // defaults
// String yourInputString; // String yourInputString;
// int yourInputInt; // int yourInputSend;
// float yourInputFloat; // float yourInputFloat;
void notFound(AsyncWebServerRequest *request) { void notFound(AsyncWebServerRequest *request) {
@ -146,8 +147,8 @@ String processor(const String& var){
if(var == "inputString"){ if(var == "inputString"){
return readFile(SPIFFS, "/inputString.txt"); return readFile(SPIFFS, "/inputString.txt");
} }
else if(var == "inputInt"){ else if(var == "inputSend"){
return readFile(SPIFFS, "/inputInt.txt"); return readFile(SPIFFS, "/inputSend.txt");
} }
else if(var == "inputFloat"){ else if(var == "inputFloat"){
return readFile(SPIFFS, "/inputFloat.txt"); return readFile(SPIFFS, "/inputFloat.txt");
@ -283,7 +284,7 @@ void setup() {
// Read in existing data // Read in existing data
yourInputString = readFile(SPIFFS, "/inputString.txt"); yourInputString = readFile(SPIFFS, "/inputString.txt");
yourInputInt = readFile(SPIFFS, "/inputInt.txt").toInt(); yourInputSend = readFile(SPIFFS, "/inputSend.txt").toInt();
yourInputFloat = readFile(SPIFFS, "/inputFloat.txt").toFloat(); yourInputFloat = readFile(SPIFFS, "/inputFloat.txt").toFloat();
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
@ -310,11 +311,11 @@ void setup() {
writeFile(SPIFFS, "/inputString.txt", inputMessage.c_str()); writeFile(SPIFFS, "/inputString.txt", inputMessage.c_str());
yourInputString = inputMessage; yourInputString = inputMessage;
} }
// GET inputInt value on <ESP_IP>/get?inputInt=<inputMessage> // GET inputSend value on <ESP_IP>/get?inputSend=<inputMessage>
if (request->hasParam(PARAM_INT)) { if (request->hasParam(PARAM_SEND)) {
inputMessage = request->getParam(PARAM_INT)->value(); inputMessage = request->getParam(PARAM_SEND)->value();
writeFile(SPIFFS, "/inputInt.txt", inputMessage.c_str()); writeFile(SPIFFS, "/inputSend.txt", inputMessage.c_str());
yourInputInt = inputMessage.toInt(); yourInputSend = inputMessage.toInt();
} }
// GET inputFloat value on <ESP_IP>/get?inputFloat=<inputMessage> // GET inputFloat value on <ESP_IP>/get?inputFloat=<inputMessage>
if (request->hasParam(PARAM_FLOAT)) { if (request->hasParam(PARAM_FLOAT)) {
@ -327,10 +328,6 @@ void setup() {
// } // }
request->send(200, "text/plain", inputMessage); request->send(200, "text/plain", inputMessage);
// // Update data from files
// String yourInputString = readFile(SPIFFS, "/inputString.txt");
// int yourInputInt = readFile(SPIFFS, "/inputInt.txt").toInt();
// float yourInputFloat = readFile(SPIFFS, "/inputFloat.txt").toFloat();
}); });
server.onNotFound(notFound); server.onNotFound(notFound);
server.begin(); server.begin();
@ -356,20 +353,25 @@ void loop() {
//arduinomorse //arduinomorse
//sender.continueSending(); //sender.continueSending();
//String yourInputString = readFile(SPIFFS, "/inputString.txt"); // if you want to send continuous code, and it's not sending, then start it up
//int yourInputInt = readFile(SPIFFS, "/inputInt.txt").toInt(); if((yourInputSend == 1) & (morseLed.IsRunning() == false)){
// float yourInputFloat = readFile(SPIFFS, "/inputFloat.txt").toFloat();
// if you want to send code, and it's not sending, then start it up
if((yourInputInt == 1) & (morseLed.IsRunning() == false)){
//jled //jled
morseLed.Reset().Update(); morseLed.Reset().Update();
//morse.send("CQ CQ CQ DE W1CDN K"); //etherkit morse //morse.send("CQ CQ CQ DE W1CDN K"); //etherkit morse
//telegraph26.send("CQ CQ CQ DE W1CDN K"); //telegraph //telegraph26.send("CQ CQ CQ DE W1CDN K"); //telegraph
// if you want to send code, and it is sending, keep sending // if you want to send continuous code, and it is sending, keep sending
} else if((yourInputInt == 1) & (morseLed.IsRunning() == true)){ } else if((yourInputSend == 1) & (morseLed.IsRunning() == true)){
morseLed.Update(); morseLed.Update();
// if you want to send cycle code and it is sending, keep sending
} else if((yourInputSend == 2) & (morseLed.IsRunning() == true)){
morseLed.Update();
// if you want to send cycle code and it's not sending, then start it up
} else if((yourInputSend == 2) & (morseLed.IsRunning() == true)){
morseLed.Reset().Update();
// if you don't want to send code // if you don't want to send code
} else { } else {
// stop sending and make sure the pin is off // stop sending and make sure the pin is off
@ -394,18 +396,4 @@ void loop() {
// output26State = "off"; // output26State = "off";
// } // }
// // To access your stored values on inputString, inputInt, inputFloat
// String yourInputString = readFile(SPIFFS, "/inputString.txt");
// Serial.print("*** Your inputString: ");
// Serial.println(yourInputString);
// int yourInputInt = readFile(SPIFFS, "/inputInt.txt").toInt();
// Serial.print("*** Your inputInt: ");
// Serial.println(yourInputInt);
// float yourInputFloat = readFile(SPIFFS, "/inputFloat.txt").toFloat();
// Serial.print("*** Your inputFloat: ");
// Serial.println(yourInputFloat);
// delay(5000);
} }