In 2014 might have started a revolution in the Internet of Things. New ESP8266 Wi-Fi modules are tiny, cost less than 5 USD and take care about Wi-Fi connection and encription in Access Point mode and in client mode. Communication to the module is via simple serial RX and TX lines using "AT" type commands and data. ESP8266 is intended for use in smart power plugs, mesh networks, IP cameras, wireless sensors, wearable electronics, etc.
It is based on 32-bit processor Tensilica’s L106 Diamond series. Boots from external flash chip.
Some links:
- Specifications, schematics: http://www.mikrocontroller.net/attachment/231858/0A-ESP8266_Specifications_v4.pdf
- Can be programmed from Arduino IDE https://learn.sparkfun.com/tutorials/esp8266-thing-hookup-guide/installing-the-esp8266-arduino-addon
- Wi07c - ElectroDragon
- https://nurdspace.nl/ESP8266
- wireless:esp8266 [Boxtec Playground]
- Range tests >300m, 4km with dish UBIQUII M2 dish
http://www.element14.com/community/people/Problemchild/blog/2014/09/29/esp8266-wifi-rangedistance-tests - Schematics ESP8266 WiFi Serial Module Costs Just $5
- https://www.youtube.com/watch?v=9QZkCQSHnko
- http://scargill.wordpress.com/2014/09/27/investigating-the-esp8266-serial-killing/
- A very good tutorial about upload to thingsspeak.com and firmware upload
http://www.instructables.com/id/ESP8266-Wifi-Temperature-Logger/?ALLSTEPS - GCC toolchain, 10bit ADC(not useful when RF running) https://github.com/esp8266/esp8266-wiki/wiki
- Cloud updating your Wi07C ESP8266 http://blog.electrodragon.com/cloud-updating-your-wi07c-esp8266-now/
- Interfacing with Teensy http://kaspars.net/blog/electronics/esp8266-teensy-arduino
ESP8266 control from a PC via USB-serial
As a first step it is a good idea to check that the module works using RX TX lines from an USB-serial adapter.
- USB-serial with a CP2102 chip could not supply enough current and I used an external 3.3V LDO regulator on a SD card board that I just had around.
- ESP8266_RST needs to be connected to 3.3V. It can also be used to reset the module any time.
- Connection speed is 115200 bps. USBserial transmitting signal went directly to ESP8266, no problem that it has 5V peak.
- CH_PD is enable pin and should be at VCC. To reset module pull RST low. To upload new firmware pull GPIO2 low.
Connect to COM port via a serial console like Putty or on Arduino IDE at 115200 and send a command AT. Responce should be OK. Blue onboard LED should blink shortly.
If get responce busy p... you need to pull reset connection low. Better to connect reset to VCC (directly or via resistor).
ESP8266 happily accepts data at 5 V (datasheet says inputs are 5V tolerant). ESP8266 power supply remains at 3.3 Volts.
All digital IO pins are protected from over-voltage with a snap-back circuit connected between the pad and ground. The snap back voltage is typically about 6V, and the holding voltage is 5.8V. This provides protection from over-voltages and ESD. The output devices are also protected from reversed voltages with diodes.
Command | Response | Description |
---|---|---|
AT+RST | ets Jan 8 2013,rst cause:4, boot mode:(3,7) wdt reset load 0x40100000, len 24444, room 16 tail 12 chksum 0xe0 ho 0 tail 12 room 4 load 0x3ffe8000, len 3168, room 12 tail 4 chksum 0x93 load 0x3ffe8c60, len 4956, room 4 tail 8 chksum 0xbd csum 0xbd ready | Reset |
AT+CWMODE=1 | OK | Wi-Fi client |
AT+CWJAP="OpenWrt","" | OK | Connect to my Wi-Fi router. I have no passowrd. |
AT+CIFSR | 192.168.1.200 | Ask what IP address it got. ESP8266 is pingable from a PC. |
AT+CIPMUX=0 | Set the single connection mode | |
AT+CIPSTART="TCP","220.181.111.85",80" | Ok Linked | Start a TCP socket |
AT+CIPSEND=22 GET / HTTP/1.0\r\n\r\n 1234567890123456789012 | SEND OK Unlink | Send 22 bytes of data |
AT+CIPCLOSE | Close connection | |
AT+GMR | 00160901 | Firmware version |
AT+CIPSTO | Timeout value | |
AT+CWLAP | +CWLAP:(0,"OpenWrt",-51) +CWLAP:(0,"PC_Network",-93) | List APs around + CWLAP: <ecn>, <ssid>, <rssi> [, <mode>] ecn: 1 WEP 2 WPA_PSK 3 WPA2_PSK 4 WPA_WPA2_PSK |
AT+CWJAP? | +CWJAP:"yourWiFinetworkid" | To check if it has joined the network. |
Firmware update
Original firmware of ESP8266 supports only 115200 bps and has to be updated to be used with Arduino SoftwareSerial working at max 9600 bps
Main (hardware) serial of Arduino is very convenient to use for programming and debug use.
Firmware update is described by Electrodragon and adds some new functionality. Flashing utility can only use USBserial port COM1-COM6. I had to tweak that number in Windows device manager. Fig. 1.
During update GPIO2 (or 0) needs to be connected to GND. v9.22: single file upload to 0x00000. v9.25: needs two files. First file is transfered at 115200 to adress 0x00000. After first flashed file changed speed to 9600 and flashed the second file at address 0x40000. It took me a couple of hours to learn updating for the first time with intermediate bricking. But updating was well worth it.
Commands: Test inquiry range: AT+CIOBAUD=? Check current baudrate: AT+CIOBAUD? Set: AT+CIOBAUD=9600
ESP8266 + Arduino + Xively upload
- 5V from USB-serial is connected to the 3.3V LDO regulator (LM1117 with blocking capacitors) that supplies both Arduino and ESP8266.
- I use Arduino Pro.Mini328p without onboard USB because it is possible then to power Arduino from external 3.3V.
- Arduino hardware serial is connected to USB-serial adapter for programming and debugging and software serial is connected to ESP8266.
- ESP_RST should be pulled up. It has to be activated if the module returns busy p... message.
- I implemented power down mode by controling CH-PD pin. See notes about consumption below.
Power consumption
I connected a multimeter in a 3.3V line. While Wi-Fi is working the multimeter is jumping between 25 and 75 mA. When in power-down mode (CH-PD low) current drops to 0.3 mA. This is drawn by the red LED. After removing the red onboard LED, the ESP8266 board current consumption is only 16 uA. That is amazingly low. Arduino current consumption is not measured.
Xively upload
Code for Arduino 1.02 is attached at the end of this blogpost. For simplicity some random data are uploaded. Uploading to Xively works fine on long term without freezing. Live link is https://xively.com/feeds/1784300880
When the program works it provides following debug information over USB-serial:
AT+RST
OK
[System Ready, Vendor:www.ai-thinker.com]
Connecting to AP
AT+CIFSR
192.168.1.200
AT+CIPSTART="TCP","64.94.18.120",80
Linked!
AT+CIPSEND=319
PUT /v2/feeds/1784300880 HTTP/1.1
User-Agent: ESP8266
Host: atomar.de
Content-Type: application/json
Content-Length: 136
X-ApiKey: qpLG77lHBQVhhJlJ5yAhOAin_CggAaW5tnTVnyGj09k
{"version":"1.0.0", "datastreams": [{"id": "temperature", "current_value": "4.19 "}, {"id": "humidity", "current_value": "53.33 "}]}
success X-Request-Id
955e9a9c4584286436fd227153f12bdede7c8801
sleeping...
Major programming complication with Xively is that it is difficult to prepare json data for upload. One needs to insert data into special place into json and count the length of message.
I don't understand why HTTP GET method can not be used for sending data. Something like this http://xively.com/?key=xxxxxxxxxxxx&datastream=temperature&value=20.0
http GET is used for data retrieval from Xively. Xively has not repplied to my email about this question. Probably it is not possibleand they are too busy.
Xively ALERT on November 2014: Can not sign-up a new user
"Free Developer Sign-Up:
We currently have a waiting list for free developer account sign-ups on Xively.
If you would like to request access, please fill out the access request form and we will notify you as soon as a spot opens up."
Because of that had to look for an alternative IoT proivider.
Things Speak
It allows to upload IoT data, makes graphs and allows to download data or emmbed them in own website as live graph. A very nice tutorial is in Instructables:
ESP8266 Wifi Temperature Logger
I signed up, got a channel and a key for it:
https://thingspeak.com/channels/19501
Can upload data using HTTP GET where do not need to count message that significantly simplifies life compared to HTTP PUT:
https://api.thingspeak.com/update?key=X7XV2EFC3WQIBGHZ&field1=71&field2=12.34
Uploading from a microcontroller:
GET 184.106.153.149/update?key=X7XV2EFC3WQIBGHZ&field1=20.43
View data as json:
http://api.thingspeak.com/channels/19501/feed.json?key=X7XV2EFC3WQIBGHZ
Download as text csv:
http://api.thingspeak.com/channels/19501/feed.json?key=X7XV2EFC3WQIBGHZ
Chart API which takes the data and displays it as configurable chart:
http://community.thingspeak.com/documentation/api/#charts
Here is the chart: