mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-27 00:55:52 +03:00
[GH-ISSUE #656] Accessing portal after connected to local wifi #549
Labels
No labels
📶 WiFi
🕸️ HTTP
Branch
DEV Help Wanted
Discussion
Documentation
ESP32
Example
Good First Issue
Hotfix
In Progress
Incomplete
Needs Feeback
Priority
QA
Question
Task
Upstream/Dependancy
bug
duplicate
enhancement
invalid
pull-request
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/WiFiManager#549
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @vaz83 on GitHub (Jul 14, 2018).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/656
Basic Infos
Hardware
WiFimanager Branch/Release: Development
Esp8266/Esp32:
Hardware: NodeMCU ESP8266 Lua WiFi Internet Development Board
Core Version: 2.4.0, staging
Description
Hi, can anyone tell me how to access the webportal in runtime? I have seen some examples around here but to acess the webpage the user needs to push a button and then connect to the wifi created by the wifiManager. What i would need is after the wifiManager is configured and available on my local network, every time i enter its address on the web browser, it opens by default the configuration portal. Is is possible?
@tablatronix commented on GitHub (Jul 14, 2018):
Ondemandwebportal example
@vaz83 commented on GitHub (Jul 14, 2018):
Hi tablatronix,
I have checked the example you said, but it's not what I want exactly. on that example, the user needs to trigger a button in order to activate the portal. What I am looking for, is that when the esp is connected to my local network, when I put it's IP address on the web browser, that it can open the portal by default. I have tried to create a webserver so that when i detect someone is trying to connect, i call the wm.startWebPortal(), but it doesnt work that way. Any sugestions ?
@tablatronix commented on GitHub (Jul 14, 2018):
it is an example...
Then do not use a button, just do it whenever you want.
It should work just the same, not sure what the issue is "doesnt work"
@vaz83 commented on GitHub (Jul 14, 2018):
Yes, I know, but i am struggling to get the correct code, can I please ask you some little help on how can i do it?
@tablatronix commented on GitHub (Jul 14, 2018):
When do you want it to turn on? What is the logic
@vaz83 commented on GitHub (Jul 14, 2018):
I want to turn it on every time i access it's ip address on the local network
@tablatronix commented on GitHub (Jul 14, 2018):
So leave it on all the time?
@vaz83 commented on GitHub (Jul 15, 2018):
Yes, and accessing the configuration portal through the local network and not by the auto generated wifi of the device
@tablatronix commented on GitHub (Jul 15, 2018):
so after your wifi connect code, or after checking to make sure wifi is connected however you are doing that just wm.startWebPortal, and wm.process() in your loop
@vaz83 commented on GitHub (Jul 16, 2018):
done! Thanks man, you're awesome! I am sharing the code here so I can help someone who get's the same problem i did.
@tablatronix commented on GitHub (Jul 16, 2018):
startconfigportal already starts the webserver, you are starting it twice
@tablatronix commented on GitHub (Jul 16, 2018):
if you want to only start the webportal when the ap has a client you can use this.
But you will have to start the ap yourself and not use startconfigportal
WiFi_softap_num_stations() > 0@vaz83 commented on GitHub (Jul 16, 2018):
changed it! thanks again :)
@tablatronix commented on GitHub (Jul 16, 2018):
So that handleroot is not necessary, also a few people have tried to run a webserver and wm at the same time and have not had much success
@vaz83 commented on GitHub (Jul 16, 2018):
I am noticing now, that if I comment the startConfigPortal on the setup void, and keep the handleroot as it was, when i go to the device IP it does not open the wifimanager no more. is it asking too much if you could tell me what I need to change in the code? I just want to start the webportal when i acess the IP on the local network
@tablatronix commented on GitHub (Jul 16, 2018):
You cant detect "access the ip" unless you have a server running, so not exactly sure what you are trying to do or why.
You cannot do both, either start configportal(softap+webportal) or start webserver(webportal)
maybe the webportal wont start if you already have one running on port 80
@vaz83 commented on GitHub (Jul 16, 2018):
I am trying to explain my best, my english is not that good i guess :) I just wanted that once the ESP is connected to the local network, i can access the webportal without the wifiManager launch the AP mode. When i call the startWebPortal(), the ESP is creating an AP, which I don't want. can i call the startWebPortal without the wifiManager creating a AP?
@tablatronix commented on GitHub (Jul 16, 2018):
startWebPortal should not start an AP, however the esp will start an AP if it got saved to flash.
Add
WiFi.mode(WIFI_STA)after setup, in case its saved in memory also ( erase flash )@vaz83 commented on GitHub (Jul 17, 2018):
It's now working perfectly, here's the code:
`#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager WiFi Configuration Magic
WiFiManager wm;
ESP8266WebServer server(80);
//############################################# CUSTOM PARAMETERS FOR THE WIFI MANAGER ##########################################
char mqtt_server[40] = "0.0.0.0";
char mqtt_topicIN[80] ="IOT_Device/IN";
char mqtt_topicOUT[80] ="IOT_Device/OUT";
char mqtt_port[6] = "1883";
WiFiManagerParameter custom_mqtt_server("server", "Server IP", mqtt_server, 40);
WiFiManagerParameter custom_mqtt_port("port", "Port", mqtt_port, 6);
WiFiManagerParameter custom_mqtt_topicIN("topicIn", "Input Topic", mqtt_topicIN, 80);
WiFiManagerParameter custom_mqtt_topicOUT("topicOut", "Output Topic", mqtt_topicOUT, 80);
WiFiManagerParameter custom_mqtt_messages("messages", "Messages Topic", mqtt_topicOUT, 80);
//###############################################################################################################################
//################################################### GENERAL VARIABLES #########################################################
bool blockWM = true; // Change this to false if you want your code to continue to run on the loop void even if you are not conected to any wifi.
//###############################################################################################################################
void handleNotFound()
{
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i=0; i<server.args(); i++)
{
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
}
/*
*/
void setupDeviceWM()
{
//wifiManager.resetSettings();
wm.addParameter(&custom_mqtt_server);
wm.addParameter(&custom_mqtt_port);
wm.addParameter(&custom_mqtt_topicIN);
wm.addParameter(&custom_mqtt_topicOUT);
wm.addParameter(&custom_mqtt_messages);
wm.setConfigPortalBlocking(blockWM);
String ssid = "IOT_ESP_" + String(ESP.getChipId());
if(wm.autoConnect(ssid.c_str()))
{
//if you get here you have connected to the WiFi
Serial.println("Connected to wifi network!");
WiFi.mode(WIFI_STA);
wm.startWebPortal();
}
else
{
Serial.println("Non blocking config portal running!");
}
// call the code down to activate wifi so users can configure the device, event if it's connected to the local network
//wm.startConfigPortal("IOT_Device");
//
server.onNotFound(handleNotFound);
server.begin(); // declare this at the beggining of the code => ESP8266WebServer server(80);
}
/*
*/
void loopDeviceWM()
{
wm.process();
server.handleClient();
}
void setup()
{
Serial.begin(115200);
delay(3000);
Serial.println("Setup mode...");
//wifiManager.resetSettings();
setupDeviceWM();
}
void loop()
{
loopDeviceWM();
}`
@SudhaMaanasa commented on GitHub (Jun 20, 2020):
@vaz83
Could u please help me the same with my code.
WifiManagerWithWebserver.txt
@pioioTwo commented on GitHub (Aug 17, 2020):
it is possible to put a password for access, example login acess portal?