Wifimanager config conflicting with Littlefs html page

Hi.
I am trying to use wifimanager and serve another html page using Littlefs but it is creating problem with connecting their respective IPs in the browser.

If I connect to wifi config page through its IP 1st and then exit that page then the "connection is refused" for the html page's IP.
And instead, If it connects to previously saved wifi credentials 1st and if then the connection is lost and it starts an AP but instead of serving wifimager's config page on wifimanager's IP the html page is served there.

Board is NodeMCU 1.0(ESP-12E)
Code is below:

#include "LittleFS.h"
// #include <LittleFS.h>
#include <ESP8266WiFi.h>
#include <Arduino.h>
// #include <FS.h>
#include <WiFiManager.h>
#include <ESPAsyncWebServer.h>

// Network credentials
const char* APName = "ESP-AP";
const char* password = "12341234";

// const int wifiLed = LED_BUILTIN;
String broadCast;

String processor(const String& var){
  if(var == "BROADCAST"){
    return String(broadCast);
  }
  return String();
}

AsyncWebServer server(80);

void initFS() {
  if (!LittleFS.begin()) {
    Serial.println("An error has occurred while mounting LittleFS");
  }
  else{
   Serial.println("LittleFS mounted successfully");
  }
}

// Wifi Setup
void initWiFi(){
  WiFiManager wifiManager; 
  wifiManager.setConnectTimeout(60);
  wifiManager.autoConnect(APName, password);
  Serial.print("Connecting to WiFi.. ");
  broadCast = WiFi.localIP().toString();
  Serial.print("LocalIP:");
  Serial.println(broadCast);
}

void setup() {
  Serial.begin(115200);
  initFS();
  initWiFi();
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send(LittleFS, "/index.html", String(), false, processor);
  });
  server.serveStatic("/", LittleFS, "/");

  server.begin();
}

void loop(){
  while (WiFi.status() != WL_CONNECTED) {
    initWiFi();
  }
}

Is it a SPIFFS / LittleFS conflict or something else?

If you look at the WifiManager examples, you are not testing the return value of .autoConnect() so you don't know if you are really connected or not and it may be possible that your variable broadCast isn't valid anymore.

Tried with the callback but still giving the same problem. And I can see in access point's UI that it connects to it successfully.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.