Last active
June 11, 2019 13:13
-
-
Save iotguider/d643d5c96bf076c1e743186183f2caac to your computer and use it in GitHub Desktop.
Code for Creating web server with ESP8266/NodeMCU
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <ESP8266WebServer.h> | |
ESP8266WebServer server(80); | |
const char* ssid = "WiFi_SSID"; //Enter Wi-Fi SSID | |
const char* password = "WiFi_Password"; //Enter Wi-Fi Password | |
void setup() { | |
Serial.begin(115200); //Begin Serial at 115200 Baud | |
WiFi.begin(ssid, password); //Connect to the WiFi network | |
while (WiFi.status() != WL_CONNECTED) { //Wait for connection | |
delay(500); | |
Serial.println("Waiting to connect..."); | |
} | |
Serial.print("IP address: "); | |
Serial.println(WiFi.localIP()); //Print the local IP | |
server.on("/", handle_index); //Handle Index page | |
server.begin(); //Start the server | |
Serial.println("Server listening"); | |
} | |
void loop() { | |
server.handleClient(); //Handling of incoming client requests | |
} | |
void handle_index() { | |
//Print Hello at opening homepage | |
server.send(200, "text/plain", "Hello! This is an index page."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dear Sir,
Code is not working.
can you help me with this ?