Allow easy switch between AP and station

This commit is contained in:
Gabriel Augendre 2023-01-01 01:02:18 +01:00
parent bebf8b5af3
commit 61c9623f71
3 changed files with 19 additions and 3 deletions

1
.gitignore vendored
View file

@ -58,3 +58,4 @@ Temporary Items
.apdisk .apdisk
# End of https://www.toptal.com/developers/gitignore/api/osx # End of https://www.toptal.com/developers/gitignore/api/osx
creds.h

3
src/creds.dist.h Normal file
View file

@ -0,0 +1,3 @@
// Copy to creds.h and edit
const char *ssid = "buzzer";
const char *password = "123456789";

View file

@ -1,9 +1,9 @@
#include <Arduino.h> #include <Arduino.h>
#include <ESPAsyncWebServer.h> #include <ESPAsyncWebServer.h>
#include <SPIFFS.h> #include <SPIFFS.h>
#include "creds.h"
const char *ssid = "buzzer"; // #define B_WIFI_AP
const char *password = "123456789";
const byte led = 2; const byte led = 2;
bool ledOn = false; bool ledOn = false;
@ -52,10 +52,22 @@ void setup()
} }
// Wifi // Wifi
#ifdef B_WIFI_AP
Serial.println("Setting up AP..."); Serial.println("Setting up AP...");
WiFi.softAP(ssid, password); WiFi.softAP(ssid, password);
Serial.print("IP address: "); Serial.print("IP address: ");
Serial.println(WiFi.softAPIP()); Serial.println(WiFi.softAPIP());
#else
Serial.print("Connecting to wifi...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(100);
}
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
#endif
// Server // Server
server.on("/play", HTTP_GET, onPlay); server.on("/play", HTTP_GET, onPlay);