ESP32 web server; creates WiFi channel but does not load web pages; changing channel did not fix problem; changing IP address, still not loading web pages on either cell phone or laptop; Arduino 1.8.19, board manager esp32 2.0.5; ESP32-WROOM-DA Module, default 4MB, 240MHz, 4MB, core 1
#include <FastLED.h> #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3003000) #warning "Requires FastLED 3.3 or later; check github for latest code." #endif #include <WiFi.h> #include <WebServer.h> #include <FS.h> #include <SPIFFS.h> #include <EEPROM.h> WebServer webServer(80); const char* ssid = "JailCell"; const char* password = "1234567890"; const int channel = 10; const bool hide_SSID = false; IPAddress local_ip(192,168,55,1); IPAddress gateway(192,168,55,1); IPAddress subnet(255,255,255,0); const int led = 5; uint8_t autoplay = 0; uint8_t autoplayDuration = 10; unsigned long autoPlayTimeout = 0; uint8_t currentPatternIndex = 0; uint8_t gHue = 0; uint8_t power = 1; uint8_t brightness = 8; uint8_t speed = 30; uint8_t cooling = 50; uint8_t sparking = 120; CRGB solidColor = CRGB::Blue; uint8_t cyclePalettes = 0; uint8_t paletteDuration = 10; uint8_t currentPaletteIndex = 0; unsigned long paletteTimeout = 0; #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) #define DATA_PIN 18 #define LED_TYPE WS2812 #define COLOR_ORDER GRB #define NUM_STRIPS 1 #define NUM_LEDS_PER_STRIP 64 #define NUM_LEDS NUM_LEDS_PER_STRIP * NUM_STRIPS CRGB leds[NUM_LEDS]; #define MILLI_AMPS 1600 #define FRAMES_PER_SECOND 120 #include "patterns.h" #include "field.h" #include "fields.h" void listDir(fs::FS &fs, const char * dirname, uint8_t levels) { Serial.printf("Listing directory: %s\n", dirname); File root = fs.open(dirname); if (!root) { Serial.println("Failed to open directory"); return; } if (!root.isDirectory()) { Serial.println("Not a directory"); return; } File file = root.openNextFile(); while (file) { if (file.isDirectory()) { Serial.print(" DIR : "); Serial.println(file.name()); if (levels) { listDir(fs, file.name(), levels - 1); } } else { Serial.print(" FILE: "); Serial.print(file.name()); Serial.print(" SIZE: "); Serial.println(file.size()); } file = root.openNextFile(); } } void setup() { pinMode(led, OUTPUT); digitalWrite(led, 1); Serial.begin(115200); Serial.println("\n[*] Creating AP"); SPIFFS.begin(); listDir(SPIFFS, "/", 1); WiFi.mode(WIFI_AP); WiFi.softAPConfig(local_ip, gateway, subnet); WiFi.softAP(ssid, password, channel, hide_SSID); delay(2000); // to avoid crash on WiFi connection Serial.print("[+] AP Created with IP Gateway "); Serial.println(WiFi.softAPIP()); setupWeb(); FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); FastLED.setMaxPowerInVoltsAndMilliamps(5, MILLI_AMPS); FastLED.setBrightness(brightness); autoPlayTimeout = millis() + (autoplayDuration * 1000); } void setupWeb() { webServer.on("/all", HTTP_GET, []() { digitalWrite(led, 0); String json = getFieldsJson(fields, fieldCount); webServer.send(200, "text/json", json); digitalWrite(led, 1); }); webServer.on("/fieldValue", HTTP_GET, []() { digitalWrite(led, 0); String name = webServer.arg("name"); String value = getFieldValue(name, fields, fieldCount); webServer.send(200, "text/json", value); digitalWrite(led, 1); }); webServer.on("/fieldValue", HTTP_POST, []() { digitalWrite(led, 0); String name = webServer.arg("name"); String value = webServer.arg("value"); String newValue = setFieldValue(name, value, fields, fieldCount); webServer.send(200, "text/json", newValue); digitalWrite(led, 1); }); webServer.serveStatic("/", SPIFFS, "/index.htm", "max-age=86400"); webServer.serveStatic("/index.htm", SPIFFS, "/index.htm", "max-age=86400"); webServer.serveStatic("/favicon.ico", SPIFFS, "/favicon.ico", "max-age=86400"); webServer.serveStatic("/css/styles.css", SPIFFS, "/css/styles.css", "max-age=86400"); webServer.serveStatic("/js/app.js", SPIFFS, "/js/app.js", "max-age=86400"); webServer.serveStatic("/images/atom196.png", SPIFFS, "/images/atom196.png", "max-age=86400"); webServer.begin(); Serial.println ( "HTTP server started" ); } void handleWeb() { static bool webServerStarted = false; // check for connection if ( WiFi.status() == WL_CONNECTED ) { if (!webServerStarted) { // turn off the board's LED when connected to wifi digitalWrite(led, 1); Serial.println(); Serial.println("WiFi connected"); Serial.print("IP address: "); Serial.println(WiFi.localIP()); webServerStarted = true; setupWeb(); } webServer.handleClient(); } else { // blink the board's LED while connecting to wifi static uint8_t ledState = 0; EVERY_N_MILLIS(125) { ledState = ledState == 0 ? 1 : 0; digitalWrite(led, ledState); Serial.print ("."); } } } void loop() { handleWeb(); if (power == 0) { fill_solid(leds, NUM_LEDS, CRGB::Black); } else { patterns[currentPatternIndex].pattern(); EVERY_N_MILLISECONDS(40) { nblendPaletteTowardPalette(currentPalette, targetPalette, 8); gHue++; } if (autoplay == 1 && (millis() > autoPlayTimeout)) { nextPattern(); autoPlayTimeout = millis() + (autoplayDuration * 1000); } if (cyclePalettes == 1 && (millis() > paletteTimeout)) { nextPalette(); paletteTimeout = millis() + (paletteDuration * 1000); } } FastLED.show(); FastLED.delay(1000 / FRAMES_PER_SECOND); } void nextPattern() { currentPatternIndex = (currentPatternIndex + 1) % patternCount; } void nextPalette() { currentPaletteIndex = (currentPaletteIndex + 1) % paletteCount; targetPalette = palettes[currentPaletteIndex]; }
monitor output:
11:51:57.734 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) 11:51:57.734 -> configsip: 0, SPIWP:0xee 11:51:57.734 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 11:51:57.734 -> mode:DIO, clock div:1 11:51:57.734 -> load:0x3fff0030,len:1344 11:51:57.734 -> load:0x40078000,len:13864 11:51:57.734 -> load:0x40080400,len:3608 11:51:57.767 -> entry 0x400805f0 11:51:58.000 -> [1][V][WiFiServer.h:42] WiFiServer(): WiFiServer::WiFiServer(port=⸮brrrJj 11:51:58.000 -> [1][V][WebServer.cpp:87] WebServer(): WebServer::Webserver(port=80) 11:51:58.034 -> [7][D][esp32-hal-cpu.c:244] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz 11:51:58.034 -> 11:51:58.034 -> [*] Creating AP 11:51:58.167 -> Listing directory: / 11:51:58.352 -> FILE: app.js SIZE: 13101 11:51:58.352 -> FILE: favicon.ico SIZE: 4286 11:51:58.352 -> FILE: atom196.png SIZE: 5469 11:51:58.352 -> FILE: styles.css SIZE: 31 11:51:58.352 -> FILE: index.htm SIZE: 10733 11:51:58.352 -> [307][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 0 - WIFI_READY 11:51:58.394 -> [395][I][WiFiGeneric.cpp:1354] setDualAntennaConfig(): TX Antenna will be automatically selected 11:51:58.401 -> [395][V][WiFiGeneric.cpp:390] _arduino_event_cb(): AP Started 11:51:58.438 -> [396][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring SoftAP static IP: 192.168.55.1, MASK: 255.255.255.0, GW: 192.168.55.1 11:51:58.438 -> [399][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 10 - AP_START 11:51:58.438 -> [418][V][WiFiGeneric.cpp:143] set_esp_interface_ip(): SoftAP: 192.168.55.1 | Gateway: 192.168.55.1 | DHCP Start: 0.0.0.0 | Netmask: 255.255.255.0 11:51:58.438 -> [431][V][WiFiGeneric.cpp:190] set_esp_interface_ip(): DHCP Server Range: 192.168.55.2 to 192.168.55.12 11:52:00.463 -> [+] AP Created with IP Gateway 192.168.55.1 11:52:00.463 -> [2442][V][RequestHandlersImpl.h:73] StaticRequestHandler(): StaticRequestHandler: path=/index.htm uri=/ isFile=1, cache_header=max-age=86400 11:52:00.463 -> 11:52:00.463 -> [2446][V][RequestHandlersImpl.h:73] StaticRequestHandler(): StaticRequestHandler: path=/index.htm uri=/index.htm isFile=1, cache_header=max-age=86400 11:52:00.547 -> 11:52:00.547 -> [2506][V][RequestHandlersImpl.h:73] StaticRequestHandler(): StaticRequestHandler: path=/favicon.ico uri=/favicon.ico isFile=1, cache_header=max-age=86400 11:52:00.547 -> 11:52:00.547 -> [2510][V][RequestHandlersImpl.h:73] StaticRequestHandler(): StaticRequestHandler: path=/css/styles.css uri=/css/styles.css isFile=1, cache_header=max-age=86400 11:52:00.547 -> 11:52:00.622 -> [2569][V][RequestHandlersImpl.h:73] StaticRequestHandler(): StaticRequestHandler: path=/js/app.js uri=/js/app.js isFile=1, cache_header=max-age=86400 11:52:00.622 -> 11:52:00.622 -> [2573][V][RequestHandlersImpl.h:73] StaticRequestHandler(): StaticRequestHandler: path=/images/atom196.png uri=/images/atom196.png isFile=1, cache_header=max-age=86400 11:52:00.622 -> 11:52:00.622 -> HTTP server started 11:52:00.729 -> .........................................