mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-27 09:05:56 +03:00
[GH-ISSUE #488] Using basic autoconnect example... #409
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#409
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 @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 loop() {
// put your main code here, to run repeatedly:
}`
**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. **