From 8106d576be61b577edcb0f35b67bd1d8b308bc7d Mon Sep 17 00:00:00 2001 From: mattbk Date: Mon, 25 Sep 2023 21:36:37 -0500 Subject: [PATCH] Add option to set up for wifi or ap on compile. --- vulpes/src/main.cpp | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/vulpes/src/main.cpp b/vulpes/src/main.cpp index 6f49a1d..294dbf1 100644 --- a/vulpes/src/main.cpp +++ b/vulpes/src/main.cpp @@ -34,9 +34,19 @@ const int blinker = LED_BUILTIN; RTC_DS3231 rtc; // set up RTC const int alarmPin = 4; // pin to monitor for RTC alarms +// Network options: "wifi" for existing netowrk, "ap" to be an access point +const char* network = "ap"; +// Connect to existing network // Read from config.h const char* ssid = WIFI_SSID; const char* password = WIFI_PASSWORD; +// Create a new access point +// Replace with your network credentials +const char* ssid_ap = "vulpes001"; +const char* password_ap = NULL; //"123456789"; +IPAddress local_ip(192,168,0,1); +IPAddress gateway(192,168,0,1); +IPAddress subnet(255,255,255,0); const char* PARAM_SEND = "inputSend"; const char* PARAM_WPM = "inputWPM"; @@ -347,15 +357,25 @@ void setup() { sender_key.setMessage(String("mo5 ")); } - WiFi.mode(WIFI_STA); - WiFi.begin(ssid, password); - if (WiFi.waitForConnectResult() != WL_CONNECTED) { - Serial.println("WiFi Failed!"); - return; + WiFi.setHostname("vulpes"); + if (network == "wifi"){ + // Attach to existing wifi + WiFi.mode(WIFI_STA); + WiFi.begin(ssid, password); + if (WiFi.waitForConnectResult() != WL_CONNECTED) { + Serial.println("WiFi Failed!"); + return; + } + Serial.println(); + Serial.print("IP Address: "); + Serial.println(WiFi.localIP()); + } else if (network == "ap"){ + // Act as new access point + WiFi.softAPConfig(local_ip, gateway, subnet); + WiFi.softAP(ssid_ap, password_ap); } - Serial.println(); - Serial.print("IP Address: "); - Serial.println(WiFi.localIP()); + + // Send web page with input fields to client server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){