57
 Contiki: Open Source OS for the Internet of  T hi ngs

contikseminar1-140818182506-phpapp01

Embed Size (px)

DESCRIPTION

ppppp

Citation preview

PowerPoint Presentation

Contiki: Open Source OS for the Internet of Things

The Internet of Things applicationsWhy Choose Contiki?

Contiki is an open source operating system for the Internet of Things. Contiki connects tiny low-cost, low-power microcontrollers to the InternetThe 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.Get Started with Contiki

FirstlyCooja makes Contiki easy to install and get started with it.Download Instant Contikihttp://sourceforge.net/projects/contiki/files/Instant%20Contiki/Install VMWare Playerhttps://my.vmware.com/web/vmware/free#desktop_end_user_computing/vmware_player/6_0Register and rebootStart Instant ContikiStart Instant Contiki by running InstantContiki2.6.vmx. Wait for the virtual Ubuntu Linux boot up.Log into Instant Contiki. The password isuser.

Boot Ubuntu

Log in

The password isuser.8Step 2: Start Cooja

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.Open a terminal window

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

Start Cooja

Start Cooja by In the terminal window, go to the Cooja directory:

Start Cooja with the command:

Running Cooja

Cooja UI

Step 3: Run Contiki in simulation

Creating Simulation Click theFilemenu and clickNew simulation

Create New Simulation:

Simulation Window

Networkwindow(motes)TimelineWindow->all communicationsSimulation windowsNetworkwindow-Top left-shows all motes in the simulated area

Timeline windowAt the bottom of screen Shows all communication events in the simulation over time very handy for understanding what goes on in the networkNoteswindow- On the top right is where we can put notes for our simulation. Mote output windowon 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 simulation

Add mote to the interfaceBefore we can simulate our network, we must add one or more motes. We do this via theMotesmenu, where we click on Add motes.... Since this is the first mote we add, we must first create a mote type to add. ClickCreate new mote type...and select one of the available mote types. For this example, we clickSky mote...to create an emulated Tmote Sky mote type.Choose the hardware then install the firmware with any functionality that you desire

Add mote to the interface

Simulation window

Step 4Run Contiki on hardware

Platform portingwe assume you have aZolertia Z1mote connected to a USB port of your PCEnable the Z1 in Instant Contiki, so that Instant Contiki is able to talk to itcd contiki/examples/FOLDER/

Then upload the compiled firmware to the hardware

Then make loginTo access the burnt firmware on the device

make login23Hi.c file

24MakeFile

./hi.nativeThe we have to compile the files by make TARGET=z1 hiIf there are not errors then some files will be produced like .nativefilename.native

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

Connection prob.Platform in contikiContiki platformsThe contiki supports multiple independent platforms The picture below from the directory of contiki

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 Bjrn Grnvall as part of the RUNES project. The Tmote Sky port was integrated into the Contiki build system in March 2007.

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.cCode 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.

More information about the Tmote Sky, including data sheets, can befound at Moteiv's web site http://www.moteiv.com

31Blink Application example-Code -explanation-Cooja runnin-video Blink example code

-Code

No addition stack is needed Basically is used to handle the memory constraint in limited devices.33Code detail PROCESS(name,strname ) Declare a process. PROCESS(blink_process, "Blink");AUTOSTART_PROCESSES(&blink_process);Starting a process automatically&blink_processROCESS_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 processCode explanationCode 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 expiresleds_on(LEDS_ALL);On the LEDSleds_off(LEDS_ALL);Off the LEDsCode explanationLED APISimple and important to communicate with the userThe platform startup code initializes the LEDs library by calling leds_init() initializes the APIledv: is LED vector platform independent #define LEDS_GREEN 1 #define LEDS_YELLOW 2 #define LEDS_RED 4 #define LEDS_ALL 7leds_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 argumentledv.

The functionleds_toggle()is an alias forleds_invert(), and is only kept for backward compatibility.36

Cooja capturePlatform dependent blink37Youtube Demo http://www.youtube.com/watch?v=9WohGp8udOQAPIsESB platform sensors

button_battery_sensor - query the battery voltage levelsensor - query the on-board buttonpir_sensor - query the passive IR sensor (motion detector)radio_sensor - query the radio signal strengthsound_sensor - query the microphonetemperature_sensor- query the temperature sensorvib_sensor - query the vibration senso

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 sensorSENSORS_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)

41processPROCESS_BEGIN()

-Define the beginning of a processPROCESS_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.

42LED functions

Basic LED functions leds_on() - turn LEDs onleds_off() - turn LEDs offleds_invert() - invert LEDsleds_blink()- blink all LEDs

Beeper functions

Implements a beep function to emit a beep sound Also play polyphonic tune using buzzerbeep()- click the beeperbeep_beep()- beepbeep_down()- pitchbend down beepbeep_quick() - a number of quick beepsbeep_spinup()- pitchbend up beep

Timer functions

Event TimerCallback timerSimple 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 expiredetimer_expired()etimer_resetetimer_set()etimer_restart()ctimer_expired()ctimer_resetctimer_set()ctimer_restart()

timer_expired()timer_resettimer_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.

Sky websenseLight and temperatur sensor web demoBorder router set-upHaving able to connect to sensors is very significant step in IOTThis 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-routerSimulation in Cooja is in examples\ipv6\sky-websenseSteps 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]/In step 2 , the user need to open the terminal and go to the same folder and connect to the webserver using the command make connect-router-coojaThen , ping the COOJA nodes to test the connectivity. Type in the terminal the ping6 aaaa::0212:7402:0002:0202 ping6 aaaa::0212:7403:0003:030348tunslip6 Before being able to view the sensor readings from the webserver, A serial connection to the server through the command

In the Make file in sky-websense folder configuration of the tunslip6 is handled there,Here is the configuration of the tunslip6 which is included in the MakeFile$(CONTIKI)/tools/tunslip6:$(CONTIKI)/tools/tunslip6.c(cd $(CONTIKI)/tools && $(MAKE) tunslip6)

connect-router:$(CONTIKI)/tools/tunslip6sudo $(CONTIKI)/tools/tunslip6 aaaa::1/64

connect-router-cooja:$(CONTIKI)/tools/tunslip6sudo $(CONTIKI)/tools/tunslip6 -a 127.0.0.1 aaaa::1/642- more information on the SLIP http://en.wikipedia.org/wiki/Serial_Line_Internet_Protocolhttps://github.com/maniacbug/contiki-avr-zigduino/wiki/Using%3ASLIP#What_is_SLIP49outputThe Cooja simulator provides you with important details about every sensor node in the network

50Websense code detailsIncluding the required libraries

Define processes

Opens the tcp server socket which defined in httpd.c

Websense code detailsThe 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

http_appcall() function exists in apps/webserver/httpd.c52Review Question

Questionwhat is uIP TCP/I P ?provides Internet communication abilities to ContikiWhat 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

QuestionsWhat is used for? Contiki is designed for microcontrollers with small amounts of memory.Operating system for memory-efficient networked embedded systems and wireless sensor networksWhat is the typical size of Contiki?A typical Contiki configuration is 2 kilobytes of RAM and 40 kilobytes of ROM.

QuestionWhat is COOJA?Coojais a simulator provided by Contiki, which unlike most simulators also allows real hardware platforms to be emulated

Referenceshttp://www.contiki-os.org/start.htmlhttp://virtual-sense.googlecode.com/git/VirtualSense/examples/rest-example/READMEhttp://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