Link to previous posts 1.AT Commands , 2. 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.
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
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.
The configuration window of Router appears.
Select “QUICK SETUP”
Click Next button.
Select Internet access mode as “3G/4G ONLY”.
Select your Mobile ISP from the drop down menu .Mine is MTS .
Rest of the settings you can leave it for defaults.
Click NEXT & under Wireless Security select WPA2_PSK mode & provide a password.
Click Next & then FINISH to complete the quick setup.
Under Status you can see the 3G/4G USB Modem as Identified Successfully
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.
Join TPLINK AP using the password we’ve setup already with the Router.
AT+CWJAP=”TP-LINK_E83900”,”alselectro”
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
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
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..
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.
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 “
Select “INBOUND RULES “ on the left pane.
Click on “NEW RULES” on the right Actions pane
Select PORT as Rule type on the next screen.
Select Protocol as TCP & enter the port number 333 under Specific Local Ports.
Select “Allow the Connection “.
Apply rule to all Domain,Private & Public.
You can name the rule & click Finish to save it.
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.
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.
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
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.
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.
The following is the screen shot of Distant PC Putty window.
Note the IP address of distant PC on top of putty window.
To close the Server on the ESP side , use command :
AT+CIPSERVER=0
& then Restart using AT+RST
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 !!!!
Thanks for the info. only thing i do not understand when I check “whatismyip” it will give IP of my PC or ESP Module?
Whatismyip gives the External IP of your PC which is allotted by your Internet Service Provider. ESP module’s IP is internal & is allotted by the Router or Access point to which it’s connected to.All internal IPs start with address 192.x.x.x & you can’t communicate with this local address from external world.Port forwarding setup in Router is needed for this communication.
Hi Alselectro. Your suggestions have given me another solution to my problem. I have IP camera which I need to access remotely over the internet. I have MTS WIFI dongle which does not allow me to access the camera. Now with the recommended solution, can I go with the tp link mr3420 router and connect my MTS WIFI dongle. By this I can turn off the MTS router and in turn connect with TP-link router and this might we access to the IP camera over the internet.
Yes you can go ahead with this solution.TPLINK router provides a WIFI hotspot as well as LAN connections so that you can easily connect your IP camera for internet view.
As your IP camera is WIFI , you can invest on Huawei 8221 power WIFI dongle & use any data sim .This will provide an AP to which your camera can be paired with.You can avoid TPLINK .check my blog here :
https://alselectro.wordpress.com/2015/07/04/port-forwarding-part-2-solution/
🙏please help me sir
whenever i upload any program i get this error..
‘warning: espcomm_sync failed// ESP-01’
‘ error: espcomm_open failed ‘
please help me sir waiting for your reply
GPIO0 pin should be connected to GND before powering up the module.CH-PD ,RST should be pulled high.
You can go for this ready to use board :
http://www.alselectro.com/wifi-esp8266-esp-01-demo-board.html
Still problem persists, then replace ESP-01 module
Hello Sir,
Your post is awesome and in a neat explanatory manner. Thanks for your Good work.
I’m trying this. I was able to make all the steps till STEP 5. Though following all these procedures i could not get a success message at open port tool(canyouseeme.org).
I’m using TP-Link W8968 module with a Vodafone 3G dongle.
Hope you can give me a better solution. Your input on this problem will be much awaited.
Thanks and Regards
Latha
Hello Sir,
Thanks for your Valuable inputs. Your post is really helpful.
I have a problem. I was able to do all the 5 steps. Though after following all the steps i can not get a success message for port open in canyouseeme.org.
I have used TP-LINK- W8968 router and Vodafone 3G dongle. Also i have deacivated all the antivirus protection and inbound rules are set.
Your inputs to solve this problem is much awaited Sir.
Thanks and Regards
Latha
Generally company supplied ready to use dongles like MTS & Vodafone do not support virtual server settings or port forwarding.
TP-Link W8968 is similar to 8970 , I suppose.You can follow this procedure
https://portforward.com/tp-link/td-w8970/
or You can try with any data enabled SIM on a HUAWEI dongle .In case of HUAWEI8221 dongle you need not use a TPLINK , as the dongle itself has virtual server capability.
https://alselectro.wordpress.com/2015/07/04/port-forwarding-part-2-solution/
Hi Sir,
I have airtel usb modem(dongle) there is no virtual servers in that settings
It is showing only the following options
1. Port Filtering
2. Port Forwarding
3. UPnP
4. DMZ
Is Port Filtering and virtual servers are same or different
Please help me sir!
Company supplied ready to use dongles like Airtel or MTS do not support port forwarding or virtual server.Instead you can use a Huawei dongle with virtual server facility on which you can use any SIM
https://alselectro.wordpress.com/2015/07/04/port-forwarding-part-2-solution/
A virtual server is defined as a service port, and all requests from Internet to this service port will be redirected to the computer specified by the server IP.So port forwarding & virtual server both means the same.
hello sir,
I’m working on this idea, thanks for such an interactive and valuable post.
I have few problems while understanding this. plz help help me to get through them:
1. I have a broadband internet connection from a local vendor who provides his service to many apartments of my building. I am using a TENDA router at my place for connecting the devices( such as laptop,mobile phone etc) to connect to internet. So, my question is do i need to configure my router for the port forwarding purpose or the router of the vendor?
2. second question is if I want to contact my esp module through a webpage on a webhosting website, then do i still need to configure firewall of the whichever pc I will be using to access the same?
Vendors do not permit access their router config.You can try port forwarding in your Tenda router under Virtual router. A virtual server is defined as a service port, and all requests from Internet to this service port will be redirected to the computer specified by the server IP.But in your case public IP is provided by the vendors router, so port forwarding may not be successful.Instead you can use a stan alone dongle like Huawei which has virtual server settings & use any data enabled SIM on the dongle.
Regarding ESP module , you’.ll be hosting a server ( web page will be client) through a port for which Windows firewall has to allow communication on this port.
Hello Sir,
A very nice article indeed. I am building an application using ESP8266 which will sense water level in the tank. It will give an alert to user over a mobile app whenever the water level goes below a certain threshold. I will read the water level using a micro and transmitt the level to ESP8266 using tx rx lines. I want the ESP8266 to be connected to my home network.
I have doubts regarding this concept and I am sure you can clarify those:
1. I will have to do one time configuration of my router. Also, I need give SSID and Password to ESP to connect to home network. Can I do the second configuration from my mobile app? I guess I will have to connect it in hotspot mode to ESP. Please correct me if I am wrong.
2. Once I am connected to router, esp will get the IP. How can we set the esp ip address through the app?
3. Also, as you said, on power ON this ip will change, so how the app will communicate with newly assigned Ip address?
Your help is highly appreciated.
Thank you
Nikhil Kulkarni
You can use Ultrasonic sensor for sensing water level.Place the set up micro,sensor & ESP near the tank.On power on , your ESP will be connected to the SSID of your home network.This can be done through Android app which will ask for the SSID,pwd to connect with.Android part can be developed using MIT App inventor.
ESP is connected to your router which will assign it an IP.On router configuration you can make this IP Static, but you cannot assign IP from App.Once you make IP static . your ESP will always be assigned the same IP.This can also be achieved with new firmware for ESP & new AT commands
Watch out my blog for more such ESP tutorials soon.
Hello Sir,
I am using a biometric device which is connected over the wifi, This Biometric device is purchased from a vendor, I would like to get the device data and forward that to the online server. I already spend a lots of hour for that but not getting anything. I already forward the device ip port and check that too. I don’t know how to communicate with the device and so on. My device is responding me by XML data. Please suggest me something.