Contents
|
WiFi with ESP8266
Since end of 2014 there is a very interesting WiFi module with application processor, called ESP8266, on the market, at a price of about 3 EUR. The main application is a Serial to WiFi Bridge, named AT.
Look at http://www.ebay.de for ESP8266 Serial WIFI Wireless Transceive Modul LWIP AP+STA.
I already used an ESP-01 module in a project as a Serial Transparent Bridge (from beckdac), see ArduinoLabPSU2#WiFi_ESP-01.
Update 2016-10-08, Transparent Bridge
If your Access Point changes, it is annoying to change the credentials in the Transparent Bridge via programm change. So I was looking for a better solution.
1. A promising software is esp-link, it works reliable since version 2.2.3.
2. An other software is a fork of beckdac, ESP8266-bridge, which allows to set the cedentials from the serial side via +++ commands.
3. There is in the Arduino ESP8266 libraries an example WiFiTelnetToSerial.ino for a Transparent UART to Telnet Server. I added to this example a WPS (WiFi Protected Setup) functionality via push button switch, named WiFiTelnetToSerialWPS.ino.
Now, in case of an Access Point change, it is no longer needed to enter manually the credentials into the ESP8266, if the WiFi Access Point supports WPS.
There is a 5 minute timeout in the ESP8266 WiFi stack. That means, if you have after the first WLAN connection a data traffic pause longer than 5 minutes, you to have to resync the connection by sending some dummy characters.
It is much easier to develop application programs for the ESP8266 via Arduino IDE (actual version 1.6.12), than with the Espressif programming environment (SDK).
ESP8266 module
Features:
- SDIO 2.0, SPI, UART
- 32-pin QFN package
- Integrated RF switch, balun, 24dBm PA, DCXO, and PMU
- Integrated RISC processor, on-chip memory and external memory interfaces
- Integrated MAC/baseband processors
- Quality of Service management
- I2S interface for high fidelity audio applications
- On-chip low-dropout linear regulators for all internal supplies
- Proprietary spurious-free clock generation architecture
- Integrated WEP, TKIP, AES, and WAPI engines
Specifications:
- 802.11 b/g/n
- Wi-Fi Direct (P2P), soft-AP
- Integrated TCP/IP protocol stack
- Integrated TR switch, balun, LNA, power amplifier and matching network
- Integrated PLLs, regulators, DCXO and power management units
- +19.5dBm output power in 802.11b mode
Power down leakage current of <10uA
- Integrated low power 32-bit CPU could be used as application processor
- SDIO 1.1/2.0, SPI, UART
- STBC, 1×1 MIMO, 2×1 MIMO
A-MPDU & A-MSDU aggregation & 0.4ms guard interval
Wake up and transmit packets in < 2ms
Standby power consumption of < 1.0mW (DTIM3)
ESP-01
The most common module with printed PCB antenna:
- 2x4 2.54 mm pitch header
- built-in PCB-printed antenna
- 3 GPIOs: GPOI0/2/16
- UART URXD/UTXD
- RESET and CH_PD (Power Down)
- VCC/GND 3.3 V
- 14.2 mm W x 25 mm L
Flash ROM size: 512 KB - 4 MBit Links #18
LED, blue: TX Data
LED, red: Vcc = 3.3 V
Pinout: UTXD-OUT GND CH_PD GPIO2 GPIO16 GPIO0 VCC 3.3V ONLY URXD-IN /!\ pull up CH_PD, GPIO0, GPIO2 and RST with a 3.3 - 10 KOhm resistor each to 3.3 V. That will improve the noise immunitiy. CH_PD: VCC - start from Flash ROM (normal operation) GPIO0: Hold short to GND while releasing RST - enter update firmware mode Timing diagram: ----+ +--------- 3.3 V RST | | +--------+ 0 V -------+ +----- 3.3 V GPIO0 | | +---------+ 0 V Connecting on an USB-Serial interface, RDX and TXD should be crossed.
Because of the 4 MBit Flash ROM size for the ESP-01 module, only firmware version up to 1.2 (SDK) are programmable.
esptool.py
For programming the ESP-01 under Ubuntu and with an USB-Serial adapter (3V3 version), you can download from here. After unpacking the archive the user must get the dialout group permission:
$ sudo usermod -a -G dialout rudi # logout, login and check: $ groups rudi adm dialout cdrom sudo dip plugdev lpadmin sambashare vboxsf # test the connection $ ./esptool.py read_mac esptool.py v1.0.2-dev Connecting... MAC: 18:fe:34:9d:4d:95
Quick Start
There is a lot of information in the Internet about this interesting module. I will use module ESP-01 with patch antenna on board.
For a beginner, you should start with Links #6
You need an USB-Serial adapter for that. Take care to use a 3.3V unit, not 5V.
That works also in a VirtualBox installation, just announce the USB adapter to the virtual machine (e.g. FTDI FT232R USB UART [0600], or Silicon Labs CP2102 USB to UART Bridge Controller [0100]). If it does not work, try to swap RXD/TXD on one end.
- Setup the Terminal program:
- select port to USB-Serial adapter
- Baud rate: 9600 8N1 (firmware 0902), it maybe also 115200 baud
ENTER: CR + LF = CTRL J (needed) # PuTTY has no automatic for that
Setup your ESP-01 for WLAN Router access, those data are stored in Flash-ROM and survive also a firmware update.
- Reset Command
AT+RST OK bB....Sbr....H.....J...H. [Vendor:www.ai-thinker.com Version:0.9.2.4] ready
- Check the firmware version:
AT+GMR 0018000902-AI03 OK SDK version: 18 Firmware version: 0902
- Update to firmware 1.0
AT+GMR AT version:0.22.0.0(Mar 20 2015 10:04:26) SDK version:1.0.0 compile time:Mar 20 2015 11:00:32 http://www.instructables.com/id/ESP8266-Wi-fi-module-explain-and-connection/step6/Talking-to-the-ESP8266/
- Enable the module to act as a “Station”:
AT+CWMODE=1 OK
List surrounding WiFi networks:
AT+CWLAP +CWLAP:(4,"DonnerNet",-93,"84:9c:a6:34:46:44",2) +CWLAP:(3,"FRITZ-7170R",-70,"00:1f:3f:d1:15:00",11) +CWLAP:(3,"FRITZ-7170R",-84,"00:1f:3f:1b:87:8a",11) OK
- Connect to a network.
AT+CWJAP="Wifi SSID","password" # Syntax AT+CWJAP="FRITZ-7170R","password" OK
- Find your IP address:
AT+CIFSR 192.168.4.1 192.168.17.199 OK
- Check SSID:
AT+CWJAP? +CWJAP:"FRITZ-7170R" OK
- Fritz-Box information:
192.168.17.199 18:FE:34:9D:49:43 54 MBit/s WPA2 ESP-01 module #1 of 5
Community Forum and Wiki
There is a ESP8266 Community Forum and wiki at Links #1. I will mention important postings.
- how is the code in the spi flash executed? is it memory mapped? or copied to (D)RAM?
- Copied to DRAM on reset
- The SoC is built around the Tensilica Xtensa LX3 processor (see the compiler info in the library binaries)
- The CPU is clocked at 80 MHz (esp_iot_sdk_v0.6/include/eagle_soc.h, line 58)
hackaday.io info, see Links #2
- how is the code in the spi flash executed? is it memory mapped? or copied to (D)RAM?
Official GCC compiler VM from Espressif
Alternative: github esp-open-sdk
Wireless Througput Tests with netio, about 20 KB/s RX.
Youtube, LUA firmware einrichten (German, 31 min, 2015-01-17)
Transparent Bridge
It is the best compromise to set the baud rate to 115200 baud, which is stored in EEPROM.
You need an USB-Serial adapter for that (ESP-01). Take care to use a 3.3V unit, not 5V.
Do not use the 3.3 V supply of a CP2102 USB-UART converter, it allows 100 mA only
Better is a AMS1117-3.3V Modul (max. 800 mA), cost is about 1 EUR (delivered from China).
Unfortunately with the original firmware (version 0.9.2 - 1.0.0) a serial transparent bridge is possible only in send mode, not in receive mode. Therefore the effort of some programmers to create a software for a Transparent Bridge for both directions.
Following some implementations.
beckdac
This was the first Transparent Bridge open source software, but the most difficult to use, especially for setup or changing the credentials (SSID, password).
Fortunately a nice programmer (on github named beckdac, on Forum named dacb) extended the firmware with a serial transparent bridge in both directions, see Links #11,12,13.
It looks like, that with this software the Station login credentials can not be set. So, set first the Station login credentials with the expressif firmware (up to version 1.2 for 4 MBit ESP-01). Then flash the Transparent Bridge software.
Version May 2016 will now allow to control the GPIO2 output via AT command (0, 1, 2=pulse down for 100ms).
The programming of the Flash ROM can be done with esptool.py, see Link #14, 15. That needs also Python package pyserial, which is also installed, when esptool gets installed.
It looks like, that firmware version 0.9.5 was the base.
To program this software to the ESP-01 module do the following, under Linux/Ubuntu 14.04.
That works also in a VirtualBox installation, just announce the USB adapter to the virtual machine (e.g. FTDI FT232R USB UART [0600], or Silicon Labs CP2102 USB to UART Bridge Controller [0100]). If it does not work, try to swap RXD/TXD on one end.
# Download the github master ZIP: ESP8266-transparent-bridge-master.zip # unpack archive # Download the github master ZIP: esptool-master.zip # unpack archive (version 1.04, 2016) $ cd esptool-master $ sudo apt-get install python-setuptools $ sudo python setup.py install default port: /dev/ttyUSB0 default baud: 115200 # connect the ESP-01 to an USB-Serial adapter, GND, RXD, TXD and 3.3 V (max. 250 mA) # connect at the ESP-01 module CH_PD to VCC (via 10k resistor) # connect at the ESP-01 module RST to GND (Reset) # connect at the ESP-01 module GPIO0 to GND # connect at the ESP-01 module RST to VCC (via 10k resistor) # connect at the ESP-01 module GPIO0 to VCC (via 10k resistor) U = 1.9 V # pulse at the ESP-01 module RST to GND (Reset), or reconnect modul # GPIO0 should show now U = 3.2 V # test the connection $ ./esptool.py read_mac (in another folder $ esptool.py ...) Connecting... MAC: 18:fe:34:9d:49:43 # that looks good or on MAC OS X $ ./esptool.py --port /dev/tty.SLAB_USBtoUART read_mac Connecting... MAC: 18:fe:34:9d:46:94 # copy esptool.py to the folder ESP8266-transparent-bridge-master/bin $ cd ESP8266-transparent-bridge-master/bin # if your USB-Serial adapter is not on /dev/ttyUSB0, use option --port <port name/path> ./esptool.py write_flash 0x00000 eagle.app.v6.flash.bin 0x40000 eagle.app.v6.irom0text.bin Connecting... Erasing flash... Writing at 0x00008000... (100 %) Erasing flash... Writing at 0x00064c00... (100 %) Leaving... # remove the jumper from GPIO0 to GND, and power cycle, to go back to normal mode
The AT commands must be given only via telnet.
The initial baud rate could be 74880 baud. In my case I need 9600 baud. So, my first command is:
# In a terminal program $ telnet 192.168.17.199 Trying 192.168.17.199... Connected to 192.168.17.199. Escape character is '^]'. +++AT BAUD BAUD=115200 8 N 1 OK type: +++AT BAUD 9600 ENTER OK type: '^]' telnet> type: 'q' ENTER Connection closed.
The AT commands are case sensitive, please use always upper case:
+++AT # do nothing, print OK +++AT MODE # print current opmode +++AT MODE <mode: 1= STA, 2= AP, 3=both> # set current opmode, 1=Station, 2=Access Point +++AT STA # print current ssid and password connected to +++AT STA <ssid> <password> # set ssid and password to connect to +++AT AP # print the current soft ap settings +++AT AP <ssid> # set the AP as open with specified ssid +++AT AP <ssid> <pw> [<authmode> [<ch>]]]# set the AP ssid and password, authmode:1= WEP, # 2= WPA,3= WPA2,4= WPA+WPA2, # channel: 1..13 +++AT BAUD # print current UART settings +++AT BAUD <baud> [data [parity [stop]]] # set current UART baud rate, optional data bits = # 5/6/7/8 , parity = N/E/O, stop bits = 1/1.5/2 +++AT PORT # print current incoming TCP socket port +++AT PORT <port> # set current incoming TCP socket port (restarts ESP) +++AT FLASH # print current flash settings +++AT FLASH <1|0> # 1: The changed UART settings (++AT BAUD ...) are saved # (Default after boot), 0=no save to flash. +++AT RESET # software reset the unit +++AT GPIO2 <0|1|2 100> # 1: pull GPIO2 pin up (HIGH) 0: pull GPIO2 pin down (LOW) # 2: reset GPIO2, where 100 is optional to # specify reset delay time in ms (default 100ms)
Upon success, all commands send back "OK" as their final output. Note that passwords may not contain spaces.
The settings are saved after the commands +++AT PORT +++AT BAUD ...
After +++AT FLASH 0 the parameter of command +++AT BAUD ... are NOT saved to the flash memory. The new settings are applied to the UART and saved only in RAM. But a following +++AT PORT need to flash the settings for the necessary reboot. Then also the changed UART setting are saved to flash.
Reason for FLASH 0
The disable of flash of the settings is for devices with baud rate changes to avoid permanently flash of the setting sector. Some electric meter start conversion with 300 baud and accept a command to change to 9600.
A very good HowTo to this application for Quadrocopter you can find at Links #17
esp-link
A promising software is esp-link from Thomas (tve), version 2.2 beta was not so reliable, but now version 2.2.3 (2016-06-22) works reliable.
There is one peculiarity. If you connect via Telnet, after 5 minutes of inactivity you get the message from the Telnet client:
Connection closed by foreign host.
This is a timeout limitation from Espressif SDK, but if you know in advance, you can send on a regular base a live trigger, to overcome this timeout.
If the program can not connect to an Access Point (AP), it will switch to AP mode on IP address 192.168.4.1 and offers a web mask on port 80 in order to enter the new credentials (SSID, password).
It is the best to use a tablet for that handling. Connect to the ESP8266 hotspot named ESP_XXXXXX. The XXXXXX are the last 3 bytes (in hexadecimal) of the MAC number of your ESP8266 module. I used an Android version 4.1.1 tablet.
Be aware, that the web mask handling is very slow. Once you are used to it, and after some retries, it worked for me to set the credentials.
The programming under Mac OS 10.11.5:
$ ./esptool.py --port /dev/tty.SLAB_USBtoUART write_flash -fs 4m -ff 40m 0x00000 boot_v1.5.bin 0x1000 user1.bin 0x7E000 blank.bin
ESP-bridge
For download of the binary archiv ESP8266_F1_1.9.19.zip (Sep. 2016) and programming of the ESP8266 see the instructions. The author is Jim Spence (jimeer).
For the WiFi credentials (SSID, password) it is possible to use a web page, but on a smartphone it is difficult to enter the data.
It is easier to enter the credentials (SSID, password) on the Serial Port of the ESP8266 module, via +++ commands.
The +++ commands are documented in a pop-up page.
Take care to start and finish every +++ command with the Enter key.
That works quit well. There is only one drawback, with the +++info command, see following:
<enter>+++info<enter> Firmware version vF1_1.9.19 Chip ID: 9d4694 Flash ID: 1340c8 sys Flag: 30 Current Device Sockets: remote port 0 local port 80 local IP 0.0.0.0 remote IP 0.0.0.0 Mode is 1 (STATION) Station mode the following applies: FRITZ-7360 <password> ****** the passowrd in in clear text 192.168.17.152,192.168.17.1,255.255.255.0 Port 80
The Access Point password is printed in clear text. That should not be for security reasons. I contacted the author about it. He will change that with the next revision of the program.
The programming under Ubuntu 16.04:
$ ./esptool.py write_flash 0x00000 0x00000.bin 0x40000 0x40000.bin esptool.py v1.0.2-dev Connecting... Running Cesanta flasher stub... Flash params set to 0x0000 Writing 40960 @ 0x0... 40960 (100 %) Wrote 40960 bytes at 0x0 in 3.6 seconds (92.1 kbit/s)... Writing 172032 @ 0x40000... 172032 (100 %) Wrote 172032 bytes at 0x40000 in 14.9 seconds (92.3 kbit/s)... Leaving... # to clear the data $ ./esptool.py write_flash 0x7E000 blank.bin
WiFiTelnetToSerialWPS
By combining 3 pieces of existing software I made it to allow an Access Point change for the Serial Transparent Bridge just by using a Push Button switch together with a WPS functionality. The next chapter WPS explaines the setup and usage.
Please see for the details the source code WiFiTelnetToSerialWPS.c.
If you download the software, you have to rename the program extension .c to .ino for the use in the Arduino IDE. The extension .c allows pretty printing of the source code in the wiki.
WPS
WPS (WiFi Protected Setup, see Links #19) allows to connect to a new WiFi Access Point via push button switch, instead of entering the credentials manually.
For the wiring of the Push Button switch and a LED for indication see the schematic:
* Connection of ESP8266 GPIO0 and GPIO2 for WPS push button and LED indicator: * Vcc Vcc Vcc = 3.3 V * | | | * 4K7 4K7 1k0 pull up resistors (3K3 to 10K Ohm) * | | +-|<|-+ LED red * | | | * GPIO0 - +--------+---o | * | | -> | push button switch for WPS function * GPIO2 -------+-------o | * * from http://www.forward.com.au/pfod/ESP8266/GPIOpins/index.html
If you power up the ESP8266 module, and the red LED (WPS indicator) lits (ON), it signals, that the WiFi module has lost the connection to the known Access Point, or the credentials of the Access Point had changed.
In case of changed credentials, it is possible to connect to the Access Point via WPS. The procedure is:
Push the WLAN/WPS button at your Access Point, until it is signallsing the WPS mode. You have a 2 minute timeout.
Push the WPS button switch at the ESP8266 module. The ESP8266 module is now trying to connect to the Access Point.
- If the connect was successful, the LED goes OFF.
Check the WiFi connection via ping command in a terminal, or the application program, or the WiFi Access Point status web page.
Compile Firmware
Help comes from Official GCC compiler VM from Espressif. To make the compile process easier, a Virtual Machine with Lubuntu 32Bit 14.04 LTS was setup (File: ESP8266_lubuntu_20141021.ova), which can be used with Virtualbox.
The original download address http://pan.baidu.com/s/1gd3T14n, see Links #3, did not work (error latest at 512 KB).
The download from google drive did work (ESP8266_lubuntu_20141021.ova, 989 MB).
- I am using Virtualbox version 4.3.20 under Mac OS.
The actual firmware source code (version 0.9.5, 2015-01-30) can be found at Links #4.
A problem I had, I named my host share share and that gave me a protocol error as I was trying to mount the shared folder in the guest environment. Changing the name to vboxshare on the host and client side (in mount.sh) fixed the problem.
Compiling in the shared folder, as mentioned in the guide, did not work under Mac OS (permission problem).
Expand the archive esp_iot_sdk_v0.9.5_15_01_23.zip in /home/esp8266. Then do:
# check Lubuntu version $ lsb_release -a ... Description: Ubuntu 14.04.1 LTS # user: esp8266, password: espressif # change time zone with: Menu: System Tools -> Time and Date (unlock with password) # change keyboard layout (in my case: Germany) $ cd esp_iot_sdk_v0.9.5 # Compile the AT application (WiFi to serial) # Copy the contents from examples/at/* to app $ cp -R examples/at/* app/ # Test with "make" $ make ... !!! No boot needed. Generate eagle.flash.bin and eagle.irom0text.bin successully in folder bin. eagle.flash.bin-------->0x00000 eagle.irom0text.bin---->0x40000 !!! # OK, it works # now make specific version $ ./gen_misc.sh Please follow below steps(1-5) to generate specific bin(s): STEP 1: choose boot version(0=boot_v1.1, 1=boot_v1.2+, 2=none) enter(0/1/2, default 2): boot mode: none STEP 2: choose bin generate(0=eagle.flash.bin+eagle.irom0text.bin, 1=user1.bin, 2=user2.bin) enter (0/1/2, default 0): generate bin: eagle.flash.bin+eagle.irom0text.bin STEP 3: choose spi speed(0=20MHz, 1=26.7MHz, 2=40MHz, 3=80MHz) enter (0/1/2/3, default 2): spi speed: 40 MHz STEP 4: choose spi mode(0=QIO, 1=QOUT, 2=DIO, 3=DOUT) enter (0/1/2/3, default 0): spi mode: QIO STEP 5: choose spi size(0=256KB, 1=512KB, 2=1024KB, 3=2048KB, 4=4096KB) enter (0/1/2/3/4, default 1): spi size: 512 KB start... make[1]: Entering directory `/home/esp8266/esp_iot_sdk_v0.9.5/app/user' ... !!! No boot needed. Generate eagle.flash.bin and eagle.irom0text.bin successully in folder bin. eagle.flash.bin-------->0x00000 eagle.irom0text.bin---->0x40000 !!!
LUA firmware
Links
List of pages in this category:
-- RudolfReuter 2015-02-15 16:55:39
Go back to CategoryAVR or StartSeite ; KontaktEmail (ContactEmail)