Jan 24, 2015

ESP8266 First Impressions

It's Have Been the while since i posted something in the blog , but now i will pay attention and i promise to post at least one new by week . To start again , let 's talk about the IoT revolution called " ESP8266 " ,
this small module is cheaper than an arduino nano because costs $5 bucks, it's ridiculous the chinese price and if you buy in aliexpress or ebay, you'll also see the free shipping. I'm Developing a home automation network and i'm using the Stack of LAMP, but with this module i'm thinking to change the socket communication with the hardware level to MQTT or TCP protocol instead of use the use this guy CC2530-ZigBee(one day i will post something about this). Espressif company launch this module as a solution for IoT and embedded systems, and our chinese friends develop different types of modules with the same IC. Here you will see all names of modules with 8266
OK, like everyone else, i bought this module from china and i will wait a long time to arrive (normal way in Brazil). Some specs of the module are:

  • 802.11 b / g / n
  • Wi-Fi Direct (P2P), soft-AP
  • Built-in TCP / IP protocol stack
  • Built-in TR switch, balun, LNA, power amplifier and matching network
  • Built-in PLL, voltage regulator and power management components
  • 802.11b mode + 19.5dBm output power
  • Built-in temperature sensor
  • Support antenna diversity
  • off leakage current is less than 10uA
  • Built-in low-power 32-bit CPU: can double as an application processor
  • SDIO 2.0, SPI, UART
  • STBC, 1x1 MIMO, 2x1 MIMO
  • A-MPDU, A-MSDU aggregation and the 0.4 Within wake
  • 2ms, connect and transfer data packets
  • standby power consumption of less than 1.0mW (DTIM3)

Seeing this specs wee can have an idea from what is the max range of this device, based in the Friss tranmission equation, let's calculate how is the reach of this module:

Range = [10 ^ (19.5Tx power + 3Rx antenna gain + 3Tx antenna gain + 91Rx Sensitivity  )/20] / 41.88 x Loss Factor
            = 6.53 Km 

Don't call me crazy because this is the max distance in a open transmission with a shielded module and a 3dBi antenna. But if we consider at least 10%, we have 653 meters!. I had tested this module in my house, with the wireless router TG-862 from Arris, and it works perfectly. For the first test i decided to update the firmware, because the module works with AT commands and in the old fw, some commands are not implemented yet like baudrate configuration. To update the fw, you need python 2.7 and a USB RS-232 serial to TTL converter. I'm using Ubuntu 14.04 LTS (Trusty Tahr), but you can use other distro, just clone this repo of esp-tool and download the firmware from this. I chose the v0018000902, because is the last when this post is up. After you download you need to prepare the hardware, it's simple and i will show what i did. The pins from the ESP-8266 are:
First you need to cross between your RX and TX pins from your conversor, then power with a 3.3V source with 200mA of fan out. To enable the chip, just connect CH_PD pin to VCC. Now open a terminal and verify what device is your serial converter, use this command to to this:
ls /dev/tty*
After plug and unplug your device to see which adapter has changed and then after you discover, you put this:
sudo screen /dev/ttyUSB0 115200
When you open the terminal, just put "AT" and after press ctrl+m and ctrl+j (carry return, line feed), if you see an "OK", you're ready to send the commands to the module. This list of commands that i tested are:
AT+CWJAP="yourwifinetwork","yourpassword" #Get and ip com dhcp
AT+CIPMUX=1 #Multiple connections
AT+CIPSTART=4,"TCP","",8080 #Connect to tcp server in my ip, localhost through port 8080
AT+CIPSEND=4,12 #Send data to the server
>Hello World!
I used a tcp_server described in python to test the module, but you can use any other to test, if you want my code, just ask here.