Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing wifi without having to turn on the config portal #1754

Open
VladimirVecera opened this issue Jul 29, 2024 · 7 comments
Open

Changing wifi without having to turn on the config portal #1754

VladimirVecera opened this issue Jul 29, 2024 · 7 comments

Comments

@VladimirVecera
Copy link

First of all ... wifimanager is an absolutely amazing tool and I thank you for it. Thank you very much.
I have a question. I configure the ESP32 through the config portal, the ESP32 successfully connects to wifi. In a month I want to change wifi accesses. At the same time, I have my own web administration on ESP32. Is it possible to change wifi accesses without having to activate the config portal, which works on 192.168.4.1 and is it necessary to have a wifi device at hand to set up wifi? I would like to be able to configure the wifi via the web interface on the already connected wifi. I hope you understand me.

@F1p
Copy link

F1p commented Jul 29, 2024

wifiManager.startWebPortal();

At the end of setup to run the web server when on WiFi
And in loop to handle requests and modification:

wifiManager.process();

You may also need this if saving fields to a file:
if (shouldSaveConfig) { saveConfig(); } // Handles WiFiManager Settings Changes

@tablatronix
Copy link
Collaborator

You can do it in regular esp code via begin()

@VladimirVecera
Copy link
Author

I'm a bit confused. Can you send the best code? Thank you very much in advance for your help.

@F1p
Copy link

F1p commented Jul 31, 2024

I'm a bit confused. Can you send the best code? Thank you very much in advance for your help.

Edit of basic example:

#include <WiFiManager.h>
WiFiManager wm;

void setup() {
  bool res;
  res = wm.autoConnect("AutoConnectAP", "password");
  if (!res) {
    Serial.println("Failed to connect");
  } else {
    Serial.println("connected...yeey :)");
  }

  wm.startWebPortal();  // Post connection WiFi Manager Portal Start
}

void loop() {
  wm.process();  // Handle requests
}

@VladimirVecera
Copy link
Author

VladimirVecera commented Aug 12, 2024

The problem is that the web administration of the project is already running on the web interface #include <WebServer.h>
And if I want to change the wifi configuration to the already successfully connected wifi, it doesn't work. Does it even work?

server.on("/wifiportal", []() { wm.startWebPortal(); });

@tablatronix
Copy link
Collaborator

I thought you meant in code.. you want to start the webportal you cant of you are already running another webserver

@VladimirVecera
Copy link
Author

VladimirVecera commented Aug 13, 2024

Thank you for the information. If I understand it correctly. Are you using the Webserver library so I can use wm.server->on() ? See code below along with mdns.

#include <WiFi.h>
#include <WiFiManager.h>  // Knihovna WiFiManager
#include <ESPmDNS.h>       // Knihovna pro mDNS

WiFiManager wm;

void setup() {
  Serial.begin(115200);

  // Spustí WiFiManager a připojí se k WiFi síti
  if (!wm.autoConnect("AutoConnectAP")) {
    Serial.println("Failed to connect and hit timeout");
    // Možná chcete restartovat zařízení nebo jinak reagovat
    ESP.restart();
    delay(1000);
  }

  Serial.println("Connected to WiFi!");

  // Nastavení mDNS
  if (!MDNS.begin("esp32")) {  // "esp32" je jméno mDNS, zařízení bude dostupné na "http://esp32.local"
    Serial.println("Error setting up MDNS responder!");
  } else {
    Serial.println("mDNS responder started");
  }

  // Přidání vlastního handleru pro "/mycustomurl"
  wm.server->on("/mycustomurl", HTTP_GET, []() {
    wm.server->send(200, "text/plain", "Hello, this is a custom URL!");
  });

  // Spuštění serveru
  wm.server->begin();

  Serial.println("HTTP server started");
}

void loop() {
  // Je nutné pravidelně volat loop WiFiManageru
  wm.process();
  
  // Musíte pravidelně volat MDNS.update()
  MDNS.update();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants