We are back with the second part of our IoT development series. Please check out the first part for a brief description of the CoAP protocol and introduction to what we are trying to achieve.

Where we are and what we want to do

Let us first summarize what we have done so far. First, we have implemented CoapNode - an Elixir app that mocks software that would be running on an embedded device like ESP8266. CoapNode is a CoAP server that exposes resources to the outside world. It can register its resources in CoapDirectory which is something we ultimately want to put on a Raspberry PI using Nerves. We have finished implementing the tools in the CoapDirectory to make requests to given nodes. But the directory itself does not expose any interface. And that is what we are going to do now. We will expose an HTTP API.

This is the flow we are going to achieve:

  1. Using the CoAP protocol, CoapNode registers a resource in the CoapDirectory under a path, e.g. switches/1.
  2. We hit the CoapDirectory’s HTTP API, for instance issuing a GET http://(directory_ip)/switches/1 request.
  3. The directory translates the request to corresponding CoAP request and routes it to appropriate CoapNode that has registered the resource in step 1: GET coap://(node_ip)/switches/1.
  4. CoapDirectory responds to the HTTP request from step 2 with the response to the CoAP request from step 3.

The whole idea is that any static IP that anyone needs to know is the IP of the CoapDirectory. At the end, we will also hook up a Phoenix application to the setup and allow a resource observation in the browser.

#iot #elixir #development

How to easily prototype and build an IoT platform
1.25 GEEK