Sparrow and CoAP using ESP8266

Iulia Manda - AAC

Introduction

CoAP is based on the wildly successful REST model: Servers make resources available under a URL, and clients access these resources using methods such as GET and PUT. It is intended for use in resource-constrained internet devices, such as WSN nodes.

The ESP8266 WiFi Module is a self contained SOC with integrated TCP/IP protocol stack that can give any microcontroller access to a WiFi network. Its main advantages are multicast support, very low overhead, and simplicity.

In this project, Sparrow acts as a CoAP server, which makes the resources available (e.g humidity, temperature) over the internet. The data collected by a master Sparrow node is sent to the CoAP client.

Connecting the ESP to Sparrow

Server

Arduino ESP8266 Wifi

Arduino-ESP8266 [1] is a library to manage the ESP. On short, it implements wrapper functions on top of the basic AT commands [2] that can be used to configure the ESP.

Since the already implemented library was using different commands than our version of ESP, some functions had to be changed. You can find the updated version at [3]. In case one will have problems with other functions that I did not yet use in my proof of concept example, he/she should check their implementation in ESP8266.cpp.

CoAP

The existing CoAP protocol library [4] implementations make use of the implemented support for handling UDP packets on a specific board. The definition of a CoAP instance:

Coap::Coap(
#if defined(ARDUINO)
    UDP& udp
#endif
) {
#if defined(ARDUINO)
    this->_udp = &udp;
#elif defined(SPARK)
    this->_udp = new UDP();
#endif

More details on how Sparkfun handles this can be found at [5]

As a <wifi> structure was already populated using the ESP8266 Arduino library, I decided to use it in CoAP instead of using UDP. As such, the definition of coap instance in our code looks as follows:

Coap::Coap(ESP8266& wifi)
{                                                                                
    this->_wifi = &wifi;                                                           
} 

The updated library can can be downloaded at the end of this page [6].

Client

libcoap

libcoap [7] is a C implementation of a lightweight application-protocol for devices that are constrained their resources such as computing power, RF range, memory, bandwith, or network packet sizes. This protocol, CoAP, is standardized by the IETF as RFC 7252. In our project, we use the client implementation from libcoap, as follows:

$ ./coap-client -m get coap://X.X.X.X:port/resource

where X.X.X.X is the IP assigned to the ESP after connecting to a local WiFi, the port is set in out server implementation and the resource is exposed by each implemented callback in the sever.

Copper

Copper (CU) [8] is a Firefox plugin that implements the RFC 7252 and URI handling for the 'coap' scheme. It provides interaction through GET, POST, PUT, and DELETE, resource discovery, block wise transfers and resource observation.

Testing

In order to test the functionality of the ESP and the correct interconnection of the components from software, I have used test_espmodule.ino [9], which is attached at the end of this page. It is very useful as it uses AT basic commands and there is a transparent view of the status of the ESP. It is also very simple to update.

Results and Future Work

This project is in a Proof-of-Concept state right now. Led on pin 11 can be turned on and off from the Coap client. After adding arduino-ESP8266 and COAP libraries to Arduino/libraries, espwifi_poc.ino [10] can be run to start the server. One must follow the activity on the serial in order to get the assigned IP address. This will be used afterwards in Copper (Firefox) to connect to the server, in our example as follows:

coap://<ip_address>:8083/light123

For a more efficient system, we mention the following: - CH_PD of the ESP can be used to deactivate the chip when it is not necessary; - read data from the sensors at specific larger moments of time, and use the CH_PD to also send data to the client rarely.

Resources

iothings/proiecte/2017/sparrow.txt · Last modified: 2021/12/06 22:21 by dan.tudose
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0