enter image description hereI am working on an ESP8266 ESP-12E WiFi Module to turn an LED on and off.

Yes, I was able to turn on/turn off the LED with the help of Wifiserver and NodeMCU.

The problem is I want to connect the NodeMCU with my local area network on the PC. My PC does not connect with Wi-Fi, only an Ethernet connection is present.

How can I connect the NodeMCU with my local area network connection, not with the mobile hotspot?

This is my code:

#include <ESP8266WebServer.h>

/*Put your SSID & Password*/
const char* ssid = "ssid";  // Enter SSID here
const char* password = "password";  //Enter Password here

ESP8266WebServer server(80);

uint8_t LEDpin = D2;
bool LEDstatus = LOW;

void setup() {
  pinMode(LEDpin, OUTPUT);

  Serial.println("Connecting to ");

  //connect to your local wi-fi network
  WiFi.begin( "ssid", "password");

  //check wi-fi is connected to wi-fi network
  while (WiFi.status() != WL_CONNECTED)
  Serial.print (".");
  Serial.println("WiFi connected..!");
  Serial.print("Got IP: ");  

  server.on("/", handle_OnConnect);
  server.on("/ledon", handle_ledon);
  server.on("/ledoff", handle_ledoff);

  Serial.println("HTTP server started");
void loop() {
  digitalWrite(LEDpin, HIGH);
  digitalWrite(LEDpin, LOW);

void handle_OnConnect() {
  LEDstatus = LOW;
  server.send(200, "text/html", SendHTML(false)); 

void handle_ledon() {
  LEDstatus = HIGH;
  server.send(200, "text/html", SendHTML(true)); 

void handle_ledoff() {
  LEDstatus = LOW;
  server.send(200, "text/html", SendHTML(false)); 

void handle_NotFound(){
  server.send(404, "text/plain", "Not found");

String SendHTML(uint8_t led){
  String ptr = "<!DOCTYPE html>\n";
  ptr +="<html>\n";
  ptr +="<head>\n";
  ptr +="<title>LED Control</title>\n";
  ptr +="</head>\n";
  ptr +="<body>\n";
  ptr +="<h1>LED</h1>\n";
  ptr +="<p>Click to switch LED on and off.</p>\n";
  ptr +="<form method=\"get\">\n";
  ptr +="<input type=\"button\" value=\"LED OFF\" onclick=\"window.location.href='/ledoff'\">\n";
  ptr +="<input type=\"button\" value=\"LED ON\" onclick=\"window.location.href='/ledon'\">\n";
  ptr +="</form>\n";
  ptr +="</body>\n";
  ptr +="</html>\n";
  return ptr;

  • 1
    \$\begingroup\$ You will need a WiFi network. For LAN, an Ethernet port is required, which the ESP8266 does not have. \$\endgroup\$
    – Codo
    Sep 16, 2020 at 10:49
  • \$\begingroup\$ sir please tell me how I can do ? can I use esp32 modular for this or any other \$\endgroup\$ Sep 16, 2020 at 11:02
  • \$\begingroup\$ ESP32 has a built in Ethernet MAC. When connected to an external Ethernet PHY, you can connect an ESP32 to a wired Ethenet connection. \$\endgroup\$
    – crj11
    Sep 16, 2020 at 11:16
  • \$\begingroup\$ what about node MCU 8266? I need to read these things , can you provide me any link for this? \$\endgroup\$ Sep 16, 2020 at 11:22
  • \$\begingroup\$ Does the ESP have an Ethernet port on it? \$\endgroup\$
    – user253751
    Sep 16, 2020 at 14:53

1 Answer 1


If you have a WiFi Access Point (aka WiFi router) on your local LAN then you can connect your ESP8266 to that WiFi network and then its reachable from your PC via a IP address.

The IP address is in most cases automatically configured.

There is also support for "Multicast DNS" and if you use that there is no need to remember IP addresses, just use the name that you put into your Code for your ESP8266.

Ref. Multicast DNS, https://tttapa.github.io/ESP8266/Chap08%20-%20mDNS.html

  • \$\begingroup\$ Sir, I am new in this project .thanks for advising me. \$\endgroup\$ Sep 16, 2020 at 10:53
  • \$\begingroup\$ There is a way to add a Ethernet port to a ESP8266 by adding a Ethernet module with SPI interface, esp8266hints.wordpress.com/2018/02/13/… . I wouldn't recommend it since its more cumbersome and to get a WiFi AP should be more feasible. \$\endgroup\$ Sep 16, 2020 at 10:54
  • \$\begingroup\$ sir, I need to explain to you one more time, what I am doing. simply I am controlling a led through node MCU via wifi server but my professor said to me that in our college personal computer we don't have wifi connection so, we can't control the led until if we are not connected with the same network.so we need to build a network or solution to connect the node MCU with computer pc's. sir, I am a learner, I just want a path or source where I can start my work. \$\endgroup\$ Sep 16, 2020 at 11:00
  • \$\begingroup\$ sir, please help me. what you suggest to me I will follow the same steps. \$\endgroup\$ Sep 16, 2020 at 11:04
  • 1
    \$\begingroup\$ @Mats Karlsson He needs to be aware that most large universities will have security on their networks that will stop him from connecting devices without a key and will prevent connecting devices like this. \$\endgroup\$
    – David
    Sep 16, 2020 at 11:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.