From 813970de78e23afee20db5585b1219d0a64dde41 Mon Sep 17 00:00:00 2001 From: Markus Rudel Date: Tue, 30 Jan 2018 17:30:09 +0100 Subject: [PATCH] added code from https://github.com/jasoncoon/esp8266-fastled-webserver/issues/62 --- esp8266-fastled-webserver.ino | 49 +++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/esp8266-fastled-webserver.ino b/esp8266-fastled-webserver.ino index 0ad0f0d..b1020cb 100644 --- a/esp8266-fastled-webserver.ino +++ b/esp8266-fastled-webserver.ino @@ -42,6 +42,8 @@ extern "C" { //#include "Commands.h" +const bool apMode = false; + ESP8266WebServer webServer(80); WebSocketsServer webSocketsServer = WebSocketsServer(81); ESP8266HTTPUpdateServer httpUpdateServer; @@ -50,7 +52,7 @@ ESP8266HTTPUpdateServer httpUpdateServer; #include "FSBrowser.h" -#define DATA_PIN D8 +#define DATA_PIN D4 #define LED_TYPE WS2811 #define COLOR_ORDER GRB #define NUM_LEDS 24 @@ -243,7 +245,50 @@ void setup() { Serial.printf("\n"); } - initializeWiFi(); + //disabled due to https://github.com/jasoncoon/esp8266-fastled-webserver/issues/62 + //initializeWiFi(); + + if (apMode) + { + WiFi.mode(WIFI_AP); + + // Do a little work to get a unique-ish name. Append the + // last two bytes of the MAC (HEX'd) to "Thing-": + uint8_t mac[WL_MAC_ADDR_LENGTH]; + WiFi.softAPmacAddress(mac); + String macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) + + String(mac[WL_MAC_ADDR_LENGTH - 1], HEX); + macID.toUpperCase(); + String AP_NameString = "ESP8266 Thing " + macID; + + char AP_NameChar[AP_NameString.length() + 1]; + memset(AP_NameChar, 0, AP_NameString.length() + 1); + + for (int i = 0; i < AP_NameString.length(); i++) + AP_NameChar[i] = AP_NameString.charAt(i); + + WiFi.softAP(AP_NameChar, WiFiAPPSK); + + Serial.printf("Connect to Wi-Fi access point: %s\n", AP_NameChar); + Serial.println("and open http://192.168.4.1 in your browser"); + } + else + { + WiFi.mode(WIFI_STA); + Serial.printf("Connecting to %s\n", ssid); + if (String(WiFi.SSID()) != String(ssid)) { + WiFi.begin(ssid, password); + } + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + + Serial.print("Connected! Open http://"); + Serial.print(WiFi.localIP()); + Serial.println(" in your browser"); + } checkWiFi();