TinyOS Tutorial CS580S Sensor Networks and Systems February 7, 2007 Jisu Oh Dept. of Computer Science SUNY-Binghamton.

Slides:



Advertisements
Similar presentations
How to use TinyOS Jason Hill Rob Szewczyk Alec Woo David Culler An event based execution environment for Networked Sensors.
Advertisements

TinyOS Tutorial, Part I Phil Levis et al. MobiSys 2003.
1 Tomás Sánchez López July 9, 2004 Real-time & Embedded Systems Laboratory TinyOS … in deep.
NesC Prepared for the Multimedia Networks Group University of Virginia.
Feb 2007WSN Training: First Steps in nesC Programming1 First Steps in TinyOS and nesC Programming Topics  Timer Application: MyApp  Application directory.
1 Lab 3 Objectives  Case study: “Hello world” program on motes  Write you first program on mote.
1 Lab4 Objectives  Learn to read light sensor data from sensor board  Learn to transmit a message containing the sensed data  through Mote serial port.
Mote Programming. 如何 compile 程式  make [re]install. : desired device address : target platform  install vs. reinstall install : compile the application.
TOSSIM A simulator for TinyOS Presented at SenSys 2003 Presented by : Bhavana Presented by : Bhavana 16 th March, 2005.
TinyOS Introduction Advanced Computer Networks. TinyOS Outline  Introduction to the Architecture of TinyOS and nesC  Component Model –Components, interfaces,
How to Code on TinyOS Xufei Mao Advisor: Dr. Xiang-yang Li CS Dept. IIT.
GIIS’07 – Marrakech 3 rd July 2007 Behavioural Specification of Wireless Sensor Network Applications Nelson S Rosa and Paulo R F Cunha Universidade Federal.
Programming Motes A TinyOS and TOSSIM Tutorial By: Brent Rood.
1 TinyOS Network Communication Computer Network Programming Wenyuan Xu Fall 2007.
Development of a Mica2 Mote Sensor Network Cliff Macklin Bill Ehrbar December 8, 2004 University of Colorado, Colorado Springs.
TinyOS Software Engineering Sensor Networks for the Masses.
2008EECS Embedded Network Programming nesC, TinyOS, Networking, Microcontrollers Jonathan Hui University of California, Berkeley.
PtinyOS: Simulating TinyOS in Ptolemy II Elaine Cheong Dec 10, 2004 EE290N Project Presentation (Initial NC code generator by Yang Zhao and Edward Lee)
5/5/2003MobiSys 2003 Tutorial TinyOS Tutorial, Part II Robert Szewczyk, Joe Polastre, Phil Levis, David Culler Mobisys 2003.
TOSSIM: Visualizing the Real World Philip Levis, Nelson Lee, Dennis Chi and David Culler UC Berkeley NEST Retreat, January 2003.
NesC: 1.1 Bumps and Future Directions David Gay, Intel Research, Berkeley (and the nesC and TinyOS teams)
1 Lab 3 Objectives  Case study: “Hello world” program on motes  Write you first program on mote.
TinyOS Tutorial Based on Wenyuan Xu’s slides ( NetsF06/Comnet_TinyOS_Tutorial_xwy.ppt)
1 Software Development Infrastructure for Sensor Networks  Operating systems ( TinyOS )  Resource (device) management  Basic primitives  Protocols.
The University of Iowa. Copyright© 2005 A. Kruger 1 Introduction to Wireless Sensor Networks TinyOS Overview 10 February 2005.
1 Lab 5 Objectives  Use XMesh multi-hop networking service to send sensing data to a base station  Using XServe to display the sensor data message on.
Programming in nesC (and TOSSIM)
By: R Jayampathi Sampath
1 System Architecture Directions for Networked Sensors (TinyOS & Mica2) Presented by Jang Young, Kim (Chris)
April 15, 2005TinyOS: A Component Based OSPage 1 of 27 TinyOS A Component-Based Operating System for Networked Embedded Systems Tom Bush Graduate College.
1 TinyOS Computer Network Programming Wenyuan Xu Fall 2007.
TinyOS 1/2 Onsystech Sangjae Han.
1 Lab2 Objectives  Basics of TinyOS  Basics of nesC programming language.
1 Lab2 Objectives  Basics of TinyOS  Basics of nesC programming language.
Tmote Sky Doug Schultz for FWLUG (Fort Wayne Linux Users Group)
HW2: Q&A Oct. 02, Lab Machine TinyOS is installed in one machine (531AB). But, you have to bring your kit. There is a sign up sheet. Please sign.
Wireless Sensor Networks MOTE-KITS TinyOS Crossbow UC Berkeley.
HANBACK ELECTRONICS CO., LTD. 저자권 보호됨 Light Sense Lab. Read data from light(photo diode) sensor, display using oscilloscope.
Dhanshree Nimje Smita Khartad
CIS 798 Sensor Network Implementation. Goals Learning sensor network programming with Crossbow motes Implement reasonable sized sensor applications Develop.
Lab 3 Introduction to TinyOS and nesC How to debug programs at PC Examples –Blink Timer –Blink –Hellow World Reference: 1.x/doc/tutorial/lesson1.html.
Simulation of Distributed Application and Protocols using TOSSIM Valliappan Annamalai.
TinyOS Tutorial Lesson 8 Data logging application.
HANBACK ELECTRONICS CO., LTD. 저자권 보호됨 TinyOS & NesC.
Part 2 TinyOS and nesC Programming Selected slides from:
Wireless Sensor Networks with Motes Gurdip Singh and Sumeet Gujrati.
Feb 2007WSN Training: Creating a Simple Sensor Application1 A TinyOS Sensor Application called MyApp Objectives  How to create a simple Mote firmware.
Feb 2007WSN Training: XMesh Services1 Lab6 Objectives:  Route Control Interface  Understand XMesh transport services 1.Upstream 2.Upstream with end-to-end.
HANBACK ELECTRONICS CO., LTD. 저자권 보호됨 Wireless MAC Practice (MAC I)
Main Issues Three major issues that we are concerned with in sensor networks are – Clustering Routing and Security To be considered against the backdrop.
Xiong Junjie Node-level debugging based on finite state machine in wireless sensor networks.
Lab 3, Part 2 Selected slides from: Wireless Sensor Networks Hardware/Software Tiny OS & NesC Programming borrowed from Turgay Korkmaz.
TinyOS Sandeep Gupta. Operating System (OS) What is an OS? Main functions  Process management  Memory management  Resource management Traditional OSs.
HANBACK ELECTRONICS CO., LTD. 저자권 보호됨 Gossiping Protocol.
HANBACK ELECTRONICS CO., LTD. 저자권 보호됨 Lab1: LED Control ZigbeX mote has Red, Yellow, Green LED. This lab using LED control component provided by TinyOS.
Based on slides from Andreas Larsson Table from CY Chong, SP Kumar, BA Hamilton - Proceedings of the IEEE, 2003.
HANBACK ELECTRONICS CO., LTD. 저자권 보호됨 HelloWorld By using LED & Timer components, we will display “helloworld” in a manner of Morse code.
Blink Blink.nc configuration Blink { } implementation { components Main, BlinkM, SingleTimer, LedsC; Main.StdControl -> BlinkM.StdControl; Main.StdControl.
Feb 2007WSN Training: XMesh Enabled Sensor App1 Lab 5 Objectives  Use XMesh multi-hop networking service to send sensing data to a base station  Using.
Why does it need? [USN] ( 주 ) 한백전자 Background Wireless Sensor Network (WSN)  Relationship between Sensor and WSN Individual sensors are very limited.
TinyOS Sandeep Gupta. TinyOS basics TinyOS is  Single tasking OS  Interrupt driven Written using a Component based language A set of components put.
TinyOS and nesC. Outline ● Wireless sensor networks and TinyOS ● Networked embedded system C (nesC) – Components – Interfaces – Concurrency model – Tool.
Tinyos Introduction to Programming Pritee Parwekar.
Simulation of Distributed Application and Protocols using TOSSIM
WSN Training: XMesh Enabled Sensor App
Ad Hoc Networking using Flooding protocol
An Introduction to nesC
Temperature and Humidity Lab.
WSN Training: TinyOS/nesC Basic Concepts TinyOS and nesC
SenseToRfm SenseToInt.Timer -> TimerC; configuration SenseToRfm {
Presentation transcript:

TinyOS Tutorial CS580S Sensor Networks and Systems February 7, 2007 Jisu Oh Dept. of Computer Science SUNY-Binghamton

TinyOS Program Architecture NesC application: interfaces and components Concurrency Model: Two-level scheduling Component Development TinyOS installation Configuration file vs. Module file Running TinyOS code TOSSIM PowerTossim Outline TinyOS Program Architecture NesC application: interfaces and components Concurrency Model: Two-level scheduling

NesC application = components with well-defined, bidirectional interfaces Concurrency Model Two-level scheduling TinyOS Program Architecture

Interfaces /opt/tinyos-1.x/tos/interfaces The only point of access to the component Bi-directional Declare a set of functions command Provided by a component, these provide functionality into that component Invoked by a component wired to it the interface provider must implement event A “happening” that is produced by a component and that can be responded to by any components wired to this component the interface user must implement

Interface Timer /opt/tinyos-1.x/tos/interfaces/Timer.nc interface Timer{ command result_t start (char type, uint32_t interval); command result_t stop (); event result_t fired (); }

Configurations  wiring Assemble other components together Connecting interfaces used by components to interfaces provided by others Example: TimerC.nc Components configuration TimerC{ provides interface Timer[uint8_t id]; provides interface StdControl; } implementation{ components TimerM, ClockC; TimerM.Clock → ClockC; Timer = TimerM; }

Modules Provide application code Implement one or more interface Example CC1000RadioIntM.nc Components module CC1000RadioIntM{ provides interface StdControl; uses interface StdControl as TimerControl; uses interface Timer as WakeupTimer; } implementation{ task void PacketSent(){} command result_t StdControl.init(){} event result_t WakeupTimer.fired(){} }

Mica2 CC1000 Radio Stack Architecture

Provider, User and Interface configuration TimerC{ provides interface Timer[uint8_t id]; provides interface StdControl; } interface Timer{ command result_t start(char type, uint32_t interval); command result_t stop(); event result_t fired(); } module CC1000RadioIntM{ uses interface StdControl as TimerControl; uses interface Timer as WakeupTimer; } TimerC Provider TimerControl WakeupTimer CC1000RadioIntM User StdControl Timer Interface

Interfaces Verbs or nouns In mixed case with the first letter of each internal word capitalized ex) ADC, Range, SendMsg Components Nouns In mixed case with the first letter of each internal word capitalized ex) Counter, TimerC, TimerM Files “.nc” as a suffix ex) ADC.nc, TimerC.nc Naming Conventions

Two-level scheduling Hardware event handlers Call commands, post tasks, and signal other events Preempt tasks Preempted by asynchronous hardware event handlers (events and commands) Tasks computations Concurrency Model Hardware Interrupts events commands FIFO Tasks POST Preempt Time commands Hardware Event handler Tasks

Scheduling priority summary Hardware event, async events and async command Events and commands Tasks Concurrency Model (cont.) Low High Hardware Interrupts events commands FIFO Tasks POST Preempt Time commands

Two-level scheduling Hardware interrupt 1 command 1 Time Hardware interrupt 2 FIFO Post Task 2 Post Task 1 … command 2 event 4 event 1 event 2 event 3 event 5 Preempt Task 1

TinyOS Program Architecture NesC application: interfaces and components Concurrency Model: Two-level scheduling Component Development TinyOS installation Configuration file: wiring Module file: application code Running TinyOS code TOSSIM PowerTossim Next

Install TinyOS Not TinyOS or TinyOS 2.0 Upgrade your Cygwin Cygwin distributed with TinyOS is not compatible with TinyOS or above version Upgrade nesc version >= Reboot your computer Upgrade to TinyOS CVS Snapshots to use PowerTossim Check your installation Link to installation instruction TinyOS installation for windows

An example application: Blink /opt/tinyos-1.x/apps/Blink Configuration file – Blink.nc a top-level configuration file specify how and to which other components this particular component is wired to allow the component to “provide” various interfaces to other components (that can wire to it) or “use” interfaces Module file – BlinkM.nc the actual implementation of the component itself deal with event handling, command implementation, task posting, etc. Wireing! Application code!

A component graph of Blink application

Blink.nc – A frame of Configuration files configuration Blink { } implementation { } provide interfaces use interfaces components // wiring Indicate that this is a configuration file Interfaces which this configuration provides or uses A list of components which this configuration references Connecting components

Blink.nc – in detail components Main, BlinkM, SingleTimer, LedsC; // wiring Main.StdControl → BlinkM.StdControl; Main.StdControl → SingleTimer.StdControl; BlinkM.Timer → SingleTimer.Timer; BlinkM.Leds → LedsC; configuration Blink { } implementation { } //provides interfaces //uses interfaces No interfaces are provided or used by Blink.nc BIND interfacesimplementation Component.interface

Blink.nc – Main and StdControl A component “Main” Executed first in a TinyOS application A TinyOS application must have Main component in its configuration An interface “StdControl” Used to initialize and start TinyOS components /opt/tinyos-1.x/tos/interfaces/StdControl.nc interface StdControl { command result_t init(); command result_t start(); command result_t stop(); }

BlinkM.nc – A frame of Module files module BlinkM { } implementation { } Indicate that this is a module file provides interfaces uses interfaces Interfaces which this module provides or uses Application code // implementation of commands, //events or any tasks if needed

BlinkM.nc – inside of Module part module BlinkM { } provides interface StdControl ; uses interface Timer ; uses interface Leds ; interface StdControl { command result_t init(); command result_t start(); command result_t stop(); } interface Timer { command result_t start(char type, uint32_t, interval); command result_t stop(); event result_t fired(); } interface Leds { async command result_t init(); async command result_t redOn(); // and more commands } Implementation needed

BlinkM.nc – inside of Module (cont.) implementation { command result_t StdControl.init() { call Leds.init(); return SUCCESS; } command result_t StdControl.start() { return call Timer.start(TIMER_REPEAT, 1000); } command result_t StdControl.stop() { return call Timer.stop(); } event result_t Timer.fired() { call Leds.yellowToggle(); return SUCCESS; }

Message Communication Example A component “MsgComm” A example application which shows a message communication in TinyOS

MsgComm //Message id for this application enum{ AM_MYMSG = 10 }; //Data structure for TOS_Msg.data Typedef struct MsgCommMsg{ uint16_t src; //source address uint16_t reading; //sensor reading }__attribute__((packed)) MsgCommMsg; MsgComm.h MsgComm.nc Includes MsgComm; configuration MsgComm { } Implementation{ components Main, MsgCommM, TimerC, Photo, GenericComm as Comm; Main.StdControl → MsgCommM.StdControl; Main.StdControl → TimerC; Main.StdControl → Photo; Main.StdControl → Comm; MsgCommM.ADC → Photo; MsgCommM.Timer → TimerC.Timer[unique (“Timer”)]; MsgCommM.SendMsg → Comm.SendMsg[AM_MYMSG]; MsgCommM.ReceiveMsg → Comm.ReceiveMsg[AM_MYMSG]; }

MsgComm (cont.) MsgCommM.nc (1) Includes MsgComm; module MsgCommM { provides interface StdControl; uses interface SendMsg; uses interface ReceiveMsg; uses interface ADC; uses interface Timer; } implementation { bool ch_busy; TOS_Msg tos_msg_buf; MsgCommMsg* send_buf; MsgCommMsg msg_buf; command result_t StdControl.init() { atomic ch_busy = FALSE; return SUCCESS; } // end of StdContro.init() command result_t StdControl.start() { return call Timer.start(TIMER_REPEAT, 1000); } // end of StdControl.start() command result_t StdControl.stop() { return call Timer.stop(); }//end of StdControl.stop() event result_t Timer.fired() { call ADC.getData(); return SUCCESS; } // end of Timer.fired()

task void sendData() { atomic { if(!ch_busy) { send_buf = (MsgCommMsg*)tos_msg_buf.data; send_buf->src = msg_buf.src; send_buf->reading = msg_buf.reading; if((call SendMsg.send(TOS_BCAST_ADDR, sizeof(MsgCommMsg), &tos_msg_buf)) != SUCCESS) ch_busy = FALSE; else { dbg(DBG_USR1, “Sending at node [%d]: src[%d], data[%d]\n”, TOS_LOCAL_ADDRESS, send_buf->src, send_buf->reading); } } //end of if to check channel busy } //end of atomic } //end of task sendData() async event result_t ADC.dataReady(uint16_t data) { atomic msg_buf.src = TOS_LOCAL_ADDRESS; atomic msg_buf.reading = data; post sendData(); return SUCCESS; }// end of ADC.dataReady() MsgComm (cont.) MsgCommM.nc (2)

MsgComm (cont.) event result_t SendMsg.sendDone(TOS_MsgPtr msg, result_t success) { atomic ch_busy = FALSE; return SUCCESS; } //end of SendMsg.sendDone() event TOS_MsgPtr ReceiveMsg.receive(TOS_MsgPtr m) { MsgCommMsg* data_buf = (MsgCommMsg*)m->data; dbg(DBG_USR1, “Receiving from [%d] with data [%d]\n”, data_buf->src, data_buf->reading); atomic msg_buf.src = data_buf->src; atomic msg_buf.reading = data_buf->reading; post sendData(); return m; }// end of ReceiveMsg.receive() } // end of implementation MsgCommM.nc (3)

Multihop Routing in TinyOS Uses a shortest-path-first algorithm with a single destination node (the root) and active two-way link estimation MultiHopEngineM: the overall packet movement logic for multi-hop functionality (determines the next-hop path) MultiHopLEPSM the Link Estimation and Parent Selection(LEPS) mechanisms You can import your own link estimation and parent selection mechanism instead of using this module Works on real motes, not on TOSSIM MultiHopRouter: connects above two components Reference: 1.x/doc/multihop/multihop_routing.htmlhttp:// 1.x/doc/multihop/multihop_routing.html Multihop component : /opt/tinyos-1.x/lib/Route example application: Surge /opt/tinyos-1.x/apps/Surge

TinyOS Program Architecture NesC application: interfaces and components Concurrency Model: Two-level scheduling Component Development TinyOS installation Configuration file: wiring Module file: application code Running TinyOS code TOSSIM PowerTossim Next

Running on a PC: TOSSIM Why simulation? Sensor networks are new, event-driven, large, deployed in remote locations Simulation provides: controlled, reproducible testing environment means to explore and improve design space TOSSIM P. Levis, N. Lee, M. Welsh, and D. Culler, TOSSIM: Accurate and Scalable Simulation of Entire TinyOS Applications, ACM Conference on Embedded Networked Sensor Systems (SenSys), November 2003.TOSSIM: Accurate and Scalable Simulation of Entire TinyOS Applications,

Running on a PC: TOSSIM (cont.) TOSSIM TinyOS mote simulator Scales to thousands of nodes Compiles directly from TinyOS source Simulates network at bit level Replaces hardware with software components Hardware interrupts are modeled as simulator events Manual: /opt/tinyos-1.x/doc/nido.pdf

TOSSIM Architecture

Generate Makefile component name include../Makerules optional flags Compile and Run Change directory where your application is stored cd /opt/tinyos-1.x/apps/Blink Compile the application for use in TOSSIM simulation on the host pc make pc Enable debugging mode export DBG=usr1 Run an executable file./bulid/pc/main.exe [option] N Where N is the number of nodes in the simulation How to use TOSSIM? # Makefile for Blink COMPONENT=Blink # PFLAGS = -I%T/lib/Counters Include../Makerules

dbg Configuration of debugging output at run-time Example debugging statement dbg(DBG_BOOT, “AM Module initialized\n”); Available DBG_[mode] all, boot, clock, task, sched, sensor, led, crypto, route, am, crc, packet, encode, radio, logger, etc. usr1, usr2, usr3 user output mode 1,2,3 reserved for application components Debugging: dbg

Sensor network power limited, hard to reach locations (ex, battlefield), difficult and expensive to replace batteries  Need to simulate energy usage before deployment PowerTossim a power modeling extension to TOSSIM developed by Harvard University Models power consumed by TinyOS applications Integrated into TOSSIM in the TinyOS or above PowerTossim references PowerTossim

Enable power mode for dbg export DBG=power Run your application with the –p flag and save the output to a file./build/pc/main.exe –t=60 –p 2 > out.trace Run postprocess.py on the resulting trace $TOSROOT/tools/scripts/PowerTOSSIM/postprocess.py –sb=0 –em $TOSROOT/tools/scripts/PowerTOSSIM/mica2_energy_mo del.txt out.trace Then PowerTossim (cont.)

You will see PowerTossim (cont.)

Download MsgComm.tgz, upzip and compile it Let’s run MsgComm!

Run! Let’s run MsgComm! (cont.) ↙ Turn on DBG mode USR1 and POWER ← Compile on the PC ↙ Run with 10 motes for 60 seconds and save it into a file ↖ Get a power consumption summary by using PowerTOSSIM

10output.trace Let’s run MsgComm! (cont.) From DBG_POWER From DBG_USR1

10output.power Let’s run MsgComm! (cont.) Consumed energy summary for mote 0

TinyOS official Website: TinyOS Documentation Tutorial NesC Tossim PowerTossim Sample applications In tinyos directory, /opt/tinyos-1.x/apps TinyOS CVS repository Useful URL

Questions?

THANK YOU!