Add option to set up for wifi or AP on compile #53

Merged
W1CDN merged 9 commits from access-point into main 2023-10-01 11:29:23 -05:00
Showing only changes of commit 8106d576be - Show all commits

View File

@ -34,9 +34,19 @@ const int blinker = LED_BUILTIN;
RTC_DS3231 rtc; // set up RTC RTC_DS3231 rtc; // set up RTC
const int alarmPin = 4; // pin to monitor for RTC alarms 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 // Read from config.h
const char* ssid = WIFI_SSID; const char* ssid = WIFI_SSID;
const char* password = WIFI_PASSWORD; 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_SEND = "inputSend";
const char* PARAM_WPM = "inputWPM"; const char* PARAM_WPM = "inputWPM";
@ -347,15 +357,25 @@ void setup() {
sender_key.setMessage(String("mo5 ")); sender_key.setMessage(String("mo5 "));
} }
WiFi.mode(WIFI_STA); WiFi.setHostname("vulpes");
WiFi.begin(ssid, password); if (network == "wifi"){
if (WiFi.waitForConnectResult() != WL_CONNECTED) { // Attach to existing wifi
Serial.println("WiFi Failed!"); WiFi.mode(WIFI_STA);
return; 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 // Send web page with input fields to client
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){