Starting with Internet of Things using Constrained Application Protocol (CoAP)

What is Constrained Application Protocol

In recent times, Internet of Things a.k.a. IoT has gained traction. In simple terms, it is a way to create machines that can talk to each other without human intervention. Once you solve the communication problem, you enable IoT. The foundation to this is “Machine-2-Machine” (or M2M) communication.

Just like HTTP, a new alternative was developed by IETF called CoAP ; a lightweight protocol that runs over UDP and exposes one machine to other machines as a set of RESTful URLs. Look at this CoAP tutorial on Slideshare for a brief introduction.

What is being built:

In this post, I’ll talk about building a temperature sensor. This temperature sensor will be the “server”. I’ll build another client board, that will query the “server” board to get the temperature. A classic use case could be, that, in your office conference room, you have cooling system. You put a temperature sensor that acts like a server. Another board periodically queries the temperature and as needed, adjusts the cooling from a centralized location.

What do you need to get started:

1. You need an embedded board that has the required stack for inter-networking. I’m using Netduino Plus 2 boards (2 Nos.)

2. You need a CoAP implementation using which you will build your application. Given that Netduino works on .NET, I have picked up the C# version of CoAP implementation that works with .NET Micro Framework (Netduino runs on .NET Micro Framework). The C# version of CoAP implementation, that works with .NET Micro Framework is called CoAPSharp. You can download the source and binaries from the site http://www.coapsharp.com

How it Works:

The board that acts like a server, has a “CoAP Server” implementation. It waits for a request from the client on the path “sensors/temp” . Once a request is received, it reads the temperature from the connected sensor and constructs a JSON string. This JSON string is returned back in a response CoAP message in the payload.

Excellent tutorial on implementing basic CoAP client and server can be found on the CoAPSharp site

The Basic Setup:

vsblogs-1

Both the boards are connected via Ethernet and communicate with each other using CoAP.

The temperature sensor is a DS18B20.

Download the source files from my Skydrive.

Happy IoT-ing 🙂

Advertisements

One thought on “Starting with Internet of Things using Constrained Application Protocol (CoAP)

  1. Greetings! This is my first comment here so I just wanted to give a quick shout out and say I truly enjoy reading through your posts.
    Can you suggest any other blogs/websites/forums that deal with the same subjects?
    Appreciate it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s