Skip to main content

IOT - CoAP implementation in Contiki OS

Constrained Application Protocol (CoAP) is a lightweight http protocol that reads and controls the sensors deployed for IoT.
It has actions like get, post, put, delete, observe, discover.

This coap can be accessed similar like http, For ex: to access a particular mote (Sensor) with IPv6 like this
The above line will fetch the sensor boards peripherals and one can control from the browser itself. Firefox has a Cu plugin to enable CoAP within the browser. CoAP is already available for all the devices like IOS, Android, Windows, Linux, Mac, etc,

So here is an example in contiki that shows how to use this coap based application using a border router.

Step 1: Contiki Selection

Open instant Contiki (Which runs on VMWare or Virtual Box)

Open Cooja from the Desktop directly or Open the Terminal and give the following steps

$] cd /home/user/contiki-2.7/tools/cooja
$] ant run 
If you want to simulate huge number of nodes then 
$] ant run_bigmem

Step 2: Selecting Border router

File - New Simulation -> Enter Simulation Name (Leave the defaults as it is ) and then Click "Create"

Click Add Motes -> Select Sky Mote

In the firmware, Select the following path /home/user/contiki-2.7/examples/ipv6/rpl-border-router/border-router.c
Click -> Compile (or Clean and then Compile), once compilation is over, Click Create motes and select the number of motes (1 in this case).

Step 3: Selecting the Er Example Server

Click Add Motes -> Sky Motes 
In the firmware, select the following path /home/user/er-rest-example/er-example-server.c 
Click Compile -> after compilation, click create motes and select the number of motes (2 in this case)

Step 4: Run the Simulation 

In the Simulation Control window, you can press the Start button to start the simulation. Since this application is deployed with IpV6 for all the nodes, it can be seen from the simulation that all the motes have the ipv6 addresses like this
mote 1: aaaa::212:7401:1:101 for Border router

A bridge has to be made between the border router and the other motes, to enable the bridge, Right Click Border Router Node -> Mote tools for Sky 1 ->  Serial Socket (SERVER) 

Step 5: Bridge the Border Router

Open a new terminal and select the path as given below

$] cd /home/user/examples/ipv6/rpl-border-router/
$] make connect-router-cooja 
It will ask to input the super user password, after you input, the ipv6 addresses will be assigned to the motes.
You may ping it using a new terminal, with the command "ping6 aaaa::212:7402:2:202"

Step 6: Read the sensors

You can read the sensors using the ipv6 addresses by opening the firefox browser.
Open the browser and input the following addresses in a new tab

coap://[aaaa::212:7402:2:202] or any other sensor mote
Refer the images given below

The above two images shows firefox browser with cu plugin to open the ipv6 address and read the sensor values. In the first picture the toggle value 1 for Red LED is sent from the browser by selecting the POST button (OutGoing), Upon receiving the RED LED is glowing in the Mote that indicates that the node is accepting the inputs remotely. 

Thus coAP is very handy when deals with the motes attributes. You may refer the following video for exact explanation of CoAP in Contiki

T S Pradeep Kumar


  1. Hello Sir,I have gone through your video CoAP implementation in Contiki OS and found very interesting. Thanks for sharing such video.I have downloaded contiki OS  and when I read the sensors using the ipv6 addresses by opening the firefox browser and providing following IP addersscoap://[aaaa::212:7402:2:202] ; getting the error 4.04Not Found. I could see well-known and core resources bot not the others.
    Plz help me.
    Appreciate for your reply.
    Thanking You,
    Dr. Nikita Kulakarni


Post a Comment

Popular posts from this blog

Routing in VANETs using ns3

Part 1
WAVE - Wireless Access for Vehicular environments. It might take more than an hour. The readers are requested to be patient. SUMO, VANETs, routing comparison 1. Explain the full source code (1550 lines of code) 2. Creating a real scenario using osm (Open Street Map Web Wizard) 3. Performance analysis for various vanet protocols. Location of the source code /home/pradeepkumar/ns-allinone-3.27/ns-3.27/src/wave/examples
Move this file to the scratch/ for inclusion of all modules. Step 1: Explanation of source code. Copy the file to scratch folder. This is just Part 1 of the VANET comparison

Part 2 Please watch the First Part before watching this video
Part 2 - Analysis of the results.
Please go through the first video (Part 1) and then watch this video (PArt 2)
#VANETs #NS3 #Routing
1. SUMO for web traffic ( 2. Convert this into mobility.tcl file and t…

ns3 installation in Ubuntu 16.04

This post serves the installation instructions of ns3 in ubuntu 16.04 version. Some of my students are working in ns3, this post will benefit them in installing ns3.

OS Used: Ubuntu 16.04.4
ns3 version: ns3 version 3.27

The same procedure will be applied for OS like Debian, Linux Mint.

Fresh installation of Ubuntu 16.04 Let you try the fresh installation of ubuntu in your hard disk along with windows.
Installation of ns3 dependencies ns3 needs so many dependencies, developmental libraries, drivers, etc. so install all those
$] sudo apt update  $] sudo apt upgrade
$] sudo apt-get install build-essential autoconf automake libxmu-dev python-pygoocanvas python-pygraphviz cvs mercurial bzr git cmake p7zip-full python-matplotlib python-tk python-dev python-kiwi python-gnome2 python-gnome2-desktop-dev python-rsvg qt4-dev-tools qt4-qmake qt4-qmake qt4-default gnuplot-x11 wireshark
The above command make take some time to download, compile and install it, Be Patient. 
Installing ns3 Download the…

TORA Protocol in NS-2.35 (NS2)

This post tells you how to enable the TORA (Temporally ordered routing Algorithm) protocol in Network Simulator 2 (ns-2.35)

TORA is a protocol in wireless adhoc networks that works with timing parameters. NS-2.35 comes with the TORA protocol by default but it has to be tweaked manually to make it run.
This post will help you to do that.

You can watch this video for detailed instructions:

Step 1: Generate a Scenario for TORA protoco using NS2 Scenario Generator NSG Software.
We have created a tcl file using NSG2.1.jar

$] java -jar NSG2.1.jar

Three files have to be modified
~ns-2.35/tora/ There are various websites that tells you how to configure TORA by making changes to the above three files.  Change 1: tora.h In the tora.h file, go to the end of the File before the agent completes, include these two lines

#include <classifier/classifier-port.h>
protected: PortClassifier *dmux_;

Change 2: Open the and include the follow…