HTTP control, relay control and OTA/HTTP firmware updates using an ESP8266 for just $11

The ESP8266 came out a few years ago and people were really excited about its capabilities. I stayed away from it because there were no tools, not decent peripheral libraries and a questionable supply chain.  Fast forward to today and the situation has dramatically changed. Software development is now supported in the Arduino IDE, the PlatformIO development platform and by NodeMCU.

Microcenter stocks the several different ESP8266 boards by AdaFruit, Link Sprite and others. They had the LinkSprite with mounting holes, an relay and onboard voltage regulation for sale at $11 so I bought one. The board is smaller than a playing card but larger many other ESP8266 SBCs. I like the Link Sprite because it is case ready and has soldered in headers for peripherals. The Link Sprite LinkNode R1 is essentially compatible with the Wemos D1 retired from a the programming point of view.

A video of overview is also available on YouTube.

A Simple Program for Relay Control

  • Automatic Wi-fi portal for auto-configuration on new networks.
  • A built in web server
  • Bonjour style DNS so clients can find the server by name
  • Unique host name for each device
  • Web form based relay control.
  • Direct URL (GET) relay control
  • Web based firmware updates with authentication
  • Unique password for each device.
  • Direct connect OTA firmware updates with authentication
  • Remote Reset
  • No real security.
The document to the right shows the web page home screen with both relay control and administrative functionality.

Software Components

The diagram to the right shows the major software components The source resides in this GitHub repository. It consists of the following major components: 
  1. Network and Wi-Fi
  2. An auto-configuring Wi-Fi access point
  3. Web Server
  4. Firmware update services
  5. Relay control web form and handlers
The Network, DNS, Web Server, OTA update feature and web OTA update features are all publicly available Arduino libraries.  I blended the available services, created the web form, created a form and HTTP request relay control code.

Programming Requirements 

This program was built with the Arduino IDE and ESP8266 support package 2.3.0. I had a little trouble with 2.4. See the README.md on GitHub for more details.

Initial programming must be done with a USB-to-serial cable (3 Volt). I used both a Prolific 2303 clone cable and an old UARTs Bee adapter board.  Many sites have instructions on how to use the Arduino IDE.  Link Sprite's wiki page also has links.  

Network configuration is done upon restart after a programming cycle. The ESP8266 program brings up an Access Point portal that can be sued to select a network and enter a password. This program remembers that connection information. The program remembers network connection information across program versions.

Follow on programming can be done Over the Air (OTA) without the serial cable once the device has joined a network. You can submit firmware binaries via web form or use the espota.py python scripts to do the work. See the README.md for details.

OTA updates are significantly faster than those done over USB.


Hardware

Built on Link Spring LinkNode Rx that emulates the WeMos D1 (retired)
  • ESP-87266EX
  • 5V DC power jack
  • 1 Digital/IO Relay
  • 6 Digital I/O pins
  • 1 Analog Input pin
The Arduino pinout and ESP8266 pin mapping can be found in pins_arduino.h on github The Arduino pin naming convention doesn't make sense in this context. It is simpler to just refer directly to the ESP8266 pin number itself. The following table shows both representations.
GPIOFcnAlt FcnArduino pinR4 Relay
GPIO 04SDA?D4
GPIO 05SCL?D3
GPIO 12HMISOD6S4
GPIO 13HMOSIRXD2D7S5
GPIO 14HSCLKD5S3
GPIO 15HCSTXD2D10
GPIO 16R1 relayD2S2
GPIO2 is tied to the on-module ESP8266 Blue LED

Comments

This board is pretty amazing for the price. The tooling is good. Probably my only grip is that the software can get pretty big lengthening the development cycle. 

I did blow the TX/RX lines one of mine before I got OTA working.That board won't be getting new firmware anytime soon.




Created 2018 03 14

Comments

Popular Posts