57
Contiki: Open Source OS for the Internet of Things

Contiki Operating system tutorial

Embed Size (px)

DESCRIPTION

Contiki is an open source operating system for the Internet of Things. Contiki connects tiny low-cost, low-power microcontrollers to the Internet. the presentation explains how to install the simulator, teach the reader some concepts of contiki OS, goes through API used in platform specific examples, and most importantly explains some example(Blinking example, Light and temperature sensor web demo).

Citation preview

Page 1: Contiki Operating system tutorial

Contiki: Open Source OS for the Internet of Things

Page 2: Contiki Operating system tutorial

The Internet of Things applications

Page 3: Contiki Operating system tutorial

Why Choose Contiki?

Contiki is an open source operating system for the Internet of Things.

Contiki connects tiny low-cost, low-power microcontrollers to the Internet

Page 4: Contiki Operating system tutorial

The Contiki Operating System

Contiki is an open source operating system that runs on tiny low-power microcontrollers and makes it possible to develop applications that make efficient use of the hardware while providing standardized low-power wireless communication for a range of hardware platforms.

Contiki is used in numerous commercial and non-commercial systems, such as city sound monitoring, street lights, networked electrical power meters, industrial monitoring, radiation monitoring, construction site monitoring, alarm systems, remote house monitoring, and so on.

Page 5: Contiki Operating system tutorial

Get Started with Contiki

Page 6: Contiki Operating system tutorial

Firstly

Cooja makes Contiki easy to install and get started with it.

Download Instant Contiki http://sourceforge.net/projects/contiki/

files/Instant%20Contiki/

Install VMWare Player https://

my.vmware.com/web/vmware/free#desktop_end_user_computing/vmware_player/6_0

Register and reboot

Start Instant Contiki

Start Instant Contiki by running InstantContiki2.6.vmx. Wait for the virtual Ubuntu Linux boot up.

Log into Instant Contiki. The password is user.

Page 7: Contiki Operating system tutorial

Boot Ubuntu

Page 8: Contiki Operating system tutorial

Log in

Page 9: Contiki Operating system tutorial

Step 2: Start Cooja

Page 10: Contiki Operating system tutorial

Cooja is a highly useful tool for Contiki development as it allows developers to test their code and systems long before running it on the target hardware.

Developers regularly set up new simulations both to debug their software and to verify the behavior of their systems.

Page 11: Contiki Operating system tutorial

Open a terminal window

We will now compile and start Cooja, the Contiki network simulator.

Starting the terminal

Page 12: Contiki Operating system tutorial

Start Cooja

Start Cooja by

In the terminal window, go to the Cooja directory:

Start Cooja with the command:

Page 13: Contiki Operating system tutorial

Running Cooja

Page 14: Contiki Operating system tutorial

Cooja UI

Page 15: Contiki Operating system tutorial

Step 3: Run Contiki in simulation

Page 16: Contiki Operating system tutorial

Creating Simulation

Click the File menu and click New simulation

Create New Simulation:

Page 17: Contiki Operating system tutorial

Simulation Window

Networkwindow (mot

es)

TimelineWindow->all

communications 

Page 18: Contiki Operating system tutorial

Simulation windows

Network window -Top left-shows all motes in the simu-lated area

Timeline window - At the bottom of screen - Shows all communication

events in the simulation over time

- very handy for under-standing what goes on in the network

Notes window - On the top right is where we can put notes for our sim-ulation.

 Mote output window - on the right side of the screen

- shows all serial port printouts from all the motes.

 Simulation control  -window is where we start, pause, and reload our simula-tion

Page 19: Contiki Operating system tutorial

Add mote to the interface

Before we can simulate our network, we must add one or more motes.

We do this via the Motes menu, where we click on

Add motes....

Since this is the first mote we add, we must first create a mote type to add.

Click Create new mote type... and select one of the available mote types.

For this example, we click Sky mote... to create an emulated Tmote Sky mote type.

Choose the hardware then install the firmware with any functionality that you desire

Page 20: Contiki Operating system tutorial

Add mote to the interface

Page 21: Contiki Operating system tutorial

Simulation window

Page 22: Contiki Operating system tutorial

Step 4Run Contiki on hardware

Page 23: Contiki Operating system tutorial

Platform porting

 we assume you have a Zolertia Z1 mote connected to a USB port of your PC

Enable the Z1 in Instant Contiki, so that Instant Contiki is able to talk to it

cd contiki/examples/FOLDER/

Then upload the compiled firmware to the hardware

Then make login To access the burnt firmware on the device

Page 24: Contiki Operating system tutorial

Hi.c file

Page 25: Contiki Operating system tutorial

MakeFile

Page 26: Contiki Operating system tutorial

 ./hi.native

The we have to compile the files by make TARGET=z1 hi

If there are not errors then some files will be produced like .native

filename.native

Page 27: Contiki Operating system tutorial

Upload Contiki to the hardware-in this case we have no connected hardware

Connection prob.

Page 28: Contiki Operating system tutorial

Platform in contiki

Page 29: Contiki Operating system tutorial

Contiki platforms

The contiki supports multiple independent platforms

The picture below from the directory of contiki

Page 30: Contiki Operating system tutorial

Example of contiki system(Tmote Sky platform)

The Tmote Sky platform is a wireless sensor board from Moteiv.

It is an MSP430-based board with an 802.15.4-compatible CC2420 radio chip,

a 1 megabyte external serial flash memory, and two light sensors.

Contiki was ported to the Tmote Sky by Björn Grönvall as part of the RUNES project.

The Tmote Sky port was integrated into the Contiki build system in March 2007.

Page 31: Contiki Operating system tutorial

Example of contiki system(Tmote Sky platform)

The platform-specific source code for the Tmote Sky port can be found in the directories platform/sky and cpu/msp430 in the Contiki source tree.

Code for writing to the on-chip flash ROM is in the cpu/msp430/flash.c

Code for reading and writing to the external flash is the file platform/sky/dev/xmem.c

Code for reading the light sensors is in platform/sky/dev/light.c.

Page 32: Contiki Operating system tutorial

Blink Application example

-Code -explanation-Cooja runnin’-video

Page 33: Contiki Operating system tutorial

Blink example code

-Code

Page 34: Contiki Operating system tutorial

Code detail

PROCESS ( name,strname )

Declare a process. PROCESS(blink_process, "Blink");

AUTOSTART_PROCESSES(&blink_process);

Starting a process automatically&blink_process

ROCESS_THREAD(name,ev,data )

-Define the body of a process-The process is called whenever an event occurs in the system-Start with the PROCESS_BEGIN() macro -Ends with the PROCESS_END() macro.

PROCESS_EXITHANDLER(handler ) -Specify an action when a process exits.-Comes before declaring PROCESS_BEGIN()

PROCESS_BEGIN( ) ,PROCESS_END()

-specify the beginning and the End of a process

Code explanation

Page 35: Contiki Operating system tutorial

Code detail

etimer et; -This structure is used for declaring a timer. The timer must be set with etimer_set() before it can be used.

PROCESS_WAIT_EVENT_UNTIL(c)

Wait for an event to be posted to the process, with an extra condition.-This macro is similar to PROCESS_WAIT_EVENT() in that it blocks the currently running process until the process receives an event.

PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

-Check if an event timer has expired.-Parameters:et :a pointer to the event timer.-return true if the time expires

leds_on(LEDS_ALL); On the LEDS

leds_off(LEDS_ALL); Off the LEDs

Code explanation

Page 36: Contiki Operating system tutorial

LED API

Simple and important to communicate with the user

The platform startup code initializes the LEDs library by calling leds_init() initializes the API

ledv: is LED vector platform independent #define LEDS_GREEN 1 #define LEDS_YELLOW 2 #define LEDS_RED 4 #define LEDS_ALL 7

leds_on() takes a LEDs vector argument, ledv, and switches on the LEDs set in the vector.

Led_off() takes the LED in ledv and switch it off.

leds_invert() inverts the current status of the LEDs set in the argument ledv.

Page 37: Contiki Operating system tutorial

Cooja capture

Page 38: Contiki Operating system tutorial

Youtube Demo

http://www.youtube.com/watch?v=9WohGp8udOQ

Page 39: Contiki Operating system tutorial

APIs

Page 40: Contiki Operating system tutorial

ESB platform sensors

button_battery_sensor - query the battery voltage level

sensor - query the on-board button

pir_sensor - query the passive IR sensor (motion detector)

radio_sensor - query the radio signal strength

sound_sensor - query the microphone

temperature_sensor - query the temperature sensor

vib_sensor - query the vibration senso

Page 41: Contiki Operating system tutorial

Sensor functions

Each sensor has a set of functions for controlling it and query it for its state. Some sensors also generate an events when the sensors change. A sensor must be activated before it generates events or relevant values.

SENSORS_ACTIVATE(Button_sensor ) ) - activate the button sensor

SENSORS_DEACTIVATE(sensor) 

sensor.value(0) - query the sensor for its last value (button either pressed or not)

sensors_event - event sent when a sensor has changed (the data argument will referer to the actual sensor)

Page 42: Contiki Operating system tutorial

process

 PROCESS_BEGIN() -Define the beginning of a process

PROCESS_END() -Define the end of a process. 

 PROCESS_WAIT_EVENT()

-Wait for an event to be posted to the process. -blocks the currently running process until the process receives an event.

PROCESS_WAIT_EVENT_UNTIL(c)

Wait for an event to be posted to the process, with an extra condition. 

 PROCESS_YIELD() Yield the currently running process. 

PROCESS_YIELD_UNTIL(c) Yield the currently running process until a condition occurs. 

 PROCESS_WAIT_UNTIL(c) Wait for a condition to occur. 

PROCESS_EXIT() Exit the currently running process. 

PROCESS_PAUSE() Yield the process for a short while. 

Page 43: Contiki Operating system tutorial

LED functions

Basic LED functions

leds_on() - turn LEDs on

leds_off() - turn LEDs off

leds_invert() - invert LEDs

leds_blink() - blink all LEDs

Page 44: Contiki Operating system tutorial

Beeper functions

Implements a beep function to emit a beep sound

Also play polyphonic tune using buzzer

beep()- click the beeper

beep_beep()- beep

beep_down()- pitchbend down beep

beep_quick() - a number of quick beeps

beep_spinup()- pitchbend up beep

Page 45: Contiki Operating system tutorial

Timer functions

Event Timer Callback timer Simple timer

-generates an event when the timer expires a

-call a function when the timer expires

-have to be actively queried to check when they have expired

•etimer_expired()•etimer_reset•etimer_set()•etimer_restart()

•ctimer_expired()•ctimer_reset•ctimer_set()•ctimer_restart()

•timer_expired()•timer_reset•timer_set()•timer_restart()

The Contiki kernel does not provide support for timed events. Rather, an application that wants to use timers needs to explicitly use the timer library.

Page 46: Contiki Operating system tutorial

Sky websenseLight and temperatur sensor web demo

Page 47: Contiki Operating system tutorial

Border router set-up

Having able to connect to sensors is very significant step in IOT

This example features a simple webserver running on top of the IPv6 Contiki stack on Sky motes to provide sensor values, and with a RPL border router to bridge the sensor network to Internet.

Server is located in :[Contiki home]\examples\ipv6\rpl-border-router

Simulation in Cooja is in

examples\ipv6\sky-websense

Page 48: Contiki Operating system tutorial

Steps

1. Start COOJA and load the simulation "example-sky-websense.csc"

make TARGET=cooja example-sky-websense.csc

2. Connect to the COOJA simulation using tunslip6:

make connect-router-cooja

3. You should now be able to browse to the nodes using your web browser:

Router: http://[aaaa::0212:7401:0001:0101]/

Node 2: http://[aaaa::0212:7402:0002:0202]/

Page 49: Contiki Operating system tutorial

tunslip6

Before being able to view the sensor readings from the webserver,

A serial connection to the server through the command

Page 50: Contiki Operating system tutorial

output

The Cooja simulator provides you with important details about every sensor node in the network

Page 51: Contiki Operating system tutorial

Websense code details

Including the required libraries

Define processes

Opens the tcp server socket which defined in httpd.c

Page 52: Contiki Operating system tutorial

Websense code details

The second process is

It does the sensing through the web in a way

A protothread that handles reading or getting the parameters of temperature and light from sensors

Page 53: Contiki Operating system tutorial

Review Question

Page 54: Contiki Operating system tutorial

Question

•  what is uIP TCP/I P ? provides Internet communication abilities

to Contiki

What are the applications of it?

Network enabling an embedded microcontroller makes it possible to

control electronic consumer devices or appliances such

as smart meters, heating, air conditioning, lighting

systems, grid connected electric car chargers and even door locks, radiation systems, ..anything

Page 55: Contiki Operating system tutorial

Questions

What is used for?

Contiki is designed for microcontrollers with small amounts of memory.

Operating system for memory-efficient networked embedded systems and wireless sensor networks

What is the typical size of Contiki?A typical Contiki configuration is 2 kilobytes of RAM and 40 kilobytes of ROM.

Page 56: Contiki Operating system tutorial

Question

What is COOJA?

Cooja is a simulator provided by Contiki, which unlike most simulators also allows real hardware platforms to be emulated

Page 57: Contiki Operating system tutorial

References

http://www.contiki-os.org/start.html

http://virtual-sense.googlecode.com/git/VirtualSense/examples/rest-example/README

http://www.wolfe.id.au/2014/03/02/configuring-a-simple-ipv6-network/

http://contiki-os.blogspot.kr/

http://people.inf.ethz.ch/mkovatsc/wiki/general:contiki:webserver