Tag Archive: WIFI Module


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

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

ESP8266 is an UART to WiFi module,  a really cheap and easy way to connect any small microcontroller platform (for example Arduino) wirelessly to Internet.

The ESP8266 is now one of the leading platforms for the Internet of Things. It’s super cheap, and super easy to work with.

This is a serial module with a built-in TCP/IP stack, so you can use it standalone

You can use AT commands to connect with WiFi networks and open TCP connections without need to have TCP/IP stack running in your own microcontroller: You can simply connect any microcontroller to ESP module and start pushing data up to internet.

esp1

There are several module designs called ESP-x where x is 1 to 12, so far.

I am using the ESP-1 module. The new firmware  is set at 9600 baud. provides the same 2×4 connector, Tx,Rx , RST, CH_DP(chip enable), and two GPIOs, GPIO0 and GPIO2.

ESP8266_pinout

 

ESP8266 is 3.3v device & cannot tolerate 5v levels.

Make sure you pullup the CH_DP and the RST line. I used  3k3 resistor to pull up  RST to +Vcc.

CH_PD is directly connected to +3.3v .Unless you connect CH_PD to Vcc , you won’t get any response from the module. The firmware boots up only on this connection.

So far it seems you can leave the GPIOs floating. For upgrading the firmware , however , the GPIO0 must be grounded.

The current consumption of the module is  80mA at idle state &  it can draw as much as 300mA during operation.

  1. Vcc: 3.3V, up to 300 mA
  2. GND: Ground
  3. Tx: UART Tx of the module, to be connected to the  Rx of the microcontroller
  4. Rx: UART Rx of the module, to be connected to the  Tx of the microcontroller
  5. RST: Reset/Restart, pull to GND to restart
  6. CH_PD: Chip enable, used for flash boot .
  7. GPIO0: pulled low for update mode
  8. GPIO2: not sure yet???

setup1

 

I used a USB to TTL converter for connectivity between PC & WIFI module.The converter has 3.3v output which is used to power the WiFi module. It has also a +5v supply out.

Care has to be taken with power supply as the unit is to be powered at 3.3V and using 5V will probably kill it.

For ease of connections I’ve used a Breadboard.The connection details are as below :

WIFI Module       USB-TTL

Vcc     —  3.3v

Gnd      — Gnd

Tx        — Rx

Rx        — Tx

CH_PD   — connected to 3.3v to enable chip firmware boot.

RST        —  connected to 3.3v through 3k3 resistor

CH_PD pin acts as an enable signal, without it the board is mute and deaf. If CH_PD is not pulled HIGH , you won’t get any response from the module.

Once you connect this last pin to VCC (remember 3.3V) the module is brought to life, and after some garbage in the serial port you can read the word “ready”. Once you get there things will start to get interesting.

The USB-TTL converter I used required a driver “Prolific 2303” to be installed.After installing the driver , I got the port allotment under device manager while the converter is connected to a USB port of PC.

Image 1

A serial Terminal software PuTty  is used to communicate with the port where USB-TTL converter is connected.

Open PuTty & select Serial .Feed in the port number seen under Device manager (here it’s COM41) & speed as 9600 (Baud Rate).

 

Image 2

Click on OPEN button to see the Terminal black window.

Try to type in AT .If you do not get any response , just momentarily connect the RST pin of module with GND.

You get some garbage data initially & then the address of the vendor “www.ai-thinker.com”

followed by the firmware version & then “ready”

 

Image 3

 

Now type in AT .The module will respond with OK. If not ,close the Putty window & again open it & proceed with above steps.

AT+GMR will return the current firmware version.

 

Image 4

 

Generally , you can inquire the module with AT command followed by question mark ?

or you can assign a value  , by using equal to = , after the AT command.

All AT commands must end with a “\r\n” – a carriage return & a New Line.

For detailed list of AT commands visit :

http://room-15.github.io/blog/2015/03/26/esp8266-at-command-reference/

 

AT+CIOBAUD? will return the Baud Rate the module is working with.

AT+CWMODE? returns the Mode of operation of the module.

CWMODE returns an integer designating the mode of operation either 1, 2, or 3.
1 = Station mode (client)
2 = AP mode (host)
3 = AP + Station mode (Yes, ESP8266 has a dual mode!)

 

Image 5

 

But the magic starts once you try AT+CWLAP command, that will provide you a list of available wifi access points in the area.

The command AT+CWLAP will list access points in range. This was very encouraging, not only is my access point (MBLAZE..) on the list, but the ESP can see at least as many access points as my laptop can .

The APs are listed as  +CWLAP: ecn,ssid,rssi,mac

The Parameter are

ecn:  0 OPEN  , 1 WEP , 2 WPA_PSK , 3 WPA2_PSK , 4 WPA_WPA2_PSK
ssid: string, SSID of Access Point
rssi: signal strength
mac: string, MAC address

In the above screen shot you can see my AP “MBLAZE..” is WPA2_PSK  (3) password protected.You can see some other APs which are open  & not protected with password .They are listed with ecn 0.

 

Next you want the board to join a certain access point (most of us want the board to act as a STA or WIFI client that will connect to an access point). That behavior is selected with the AT+CWMODE=1. You will need to reset your board after making this selection.

To connect to your home/office access point you issue the command AT+CWJAP=”yourSSID”,”yourWifiPassword”

The good news is that from now, every time you power the board it will try to connect to the same wifi network. You can see if it was successful by checking your router’s DHCP client list.

Even if the power is removed , the ESP module will remember the joined AP .

You can make it forget by issuing the QUIT command AT+CWQAP

 

Image 6

 

Alternatively you can check your module IP address with command AT+CIFSR. Once you know your board’s IP address you can try pinging it from your computer.

In the upcoming posts we shall investigate the module in TCP client and server modes.

 

For availability of these modules contact :

cooltext753793315   cooltext753790696