diff --git a/src/main.cpp b/src/main.cpp
index 2a36174..f7df652 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -38,8 +38,8 @@ const int alarmPin = 4; // pin to monitor for RTC alarms
const int network = 1;
// Connect to existing network
// Read from config.h
-const char* ssid = WIFI_SSID;
-const char* password = WIFI_PASSWORD;
+//const char* ssid = WIFI_SSID;
+//const char* password = WIFI_PASSWORD;
// Create a new access point
// Replace with your desired network credentials
const char* ssid_ap = "vulpes";
@@ -59,6 +59,9 @@ const char* PARAM_RUNNING = "programRunning";
const char* PARAM_STEPLENGTH = "inputStepLength";
const char* PARAM_CYCLEID = "inputCycleID";
const char* PARAM_NTRANS = "inputNtransmitters";
+const char* PARAM_NETWORK = "inputNetwork";
+const char* PARAM_SSID = "inputSSID";
+const char* PARAM_PASSWORD = "inputPassword";
// Global variables
int yourInputSend;
@@ -74,6 +77,9 @@ bool programRunning;
int yourInputStepLength;
int yourInputCycleID;
int yourInputNtransmitters;
+int yourInputNetwork;
+String yourInputSSID;
+String yourInputPassword;
long start_millis = 0;
long stop_millis = 0;
long pause_until_millis = 0;
@@ -123,6 +129,7 @@ const char index_html[] PROGMEM = R"rawliteral(
// Fill in the other form fields
document.getElementById("send-program").value = %inputSend%;
document.getElementById("message").value = %inputMsg%;
+ document.getElementById("network").value = %inputNetwork%;
}
@@ -177,6 +184,23 @@ const char index_html[] PROGMEM = R"rawliteral(
+
+
+ Network Settings
+
+
+
@@ -243,6 +267,15 @@ String processor(const String& var){
else if(var == "inputNtransmitters"){
return readFile(SPIFFS, "/inputNtransmitters.txt");
}
+ else if(var == "inputNetwork"){
+ return readFile(SPIFFS, "/inputNetwork.txt");
+ }
+ else if(var == "inputSSID"){
+ return readFile(SPIFFS, "/inputSSID.txt");
+ }
+ else if(var == "inputPassword"){
+ return readFile(SPIFFS, "/inputPassword.txt");
+ }
else if(var == "inputFloat"){
return readFile(SPIFFS, "/inputFloat.txt");
} else if(var == "inputStartTimeUnix"){
@@ -331,6 +364,9 @@ void setup() {
yourInputStepLength = readFile(SPIFFS, "/inputStepLength.txt").toInt();
yourInputCycleID = readFile(SPIFFS, "/inputCycleID.txt").toInt();
yourInputNtransmitters = readFile(SPIFFS, "/inputNtransmitters.txt").toInt();
+ yourInputNetwork = readFile(SPIFFS, "/inputNetwork.txt").toInt();
+ yourInputSSID = readFile(SPIFFS, "/inputSSID.txt");
+ yourInputPassword = readFile(SPIFFS, "/inputPassword.txt");
// Set WPM from saved value
sender_blink.setWPM(yourInputWPM);
sender_key.setWPM(yourInputWPM);
@@ -358,18 +394,22 @@ void setup() {
}
WiFi.setHostname("vulpes");
- if (network == 0){
+ if (yourInputNetwork == 1){
// Attach to existing wifi
WiFi.mode(WIFI_STA);
- WiFi.begin(ssid, password);
+ const char* ssid_char = yourInputSSID.c_str();
+ const char* password_char = yourInputPassword.c_str();
+ WiFi.begin(ssid_char, password_char);
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("WiFi Failed!");
- return;
+ // If you fail to connect, act as new access point
+ WiFi.softAPConfig(local_ip, gateway, subnet);
+ WiFi.softAP(ssid_ap, password_ap);
+ //return;
}
- Serial.println();
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
- } else if (network == 1){
+ } else if (yourInputNetwork == 0){
// Act as new access point
WiFi.softAPConfig(local_ip, gateway, subnet);
WiFi.softAP(ssid_ap, password_ap);
@@ -382,6 +422,7 @@ void setup() {
request->send_P(200, "text/html", index_html, processor);
});
+ // Form 1
// Send a GET request to /get?inputCustomMsg=
server.on("/get", HTTP_GET, [] (AsyncWebServerRequest *request) {
String inputMessage;
@@ -528,6 +569,34 @@ void setup() {
// https://techtutorialsx.com/2018/01/14/esp32-arduino-http-server-external-and-internal-redirects/
request->redirect("/");
});
+
+ // Form 2
+ server.on("/get2", HTTP_GET, [] (AsyncWebServerRequest *request) {
+ String inputMessage;
+ /// GET inputNetwork value on /get2?inputNetwork=
+ if (request->hasParam(PARAM_NETWORK)) {
+ inputMessage = request->getParam(PARAM_NETWORK)->value();
+ writeFile(SPIFFS, "/inputNetwork.txt", inputMessage.c_str());
+ yourInputNetwork = inputMessage.toInt();
+ Serial.println(yourInputNetwork);
+ }
+ /// GET inputSSID value on /get2?inputSSID=
+ if (request->hasParam(PARAM_SSID)) {
+ inputMessage = request->getParam(PARAM_SSID)->value();
+ writeFile(SPIFFS, "/inputSSID.txt", inputMessage.c_str());
+ yourInputSSID = inputMessage;
+ Serial.println(yourInputSSID);
+ }
+ /// GET inputNetwork value on /get2?inputNetwork=
+ if (request->hasParam(PARAM_PASSWORD)) {
+ inputMessage = request->getParam(PARAM_PASSWORD)->value();
+ writeFile(SPIFFS, "/inputPassword.txt", inputMessage.c_str());
+ yourInputPassword = inputMessage;
+ Serial.println(yourInputPassword);
+ }
+ request->redirect("/");
+ });
+
server.onNotFound(notFound);
server.begin();