Category: ESP8266


In this post we’ll see how to control an LED connected to NODEMCU from a WebBrowser.

The WebBrowser is a CLIENT & the NodeMCU is the SERVER .

The Nodemcu has to be installed with Boards Manager Arduino core. Refer to the previous post on how to do this.

 

Image 1

 

Connect the long pin of LED to D2 pin of NodeMCU , short pin to GND through a 470E resistor.

Connect the NodeMCU to USB port of PC & note the COM port allotted.Feed in this COM port number in IDE & select the board as NodeMcu v1.0 (ESP12E).

Upload the following code.

 

You can Download the code used in this post HERE

————————————-

 

#include <ESP8266WiFi.h>
#define LED D2
const char* ssid = “SARAVANA-ACT”;
const char* password = “str5412stk4141”;
unsigned char status_led=0;

WiFiServer server(80);

void setup() {
Serial.begin(115200);
pinMode(LED, OUTPUT);
Serial.println();
Serial.println();
Serial.print(“Connecting to “);
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED )
{
delay(500);
Serial.print(“.”);
}
Serial.println(“”);
Serial.println(“WiFi connected”);
server.begin();
Serial.println(“Server started”);
Serial.println(WiFi.localIP());
}

void loop() {
WiFiClient client = server.available();
if (!client) {
return;
}

Serial.println(“new client”);
while(!client.available())
{
delay(1);
}
String req = client.readStringUntil(‘\r’);
Serial.println(req);
client.flush();
if (req.indexOf(“/ledoff”) != -1)
{
status_led=0;
digitalWrite(LED,LOW);
Serial.println(“LED OFF”);
}
else if(req.indexOf(“/ledon”) != -1)
{
status_led=1;
digitalWrite(LED,HIGH);
Serial.println(“LED ON”);
}
String web = “HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n”;
web += “<html>\r\n”;
web += “<body>\r\n”;
web += “<h1>LED Status</h1>\r\n”;
web += “<p>\r\n”;
if(status_led==1)
web += “LED On\r\n”;
else
web += “LED Off\r\n”;
web += “</p>\r\n”;
web += “</p>\r\n”;
web += “<a href=\”/ledon\”>\r\n”;
web += “<button>LED On</button >\r\n”;
web += “</a>\r\n”;
web += “</p>\r\n”;

web += “<a href=\”/ledoff\”>\r\n”;
web += “<button>LED Off</button >\r\n”;
web += “</a>\r\n”;

web += “</body>\r\n”;
web += “</html>\r\n”;

client.print(web);
}

——————————————-

First of all, we include the ESP8266WiFi library, which will make available the functionality needed for the ESP8266 to connect to a WiFi network.Then we define the D2 pin as LED where an Led is connected.

#include <ESP8266WiFi.h>
#define LED D2

The SSID name & password are stored in char variables.

A WiFiserver object called “server “ is created & we pass the port 80 where the server will be listening ( 80 is the default port of HTTP)

WiFiServer server(80);

In the setup() function serial monitor is started at baud 115200 & the LED pin is declared as Output.

The begin() function of WiFi class is used with parameters ssid & password to start connection to WiFIi

WiFi.begin(ssid, password);

We wait till the WiFi.status() becomes WL_CONNECTED which indicates that connection is established .Until then we print a dot every 500msec.

while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(“.”);
}

Once connection is established , an IP address is allotted to NodeMCU by your Router.We print the IP address using the localIP() function.

Serial.println(WiFi.localIP());

Inside the loop we create an object called client of class WiFiClient & assign the server.available() result (it returns true or false) to it.

WiFiClient client = server.available();

It waits for a client ( here a web browser is the client) to connect with.

Once a request is received  , the client.readStringUntil (‘\r”) will read the request till it encounters a  carriage return & assign it to a String variable req

String req = client.readStringUntil(‘\r’);

indexOf() function of String is used to find out ehether the request is ledoff or ledon.

if (req.indexOf(“/ledoff”) != -1)

The indexOf() function returns a –1 if no match found.

Accordingly the LED is made ON or OFF.

Now let us see how a HTML page is served to webbrowser when a client request is received

ode will be stored in strings that will be returned in the HTTP responses

we can declare it in a string and just return it when a HTTP request is performed on the desired URL.

 

String web = “HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n”;
web += “<html>\r\n”;
web += “<body>\r\n”;
web += “<h1>LED Status</h1>\r\n”;

 

First, we  return the 200 HTTP code (OK code). Then, we need to make sure that we specify the return content as text/html, so the browser will know that it should be interpreted and rendered as such

Finally, we pass the string with the HTML/CSS code

The <html> element represents the root of an HTML document. All other elements must be descendants of this element .

The <body> tag specifies where the body of the document starts .

The <h1> tag specifies the Heading of Webpage

The <p> tag specifies a paragraph and thus we use it to indicate our description message.

 

web += “<a href=\”/ledon\”>\r\n”;
web += “<button>LED On</button >\r\n”;

The <a> tag allows us to create a hyperlink by specifying the URL of a page and the message of the hyperlink. So, in the href attribute we specify the URL we want the user to be redirected to, and between the two tags we specify the message of the hyperlink.

In this case, we are specifying a path in the current address, so we don’t need to put the IP and the port. So, when a user clicks the hyperlink, the browser knows it will need to redirect the user to

http://IP Port/[href value]

As we will see later, the paths we are specifying in the href will correspond to the paths where the NodeMcu will be programmed to return the corresponding code.

the <br> tag is just a simple line break between the hyperlinks.

One thing that is very important is that we are specifying the HTML code inside a string, and thus some details need to be taken in consideration.

First, in order to leave the code structured, we should split the declaration of the string in multiple lines. To do so, we need to put the double quotes in each line so the compiler will know that it should be considered as a single string. So, the outermost quotes of the previous code are not from the HTML but from the declaration of a string in multiple lines.

Finally, every quote that is part of the HTML code (for example, the quotes around the URLs in the <a> tag) needs to be escaped with the \ character. So, the \ characters we see before the quotes are also not part of the HTML code but rather the escaping mechanism.

The <button> tag allows for the definition of a clickable button. One of its functionalities allows us to specify a function that is executed when the button is clicked

 

web += “<button>LED Off</button >\r\n”;

Now upload the code & open the serial monitor

Image 5_1

WiFi connection starts & displays IP if connection established.

Open your web browser & type in the IP you got from the serial monitor.

Once you click the Enter button , a CLIENT request is sent to NodeMCU.

Now the HTML page is served & buttons LED ON & LED OFF are displayed on the browser.

Image 6_1

If you click LED ON button , the message string “ledon” is added to URL & sent to Nodemcu.

The string is read and accordingly the LED will be ON or OFF.

Image 7_1

 

Here is another version of code where we use client.print() to serve the Webpage

 

———————————-

 

#include <ESP8266WiFi.h>
#define LED D2  // LED at GPIO4 D2

const char* ssid = “SARAVANA-ACT”;
const char* password = “str5412stk4141”;
unsigned char status_led=0;

WiFiServer server(80);

void setup() {
Serial.begin(115200);
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);

// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print(“Connecting to “);
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(“.”);
}
Serial.println(“”);
Serial.println(“WiFi connected”);

// Start the server
server.begin();
Serial.println(“Server started at…”);
Serial.println(WiFi.localIP());

}

void loop() {

// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}

// Wait until the client sends some data
Serial.println(“new client”);
while (! client.available())
{
delay (1);
}

// Read the first line of the request
String req = client.readStringUntil(‘\r’);
Serial.println(req);
client.flush();

// Match the request

if (req.indexOf(“/ledoff”) != -1)  {
status_led=0;
digitalWrite(LED, LOW);
Serial.println(“LED OFF”);
}
else if(req.indexOf(“/ledon”) != -1)
{
status_led=1;
digitalWrite(LED,HIGH);
Serial.println(“LED ON”);
}

// Return the response
client.println(“HTTP/1.1 200 OK”);
client.println(“Content-Type: text/html”);
client.println(“Connection: close”);
client.println(“”);

client.println(“<!DOCTYPE HTML>”);
client.println(“<HTML>”);
client.println(“<H1> LED CONTROL </H1>”);
client.println(“<br />”);

client.println(“<a href=\”/ledon\”\”> <button style=’FONT-SIZE: 50px; HEIGHT: 200px;WIDTH: 300px; 126px; Z-INDEX: 0; TOP: 200px;’> LED ON </button> </a>”);
client.println(“<a href=\”/ledoff\”\”> <button style=’FONT-SIZE: 50px; HEIGHT: 200px; WIDTH: 300px; 126px; Z-INDEX: 0; TOP: 200px;’> LED OFF </button> </a>”);
client.println(“</html>”);

delay(1);
Serial.println(“Client disconnected”);
Serial.println(“”);

}
———————————–

Inside <button> tag we create a style to make big size buttons.

On clicking the respective buttons the LED is made ON or OFF.

 

Image 9

 

Image 10

 

Image 11

VIDEO DEMO :

cooltext753793315   cooltext753790696

Advertisements

NODEMCU is built on ESP8266 12E Module & is an excellent , economical IOT PLATFORM.

Generally it is shipped from factory with NODEMCU FIRMWARE which can be programmed with LUA Script.

In this post we shall install the ARDUINO CORE for ESP8266 on NODEMCU & start exploring how to use the ARDUINO IDE to code NODEMCU

nodemcu_pins1

 

To use the ARDUINO IDE , first thing is to install the ARDUINO CORE on to NODEMCU.

Open the ARDUINO IDE & under FILE –> PREFERENCES paste the link provided below :

Arduino Boards Manager file link is HERE

 

Image 1

under Tools –> BOARDS –> BOARDS MANAGER

search for ESP8266 & then click on it to install the latest version.

Image 2

 

Connect the NODEMCU to the USB of PC & open the DEVICE MANAGER to note the COM PORT allotted.If you see exclamation mark , then install the CP2102 driver for the NODEMCU.

Under Tools –>

select the board as NODEMCU V1.0 (ESP12E) , Port as the COM port alloted, Programmer as USBASP , UPLOAD SPEED as 115200.

Image 3

 

Under FILE –> EXAMPLES –> ESP8266 select the BLINK sketch

Image 4

 

Here the LED_BUILTIN is mapped to the inbuilt LED on board NODEMCU.

So , just click on the UPLOAD button.

Image 5

 

Once the sketch is compiled , the uploading starts , as seen at the bottom of the IDE.

It takes some time to upload ( i.e the reason to select upload speed 115200 , to make it fast)

as the code upload is like upgrading Firmware.

As the sketch is uploaded , the blue LED on the ESP chip (near WIFI antenna) flickers & finally the RED LED on board blinks.

In the next example let us connect an LED at pin D2 through a resistor.

D2 pin is GPIO4 of NODEMCU , but in the code we use the notation Dx to represent GPIO pin.

To control GPIO4 pin we use D2 in the code & not GPIO4 directly.

Image 7

 

In the blink code , the following line is added

#define LED_BUILTIN D2

Image 8

Upload the code to see the LED connected at DS2 blinking.

In the same way we can use ANALOG WRITE function to give a fade effect on the LED.

 

Now let us explore the NETWORKING capabilities of NODEMCU.

To start with we include the ESP8266WiFi.h header file.

The WIFI library is enhanced version of Arduino & is installed along with the Boards Manager.

This ESP8266WiFi  library has several classes, methods and properties  , which combines many powerful FUNCTIONS .

In the first line of sketch #include <ESP8266WiFi.h> we are including ESP8266WiFi library. This library provides ESP8266 specific Wi-Fi routines we are calling to connect to network.

After the header file  , we store the SSID name & Password as character arrays

#include <ESP8266WiFi.h>
char ssid[]=”SSID_NAME”;
char pass[]=”Password”;

Inside the setup function , Serial communication is started with 9600 baud & the name of SSID is printed.

void setup() {
Serial.begin(9600);
delay(500);
Serial.print(“Connecting to..”);
Serial.println(ssid);
delay(500);

WiFi.disconnect() function is called to disconnect any previous connections

While using the WiFi CLASS , there is no need to create WiFi Object.Simply call the function like

begin(),  SSID(), status(), disconnect(), scanNetworks(), localIP(), etc..

Actual connection to Wi-Fi is initialized by calling the begin() function.We pass on the 2 parameters to WiFi.begin() function to start the connection

  WiFi.disconnect();
WiFi.begin(ssid,pass);

We use a While loop to test the status of WiFi.status(). Here we check whether it returns WL_CONNECTED

IF not connected , a dot is printed every 500 msec.

while(WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.println(“.”);
}

Once connection is established , it jumps out of loop & prints the SSID name connected with.

if connection is established, and then lost for some reason, ESP will automatically reconnect to last used access point once it is again back on-line. This will be done automatically by Wi-Fi library, without any user intervention.

Serial.print(“SSID…”);
Serial.println (WiFi.SSID());
Serial.println(“Successfully connected!!!”);

 

Next the IP address allotted to the NODEMCU by the Router  (by DHCP method) is printed by calling the function WiFi.localIP()

The MAC address is printed using WiFi.macaddress()

 

Serial.print(“IP Address allotted to NodeMcu ESP..”);
Serial.println(WiFi.localIP());

Serial.print(“MAC Address of ESP…”);
Serial.println(WiFi.macAddress());

WiFi.printDiag(Serial) prints all the WiFi credentials like Channel , SSID name , Password , etc..

This specific function  prints out key Wi-Fi diagnostic information:

WiFi.printDiag(Serial);
}

void loop()
{
}

Upload the code & open the Serial monitor at baud 9600 to see the result.

 

Image 10

Next example is to scan the surrounding networks & print the name of SSIDs.

Here we use the function scanNetworks() which returns an Integer value on the number of surrounding SSIDs.

We assign this to an integer variable

int n = WiFi.scanNetworks();

& then in a For loop iterate to print out name of each surrounding SSIDs

 

for (int i=0; i<n; i++)

{

Serial.println(  WiFi.SSID (i) )

}

Image 11

 

Scan for available Wi-Fi networks in one run and return the number of networks that has been discovered.

WiFi.scanNetworks();

There is on Overload of this function that accepts two optional parameters to provide extended functionality of asynchronous scanning as well as looking for hidden networks

WiFi.scanNetworks(async,show_hidden);

Both function parameters are of boolean type. They provide the flowing functionality: * asysnc – if set to true then scanning will start in background and function will exit without waiting for result. To check for result use separate function scanComplete . * show_hidden – set it to true to include The in scan result networks with hidden SSID.

 

Image12

Download code samples HERE

Download ESP8266 Library document PDF HERE

VIDEO TUTORIALS :

 

 

cooltext753793315   cooltext753790696

 

In the previous post we’ve seen how to program ESP8266 using Arduino IDE by installing the Boards Manager.

This post is on using the powerful ESP8266 WiFi Library which is automatically installed while using the Boards Manager.When you proceed with the  board package for the ESP8266,as explained in previous post, the ESP8266 WiFi library is automatically installed for you.

Now, any time you want to use the classes and the functions from that ESP8266 WiFi library,  use the Include statement at the top of the program first, followed by the header name

#include <ESP8266WiFi.h>

at the starting of Arduino code & start using the Classes associated with this library.

ESP8266 WiFi library is designed after the the standard Arduino WiFi library but has even more functionality than the standard Arduino library .The standard Arduino WiFi library is used for the WiFi shield or with the Arduino boards like YUN with inbuilt WiFi.

With the introduction of ESP8266 , the WiFi functionality has become much cheaper & easy to use.

The WiFi library has many classes that you can use. Each class has functions in it that are specific to that class. There’s the WiFi class, the IP address class, the server class, the client class and the UDP class.

 

class1

 

In this post we’re going to explore the WiFi class & its functions.

The WiFi class allows to establish a connection with an access point.

What’s cool about the WiFi class is that we don’t  have to create an instance of this class. We can  go ahead and start using it. It’s like the serial library of Arduino. We don’t need to create an instance of the serial library.

class2

 

First Function of the library is WiFi.begin().

The usage of this function is similar to our Serial.begin().

Just like Serial.begin() , we use WiFi.begin() .WiFi.begin() requires 2 strings as arguments. You need to pass the SSID and the password of the Access point you wish to connect.You need to pass the arguments as character arrays or strings with a lower case s.

WiFi.begin(ssid,pass);

The possible return values are

WL_CONNECTED      after successful connection is established with the Access Point

WL_IDLE_STATUS       when Wi-Fi is in process of changing between statuses

WL_NO_SSID_AVAIL     in case configured SSID cannot be reached

WL_CONNECT_FAILED  if password is incorrect

WL_DISCONNECTED        if module is not configured in station mode

 

The status function in the WiFi class, doesn’t take any arguments but it returns stuff depending on the status of the network that you’re connected to.

Usually, first, you call WiFi.begin, you pass the SSID and the password because you’re trying to establish a connection with the network. Then, what you do is you wait in a loop until WiFi.status returns the value WL_CONNECTED.

——————————

WiFi.begin(ssid,password);

while (WiFi.status() != WL_CONNECTED)

{

delay(500);

Serial.print(“.”);

}

——————————

 

WiFi.SSID();

WiFi.SSID doesn’t take any arguments but it returns the name of the SSID that you’re connected to.

 

WiFi.RSSI()

Returns the current signal strength in  dB

 

WiFi.scanNetworks()

Returns the number of discovered networks.It will not list the network names , but returns the number of networks.

WiFi.macAddress()

Returns the MAC address of the ESP device

There is a specific function available to print out key Wi-Fi diagnostic information:

WiFi.printDiag(Serial);

Here is a sample sketch to demonstrate the WiFi library.

—————————————————-

#include <ESP8266WiFi.h>

void setup()
{
Serial.begin(115200);
Serial.println();

//disconnect any previous connections
WiFi.disconnect();
delay(1000);

//scan for number of nearby networks & print SSIDs

Serial.print(“Nearby networks found  :”);
Serial.println(WiFi.scanNetworks());
delay(500);

Serial.println(“List of surrounding Network SSIDs…:”);
int n = WiFi.scanNetworks();
for (int i = 0; i < n; i++)
{
Serial.println(WiFi.SSID(i));
}
Serial.println();

//connect to preferred SSID

WiFi.begin(“SARAVANA-ACT”, “mypass123”);

Serial.println(“Connecting”);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(“.”);
}
Serial.println();

// print SSID name,local IP allotted ,MAC address & signal strength

Serial.println();
Serial.print(“Connected to SSID          : “);
Serial.println(WiFi.SSID());

Serial.print(“IP address allotted to ESP : “);
Serial.println(WiFi.localIP());

Serial.print(“MAC Address of ESP         : “);
Serial.println(WiFi.macAddress());

Serial.print(“Signal strength is         : “);
Serial.println(WiFi.RSSI());

}

void loop()
{
}

——————————————————–

The screenshot shows the result in the serial monitor of Arduino IDE

scan3

 

The Client & Server classes & their methods are shown in screen shots below :

class3

 

 

class4

Here is the complete tutorial link for the WiFi library :

http://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/readme.html

cooltext753793315   cooltext753790696

The ESP8266 by itself hosts a 32 bit Microcontroller on it & you can now program your ESP using Arduino IDE. Best part is that NO Arduino board is required.You can upload your code from Arduino IDE , as if you were upgrading the Firmware on ESP.

You can pretty much write any code  for an Arduino and run it on the ESP8266. Of course there is a limit to the I/O on some of the modules, but the Flash on the ESP-12E (Black) module is 4MB and the RAM is 80kB! Add to that the 80MHz 32-bit processor and you have a pretty impressive little cute Arduino.

A sample Blink example program on the ESP8266 turns out to be around 225kB, but that includes the core code.So it’s advisable to use an ESP8266 with more FLASH Memory.Generally the BLACK ones are with higher memory than the Blue ones.The new ESP12E has a Flash of whooping 4MB !!  The Arduino UNO has just 32k Flash & Mega 256k.

esp_blue_black

 

esp12e_bl_black

 

Program uploading is done at 115,200 Baud, the default for the module. But It still takes a while to upload a sketch to the module , unlike a regular Arduino.

To begin, you must install the ESP8266 board files in the Arduino IDE.

That is easy enough to do. Make sure that your Arduino IDE is latest

Open the Arduino preferences from File  —> Preferences

Image 1

 

Add the following URL to the “Additional Boards Manager URLs” seen at the bottom of Preferences Window

http://arduino.esp8266.com/stable/package_esp8266com_index.json

Image 2

 

Click OK to close the Preferences Window.

Click on TOOLS –. BOARDS—> BOARDS MANAGER

Image 4

When the Boards Manager opens, scroll to the bottom. You should see the esp8266 entry.

Select the latest version & then click on INSTALL button.

Image5

It takes a while to download & install .

 

Image 6

Once installation is over , close the IDE & start again,

Under Tools –> Boards you can now see a new list of ESP8266 Modules.

Image 7

Its time to test some example code.

While using the ESP module make sure that

Power source is 3.3v DC

CH_PD & RESET pins pulled HIGH through resistor.

You can use a development board available at

http://www.alselectro.com/wifi-esp8266-esp-12-demo-board.html

Image26

An LED is connected to GPIO4 through a resistor.

Image 22

An USB-TTL board is used to connect ESP with USB port of PC.

Rx of USB-TTL board goes to Tx of ESP board

Tx of USB-TTL goes to Rx (3.3v level) of ESP board

GND is made common.

5v of USB-TTL is connected to Vcc of ESP board.As the ESP board has a built in 3.3v regulator we can connect to 5v safely.

Connect the GPIO0 pin to GND.

IMG_20161107_080700

 

Open the Arduino IDE & select the COM port allotted to the USB-TTL board.

Other settings are done under Tools tab as seen in screenshot below :

Image23

From File —> Examples —> ESP8266 select the BLINK sketch.

As we’ve connected an LED at GPIO4 pin , change the pinMode & digitalWrite pin to 4.

Ensure that GPIO0 is connected to GND & click on UPLOAD button.

It takes a while to compile & then uploading starts.

Image25

Once the Uploading is done the LED connected at pin 4 , starts blinking.

Remember to upload another sketch, you need to ground GPIO0 and push the reset switch. The ESP8266 will be put in UPLOAD mode.

When the upload is done, the sketch will start running. If you reset with GPIO0 still grounded, the sketch will not start running because the ESP8266 will be in PROGRAMMING mode. To exit programming mode, remove the ground from GPIO0.

WATCH THIS VIDEO :

 

 

In the next post we shall see how to use the built in WIFI library in your code.

cooltext753793315   cooltext753790696

In the previous post PART 1  we explored the ways to make the local IP address of PC/ESP8266 STATIC.

In this part 2 we shall see how to make your Dynamic Public IP as STATIC using NO-IP account & then Port forward to the server started on port 350 of ESP.

PORT FORWARDING

First let us do the PORT FORWARD  settings.

For this , type in your Router’s Gateway IP in the browser & log in to Router’s Settings.Here my Router’s gateway is 192.168.1.1

The PORT Forwarding is done under VIRTUAL SERVER.

For different Router , you can check out this excellent link which guides settings for almost all types of Routers in the World.

https://portforward.com/router.htm

In my case the VIRTUAL SERVER is under ADVANCED —> NAT

 

image1

Under Virtual Server feed in the WAN & LAN ports as 350.

Under LAN IP feed in the static IP of our ESP8266.Here it is 192.168.1.10 which we made static as described in part 1.

Once the APPLY CHANGES button is clicked , the entry appears under Forwarding Table.

Image 2

 

WINDOWS FIREWALL SETTINGS

 

Next is the Windows firewall settings to allow communication through port 350.

Open Windows Firewall with Advanced Security.

Click on Inbound Rules & then New Rule.

 

Image 3

 

Select Rule Type as PORT.

protocol as TCP.

 

Image 4

Under Action select “Allow the Connection”

& tick mark all under the Profile.

Provide a Name for the Rule & save it.

Image 5

 

START SERVER ON ESP8266

Now open the Putty window where you’ve connected ESP8266 ( refer part 1 for details)

Before starting server , issue the command

AT+CIPMUX=1

Then start the server on port 350 using

AT+CIPSERVER=1,350

Image 111

Now the Server starts listening on PORT 350.

 

Convert Public IP to STATIC

The external world communicates with your ESP server using the Public IP of your Network.This IP is generally DYNAMIC which means it changes on every boot of your Router.

To make it STATIC we shall use a service called NO-IP which converts your public IP to a Domain name & follows the changes.

Visit www.noip.com

Sign up by providing your EMAIL.

Image 6

LOG IN  your NO-IP account.

Under Dynamic DNS click on ADD HOSTNAME.

Image 7

Enter the host name, for e.g , as   testmyiot  & from the dropdown select a domain , say, ddns.net.

Now your new host name is

testmyiot.ddns.net

 

Image 8

Next , click on Device Configuration Assistant.

Image 9

 

Under the dropdown select the host name we created , testmyiot.ddns.net

 

Image 10

Next step is to fill in the Device details.

Device type is SERVER

Device Brand is WEB SERVER

Router make – select your router name .If not found in list then select other

& then enter Router type as Home.

Image 12

On the Next window answer NO

We shall come back to this window shortly after setting the Router for NO-IP.

Image 13

 

On the next window , before clicking YES to log in device, go to the Router settings in browser where you typed in 192.168.1.1

Image 14

 

Click on SERVICE & then DDNS.

Most of the Routers support NO-IP & is listed on the drop down.

Select NO-IP

Image 15

Feed in the Host Name as testmyiot.ddns.net

Provide the email & password you used to create the NO-IP account.

Image 17

Click on ADD to save to DDNS Table of Router.

Now go back to your NO-IP account window.

Click YES to log in device.

Image 18

On next window click on TEST CONNECTION

Image 19

After a short time you should see SUCCESS.

Now you’re done with DDNS settings.You need not go further to Port forward tab, as we’ve already done it.

Image 20

 

Following is the procedure , in case your Router doesn’t support NO-IP .

If you do not see NO-IP under drop down of DDNS settings of Router,

go back to your NO-IP account & click YES to the question “Is there a computer always running on your Network?”.

 

Image 22

 

You’ll be taken to next window to download DUC.

DUC- Dynamic Update Client is a software which runs in the background of your PC to follow your public IP.

Download it & install.

Image 23

Before FINISH ensure to tick mark “Run DUC in the background”

Image 24

Now you’ll be asked to login your NO-IP account again

Image 25

Once you log in, the following windows appear.

Select the host name you created & click save.

Image 26

Now you can see all TICK marks in the DUC window.

DUC runs in the background & follows your public IP to the domain name you created.

Image 28

 

You can test the access to ESP server now from a distant PC.

From anywhere in the world , make open a PUTTY window.

Select RAW & feed in the host name testmyiot.ddns.net & port as 350.

Image 29

You get CONNECTED to the ESP server

 

Watch this demo video :

 

 

 

cooltext753793315   cooltext753790696

This post is all about converting your device address in Network to STATIC & establish PORT FORWARDING.

For IOT projects it is easy to test in local setup using  the LAN IP starting with 192.x.x.x .But from outside world this IP cannot be reached.Here I will walk you through the steps to contact the local IP from outside world.This procedure is a major step needed in IOT projects  , without which external control is not possible.

Following is the setup of my Network. A ROUTER is on the top of the network for which the Internet Service Provider is Airtel . The Router is WIFI enabled so that I can connect multiple devices wirelessly.

Total 3 devices are connected to the Router as shown below.

 

setup_ok

 

On switching on the power , the Router (DHCP enabled) assigns local IP addresses to all the devices connected.The IP address assigned is DYNAMIC which means , it changes every time I switch on the Router.

There are two types of IP addresses: STATIC & DYNAMIC

STATIC addresses are just that – unchanging

Dynamic IP addresses are assigned on-the-fly & keeps on changing by every reboot.

Because most home users tend to turn their computers off, even broadband connections, such as DSL and cable, continue to use dynamic addresses. If your computer is off, you don’t need an IP address so someone else might get to use it.

Each time you connect to the internet, your ISP assigns you an IP address to use. This IP address is the Public IP which others use to communicate to your PC.This IP address is DYNAMIC which changes every time you newly connect to web.

The next time you connect, you might get a different address. If you’re only connecting out to the internet, that’s all you need.

If you expect people to connect in, say you want to run a web server that you want people to be able to find and visit, you’ll most likely need a STATIC IP address. A static IP is assigned by your ISP at an extra cost which is unnecessary for a home network.

In this post I shall explain the ways of changing the LOCAL IP address  as well as the PUBLIC IP address to STATTIC.Suppose you run a web server on your ESP or Raspberry PI & wish to connect from external world.It will work only for the first time , as you use Dynamic IP to communicate.

Next time you power up , the IP address might have changed.So using a STATIC IP is a must .

 

SETTING the Local IP of PC / Laptop to STATIC :

 

In my network the PC assigned a Dynamic IP of  192.168.1.10

Run –> CMD –> ipconfig /all       reveals the  address details as seen below :

ipconfig

 

Here you can see the Default Gateway is 192.168.1.1 which is the IP of the Router .To port forward settings we need to use this IP on a browser to enter the settings , which we will see later in the post.

Local IP assigned to the PC is the IPV4 address 192.168.1.10

Let us change this to STATIC now.

Open the CONTROL PANEL –> NETWORK and Internet  –> Network and Sharing center

Click on “Change adapter settings”

Image 10

 

Right Click on the Network connection & select Properties

Image 11

 

Select the Internet Protocol Version 4 & double click on it.

Image 12

Now you see the following screen where selection is done by default to obtain IP automatically.

Change this selection o “USE the following IP address “ & enter the IP as 192.168.1.150

The first three bytes must match that of the default gateway address which is 192.168.1.1

The last byte can be assigned at your will , within the IP range allowed by the router.

Here I change the IP to 192.168.1.150.  Note that only the last byte I’ve changed.

Subnet mask & Default gateway are entered as seen in the ipconfig /all window above.

 

Image 13

 

DNS server address also changed as seen in the screen shot below

Image 14

Image 15

Reboot your PC to see the changes effective.

Now the IP address of my PC will be 192.168.1.150 & remains STATIC even after reboot.

The above task can also be done automatically by a trial software :

PF_1

 

You can download the trial version here :

http://portforward.com/store/download-instructions/pfconfig/

The trial version allows all other tools except port forwarding.Open the tool & click on STATIC IP Address & follow the guidelines to fix your PC’s IP as STATIC.

 

STATIC IP for other devices ESP & Raspberry PI:

 

For making the Raspberry Pi’s Local IP to STATIC you can follow this blog :

https://www.modmypi.com/blog/tutorial-how-to-give-your-raspberry-pi-a-static-ip-address

 

Regarding the IP of ESP8266 we need not change anything.Once the STATION IP is assigned to ESP8266 , the module remembers the Access Point it has connected & the STA IP assigned .

or issue the command

AT+CIPSTA=”192.168.1.5”

Image 16

The ESP module remembers the Access Point it has joined with & the IP till you quit the AP.

But on Reset it seems to get changed.

The only way to assign STATIC IP to ESP module is through the Router settings.

In your browser type in the IP address of your Gateway , here it is 192.168.1.1

Under LAN setup look out for DHCP settings.

In latest Routers you see a setting called DHCP RESERVATIONS.

In the IP Address field, type the IP address to assign to the computer or server.
Choose an IP address from the router’s LAN subnet, such as 192.168.1.x.

Type the MAC address of the ESP MODULE server.
As the ESP has already joined the AP, it  is already on your network, you can copy its MAC address from the Attached Devices screen and paste it here.

Here I will show an example of setting the Static IP in DHCP Reservation under BEETEL Router

In almost all the Routers the settings are the same.Just look out for the wordings Open-mouthed smileHCP RESERVATION” or “DHCP STATIC “ under the LAN setup.

 

dhcp1

 

Under DHCP STATIC tab , enter the IP address you want to fix for the ESP module

dhcp2

 

Feed in the MAC ADDRESS of the ESP device.

dhcp3

You can learn the MAC address from the AT command AT+CIFSR of ESP module.

dhcp4

The MAC address to be entered without any special character like colon.Please check out your Router settings for entering the MAC address (generally given near the MAC address box , how to feed in the address).

dhcp5

Click on ADD to save the settings

dhcp6

Now RESET or power back the ESP module.

The IP address will be the same for ever.The Router will always assign the IP you’ve set for the ESP module.

dhcp7

 

In a  D-Link router, it is under  the setup.Go to Setup / Network settings / DHCP reservation. You can then ask the router to give a given MAC address a fixed IP address.
Alternatively, the ESP can request a certain IP address from the router which we’ve seen in the example of Beetel Router above.

Now that the STATIC IP is assigned, let us see the methods of PORT FORWARDING & converting your public IP to STATIC using NO-IP account in PART 2.

 

Image 2

 

Image 1

 

Introducing a new ESP8266 Development Board with an ESP-12, a 3x AA battery holder, a voltage regulator, an RGB LED, several red LEDs, and a light sensor LDR on the ADC input all on one board.

The board can be controlled by an open source Android App which is available from the AI-THINKER Website.

GPIO pins are extended with berg pins for easy external connections. RXD,TXD & GND pins are provided for programming / firmware upgrading. A yellow jumper is provided to pull GPIO0 pin to GND during programming. During normal operation this jumper must be removed.

The board is powered by 3 nos AA batteries , for which a battery box is already wired. On board 3.3v regulator is provided for a stable power supply.

No power switch or Reset switch is provided. To switch off you need to pull out one of the batteries.

The board comes pre-loaded with a demo which does actually seem to work.  If you have an Android based phone or tablet you can download AI-Thinker’s app to control and mix the color balance on the RGB LED and to switch the other LEDs on and off.

The Android Application can be downloaded from :

https://play.google.com/store/apps/details?id=com.duvallsoftware.iotdemoapp

 

There are also 6 red LEDs fixed with the necessary resistors connected to GPIO16, GPIO14, GPIO5, GPIO4, GPIO0 and GPIO2. A BLUE LED is always ON if the board is powered.

The GPIO13, GPIO12 and GPIO15 are connected to a RGB LED which allows you color mixing using PWM.

ADC

The analog-digital converter is also available on a pin & connected to a light resistor. This lets you quickly test the ADC and you still can clip the resistor off if you want to measure another analog source.Remember the range of ADC is max 1v & not 0 to 3.3v

If you don’t want to use the light sensor or the LEDs you can simply clip them off. Then you’ll just have an  ESP8266 with 3xAA power supply, 9 available GPIO pins and one ADC.

On the playstore of your Android device search for  IOT DEMO App & install it.

Open the Settings & enable WIFI of the Android phone.Now power on the ESP board to see the AI-THINKER SSID on your mobile.

PAIR this with the ESP board using password ai-thinker

Now open the app & touch on LED 1 to 6 , to see the corresponding light glowing on the ESP board.On the top you can see 3 icons with sliders in the App. Use this to mix colors on the 3 color LED of ESP board.

Once the functioning of board is verified , you can proceed to connect the GPIO pins of ESP board with a 4 channel Relay board.

The 4 channel relay board used requires a separate power source of 5V, 1amp.For demo 2 of the GPIO pins are connected to relay 1 & relay 3.The GND pins of both ESP & the Relay. board to be made common.

You can watch this video to learn the home automation basics with ESP board :

 

 

 

cooltext753793315    cooltext753790696

ESP8266 WIFI Module comes with an inbuilt firmware which supports serial interface and can be controlled using AT commands. Even though we can use this module to offer WiFi functionality from another micro controller ,this module is not just a simple serial to WiFi transceiver .

It is comprised of  a 32Bit processor ( 80MHz) ,  512KB SPI FLASH , 64KB SRAM ,96KB DRAM , GPIO Pins & WIFI Transceiver.

In this post I shall walk you through how to upgrade new Firmware on to the ESP module.This procedure can also be followed in case  esp8266 stopped working , or giving out some random garbage data.

Before starting upgrading I downloaded following 2 files .

http://tinyurl.com/pohvwfh

http://www.alselectro.com/files/esp8266_flasher_simple.zip

1. ESP SIMPLE FLASHER – FLASH DOWNLOAD TOOL

2. FIRMWARE latest BIN file  version 9.5.0

image2

I used a  USB – TTL converter between my ESP-01 board & PC. As the ESP device requires 200ma current which cannot be sourced from USB-TTL module , I used a separate power source 5v/1Amp adaptor followed by a 3.3v regulator ( 1117 3.3v).

Please note that while I used a separate power source for ESP module , the operation was smooth.

I connected the ESP module with USB-TTL board as per following wiring diagram :

Image 2

CH-PD is CHIP ENABLE which is directly connected to +3.3v

RST is pulled HIGH through a 2k2 resistor.A press switch is connected to GND , so that when it is pressed RST pin is grounded.

TX of ESP is connected to RX of USB-TTL module

RX is connected to TX .

Vcc is connected to +3.3v of the external Regular. GND is made common for all , i.e GND of ESP ,USB-TTL & that of 1117 regulator are ALL MADE COMMON.

GPIO0 pin is connected to GND to upload firmware.

After uploading firmware , this GPIO0 connection must be removed from GND.

The USB-TTL converter I used is built on Silicon Labs CP2102 chip which is highly reliable one.The other type available in the market is built on Prolific chip (Chinese one , not original) , which has got some issues with driver installation .

I connected the USB-TTL board to my PC & from the Device Manager I noted the Port allotted .

COM port COM9 is allotted.

Image 4

Next , I browsed to the folder where I’ve already downloaded the 2 required files , one is the simple flasher & the other one is the latest firmware to be uploaded.

On double clicking the esp8266_flasher .exe file , I got this Downloader window open

image3

I clicked on the BIN button & browsed to the location of the folder to select firmware.bin file.

Before clicking the DOWNLOAD button I changed the COM port number , where USB-TTL is connected to PC.

The default address 0x000000  is automatically displayed after COM port

image4

First time when I clicked the Download button I got “Failed to connect”   error.

This was because I’ve connected GPIO0 to GND after the power to ESP board is ON.

GPIO0 pin must be at GND level when the power is initially provided to the ESP module.

image5

Second time when I clicked on the Download button , Writing started  but abruptly failed .

image6

You can see the “Failed to write to target Flash” message in the screenshot below .

image7

After repeated trials I finally found that , connecting 100uf capacitor between Vcc & Gnd

solved the problem.

image8

Finally I hit the Download button and waited for the flashing process to complete. The STATUS BLUE LED blinked fast while the uploading was going on.

“ Failed to leave Flash mode “ message after 99% writing ,does not affect the flashing process in any way and can be ignored.

After the firmware flashing, ESP8266 module settings changed. The default baud rate now is 9600 & can be modified using AT+CIOBAUD command.

It is even possible to cloud update ESP8266 Wi-Fi module firmware using AT+CIUPDATE command.But I suggest you not to try this cloud update , as it’s got some issues.

Now I removed GPIO0 pin from GND & pressed RESET switch & then closed the Flasher application.

I opened the terminal software Putty & selected Serial COM Port 9 & baud rate 9600.

Image 5

I typed in AT command & got an OK response from the ESP module.

AT+GMR returned the upgraded firmware version 9.5.

Image 6

Watch this support Video :

cooltext753793315     cooltext753790696

In the previous post we’ve seen the ways to control the ESP8266 WIFI module from anywhere in the world.The key to success depends on the PORT FORWARDING , where we route the contact on particular port to the local IP address of the WIFI module.

Nowadays USB dongles are used widely for internet access .This post will help you troubleshoot PORT FORWARDING.

Following is the SETUP diagram .

TPLINK ROUTER is on the top of the NETWORK. An MTS USB dongle is plugged to TPLINK Router (model TL-MR 3420 with 3G/4G support).

A Laptop is connected to TPLINK Router on Ethernet using RJ45 cable.

A USB to TTL board is connected to PC on which the ESP 8266 module is wired.

The ESP module is linked to TPLINK Router on WIFI using the AT Command AT+CWJAP=”SSID”,”password”

 

ip8

On switching ON the ROUTER , it assigns LOCAL IP address to the modules connected to it either on RJ45 (wired) or on WIFI.

In our set up the LAPTOP which is connected by wire is assigned 192.168.0.100

& the ESP module which is connected on WIFI is assigned 192.168.0.101.

Note that the allotment of address is on first come basis.When you power off & on the Router again , this allotment may vary.

You can RESERVE the address by selecting the DHCP tab of TPLINK configuration.Here select

Address Reservation & then feed in the MAC address of the devices you’ve connected to the Router.

To know the MAC address you can use the ADVANCED IP SCANNER TOOL.

Download & install the tool. Start the scanner to know the IP address & MAC address of the devices connected .

ip12

STEP 1:

Confirm that you’ve Internet access after plugging  the USB dongle to the TPLINK Router .You need to login the TPLINK configuration with address 192.168.0.1 & enter the QUICK SETUP for this process.

STEP 2 :

Start the SERVER on ESP module

ip2

 

 

STEP 3 :OPEN PORT SCANNER

To confirm that the port we’ve started server ( here port no. 333) is OPEN , we use a  port scanner tool .

Advanced Port Scanner is a small, fast, robust and easy-to-use port scanner for Win32 platform. It uses a multithread technique, so on fast machines you can scan ports very fast.

Also, it contains descriptions for common ports, and can perform scans on predefined port ranges.

Download it & install.

http://download.cnet.com/Advanced-Port-Scanner/3001-18508_4-98269.html?hlndr=1&part=dl-73294

Open Port scanner & under Select port range enter 100 to 500 . As we’ve to check port 333 , we enter the range below 500 .Click on SCAN .

IP4

 

The PORT SCANNER displays the result regarding status of PORTs of your PC as well as the module connected to PC.

Here we can confirm that port 333 is OPEN on IP 192.168.0.101 (ESP module).

 ip5

 

STEP 4 : SET UP FORWARDING RULE on TPLINK CONFIGURATION

On TPLINK configuration window , under FORWARDING select the tab VIRTUAL SERVERS.

Click on ADD NEW.. & enter the Service & Internal port as 333 .

IP Address as 192.168.0.101 , which is the local IP allotted by Router to ESP module.

Select Protocol as TCP & then SAVE the settings.

 

IP9

 

IP 10

 

STEP 5 : WINDOWS FIREWALL SETTINGS

Open Windows Firewall Advanced settings & click on INBOUND RULES.

SET the rule to allow communication on port 333.

IP11

 

Now you are set to check the condition of PORT 333 externally.

For this we make use of an online tool www.canyouseeme.org

On opening the site your external IP will be automatically displayed.Enter the port number to check.

Click on CHECK PORT.

ip 13

Unless you see SUCCESS on this test , you can’t contact your ESP module from external world.

If you get ERROR , open the TPLINK configuration & click on STATUS.

Note IP Address displayed under 3G/4G.

From another computer with a different internet connection try to PING this IP address.

Open CMD & type in PING x.x.x.x

ip1

 

If the PING result is OK , you can be sure that the ESP module can be contacted from outside world.

If the PING result is TIMED OUT , you can’t communicate with ESP.

The   STATUS tab in my case , as shown in above screen shot , indicates an IP address starting 100.86.x.x

Generally following IP address ranges are PRIVATE IP ADDRESS RANGES :

10.x.x.x

172.16.x.x

192.168.x.x

These are reserved by IANA for private Intranets & NOT ROUTABLE TO INTERNET.

Private addresses are not reachable on the Internet. Therefore, Internet traffic from a host that has a private address must either send its requests to an Application layer gateway (such as a proxy server), which has a valid public address, or have its private address translated into a valid public address by a network address translator (NAT) before it is sent on the Internet.

In my case , the MTS ISP provider hide the PUBLIC IP address.

The MTS dongle does not support VIRTUAL SERVER settings , which means PORT FORWARDING IS NOT POSSIBLE with MTS.

What I couldn’t understand was , while writing my previous blog ,it worked sometimes.While MTS customer support was contacted repeatedly , they finally accepted that port forwarding is blocked by them.

After sleepless nights I’ve found a solution….. Read on my next post ….

 

cooltext753793315    cooltext753790696

Link to previous posts 1.AT Commands2. TCP Client/Server  , 3. Connect to Android

 

In the previous posts we’ve tested the WIFI module in TCP Server/Client mode & how to control from an Android mobile.These are related to LAN – Local Area Network where the WIFI module & Mobile are connected to the same ACCESS POINT (AP).

The AP  I’ve used is a WIFI Dongle MTS MBLAZE. For the outside world to contact the ESP module connected to MTS , PORT FORWARDING should be done. This is a method by which the IP address of ESP module is forwarded , so that any one accessing the particular port of external IP will land on the ESP module.

The problem is WIFI Dongles do not allow Port Forwarding  . As I’ve previous experience in CCTV  DVR port forwarding  (you can watch my video on DVR port forwarding Here )  using land line Internet connection , I decided to apply the same technique for ESP WIFI.

No Internet Dongle allows port forwarding. TPLINK MR3420 Wireless 3G/4G Router came to my rescue.

TL-3420-800x800

Following are the tasks we need to do :

1.Configure TPLINK ROUTER  to accept 3G Internet Dongle

2.Connect ESP to TPLINK on WIFI & Start a SERVER on port 333

3.PORT FORWARDING ESP’s IP on TPLINK ROUTER CONFIGURATION

4.WINDOWS FIREWALL SETTINGS

5 :Know your External IP & Port Open Condition

6.Connecting from a Distant PC anywhere in the World

 

STEP 1.CONFIGURE TPLINK TO ACCEPT 3G DONGLE

The TPLINK Router accepts USB Dongle as well as WAN connection.I plugged in my MTS dongle to the USB port of TPLINK.

One of the Ethernet ports is connected to the PC using RJ45 cable.

To configure the Router , open the browser & type in the Address of the Router .The IP address is 192.168.0.1

Both user name & password is admin

tp1

To know the Routers IP , you can type in CMD to open Command window .

After the prompt type the command “ipconfig” .The Default Gateway address is the IP of Router.

cmd1

The configuration window of Router appears.

Select “QUICK SETUP”

tp2

Click Next button.

tp3

Select Internet access mode as “3G/4G ONLY”.

tp4

Select your Mobile ISP from the drop down menu .Mine is MTS .

 

tp5

Rest of the settings you can leave it for defaults.

tp6

Click NEXT  & under Wireless Security select WPA2_PSK mode & provide a password.

tp7

 

tp13

Click Next & then FINISH to complete the quick setup.

tp8

 

Under Status  you can see the 3G/4G USB Modem as Identified Successfully

tp11

 

For now the TPLINK Configuration is completed.We shall connect the ESP WIFI to TPLINK Access Point , Start a Server on ESP Module & again come back to TPLINK to configure PORT FORWARDING.

 

STEP 2 : Connect ESP to TPLINK on WIFI & Start a SERVER on port 333

We make use of Putty Terminal software to communicate with ESP module.

You can download PuTty here.

Open Putty & select Serial .Feed in the COM port where ESP is connected (through USB –TTL board) & select the Baud rate as 9600.

Now if you type in AT , you get OK response.

From the Putty window ,search for the surrounding Access Points (AP) using the command

AT+CWLAP

You can see the TP-LINK under listed APs.

tp12

 

Join TPLINK AP using the password we’ve setup already with the Router.

AT+CWJAP=”TP-LINK_E83900”,”alselectro”

tp14

For allowing multiple connections

AT+CIPMUX=1

Now start a SERVER using command AT+CIPSERVER

You can use any port no. within 65536 , except the standard allotted ports like HTTP (port 80), FTP (21) , Telnet (23) , etc.,

The default server port for ESP is 333.Let us start a Server on that port using command :

AT+CIPSERVER=1,333

 

tpnew1

To know the Station IP  type in

AT+CIFSR

This returns the Access Point IP & the Station IP.

If CWMODE =1 , you get only the STAIP. Default is CWMODE=3 , which gives both IPs.

The STATION IP here is 192.168.0.100

tpnew2

 

This Station IP is an Internal IP & cannot be contacted from outside world.To enable contact this IP , we need to PORT FORWARD .

As we’ve started a Server on port 333 , we shall forward any contact on this port to the Station IP.

 

STEP 3 : PORT FORWARDING ESP’s IP on TPLINK ROUTER CONFIGURATION

 

Open the TPLINK configure window which we’ve opened initially, by typing in 192.168.0.1 (IP of TPLINK Router ) , username & password both are –  admin

Under FORWARDING select VIRTUAL SERVERS

Click on ADD NEW..

tpnew9

Enter the Service port as 333 , as we’ve started a server on this port on ESP.

Fill in IP address as 192.168.0.100 , which is the Station IP of ESP.

Select Protocol as TCP & Status Enabled.

Click on SAVE . The Internal port will be assigned same as Service port automatically.

tpnew10

 

tpnew3

 

Now we need to allow this port for incoming traffic on the Windows Firewall settings.

 

STEP 4: WINDOWS FIREWALL SETTINGS :

Type in FIREWALL on Windows search bar & select “Windows Firewall with Advanced Security “

 

tp27

Select “INBOUND RULES “ on the left pane.

 

tp28

Click on “NEW RULES” on the right Actions pane

 

tp29

Select PORT as Rule type on the next screen.

tp30

Select Protocol as TCP & enter the port number 333  under Specific Local Ports.

 

tp31

Select “Allow the Connection “.

tp32

Apply rule to all  Domain,Private & Public.

tp33

You can name the rule & click Finish to save it.

tp34

STEP 5 :Know your External IP & Port Open Condition

The Router is accessed from outside world by its external IP. This external IP is assigned by the ISP provider.Generally this IP is DYNAMIC ,which means every time you switch on your Router , a different IP is assigned.

For a fixed IP , you’ve to contact your ISP provider & pay for a STATIC IP.

Open your web browser & Google for “ what is my ip “

Your public IP address will  be displayed.Note that down.

tpnew4

Now we shall check whether the port 333 is open or not.

Visit the site  www.canyouseeme.org

Your IP will be automatically displayed.Under  “ Port to Check “ enter the port number 333

& click on CHECK PORT.

You see SUCCESS message only on following conditions :

1. Router TPLINK Port Forwarding setting is done so that incoming request on port 333 is forwarded to the Station IP of ESP.

2. Windows Firewall setting Inbound Rule is set to allow communication on port 333.

 

tpnew5

 

Only on getting  SUCCESS message under Canyouseeme.org you can proceed further.

Till now all settings & configurations are done on PC connected with TPLINK & ESP.

Next is the final step in which another PC is involved from anywhere in the world.

 

FINAL STEP 6 : Connecting from a Distant PC anywhere in the World

 

For demo purpose I’m using a separate PC with a different Internet connection.

You can see from screen shot below the IP address of the distant PC.

Open Putty window in that PC & select RAW as Connection type.

Feed in the External IP address to be contacted (that of ESP ) & enter the Port no. as 333

TPW3

After entering the details , click on Load button.

Immediately you get response on the Putty window of ESP , like ,  +IPD,0,2:

From distant PC Putty window type in some characters .This will be received in the ESP window.

 

tpnew6

To send data from ESP , use command :

AT+CIPSEND=0,20

This command waits for you to type 20 characters to be sent on channel 0.

tpnew7

The following is the screen shot of Distant PC Putty window.

Note the IP address of distant PC on top of putty window.

TPW5

 

To close the Server on the ESP side , use command :

AT+CIPSERVER=0

& then Restart using AT+RST

 

tpnew8

 

Once you know the external public IP address of the Router & the Port number on which the server is started, you can contact this ESP from anywhere in the world !!!!

 

cooltext753793315     cooltext753790696