Hi everyone, I'm having a small project that need to use the NodeMCU ESP-12 Module, so I make some small test on it. So I found a code on the Internet that allow us to change the status of an LED via Web Server. In the following code, I successfully upload the code, but the IP adress showed on the Serial Monitor leads me to an inaccessable web. Hope any one can help me to solve this problem. Thank you!
#include <ESP8266WiFi.h>
const char* ssid = "Mywifi";
const char* password = "Mywifi's password";
int LED = 4;
WiFiServer server(80);
void setup(){
Serial.begin(9600);
delay(1000);
pinMode(LED, OUTPUT);
digitalWrite(LED, HIGH);
Serial.print("Connecting to the Newtork");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
server.begin();
Serial.println("Server started");
Serial.print("IP Address of network: "); // will IP address on Serial Monitor
Serial.println(WiFi.localIP());
Serial.print("Copy and paste the following URL: https://");
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop(){
WiFiClient client = server.available();
if (!client){
return;}
Serial.println("Waiting for new client");
while(!client.available())
{
delay(1);
}
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
int value = HIGH;
if(request.indexOf("/LED=ON") != -1){
digitalWrite(LED, LOW); // Turn LED ON
value = LOW;
}
if(request.indexOf("/LED=OFF") != -1){
digitalWrite(LED, HIGH); // Turn LED OFF
value = HIGH;
}
//*------------------HTML Page Code---------------------*//
client.println("HTTP/1.1 200 OK"); //
client.println("Content-Type: text/html");
client.println("");
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.print(" CONTROL LED: ");
if(value == HIGH){
client.print("OFF");
}
else
{
client.print("ON");
}
client.println("<br><br>");
client.println("<a href=\"/LED=ON\"\"><button>ON</button></a>");
client.println("<a href=\"/LED=OFF\"\"><button>OFF</button></a><br />");
client.println("</html>");
delay(1);
Serial.println("Client disonnected");
Serial.println("");
}

