I started playing with an ESP8266-01 WIFI module a bit in the last week. The ESP8266 is a cheap and small WIFI module that communicates serially almost exactly like the GPRS cellular radio I was playing with last month.
You can connect it to an Arduino (or a PC for that matter) and xmit/receive data serially much as you would have done with a modem way back when. But, people have been tweaking it to the extent that you may well not even need an arduino.
I purchased my first ESP8266 from Amazon Prime so it would show up pretty quick, and it was still pretty cheap at $8:
I didn’t sit down to figure anything out until it arrived. I discovered that it needs 3.3v and the data pins are not 5v tolerant. I only have a 5V FTDI cable. You could play with voltage dividers, level converters, or get a 3V FTDI cable. I opted to get this regulated breadboard adapter instead from ebay:
This solves the voltage problem and let’s me connect the ESP8266 into a breadboard which is handy to flash the firmware, if nothing else.
Note: the ESP8266 is oriented on this board such that the ESP8266 will hang off the adapter, not over it (in the picture of the adapter above, the ESP8266 connects with its pins on its left).
Your FTDI cable should look like this:
Using M-F jumper wires, connect VCC and GND and connect tx->rx and rx->tx (cross over).
Once the FTDI cable is connected, plug it into your PC. You should see a red LED come on solid on the ESP8266 and a blue LED will flicker momentarily at start up.
Aug 2015 Update: Don’t know how I didn’t see this first time thru, but if your FTDI cable has pinouts in the same order as listed above, you can connect it directly to the adapter.
At this point, you are connected and you can go into the terminal emulator of your choice.
For my ESP8266, it communicates using 9600 baud 8-n-1. When you type AT, you should see AT echo back. If not, try different baud rates.
From what I can tell, the more recent version of the firmware requires that lines be terminated with control-m control-j, not just control-m (e.g. enter). So if pressing just ENTER does not give you a OK response, type control-j and that should do it. See here for more info on the control-j issue:
For my ESP8266, typing AT+RST resets the chip and displays the revision of the firmware.
I had trouble finding the actual updated firmware. Most of the instructions point to electrodragon.com to a page that no longer exists. This probably changes on a weekly basis, so the best bet is to google esp8266 firmware update and see what you can find. My link below may very well go out of date quickly.
I found this website had links to a loader and firmware (.09.02.02) that worked for me:
To do the upgrade,
- Unplug ESP8266 from USB
- Connect GPIO0 pin to ground
- Plug ESP8266 back into USB
- Start the esp8266_flasher.exe program.
- Enter the name of the file containing the firmware
- Enter the appropriate COM port.
- Click download button
It’s OK to get the ‘failed to leave flash mode’ message.
I reconnected to the ESP8266 and verified that I could connect to it serially.
Testing the ESP8266
Working from the wiki, I tried several types of communication to my echo server to verify I understood how to communicate.
The wiki is here: http://www.esp8266.com/wiki/doku.php?id=start
Info on setting up an echo server is here: https://bigdanzblog.wordpress.com/2015/03/20/using-the-echo-service-on-raspberry-pi-for-network-testing/
Establishing a Network Connection
CWMODE=1 sets the ESP8266 to act as a station (rather than an access point). The we list all visible Access points:
AT+CWMODE=1 OK AT+CWLAP +CWLAP:(4,"Chameleon",-64,"6c:fe:b9:4c:e9:be",1) +CWLAP:(2,"SMOKEY",-65,"6e:fd:bn:4c:e9:be",1) +CWLAP:(0,"xfinitywifi",-94,"c6:27:95:32:d7:80",1) +CWLAP:(3,"NETGEAR96",-92,"74:44:01:31:75:74",2) +CWLAP:(0,"Wind Wireless 10",-88,"00:15:6d:63:a1:74",9) +CWLAP:(3,"246C 2.4",-93,"e4:f4:c6:13:7c:26",9) +CWLAP:(3,"Chameleon",-71,"6c:fd:b4:4c:f5:2a",11) +CWLAP:(3,"Chameleon",-32,"68:1c:a2:10:9a:bc",11) +CWLAP:(4,"HOME-4582",-88,"00:ac:e0:d6:45:80",1) +CWLAP:(0,"xfinitywifi",-93,"06:ac:e0:d6:45:80",1) OK
Now we connect to the access point and request the assigned IP address:
AT+CWJAP="Chameleon","<yourpassword>" OK AT+CIFSR 126.96.36.199 OK
Send TCP Data in Non-transparent Mode
CIPMUX=0 indicates we will allow for only 1 connection. We then setup the TCP session with CIPSTART. AT+CIPSEND must be told the number of characters to be transmitted. The data, hello world, is then typed. We receive the data echoed back as +IPD,11 … and finally we close the the session:
AT+CIPMUX=0 OK AT+CIPSTART="TCP","188.8.131.52",7 OK Linked AT+CIPSEND=11 > hello world SEND OK +IPD,11:hello world OK AT+CIPCLOSE OK Unlink
Transmit TCP data in Transparent Mode
Transparent Mode is like serial modems used to act. Once the connection is made, data flows back and forth until it is interrupted with ‘+++’. In this example, as I type each character, it is echoed back to me immediately by the echo server so you will not see the data in a separate line as you did above.
Note, the +++ must be typed in fast. To do this, copy +++, then paste it into the terminal emulator.
AT+CIPMODE=1 OK AT+CIPSTART="TCP","184.108.40.206",7 OK Linked AT+CIPSEND >This is a test hello world <<< +++ was pasted here >> AT+CIPCLOSE OK Unlink
Sending a UDP Packet
To send a UDP packet, you must allow mutiple connections via CIPMUX=1. Otherwise, it is very similar to TCP above:
AT+CIPMUX=1 OK AT+CIPMODE=0 ERROR AT+CIPSTART=4,"UDP","220.127.116.11",7 OK AT+CIPSEND=4,11 > hello world +IPD,4,11:hello world OK SEND OK AT+CIPCLOSE=4 OK Unlink