Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
KC868-A16 - Custom Form Wifimanager Root content
#1
Hi All,
I am trying to add new form to root page and configure the form as per my requirements

Please check below sample code is not working. 

And send me Latest Arduino IDE wifimanager sample example  code. 





#include <WiFiManager.h>          // https://github.com/tzapu/WiFiManager
#include <FS.h>
#include <SPIFFS.h>
const char* htmlFile = "/index.html";
void setup() {
  Serial.begin(115200);
 
  // Initialize SPIFFS
  if (!SPIFFS.begin(true)) {
    Serial.println("An Error has occurred while mounting SPIFFS");
    return;
  }
  // Create WiFiManager instance
  WiFiManager wifiManager;
  // Set custom root page handler
  wifiManager.setCustomHeadElement("<style>body{background-color:#f0f0f0;}</style>");
  wifiManager.setAPCallback([](WiFiManager *wm) {
    // This runs when AP mode is started
 
   
   // Add custom route handler for root page
    wm->server->on("/", HTTP_GET, [wm]() {
      if (SPIFFS.exists(htmlFile)) {
        File file = SPIFFS.open(htmlFile, "r");
        if (file) {
          wm->server->sendHeader("Content-Encoding", "gzip"); // If file is compressed
          wm->server->streamFile(file, "text/html");
          file.close();
          return;
        }
      }
      // Fallback to default if file not found
      wm->server->send(200, "text/html",
        "<html><body><h1>WiFi Config</h1>"
        "<p>Please connect to WiFi network</p>"
        "<p>Then configure your settings</p></body></html>");
    });
  });
  // Start WiFiManager
  if (!wifiManager.autoConnect("MyAP")) {
    Serial.println("Failed to connect");
   //////////// ESP.restart();
  }
  Serial.println("Connected!");
}
void loop() {
  // Your code here
}
Reply
#2
maybe you can change your ESP32 board verison in arudino IDE.
about "wifiManager", you can visit author's webpage download directly.
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)