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* PARAM_STRING = "inputString";
const char* PARAM_INT = "inputInt";
const char* PARAM_SEND = "inputSend";
const char* PARAM_FLOAT = "inputFloat";
// Global variables
String yourInputString;
int yourInputInt;
int yourInputSend;
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(
<!DOCTYPE HTML><html><head>
<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>
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="0">Cycle</option>
<option value="2">Cycle</option>
</select><br>
inputFloat (current value %inputFloat%): <input type="number " name="inputFloat" value = %inputFloat%><br>
@ -101,7 +102,7 @@ bool toggle_gpio_26(void *) {
// defaults
// String yourInputString;
// int yourInputInt;
// int yourInputSend;
// float yourInputFloat;
void notFound(AsyncWebServerRequest *request) {
@ -146,8 +147,8 @@ String processor(const String& var){
if(var == "inputString"){
return readFile(SPIFFS, "/inputString.txt");
}
else if(var == "inputInt"){
return readFile(SPIFFS, "/inputInt.txt");
else if(var == "inputSend"){
return readFile(SPIFFS, "/inputSend.txt");
}
else if(var == "inputFloat"){
return readFile(SPIFFS, "/inputFloat.txt");
@ -283,7 +284,7 @@ void setup() {
// Read in existing data
yourInputString = readFile(SPIFFS, "/inputString.txt");
yourInputInt = readFile(SPIFFS, "/inputInt.txt").toInt();
yourInputSend = readFile(SPIFFS, "/inputSend.txt").toInt();
yourInputFloat = readFile(SPIFFS, "/inputFloat.txt").toFloat();
WiFi.mode(WIFI_STA);
@ -310,11 +311,11 @@ void setup() {
writeFile(SPIFFS, "/inputString.txt", inputMessage.c_str());
yourInputString = inputMessage;
}
// GET inputInt value on <ESP_IP>/get?inputInt=<inputMessage>
if (request->hasParam(PARAM_INT)) {
inputMessage = request->getParam(PARAM_INT)->value();
writeFile(SPIFFS, "/inputInt.txt", inputMessage.c_str());
yourInputInt = inputMessage.toInt();
// GET inputSend value on <ESP_IP>/get?inputSend=<inputMessage>
if (request->hasParam(PARAM_SEND)) {
inputMessage = request->getParam(PARAM_SEND)->value();
writeFile(SPIFFS, "/inputSend.txt", inputMessage.c_str());
yourInputSend = inputMessage.toInt();
}
// GET inputFloat value on <ESP_IP>/get?inputFloat=<inputMessage>
if (request->hasParam(PARAM_FLOAT)) {
@ -327,10 +328,6 @@ void setup() {
// }
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.begin();
@ -356,20 +353,25 @@ void loop() {
//arduinomorse
//sender.continueSending();
//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
if((yourInputInt == 1) & (morseLed.IsRunning() == false)){
// if you want to send continuous code, and it's not sending, then start it up
if((yourInputSend == 1) & (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 == 1) & (morseLed.IsRunning() == true)){
// if you want to send continuous code, and it is sending, keep sending
} else if((yourInputSend == 1) & (morseLed.IsRunning() == true)){
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
} else {
// stop sending and make sure the pin is off
@ -394,18 +396,4 @@ void loop() {
// 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);
}