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

Installing ns-3.34 in Ubuntu 20.04

This post shows how to install ns 3.34 in Ubuntu 20.04 LTS Prerequisites: Fresh installation of Ubuntu Version 20.04 LTS  ns3.34 can be downloaded from here Follow the video link for complete step by step instructions on the installation.  This version fixes the compilation issues of vanet-routing-compare.cc (bug in ns3.33)  Issue the following commands after opening a terminal  $ sudo apt update $ sudo apt install g++ python3 python3-dev python-dev pkg-config sqlite3 python3-setuptools git qt5-default gir1.2-goocanvas-2.0 python3-gi python3-gi-cairo python3-pygraphviz gir1.2-gtk-3.0 ipython3 openmpi-bin openmpi-common openmpi-doc libopenmpi-dev autoconf cvs bzr unrar openmpi-bin openmpi-common openmpi-doc libopenmpi-dev tcpdump wireshark libxml2 libxml2-dev Unzip or untar the ns-allinone-3.34.tar.bz2 in the home folder (in my case its /home/pradeepkumar) $ cd ns-allinone-3.34/ $ ./build.py --enable-examples --enable-tests  Once the installation is completed, you may get an output show

Installation of ns3 in Windows 10 and Windows 11 OS using WSL (Windows Subsystem for Linux)

This post shows how to install ns-3.33 in Windows 10 through WSL (Windows Subsystem for Linux) This posts works for Windows 11 also (I have tested it on a Windows 11 ISO and it works the Same way as mentioned in the following post.) This post will work for ns-3.3x version. Prerequisites : Install Windows Subsystem for Linux with GUI: Please refer the following video  System Information: OS used: Windows 10 and WSL (Ubuntu 20.04) GUI: XServer for Windows NS3 Version: ns-3.33 See the following complete video on how to install ns3 in Windows 10 Step 0 : Open XLaunch Step 1 :  Open WSL using PowerShell and open it as Administrator Command:/  wsl $ xfce4-session The GUI of Ubuntu Opens within Windows 10 OS. Step 2 : Download ns3 from nsnam.org website through Mozilla Firefox browser Step 3: Open a Terminal  $ sudo apt update $ sudo apt install build-essential autoconf automake libxmu-dev python3-pygraphviz cvs mercurial bzr git cmake p7zip-full python3-matplotlib python-tk python3-dev qt5-q

Installing NS-3.32 in Ubuntu 20.04

This is about installing ns version 3.32 in Ubuntu 20.04 LTS. #ns3 #ns3 .32 #networksimulation The commands used in the video are given here. $] sudo apt update $] sudo apt install build-essential autoconf automake libxmu-dev python3-pygraphviz cvs mercurial bzr git cmake p7zip-full python3-matplotlib python-tk python3-dev qt5-qmake qt5-default gnuplot-x11 wireshark Download the ns-allinone-3.32.tar.bz2 package from nsnam.org and copy it to /home/ folder See the full video for detailed instructions Extract it either in GUI or using command $] tar jxvf ns-allinone-3.32.tar.bz2 $] cd ns-allinone-3.32/ $] ./build.py --enable-examples --enable-tests The above command will take some time to install all the packages  You can see the output as shown below ns3 To check whether ns3 installed successfully, use the following commands. $] cd ns-3.32/ $] ./waf --run hello-simulator You should get the output as Hello Simulator $] ./waf --run first This is the example from the ns-3.32/exa