mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-27 00:55:52 +03:00
[GH-ISSUE #582] webserver availability once esp8266 joined the wifinetwork #485
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#485
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 @sorriso93 on GitHub (Apr 5, 2018).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/582
Hello
an example how to use the web server after the WIFiManager configuration to add a simple on/off switch relay?
Just as example, I tried to call server.begin and this code after configuration but the webserver on the ESP8266 doesn't replay to request. Without WifiManager the code is ok and the webserver replay to requests. Where should I put this loop code?
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}
// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
//Match the request, checking to see what the currect state is
int value = LOW;
//if (request.indexOf("/relay=ON") != -1) {
if (request.indexOf("/on") != -1) {
digitalWrite(relayPin, HIGH);
value = HIGH;
}
//if (request.indexOf("/relay=OFF") != -1){
if (request.indexOf("/off") != -1){
digitalWrite(relayPin, LOW);
value = LOW;
}
// Return the response, build the html page
//
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // do not forget this one
client.println("");
client.println("<html>");
client.print("Relay is now: ");
if(value == HIGH) {
client.print("Engaged (ON)");
} else {
client.print("Disengaged (OFF)");
}
client.println("
");
client.println("<a href="/on">Click here to engage (Turn ON) the relay.
");
client.println("<a href="/off">Click here to disengage (Turn OFF) the relay.
");
client.println("</html>");
delay(1);
Serial.println("Client disconnected");
Serial.println("");
----------------------------- Remove above -----------------------------
Basic Infos
Hardware
WiFimanager Branch/Release: Development
Esp8266/Esp32: WEMOS D1
Hardware: WEMOS D1
Core Version: 2.4.0, staging
Description
Problem description
Settings in IDE
Module: NodeMcu, Wemos D1
Additional libraries:
Sketch
Debug Messages
@tablatronix commented on GitHub (Apr 5, 2018):
#461
There has been several discussions on how best to do this, it seems that simply making the webserver public should work
development has options to keep webserver alive, or ondemand start it whenever you want
@sorriso93 commented on GitHub (Apr 5, 2018):
Hi, checked all discussion and tried some code, for example add_endpoint but with no success (I get compilation error
'class WiFiManager' has no member named 'sendResponse'
in the last row of the callback...
void callback(WiFiManager *wifiManager) {
//do the work
digitalWrite(LED, !digitalRead(LED));
//make the json response
DynamicJsonBuffer jsonBuffer;
JsonObject& json = jsonBuffer.createObject();
json["pin_state"] = digitalRead(LED);
char buffer[json.measureLength() + 1];
json.printTo(buffer, sizeof(buffer));
//send the response back
wifiManager->sendResponse(200, "application/json", buffer);
}
@tablatronix commented on GitHub (Apr 5, 2018):
you would move the webserver pointer to public in the library
and use that,
wifiManager->sendResponseis totally wrongit should be something like
wm->WebServer->sendRepsonse