Skip to main content

Contiki OS - An Operating System and Framework for IOT (Internet Of Things)

This article is published in the "Open Source For you" magazine in India in this month September 2014. This article is under the creative commons license. For any queries related to this software, please input your queries through the comment section of this page.

Introduction to Contiki OS
Contiki is an open source operating system for connecting the tiny low cost microcontrollers, sensors to the internet. Contiki is preferred because it supports the various internet standards, rapid development, selection of hardware, active community to help and commercial support altogether with a open source license. 

Contiki is designed for tiny devices and thus the memory footprint is very less when compared with other systems, it supports the Full TCP with IPv6, it handles power awareness where in the device power management is handled by the OS, all the modules of Contiki is loaded and unloaded during the run time,  it implements protothreads, uses a light weight file system, various hardware platforms with sleepy routers (to make the routers sleep between message relays). 

One of the important feature of contiki is the use of Cooja Simulator to emulate if any of the hardware devices is not available.

Installation of Contiki
Contiki can be downloaded as “Instant Contiki”. Instant Contiki is available in a single download that contains an entire Contiki development environment. It is an Ubuntu Linux virtual machine that runs in VMWare player and has Contiki and all the development tools, compilers, and simulators used in Contiki development installed. Most of the users prefer instant Contiki over the Source code binaries. 

The current version of Contiki (at the time of writing this post) is 2.7.  
Step 1: Install VMWare Player (which is free for academic and personal use)
Step 2: Download the Instant Contiki virtual image of size 2.5GB approximately (http://sourceforge.net/projects/contiki/files/Instant%20Contiki/) and unzip it.
Step 3: Open the Virtual Machine  and open the Contiki OS and wait till the login screen appears
Step 4: Input the password as “user” and the shows the desktop of Ubuntu(Contiki)

Running the simulation
To run with a simulation, contiki comes with many prebuilt modules that can be readily run on the Cooja simulator or on the real ha7rdware platform.  There are two methods of opening the cooja simuator window.
contiki
Contiki OS Desktop
Method 1: 
In the desktop as shown in Figure 1 – Desktop of Contiki, double click the Cooja icon and it will compile the binaries for the first time and opens the Simulation windows
Method 2: 
Open the Terminal
Go the Cooja directory 
pradeep@localhost$] cd contiki/tools/cooja 

cooja
Figure 2: Cooja Compilation

You can see the simulation window as shown in Figure 2.

Creating a new Simulation
To create a simulation in Contiki, from the File menu New Simulation and name it as shown in Figure 3.
cooja
Figure 3 – New Simulation

Select any one radio medium (in this case) -> Unit Disk Graph Medium (UDGM): Distance Loss and Click Create
The following screen shows the Simulation window (Figure 4). The simulation window has the following windows
  • Network Window – Shows all the motes in the simulated network
  • Timeline Window – shows all the events over the time
  • Mote Output Window – all serial port outputs will be shown here
  • Notes Window – User notes information can be put here
  • Simulation Control Window – Start, stop and pause the simulation 
simulation
Figure 4 – Simulation Window


Adding the Sensor Motes
Once the simulation window is opened, motes can be added to the simulation using the Menu Motes-> Add Motes. Since we add the motes for the first time, the type of the motes have to be specified. There are more than 10 types of motes are supported in contiki
Here are some of them.
  • MicaZ 
  • Sky
  • Trxeb1120
  • Trxeb2520
  • cc430
  • ESB
  • eth11
  • Exp2420
  • Exp1101
  • Exp1120
  • WisMote
  • Z1
Contiki will generate object codes for these motes to run on the real hardware and also to run on the simulator if the hardware platform is not available.
Step 1: 
To add a Mote-> Add Motes Select any of the motes given above MicaZ mote.
You will get a screen like this Figure 6. 
Step 2: 
Cooja opens the Create Mote Type dialog, in which the name of the mote type as well as the Contiki application that the mote type will run. 
For this example click the button on the right hand side to choose the Contiki application and select /home/user/contiki/examples/hello-world/hello-world.c and click Compile.  
Step 3: 
Once compiled without errors, click “Create”.  This is shown in the Figure 6.

motes
Figure 6 – Mote Creation and Compile Contiki

Step 4: Now the screen asks to enter the number of motes to be created and its position (random or ellipse, linear or manual position)
In this example, 10 motes are created and click the “start” button in the Simulation Control window and enable the mote's “Log Output: printf()'s” statements in the view menu of the Network window. The network window shows the output Hello World in the sensors. Figure 7 is represented by this

motes
Figure 7 – Log Output in Motes 
This is a simple output of the Network window where it shows the “Hello World” application. If the real MicaZ motes are connected and are written the object to the motes, the Hello World will be displayed in the LCD Panel of the Sensor Motes.  The overall output is shown in Figure 8

contiki
Figure 8 – Simulation window of Contiki


Also the output of the above hello world application can be run using the terminal also 
To compile and test the program, go into the hello-world directory:
--------------------------------CODE-----------------------------

pradeep@localhost $]  cd /home/user/contiki/examples/hello-world

This will compile the hello-world program in the 'native' target.  This causes the entire Contiki operating system and the hello-world application to be compiled into a single program that can be run by typing the following command (This is depicted in Figure 9)
Figure 9 - Compilation using Terminal
pradeep@localhost $] ./hello-world.native

This will print out the following text:
Contiki initiated, now starting process scheduling
Hello, world
--------------------------------CODE-----------------------------

The program will then appear to hang, and must be stopped by pressing the C key
while holding down the Control key.

Developing new modules
Contiki comes with numerous prebuilt modules like IPv6, IPV6 udp, hello world, sensor nets, EEPROM, IRC, Ping, Ping-IPv6, etc. These modules can run with all the sensors irrespective of their make. Also there are modules that runs only on specific sensors. For example, energy of a sky mote can be used only on Sky Motes, they give errors if running with other motes like Z1 or MicaZ. 

Developers can build new modules for various sensor motes that can be used with various sensor BSPs using the conventional C programming and can be deployed in the corresponding sensors. 

Here is the C source code for above hello-world application.
--------------------------------CODE-----------------------------
#include "contiki.h"
#include <stdio.h> /* For printf() */
/*---------------------------------------------------------------------------*/
PROCESS(hello_world_process, "Hello world process");
AUTOSTART_PROCESSES(&hello_world_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(hello_world_process, ev, data)
{
  PROCESS_BEGIN();
  printf("Hello, world\n");
  PROCESS_END();
}
--------------------------------CODE-----------------------------

Conclusion: Internet of Things is an emerging technology that leads to Smart City, Smart home, etc applications. Over these years, implementing IOT was really a challenge and now there is one such OS contiki is available to start with.  Contiki can be very useful for deploying applications like automatic lighting system in buildings, Smart refrigerators, Wearble computing systems, domestic power management for homes, offices, etc. 

Reference: 


T S Pradeep Kumar

Comments

Popular posts from this blog

Installation of ns2 in Ubuntu 18.04 - NS2 Tutorial # 2

ns2 installation in Ubuntu 18.04

Unlike earlier version of ubuntu, the 18,04 version does not support the direct installation of ns2, because of the latest C/C++ compiler (7.x), but the latest C/C++ compiler supported by ns2 is gcc-4.8. So this post and video tells you about the installation of gcc-4.8 version, then ns2 and then configuration.
Here are the steps, Please follow the video given below for more information.

$] tar zxvf ns-allinone-2.35.tar.gz


$] sudo apt install gcc-4.8 g++-4.8

if you have installed ubuntu just now, you can try these commands also in the beginning

$] sudo apt update
$] sudo apt install build-essential autoconf automake libxmu-dev

$] cd ns-allinone-2.35/ns-2.35
$] gedit Makefile.in
$] gedit linkstate/ls.h

line number 137, change erase to this->erase
$] cd ..
$] ./install

export PATH=$PATH:/home/pradeepkumar/ns-allinone-2.35/bin:/home/pradeepkumar/ns-allinone-2.35/tcl8.5.10/unix:/home/pradeepkumar/ns-allinone-2.35/tk8.5.10/unix
export LD_LIBRARY_PATH=$L…

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…

AWK Scripts for NS2 to process data from Trace Files

AWK Scripts are very good in processing the data from the log (trace files) which we get from NS2. If you want to process the trace file manually, here is the detailHere is a sample of trace file from NS2 (However ns2 supports a new type of trace file also), but this post will make you understand the old trace format only.r 0.030085562 _0_ MAC  --- 0 message 32 [0 ffffffff 1 800] ------- [1:255 -1:255 32 0] r 0.030110562 _0_ RTR  --- 0 message 32 [0 ffffffff 1 800] ------- [1:255 -1:255 32 0] s 1.119926192 _0_ RTR  --- 1 message 32 [0 0 0 0] ------- [0:255 -1:255 32 0]
AWK Scripts are very good in processing the data column wise. For example
the first column in the above trace file represents r, s which indicates receive, sent respectively. If we want to trace the entire r and s alone from this trace file we can represent it as $1
So
$1 represents ACTION
$2 Time
$3 Node ID
$4 Layer
$5 Flags
$6 seqno
$7 type
$8 Size
$14 Energy (if the network nodes includes EnergyModel)To run the awk script in Li…