Initialize the output variables as outputs Define timeout time in milliseconds (example: 2000ms = 2s) Assign output variables to Wemos D1 Wifi pin number 13 Auxiliar variables to store the current output state The complete code with html formatting given below: The response generation is modularized into a separate function, which is executed when the ‘/’ URI is accessed using the server.on function.Ĭonst char* ssid = "microdigisoft" // Your Wi-Fi NameĬonst char* password = "microdigisoft" // Wi-Fi Password For instance, when the URI ‘/’ is requested, the server responds with a 200 (OK) status code and the message ‘Hello world!’. The server’s setup defines responses to specific HTTP requests. Initially, we establish a server instance that listens for incoming HTTP requests on port 80, the default port for web servers. The core of the server code is simple yet powerful. You have to specify the target URI to send the request to, and the request method, in this case this is “/GPIO PIN number” and POST respectively. To send the POST request in the web browser is made of an HTML form. By designing a basic HTML page with “ON” and “OFF” buttons, users can interact with the web server to toggle the LED. To achieve the goal of controlling an LED through a web interface, we’ll leverage HTTP requests and the ESP8266’s capabilities. Turning on and off an LED using ESP8266 Webserver We put the code for generating a response in a separate function, and the we tell the server to execute it when ‘/’ is requested, using the server.on function. If the URI ‘/’ is requested, the server should reply with a HTTP status code of 200 (Ok) and then send a response with the words ‘Hello world!’. In the setup, we tell the server what to do with certain HTTP requests. This is the default port for web servers. First, we create a server instance that listens for HTTP requests on port 80. The actual server code is pretty straightforward.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |