[GH-ISSUE #488] Using basic autoconnect example... #409

Closed
opened 2026-02-28 01:25:10 +03:00 by kerem · 0 comments
Owner

Originally created by @kotran88 on GitHub (Jan 22, 2018).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/488

**
**
Hello :)
My code that I used to do before using WifiManager is as belows.
I used esp8266 as server to turn on/off led.

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

char *ssid = "iptime_w";
char *password ="01041538598";
int value=0;
ESP8266WebServer server(80);

void handleOn(){
digitalWrite(LED_BUILTIN,LOW);
value=1;
String message="ONnn!!!";
message += "value : ";
message += value;

server.send(200,"text/plain",message);
}
void handleOff(){
digitalWrite(LED_BUILTIN,HIGH);
value=0;
String message="OFFff"+value;
message += "value : ";
message += value;
server.send(200,"text/plain",message);
}
void handleCurrent(){
String message="";
message += value;
server.send(200,"text/plain",message);
}
void setup(void){
Serial.begin(115200);
WiFi.begin(ssid,password);

while(WiFi.status() != WL_CONNECTED){
delay(500);
Serial.print(".");
}
Serial.println(WiFi.localIP());
server.on("/on",handleOn);
server.on("/off",handleOff);
server.on("/",handleRoot);
server.on("/current",handleCurrent);

server.begin();
pinMode(LED_BUILTIN,OUTPUT);
digitalWrite(LED_BUILTIN,LOW);
value=1;
}
void handleRoot(){
Serial.println("handleRoot");
String message="maidesn!!!"+value;
message += "value : ";
message += value;
server.send(200,"text/plain",message);
}
void loop(){
server.handleClient();
}`

The only problem is that I should hard code ssid and password. so I found wifi manager.
I used basic example of autoconnect.

` #include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino

//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);

//WiFiManager
//Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wifiManager;
//reset saved settings
//wifiManager.resetSettings();

//set custom ip for portal
//wifiManager.setAPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));

//fetches ssid and pass from eeprom and tries to connect
//if it does not connect it starts an access point with the specified name
//here  "AutoConnectAP"
//and goes into a blocking loop awaiting configuration
wifiManager.autoConnect("AutoConnectAP");

//or use this for auto generated name ESP + ChipID
//wifiManager.autoConnect();


//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");

}

void loop() {
// put your main code here, to run repeatedly:

    server.handleClient();  <---- Can't use it because no access to server object

}`

**but the problem is that I should use server object to display html and control led . like the way I used to call handleOn when address is like http://121.133.222.83:8080/on, ( I already did port forwarding to my private ip 192.168.0.24)
How can I access to server object to use it as I used to do?.(routing like http://ip/current so on. **

Originally created by @kotran88 on GitHub (Jan 22, 2018). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/488 ** ** **Hello :) My code that I used to do before using WifiManager is as belows. I used esp8266 as server to turn on/off led.** #include <ESP8266WiFi.h> #include <ESP8266WebServer.h> char *ssid = "iptime_w"; char *password ="01041538598"; int value=0; ESP8266WebServer server(80); void handleOn(){ digitalWrite(LED_BUILTIN,LOW); value=1; String message="ONnn!!!"; message += "value : "; message += value; server.send(200,"text/plain",message); } void handleOff(){ digitalWrite(LED_BUILTIN,HIGH); value=0; String message="OFFff"+value; message += "value : "; message += value; server.send(200,"text/plain",message); } void handleCurrent(){ String message=""; message += value; server.send(200,"text/plain",message); } void setup(void){ Serial.begin(115200); WiFi.begin(ssid,password); while(WiFi.status() != WL_CONNECTED){ delay(500); Serial.print("."); } Serial.println(WiFi.localIP()); server.on("/on",handleOn); server.on("/off",handleOff); server.on("/",handleRoot); server.on("/current",handleCurrent); server.begin(); pinMode(LED_BUILTIN,OUTPUT); digitalWrite(LED_BUILTIN,LOW); value=1; } void handleRoot(){ Serial.println("handleRoot"); String message="maidesn!!!"+value; message += "value : "; message += value; server.send(200,"text/plain",message); } void loop(){ server.handleClient(); }` **The only problem is that I should hard code ssid and password. so I found wifi manager. I used basic example of autoconnect.** ` #include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino //needed for library #include <DNSServer.h> #include <ESP8266WebServer.h> #include <WiFiManager.h> //https://github.com/tzapu/WiFiManager void setup() { // put your setup code here, to run once: Serial.begin(115200); //WiFiManager //Local intialization. Once its business is done, there is no need to keep it around WiFiManager wifiManager; //reset saved settings //wifiManager.resetSettings(); //set custom ip for portal //wifiManager.setAPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); //fetches ssid and pass from eeprom and tries to connect //if it does not connect it starts an access point with the specified name //here "AutoConnectAP" //and goes into a blocking loop awaiting configuration wifiManager.autoConnect("AutoConnectAP"); //or use this for auto generated name ESP + ChipID //wifiManager.autoConnect(); //if you get here you have connected to the WiFi Serial.println("connected...yeey :)"); } void loop() { // put your main code here, to run repeatedly: server.handleClient(); <---- Can't use it because no access to server object }` **but the problem is that I should use server object to display html and control led . like the way I used to call handleOn when address is like http://121.133.222.83:8080/on, ( I already did port forwarding to my private ip 192.168.0.24) How can I access to server object to use it as I used to do?.(routing like http://ip/current so on. **
kerem closed this issue 2026-02-28 01:25:10 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#409
No description provided.