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
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,6 +357,9 @@ void setup() {
sender_key.setMessage(String("mo5 "));
}
WiFi.setHostname("vulpes");
if (network == "wifi"){
// Attach to existing wifi
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
@ -356,6 +369,13 @@ void setup() {
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);
}
// Send web page with input fields to client
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){