Skip to content

Instantly share code, notes, and snippets.

@iotguider
Last active June 11, 2019 13:13
Show Gist options
  • Save iotguider/d643d5c96bf076c1e743186183f2caac to your computer and use it in GitHub Desktop.
Save iotguider/d643d5c96bf076c1e743186183f2caac to your computer and use it in GitHub Desktop.
Code for Creating web server with ESP8266/NodeMCU
#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.");
}
@Muhammadadilraza
Copy link

Dear Sir,
Code is not working.
can you help me with this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment