Tag Archive: INTERNET OF THINGS


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

Advertisements

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