ESP32 web server; works in STA mode -but- not AP mode

campinLOU
Posts: 2
Joined: Fri Jan 27, 2023 8:58 pm

ESP32 web server; works in STA mode -but- not AP mode

Postby campinLOU » Sat Jan 28, 2023 2:48 am

Problem: uploaded web server created by Jason Coon via esp32-fastled-webserver; works as described in Station Mode; added softAP mode to existing code; Station mode still works without any problems -however- softAP will not connect and load web pages even though WiFi channel is created. Changed channel from default "1" to "9" with no change in working status; changed IP address with same results; changed from using Arduino 1.8.19 to VS Code, same results

*** AP Mode *****
WebServer webServer(80);
const bool apMode = true;
13: 14: 48.984 -> rst: 0x1 (POWERON_RESET), boot: 0x13 (SPI_FAST_FLASH_BOOT)
13: 14: 48.984 -> configsip: 0, SPIWP: 0xee
13: 14: 48.984 -> clk_drv: 0x00, q_drv: 0x00, d_drv: 0x00, cs0_drv: 0x00, hd_drv: 0x00, wp_drv: 0x00
13: 14: 48.984 -> mode: DIO, clock div: 1
13: 14: 48.984 -> load: 0x3fff0030, len: 1240
13: 14: 48.984 -> load: 0x40078000, len: 13012
13: 14: 48.984 -> load: 0x40080400, len: 3648
13: 14: 49.018 -> entry 0x400805f8
13: 14: 49.451 -> Listing directory: /
13: 14: 49.584 -> FILE: app.js SIZE: 13101
13: 14: 49.584 -> FILE: favicon.ico SIZE: 4286
13: 14: 49.584 -> FILE: atom196.png SIZE: 5469
13: 14: 49.584 -> FILE: styles.css SIZE: 31
13: 14: 49.618 -> FILE: index.htm SIZE: 10733
13: 14: 49.786 -> Connect to Wi - Fi access point: JailCell
13: 14: 49.786 -> and open http: //192.168.4.1 in your browser
13: 14: 49.917 -> HTTP server started
13: 14: 50.050 -> ......................................................................................



***** STA Mode: *****
WebServer webServer(80);
const bool apMode = false;
13: 21: 28.421 -> rst: 0x1 (POWERON_RESET), boot: 0x13 (SPI_FAST_FLASH_BOOT)
13: 21: 28.421 -> configsip: 0, SPIWP: 0xee
13: 21: 28.421 -> clk_drv: 0x00, q_drv: 0x00, d_drv: 0x00, cs0_drv: 0x00, hd_drv: 0x00, wp_drv: 0x00
13: 21: 28.454 -> mode: DIO, clock div: 1
13: 21: 28.454 -> load: 0x3fff0030, len: 1240
13: 21: 28.454 -> load: 0x40078000, len: 13012
13: 21: 28.454 -> load: 0x40080400, len: 3648
13: 21: 28.454 -> entry 0x400805f8
13: 21: 28.887 -> Listing directory: /
13: 21: 29.053 -> FILE: app.js SIZE: 13101
13: 21: 29.053 -> FILE: favicon.ico SIZE: 4286
13: 21: 29.053 -> FILE: atom196.png SIZE: 5469
13: 21: 29.053 -> FILE: styles.css SIZE: 31
13: 21: 29.053 -> FILE: index.htm SIZE: 10733
13: 21: 29.214 -> Connecting to SMG930V5FE3
13: 21: 29.353 -> HTTP server started
13: 21: 29.486 -> ...............
13: 21: 31.419 -> WiFi connected
13: 21: 31.419 -> IP address: 192.168.77.50
13: 21: 31.552 -> HTTP server started

Code: Select all

    // ESP32 FastLED WebServer: https://github.com/jasoncoon/esp32-fastled-webserver; Copyright (C) 2017 Jason Coon  
    #include <FastLED.h>
    #include <WiFi.h>
    #include <WebServer.h>
    #include <FS.h>
    #include <SPIFFS.h>
    #include <EEPROM.h>

    #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3003000)
    #warning "Requires FastLED 3.3 or later; check github for latest code."
    #endif

    WebServer webServer(80);
    const bool apMode = true;



    const int led = 5;

    uint8_t autoplay = 0;
    uint8_t autoplayDuration = 10;
    unsigned long autoPlayTimeout = 0;

    uint8_t currentPatternIndex = 0; // Index number of which pattern is current

    uint8_t gHue = 0; // rotating "base color" used by many of the patterns

    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 FRAMES_PER_SECOND  120
    
    #include "patterns.h"
    #include "field.h"
    #include "fields.h"
    #include "msds.h"
    #include "web.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);
    
      SPIFFS.begin();
      listDir(SPIFFS, "/", 1);
    
    
      if (apMode)
      {
        WiFi.mode(WIFI_AP);
        WiFi.softAP(hostnameChar, WiFiAPPSK, 9);
        Serial.printf("Connect to Wi-Fi access point: %s\n", hostnameChar);
        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);
        }
      }
    
      setupWeb();

      FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
      FastLED.setBrightness(brightness);
    
      autoPlayTimeout = millis() + (autoplayDuration * 1000);
    } 



    void loop()
{   
      handleWeb();
    
      if (power == 0) {
        fill_solid(leds, NUM_LEDS, CRGB::Black);
      }
      else {
        // Call the current pattern function once, updating the 'leds' array
        patterns[currentPatternIndex].pattern();

        EVERY_N_MILLISECONDS(40) {
          // slowly blend the current palette to the next
          nblendPaletteTowardPalette(currentPalette, targetPalette, 8);
          gHue++;  // slowly cycle the "base color" through the rainbow
        }

        if (autoplay == 1 && (millis() > autoPlayTimeout)) {
          nextPattern();
          autoPlayTimeout = millis() + (autoplayDuration * 1000);
        }

        if (cyclePalettes == 1 && (millis() > paletteTimeout)) {
          nextPalette();
          paletteTimeout = millis() + (paletteDuration * 1000);
        }
      }

      // send the 'leds' array out to the actual LED strip
      FastLED.show();
      FastLED.delay(1000 / FRAMES_PER_SECOND);
    }

    void nextPattern()
    {
      // add one to the current pattern number, and wrap around at the end
      currentPatternIndex = (currentPatternIndex + 1) % patternCount;
    }

    void nextPalette()
    {
      currentPaletteIndex = (currentPaletteIndex + 1) % paletteCount;
      targetPalette = palettes[currentPaletteIndex];
    }

ullixesp
Posts: 83
Joined: Wed Oct 16, 2019 9:34 am
Location: Germany

Re: ESP32 web server; works in STA mode -but- not AP mode

Postby ullixesp » Sun Jan 29, 2023 2:10 pm

This looks like the 3rd web server problem in a row, and I have the same suggestion:

before you spend more time on this I suggest to use the ASYNC server:
https://github.com/me-no-dev/ESPAsyncWebServer
A bit steeper hurdle to start, but at some point you will need it anyway!

Who is online

Users browsing this forum: No registered users and 51 guests