Anda di halaman 1dari 3

Internet of things

Contiki OS Connecting
Microcontrollers to IoT
As the Internet of Things becomes more of a reality,
Contiki, an open source OS, allows DIY-enthusiasts to
experiment with connecting tiny, low-cost, low-power
microcontrollers to the Internet
T.S. Pradeep Kumar

ontiki is an open source operating system for connecting tiny, low-cost, low-power microcontrollers
to the Internet. It is preferred because it supports
various Internet standards, rapid development, a selection
of hardware, has an active community to help and has commercial support bundled with an open source licence.
Contiki is designed for tiny devices and thus the memory
footprint is far less when compared with other systems. It
supports full TCP with IPv6, and the devices power management is handled by the OS. All the modules of Contiki
are loaded and unloaded during run time; it implements
protothreads, uses a lightweight file system and various
hardware platforms with sleepy routers (routers that sleep
between message relays).
Contiki uses the Cooja simulator for emulation in case
any of the hardware devices are not available.

Installation of Contiki
Contiki can be downloaded as Instant Contiki, which is
available in a single download that contains an entire Contiki development environment. It is a Ubuntu Linux virtual
machine that runs in VMware player, and has Contiki and
all the development tools, compilers and simulators used
in Contiki development already installed on it. Most users
prefer Instant Contiki over the source-code binaries. The
current version of Contiki is 2.7.
The steps for installing Contiki OS are:
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) from http://sourceforge.net/projects/
contiki/files/Instant%20Contiki/ and unzip it.
Step 3. Open the Virtual Machine and Contiki OS, and

Fig. 1: Contiki OS desktop

62

December 2014 | Electronics For You

wait for the login screen to appear.


Step 4. Input the password as user [this shows the desktop of Ubuntu (Contiki)].

Running the simulation


To run a simulation, Contiki comes with many prebuilt
modules that readily run on the Cooja simulator or on the
real-hardware platform. There are two methods of opening
the Cooja simulator window.
Method 1. On the desktop, as shown in Fig. 1, doubleclick on the Cooja icon. This will compile the binaries for the
first time and open the simulation windows.
Method 2. Open the terminal and go to the Cooja directory:
pradeep@localhost$] cd contiki/tools/cooja
pradeep@localhost$] ant run

The simulation window is as shown in Fig. 2.

Creating a new simulation


To create a simulation in Contiki, go to File menuNew
Simulation, and name it as shown in Fig. 3.
Select any one radio medium (in this case)Unit Disk
Graph Medium (UDGM): Distance Loss and click Create.
Fig. 4 shows the simulation window, which has the following windows.
Network window. This shows all the motes in the simulated network.
Timeline window. This shows all the events over the time.
Mote output window. All serial port outputs are shown
here.

Fig. 2: Cooja compilation


www.efymag.com

Internet of things

Fig. 3: New simulation

Fig. 4: Simulation window

Fig. 5: Mote creation and compilation in Contiki

Notes window. User notes information can be put here.


Simulation control window. Users can start, stop and
pause the simulation from here.

Adding sensor motes


Once the simulation window is opened, motes can be added
to the simulation using Menu: MotesAdd Motes.
Since we are adding motes for the first time, the type of
mote has to be specified. There are more than ten types of
motes supported by Contiki. Here are some of themMicaZ, Sky, Trxeb1120, Trxeb2520, cc430, ESB, eth11, Exp2420,
Exp1101, Exp1120, WisMote and Z1.
Contiki will generate object codes for these motes to run
on real hardware and also on the simulator, if the hardware
platform is not available.
Step 1. To add a mote, go to Add MotesSelect any of
the motes given aboveMicaZ mote; you will get the screen
shown in Fig. 5.
Step 2. Cooja opens the Create Mote Type dialogue box,
www.efymag.com

Electronics For You | December 2014

63

Internet of things
output is shown in Fig. 7.
The output of the above Hello World application can also
be run using the terminal.
To compile and test the program, go into the Hello
World directory:
pradeep@localhost $] cd /home/user/contiki/examples/hello-world
pradeep@localhost $] make

This will compile the Hello World program in the native


target, which causes the entire Contiki OS and Hello World
application to be compiled into a single program that can be
run by typing the following command (Fig. 8):

pradeep@localhost$] ./hello-world.native

This will print out the following text:

Contiki initiated, now starting process scheduling


Hello, world

The program will then appear to hang, and must be


stopped by pressing Control + C.

Fig. 6: Log output in motes

Fig. 7: Simulation window of Contiki

Developing new modules


Contiki comes with numerous pre-built 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 run
only on specific sensors. For example, the energy of a sky
mote can be used only on sky motes and gives errors if run
with other motes like Z1 or MicaZ.
Developers can build new modules for various sensor
motes that can be used with different sensor BSPs using
conventional C programming and then be deployed in the
corresponding sensors.
Here is the C source code for the above Hello World
application.
#include contiki.h
#include <stdio.h> /* For printf() */
/*------------------------------------------------------*/

Fig. 8: Compilation using the terminal

which gives 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
Then, click Compile.
Step 3. Once compiled without errors, click Create (Fig. 5).
Step 4. Now the screen will ask you to enter the number
of motes to be created and their positions (random, ellipse,
linear or manual).
In this example, ten motes are created. Click the Start
button in the Simulation Control window and enable the
motes Log Output: printf() statements in the View menu
of the Network window. The Network window shows the
output Hello World in the sensors. Fig. 6 illustrates this.
This is a simple output of the Network window. If the
real MicaZ motes are connected, Hello World will be displayed in the LCD panel of the sensor motes. The overall
64

December 2014 | Electronics For You

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();
}

The Internet of Things is an emerging technology that


leads to concepts like smart cities, smart homes, etc. Implementing IoT is a real challenge but the Contiki OS can be of
great help here. It can be very useful for deploying applications like automatic lighting systems in buildings, smart
refrigerators, wearable computing systems, domestic power
management for homes and offices, etc.

The author is a professor at VIT University, Chennai. He runs two websites


http://www.nsnam.com and http://www.pradeepkumar.org. This article first
appeared in September issue of Open Source For You
www.efymag.com

Anda mungkin juga menyukai