ESP8266 WiFi module for IoT

Wireless Module for IoT – ESP8266

This article is about using and programming a Wireless Module for IoT – ESP8266 for enhancing sensors (whether Temperature, Motion, Smoke etc) to send their telemetry data for aggregation and analysis for Internet of Things applications. One of the most widely available module/circuit for making a standard Hardware sensor talk over a network (or Internet) with a server is the Arduino based (or compatible) series of WiFi modules. So, let us go through the details about ESP8266 and its software, schematics, SDK, etc which will help you in understanding and actually developing a WiFi based embedded system.

Wireless Sensor Use-cases

As the number of sensors grow and spread over a bigger geographical area, it becomes more difficult and expensive to draw and maintain physical wires to/from each of them for monitoring. (By the way, the same holds true for Actuators too). So, learning how to program, use and interface a Wireless sensor with your hardware becomes key to a success for project deployment, management and usability.

Furthermore, with ESP8266 it has become extremely easy to integrate any sensor with WiFi these days and there are various applications that can benefit from wireless connectivity, for example:

  • A network of Motion Sensors in an Office or Apartment
  • Pollution monitoring sensors in a city
  • Smart Metering for Electricity and Water, etc

One can connect to an ESP8266 through its serial interface pins, and then of course via Wifi, through a Light Weight IP stack. In addition, to communicate with sensors, one can make use of I2C or SPI bus capabilities of the GPIO pins.

The ESP8266 based WiFi

There are WiFi solutions based on the IC ESP8266 designed for the needs of a new connected world. Each wireless module is a self-contained WiFi based networking solution. ESP8266 has on-board processing and storage capabilities as well as GPIOs to integrate with other electronics like sensors (and actuators). A basic pin-out of the ESP8266 is given in the figure below:

Legend:

VCC: 3.3 Volt, GND: Ground
CH_PD: Chip Enable, RST: Chip Reset (For both of them use 10K PULL-UP resistor  to VCC)
TX: The serial-data transmit, RX: The serial-data receive (Connect to RX/TX Serial or USB-Serial FTDI converter)
GPIO-0/2: General purpose I/O pins (with GPIO-0 to control flashing a new firmware program)

A general schematic can be found here or advanced auto-reset scheme here.

Brands, Variations & Form Factors

You can browse various ESP8266 based Wireless modules from different companies and brands some of which can suit your needs and order accordingly. Some of these are:

Related:  High-quality interior, big power and sturdy engines makes range rover a luxury saloon

The circuits packages are available in various form-factors and as SMD packages or normal circuit boards with varying amounts of memory (flash) from 0.5MB to 4MB or more. The wireless standards supported are usually the 802.11b/g/n type in this series of wireless modules.

Firmware Programming

The ESP wireless module can be programmed (for example with the Arduino IDE or the supplied tool-chain) and a C/C++ program etc can write/read from the socket API just like a normal Linux application. There is a Serial Interface is the used for writing to the ESP flash and once the image (or Sketch) is programmed, the ESP will boot and run the updated firmware (the embedded software). Caution: Programming your custom firmware program will delete/overwrite the manufacturer AT firmware and/or other functionality.

There are several way to program your device:

Default Image

When The Firmware version of the Wireless module is printed on the Serial console when we boot the device. For example, you may get something like following:

2nd boot version : 1.5
SPI Speed : 40MHz
SPI Mode : DIO
SPI Flash Size & Map: 8Mbit(512KB+512KB)
jump to run user1 @ 1000

Or, you can execute: AT+GMR and should see something like:

AT version:1.2.0.0(Jul 1 2016 20:04:45)
SDK version:1.5.4.1(39cb9a32)
Ai-Thinker Technology Co. Ltd.
Dec 2 2016 14:21:16
OK

Image update

The following information I get about the ESP device (REES52) that I used is necessary to re-image or update the firmware.

Flash size: 8Mbit: 512KB+512KB

Firmware update binaries from the OEM and address vectors for installation:

boot_v1.2+.bin                0x00000
user1.1024.new.2.bin       0x01000
esp_init_data_default.bin 0xfc000 (optional)
blank.bin                          0x7e000 & 0xfe000

AT commands

The ESP hardware (depending on the brand) usually comes with a default firmware which is usually enough to setup the WiFi without changing the flash image. With the USB-to-Serial TTY (or a direct Serial connection) various commands like the following can be executed:

  • AT+RST: Restart module.
  • AT+GMR: View version info.
  • AT+CWJAP: Connect to AP.
  • AT+CWLAP: Lists available APs.
  • etc… (refer the brand website or manual for the supported commands)
  • One comprehensive AT command reference is here
Related:  Time Synchronization in Telecommunication Networks

Here is one cool Instructable on using AT commands with ESP device.

Working with GPIO in the Wireless Module

The general APIs provided in the Arduino libraries/IDE are digitalRead(), digitalWrite(), analogRead(), analogWrite() for creating a custom program that uses the general purpose I/O pins for its particular use-case. Remember, when you flash the ESP with a custom program (or firmware) the default firmware would be erased (over-written) which also means that the AT command-set of the ESP8266 would not be available (unless you re-flash the original or similar firmware again).

That brand that I used (REES52) has the chip/SDK version from AI Thinker based on original firmware/SoC from Espressif (The AT command-set from Espressif does not have ability to read/write GPIO from the default firmware image)

Links to some useful tutorials:

Protocol Stack and RESTful API

The ESP wireless module comes integrated with TCP/IP protocol stack for communication over a network and it becomes extremely simple for any Hardware to send/receive wireless data and connect to the network or the cloud server. A socket/connect is a standard interface, and the ESP can also be programmed to communicate via HTTP and other higher layer protocols based on the server and IoT application architecture and requirements. Here are a few practical examples and libraries:

SDK, APIs and Libraries for Wireless Module

Books and Other Material

        

Other ESP8266 and IOT related books

Another of the recommended & FREE ebooks for EPS8266 is from Kolban

Interesting Applications

Related:  Chloroprene Rubber Sheet Rolls are the latest market buzz

  • Facebook Chat with ESP8266:

References

Some Practical Tips

  • The ESP8266 usually uses 9600 or 115200 baud-rate, but try with other in case you are not able to get any meaningful data on the serial terminal (you can use Putty, or Arduino IDE’s Serial Monitor etc to connect to COM-1, COM-2 as applicable)
    • The serial settings for my board were:
      • Speed: 115200
      • Data bits: 8
      • Stop bits: 1
      • Parity: None
      • NL + CR are required for communicating via AT commands.
  • For enabling a server on wireless module, you can use AT+CIPSERVER=1,80. The MUX mode should also be set to accept multiple connections with the command: AT+CIPMUX=1
  • A new firmware can be programmed on the device only after booting it to flash mode. To do this GROUND the GPIO0 pin on ESP then pulse the Reset (to GROUND) and finally release the GPIO0 from Ground. This with move the ESP into programming mode and you can flash using flash utility or Arduino IDE etc. Refer another Short tutorial.
  • If you see this error (espcomm_sync failed error: espcomm_open failed or espcomm_send_command: cant receive slip payload data) while programming, it usually means the device has not gone into FLASH mode. Re-validate if you are using DTR, or Arduino Uno to program or manually changing the mode. Some more info here.
  • If you have solid BLUE light and ESP not running your program it could be a power supply issue. Read more here.
  • Setting a Static IP for ESP8266
  • ESP8266 low-power mode (ESP8266 power consumption tests)

Alternatives to ESP8266 Wifi module

There is a new module based on STM32F4 ARM Coretex M4 microcontroller called the EMW3165, which we shall explore in a different write-up separate from this one concentrating on ESP8266.

And finally, feel free to comment about your progress with ESP based wireless module and if this article was insightful. I plan to add more details in the same page, so you can bookmark, subscribe, comment and share this page. Enjoy making your new or existing hardware-solution wireless!

Leave a Reply