Lobaro-CoAP on ESP8266

Page Summary

This page is an introduction running our CoAP (“Constrained Application Protocol”) software-stack “lobaro-coap” on the popular  ESP8266 wifi chip, which is sold for under 3€ per piece.

The target audience is embedded programmers with knowledge of the “C” programming language and the ESP8266 IoT SDK.

GitHub Repository

Quick Facts

  • Runs natively on ESP8266 SOC
  • uses only one UDP socket
  • Easy addition of new resources
  • Eclipse IDE project
  • over the air wifi config
  • Source available at GitHub

Key Terms

  • ESP8266
  • lobaro-coap
  • UDP socket
  • Eclipse
  • ESP8266 IoT SDK
  • open source (MIT)

Getting started

1. Install “Unofficial Development Kit for Espressif ESP8266”

Download & install the free gcc toolchain for ESP8266:  github.com/CHERTS/esp8266-devkit (source) or http://programs74.ru/udkew-en.html (installer)

The kit includes the compiler, firmware libraries, documentation and some extra tools for e.g. flashing the firmware. A real “one in all” package to get started with the esp8266 under windows. For linux take a look here: https://github.com/pfalcon/esp-open-sdk

2. Check Espressif SDK Version V1.51

This Demo has been tested against “ESP8266 Non-OS SDK(ESP8266_NONOS_SDK_V1.5.1_16_01_08)” -> SDK V1.51

If it’s not present in folder c:EspressifESP8266_SDK after install of the development kit above please download V1.51 from Espressif Forum and copy the zip file contents manually to c:EspressifESP8266_SDK (rename “esp_iot_sdk_v1.5.1” to “ESP8266_SDK”).

3. Install integrated development environment (IDE)

Install Eclipse:

4. Download CoAP demo eclipse project

Clone via:  git clone –recursive https://github.com/Lobaro/lobaro-coap-on-esp8266

5. Build + Flash firmware via serial bootloader

The development kit includes a binary version of “ESPTOOL” which is used to download the firmware binaries to the esp8266.

  1. Follow the instructions in section “Protocol” of its Github page to connect your esp8266 board: github.com/themadinventor/esptool
  2. Set the com-port of your pcs serial port connected to the esp inside the “Makefile”: ESPPORT ?= COMx
  3. Double-click on “flash” inside eclipse “Make Target” Tab

6. Install Copper-CU Firefox Plugin as CoAP Client

To test the CoAP server use the firefox plugin “Copper (CU)” which can be found here: Firefox Add-ON Download Page

7. Setup WIFI ssid + password

This demo firmware tries to connect to the predefined wifi access point which ssid and password are stored inside the flash memory of your esp8266. Since it’s not configured yet this attemp will fail before you configure the credentials of your local wifi network. After three failed connection attempts the firmware opens its own wifi network. You can use this network to configure your wifi ssid and password via CoAP:

  1. Power on your ESP8266 and wait for the network in step 2 to appear (max. 1 minute)
  2. Connect to wifi network “Lobaro-CoAP (ESP8266)” (password is “lobaro!!“)
  3. Open Firefox with installed Copper-CU Plugin (see step 5 above)
  4. Open a firefox tab at coap://192.168.4.1:5683 , the CoAP “control panel” should show up.
  5. Click on “Ping”, it should show up “Pong: Remote responds to CoAP”
  6. Update the address to:  coap://192.168.4.1:5683/wifi/config?key=123&ssid=YOUR-SSID&pw=YOUR-PW
  7. Click on “PUT” button, it should show up “updated”
  8. Update the address to:  coap://192.168.4.1:5683/wifi/ipconfig
  9. Click on “GET” button, it should show up the IP the esp8266 got from your access point
  10. From now on access the ESP8266 directly via “Station” IP got in step 9
  11. After power on reset the softAP will only started again if connect to external AP fails 3 times

8. Done!

Try out the existing resources on your native esp8266 CoAP server or create your own ones!

Take a look inside the projects “resources” directory to see how simple it is with lobaro-coap to create a resource!

Demo CoAP resources:

Downloads:

Binaries (for 512KByte flash esp8266, without fota, “standard” hardware):

… use “esptool” to flash the files to your esp8266

Sources: