If you look at ESP8266WebServer.cpp, you will see that server.send() is actually using client.write() under the hood.
@ceyhunkeklik, what do you means by saying that digitalWrite() is not working ?
Explore... Chat... Share...
Moderator: igrr
igrr wrote:ESP8266WebServer is an easy-to-use library to set up a web server on ESP8266. It is quite minimal, nowhere near other perfect production-ready web servers like esp-httpd or WebBase. It serves only one client at a time.
It is however very easy to set up and use.
First, include the library into your sketch and create a server object:Code: Select all#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
ESP8266WebServer server(80);
Next, in your setup function tell the server what URIs it needs to respond to:Code: Select allserver.on("/", [](){
server.send(200, "text/plain", "This is an index page.");
});
or, which is equivalent:Code: Select allvoid handle_index() {
server.send(200, "text/plain", "This is an index page.");
}
// later, in setup() function:
server.on("/", handle_index);
The first argument is the URI and the second is the function that will be called to respond to this URI.
In that function you need to callCode: Select allto actually send contents.server.send(code, content_type, content)
Processing arguments of GET and POST requests is also easy enough. Let's make our sketch turn a led on or off depending on the value of a request argument.
http://<ip address>/led?state=on will turn the led ON
http://<ip address>/led?state=off will turn the led OFFCode: Select allserver.on("/led", []() {
String state=server.arg("state");
if (state == "on") digitalWrite(13, LOW);
else if (state == "off") digitalWrite(13, HIGH);
server.send(200, "text/plain", "Led is now " + state);
});
The complete example which also shows how to do forms and images is available here:
https://gist.github.com/igrr/3b66292cf8708770f76b.
const char * headerkeys[] = {"User-Agent", "Cookie"} ;
size_t headerkeyssize = sizeof(headerkeys)/sizeof(char*);
server.collectHeaders(headerkeys, headerkeyssize ); //ask server to track these headers (nel file ESP8266WebServer.cpp)
It takes about 20-25 seconds for home assistant c[…]
I tried to upgrade tof my sonoff basic R2 with the[…]
a problem Perhaps you want to define "Probl[…]
Rebooting your router will not give you a faster I[…]
There are no other notifications from esptool.py i[…]
Using the Arduino IDE, you'll learn how to set up […]
In this project, you will post to Twitter using an[…]
In this project, we will build a water level contr[…]
I guess I'm late, but I had the same problem and f[…]
Last night I received my first D1 Minis for a lear[…]
Although I am aware that this is an old post, I fe[…]