From 61c9623f712b6719a00e4ff33bbf5cc5bc14e65b Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sun, 1 Jan 2023 01:02:18 +0100 Subject: [PATCH] Allow easy switch between AP and station --- .gitignore | 1 + src/creds.dist.h | 3 +++ src/main.cpp | 18 +++++++++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 src/creds.dist.h diff --git a/.gitignore b/.gitignore index 3e63e0e..6519c69 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,4 @@ Temporary Items .apdisk # End of https://www.toptal.com/developers/gitignore/api/osx +creds.h diff --git a/src/creds.dist.h b/src/creds.dist.h new file mode 100644 index 0000000..8bb4dd3 --- /dev/null +++ b/src/creds.dist.h @@ -0,0 +1,3 @@ +// Copy to creds.h and edit +const char *ssid = "buzzer"; +const char *password = "123456789"; diff --git a/src/main.cpp b/src/main.cpp index d8cffd0..9914731 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,9 +1,9 @@ #include #include #include +#include "creds.h" -const char *ssid = "buzzer"; -const char *password = "123456789"; +// #define B_WIFI_AP const byte led = 2; bool ledOn = false; @@ -51,11 +51,23 @@ void setup() file = root.openNextFile(); } - // Wifi +// Wifi +#ifdef B_WIFI_AP Serial.println("Setting up AP..."); WiFi.softAP(ssid, password); Serial.print("IP address: "); 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.on("/play", HTTP_GET, onPlay);