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 ns3 in Ubuntu 22.04 | Complete Instructions

In this post, we are going to see how to install ns-3.36.1 in Ubuntu 22.04. You can follow the video for complete details Tools used in this simulation: NS3 version ns-3.36.1  OS Used: Ubuntu 22.04 LTS Installation of NS3 (ns-3.36.1) There are some changes in the ns3 installation procedure and the dependencies. So open a terminal and issue the following commands Step 1:  Prerequisites $ sudo apt update In the following packages, all the required dependencies are taken care and you can install all these packages for the complete use of ns3. $ sudo apt install g++ python3 python3-dev pkg-config sqlite3 cmake python3-setuptools git qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools 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 gsl-bin libgsl-dev libgslcblas0 wireshark tcpdump sqlite sqlite3 libsqlite3-dev  libxml2 libxml2-dev libc6-dev libc6-dev-i386 libclang-dev llvm-

Installation of NS2 (ns-2.35) in Ubuntu 20.04

Installation of NS2 (ns-2.35) in Ubuntu 20.04 LTS Step 1: Install the basic libraries like      $] sudo apt install build-essential autoconf automake libxmu-dev Step 2: install gcc-4.8 and g++-4.8 open the file using sudo mode $] sudo nano /etc/apt/sources.list Include the following line deb http://in.archive.ubuntu.com/ubuntu bionic main universe $] sudo apt update $] sudo apt install gcc-4.8 g++-4.8 Step 3:  Unzip the ns2 packages to home folder $] tar zxvf ns-allinone-2.35.tar.gz $] cd ns-allinone-2.35/ns-2.35 Modify the following make files. ~ns-2.35/Makefile.in Change @CC@ to gcc-4.8 change @CXX@ to g++-4.8 ~nam-1.15/Makefile.in ~xgraph-12.2/Makefile.in ~otcl-1.14/Makefile.in Change in all places  @CC@ to gcc-4.8 @CPP@ or @CXX@ to g++-4.8 open the file: ~ns-2.35/linkstate/ls.h Change at the Line no 137  void eraseAll() { erase(baseMap::begin(), baseMap::end()); } to This void eraseAll() { this->erase(baseMap::begin(), baseMap::end()); } All changes made Step 4: Open a new termi

Installation of NS2 in Ubuntu 22.04 | NS2 Tutorial 2

NS-2.35 installation in Ubuntu 22.04 This post shows how to install ns-2.35 in Ubuntu 22.04 Operating System Since ns-2.35 is too old, it needs the following packages gcc-4.8 g++-4.8 gawk and some more libraries Follow the video for more instructions So, here are the steps to install this software: To download and extract the ns2 software Download the software from the following link http://sourceforge.net/projects/nsnam/files/allinone/ns-allinone-2.35/ns-allinone-2.35.tar.gz/download Extract it to home folder and in my case its /home/pradeepkumar (I recommend to install it under your home folder) $ tar zxvf ns-allinone-2.35.tar.gz or Right click over the file and click extract here and select the home folder. $ sudo apt update $ sudo apt install build-essential autoconf automake libxmu-dev gawk To install gcc-4.8 and g++-4.8 $ sudo gedit /etc/apt/sources.list make an entry in the above file deb http://in.archive.ubuntu.com/ubuntu/ bionic main universe $ sudo apt update Since, it&#