How to connect ESP 8266 wifi modular with local area network?

Thread Starter

Arijeet

Joined Dec 27, 2019
78
I 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:
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() {
  Serial.begin(9600);
  delay(100);
  pinMode(LEDpin, OUTPUT);

  Serial.println("Connecting to ");
  Serial.println("ssid");

  //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)
  {
  delay(1000);
  Serial.print (".");
  }
  Serial.println("");
  Serial.println("WiFi connected..!");
  Serial.print("Got IP: ");  
  Serial.println(WiFi.localIP());

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

  server.begin();
  Serial.println("HTTP server started");
}
void loop() {
  server.handleClient();
  if(LEDstatus)
  digitalWrite(LEDpin, HIGH);
  else
  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";
  if(led)
  ptr +="<input type=\"button\" value=\"LED OFF\" onclick=\"window.location.href='/ledoff'\">\n";
  else
  ptr +="<input type=\"button\" value=\"LED ON\" onclick=\"window.location.href='/ledon'\">\n";
  ptr +="</form>\n";
  ptr +="</body>\n";
  ptr +="</html>\n";
  return ptr;
}
Moderators note : used code tags for the code
 

Attachments

Thread Starter

Arijeet

Joined Dec 27, 2019
78
Isn't the whole point of the ESP8266 is that it operates on WiFi?
yes, it will work on wifi but my professor tries to find it ways that you can run this esp8266 from the local area network because in college computers we don't have the option of wifi, we can connect from only through a LAN connection. please give possible options that I can attempt.
 

Thread Starter

Arijeet

Joined Dec 27, 2019
78
yes, I am sure, I need to make the system full wireless, where anyone can access the network from the port forwarding or routing. but I don't know how to do this thing?
 
I'm confused... If you replace in your SSID and password in the code you posted it will connect to your wireless. It will also print out what IP address it gets when it connects. Next put the www;//IP address in your browser and it should bring up your page to turn on and off leds.
 

Thread Starter

Arijeet

Joined Dec 27, 2019
78
See I am explaining in very simple terms, I am using Esp8266 Wifi Modular(12-E) (NODE MCU), in the program, I have used two types of internet connections,1) Turning on the wifi in my laptop .2) Turning on the Mobile hotspot.

I was successful to perform these two experiments.
But now in my personal computer, I don't have wifi options or mobile hotspot options, my internet is connected with a LAN port through router. I am doing me in research in the institute , so my professor said to me suppose if you are anywhere on the campus and you are not connected with the same network, the same network which is your wifi modular (ESP 8266) is connected.

so you are not in the same network, you can't access the site or controller. so make the system in that in that way if an institute has an internet connection and providing to the internet through the LAN port in all the personal computer which is working in the campus, so if the user wants to use any system go the web browser and enter the IP address, easy control the system.

Hope you will understand the problem, now I have searched into the google, people are saying just try the port forwarding of the router , which states that in your router control panel (administration) you need to choose any random port number which will be assigned for your esp modular (8266), so if any user wants to access the esp modular, through that IP and port number it can access it.

I have explained everything. Now All Expertise you can correct me if I said anything wrong in the above-detailed problem, please give me valuable suggestions or ideas where I can work. please help me.
 
I think i maybe getting the idea. Basically what you want to do is make the module accessible to the campus network, but you can not connect to the campus network by wireless.

Easiest way I can think of is connect your own wireless router to your LAN connection and set up port forwarding in the router. Otherwise it could be done with an arduino shield of sorts by a wired connection.

If wrong I apologize.
 

Thread Starter

Arijeet

Joined Dec 27, 2019
78
"I can think of is connect your own wireless router to your LAN connection and set up port forwarding in the router."
I have no idea how to do port forwarding or Arduino shield. if you have done earlier please brief me.
 

Ioannis66

Joined Nov 7, 2012
36
How on earth the WiFi module will connect to a cable network? You need a access point to make the cable network wireless. And then connect ESP to that access point.
 

djsfantasi

Joined Apr 11, 2010
6,792
I 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?
Have you looked at USB WiFi Adapters? A quick search on Amazon shows many devices, which plug into a USB Jack on your PC and gives your PC WiFi capability. There are devices under $20 for this feature.
 

Thread Starter

Arijeet

Joined Dec 27, 2019
78
Have you looked at USB WiFi Adapters? A quick search on Amazon shows many devices, which plug into a USB Jack on your PC and gives your PC WiFi capability. There are devices under $20 for this feature.
sir, in my wifi module, I don't have an ethernet port.
 

thurtado

Joined Jun 6, 2017
3
If you can enable network sharing on your PC you can advertise a WiFi hot spot coming from your PC that the ESP8266 can then connect to. There should also be controls in Windows to be able to bridge the WiFI hot spot traffic to your enet connection (or maybe that happens automatically when bridging is enabled).
 

djsfantasi

Joined Apr 11, 2010
6,792
If you can enable network sharing on your PC you can advertise a WiFi hot spot coming from your PC that the ESP8266 can then connect to. There should also be controls in Windows to be able to bridge the WiFI hot spot traffic to your enet connection (or maybe that happens automatically when bridging is enabled).
If his PC has Wi-Fi capability...
 
Top