Contiki is an operating system just like Microsoft Windows and Linux but for a very specific purpose and mainly focused on ‘things’ in the internet of things (iot). Here is everything you need to know about it.
By Janardan Revuru
The Internet of Things (IoT), a technology that enables the automated exchange of key information between machines, and then ultimately to humans, promises a future where a whopping 50 billion devices will have the ability to “talk to each other” by 2020. The ‘things’ that are getting connected vary significantly in size and shape include tiny wireless sensors (smart dust) to electrical appliances at home to electronics used in space experiments. Things are characterised as low-memory and low-power devices, where memory is measured in bits or bytes (not megabytes or gigabytes) and power consumption is so low that devices can run for years with a pair of AAsize battery!
Things are also referred to as smart objects which collect valuable data from the surroundings and communicate to the networked system. Thereby smart objects become a bridge between the real and virtual worlds. They contain sensors, microprocessor, communication and power source. The operating system (OS) in these objects controls all of its operations.
While we may see the number (50 billion) questionable, there are technologies being developed to make this a reality. The fundamental piece for that is the OS such as Contiki. Just like most consumer electronics devices come with chips embedded in them, for Internet of Things it is essential that there is some basic software such as Contiki running in them.
What is Contiki?
Contiki is an OS just like Microsoft Windows and Linux, but for a very specific purpose and mainly focused on ‘things’ in the IoT. Various functions of an OS include program/process management, resource manage-
ment, memory management and communication management. The goal of Contiki is to meet requirements of the smallest devices such as smart dust. Things should be able to communicate a few bits of data to one another.
Contiki is an open source software project with the vision to create a minimalist and working OS for wide deployment. This project has broken many myths about the smallest footprint in which an OS can be stored and made to function. One such software is the uIPv6—world’s smallest IPv6 stack—which is integrated into Contiki. While there are many similar OS such as TinyOS, what makes Contiki different is the completeness and flexibility it offers to the programmers.
Features and functions of Contiki
Contiki is a completely open source software, distributed using the 3-clause BSD-style licence. The complete code is available on github for use or further development. Infrastructure is in place to run nightly regression tests to ensure the integrity of the software.
Contiki comes with a rich set of features that are deviceand programmerfriendly. This project is under active development by various developers all around the world, and the software also has consumers in companies like Cisco and Google. Contiki OS can fit into10kBofRAMand100kBofROM. It can run on devices such as 8051 SoC to ARM-powered devices. Ports are available on other platforms such as Arduino and Atmel. While standard compliance could be needed to interoperate with public networks (such as Internet), more efficient and optimised protocols are also supported. One such example is the Rime stack, developed to optimise the IPv6 protocol.
Contiki comes with much documentation apart from well documented code. There are also community forums where active discussions happen.
Operating system functions include:
1. Process and memory management. Contiki supports memory block allocation and standard ‘C’ style allocation with malloc( ). The concept and implementation of ‘protothreads’ has been introduced keeping the low system requirements in mind. ‘protothreads’ are C-language-based implementation minimising the overhead of multi-threaded programming.
2. Communication management.
Contiki supports both IPv4 and IPv6 stack implementations, which include TCP, UDP and HTTP protocols with the smallest footprints. The IP stack is standards-compliant. The OS also supports low-power variants such as 6LoWPAN.
3. File system management. Not all devices as part of IoT have luxury of persistent storage such as Flash. But for such devices, Contiki provides support through the Coffee Flash file system.
There are several applications that come packaged as part of Contiki. These include a small Web browser, Web server, calculator, shell, telnet client and daemon, email client, vnc viewer and ftp.
Developers can find tools such as Cooja simulator for application development. Contiki also provides mechanisms to measure power for var-
ious operations that help developers produce applications that are powersensitive. Software bundle also comes with a UNIX-style shell for interacting with OS and debugging.
Communication components in Contiki
uIP and uIPv6. There are several advantages of having the Internet protocol stack embedded in the OS. It allows communication with the existing devices/computers in the Internet. For this reason, the IP stack has been trimmedtofit1kBofRAMandafew kB of ROM, in comparison with Linuxbased IP stack that requires 1MB RAM. This trimming of memory comes at the cost of reduced throughput.
uIPv6 is in contrast to the IPv6certified version of IPv6, which was developed by Cisco. Support of IP stack along with TCP and UDP protocols makes it possible for devices running Contiki to directly interact with a Web server or tweak messages to the Internet.
LoWPAN (IEEE 802.15.4) and 6LoWPAN. Low-power wireless personal area networks have the characteristics of small packet sizes, low data rates, low-power devices and large number of devices. The IPv6 extension of the same is the 6LoWPAN standard developed by IETF working group. For saving power, the transmission and receiving periods are short spaced along with long periods of sleep mode by devices. Also, for power constraint reasons the communication is hopbased and short-range.
To get started with Contiki, download the code and compile it on the target machine. Or, you can directly down-
load the virtual machine image, called Instant Contiki, to play around.
Below is the Hello World! program written by founding developer Adam Dunkels:
* A very simple Contiki application
showing how Contiki programs look
* Adam Dunkels <email@example.com>
#include <stdio.h> /* For printf() */ /*——————————–*/ PROCESS(hello_world_process, “Hello world process”); AUTOSTART_PROCESSES(&hello_world_ process); /*——————————–*/ PROCESS_THREAD(hello_world_process, ev, data)
For compiling the code and developing applications, references are:
1. Contiki Home—http://www.contiki-os.org/
2. Talk on Contiki by Adam Dunkels—http://webbtv.compodium.se/trefpunkt22/007/ 3. Getting started with Instant Contiki—http://www.contiki-os.org/start.html
4. Develop your first app on Contiki—http://www.sics.se/contiki/wiki/index.php/Develop_your_first_application
5. Interconnecting Smart Objects with IP—The Next Internet , Jean-Philippe Vasseur and Adam Dunkels
TinyOS. It is an embedded operating system, developed by UC Berkeley in collaboration with Intel Corp, specifically designed for wireless sensor networks. Apart from internal architectural differences with Contiki, applications in TinyOS are developed using nesC, which is a dialect of ‘C.’
FreeRTOS. It is a real-time OS designed with scalability and small footprint in mind. It supports preemptive and hybrid scheduling configurations. Supported devices include ARM, NXP , NEC, Infineon and Freescale.
The author, Janardan Revuru, is passionate about open source and productivity tools. He is currently a project manager at Hewelett-Packard.