1 TinyOS Computer Network Programming Wenyuan Xu Fall 2007.

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

A System Architecture for Tiny Networked Devices
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.
KFUPM, COE 499. Ayman Al Bassam COE 499 Wireless Sensor Networks LAB 1.
Overview: Chapter 7  Sensor node platforms must contend with many issues  Energy consumption  Sensing environment  Networking  Real-time constraints.
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.
TinyOS Introduction Advanced Computer Networks. TinyOS Outline  Introduction to the Architecture of TinyOS and nesC  Component Model –Components, interfaces,
Towards System Architecture for Tiny Networked Devices David Culler U.C. Berkeley Wireless hoo-hah 5/30/2000.
TinyOS Tutorial Communication Networks I Wenyuan Xu Fall 2006.
How to Code on TinyOS Xufei Mao Advisor: Dr. Xiang-yang Li CS Dept. IIT.
Programming Motes A TinyOS and TOSSIM Tutorial By: Brent Rood.
1 TinyOS Network Communication Computer Network Programming Wenyuan Xu Fall 2007.
A System Architecture for Tiny Networked Devices Jason Hill U.C. Berkeley 9/22/2000.
Development of a Mica2 Mote Sensor Network Cliff Macklin Bill Ehrbar December 8, 2004 University of Colorado, Colorado Springs.
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.
1 EE249 Discussion System Architecture Directions for Networked Sensors (J. Hill, et al) Presented By: Sarah Bergbreiter EE249 Discussion Section October.
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.
TinyOS Tutorial Jianping Wang (merge several tutorials found online)
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.
April 15, 2005TinyOS: A Component Based OSPage 1 of 27 TinyOS A Component-Based Operating System for Networked Embedded Systems Tom Bush Graduate College.
TinyOS 1/2 Onsystech Sangjae Han.
1 Lab2 Objectives  Basics of TinyOS  Basics of nesC programming language.
KFUPM, COE 499. Ayman Al Bassam COE 499 Wireless Sensor Networks LAB 1.
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.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
HANBACK ELECTRONICS CO., LTD. 저자권 보호됨 Light Sense Lab. Read data from light(photo diode) sensor, display using oscilloscope.
Dhanshree Nimje Smita Khartad
System Architecture Directions for Networked Sensors Jason Hill, Robert Szewczyk, Alec Woo, Seth Hollar, David Culler, Kris Pister Presented by Yang Zhao.
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.
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)
@ nesC Programming KETI / Ubiquitous Computing Center Jeonghoon Kang
Xiong Junjie Node-level debugging based on finite state machine in wireless sensor networks.
WSN Software Platforms - concepts Vinod Kulathumani Lecture uses some slides from tutorials prepared by authors of these platforms.
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.
System Architecture Directions for Networked Sensors.
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.
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.
Cyber-Physical Programming
Why does it need? [USN] ( 주 ) 한백전자 Background Wireless Sensor Network (WSN)  Relationship between Sensor and WSN Individual sensors are very limited.
Software Architecture of Sensors. Hardware - Sensor Nodes Sensing: sensor --a transducer that converts a physical, chemical, or biological parameter into.
TinyOS Sandeep Gupta. TinyOS basics TinyOS is  Single tasking OS  Interrupt driven Written using a Component based language A set of components put.
Tinyos Introduction to Programming Pritee Parwekar.
Simulation of Distributed Application and Protocols using TOSSIM
WSN Training: XMesh Enabled Sensor App
An Introduction to nesC
Embedded Operating Systems
WSN Training: TinyOS/nesC Basic Concepts TinyOS and nesC
SenseToRfm SenseToInt.Timer -> TimerC; configuration SenseToRfm {
Modeling Event-Based Systems in Ptolemy II EE249 Project Status Report
Presentation transcript:

1 TinyOS Computer Network Programming Wenyuan Xu Fall 2007

2 Lecture Overview 1. Hardware Primer 2. Introduction to TinyOS 3. Programming TinyOS 4. Network Communication

3 UC Berkeley Family of Motes

4 Mica2 and Mica2Dot ATmega128 CPU  Self-programming  128KB Instruction EEPROM  4KB Data EEPROM Chipcon CC1000  Manchester encoding  Tunable frequency 315, 433 or 900MHz  38K or 19K baud Lower power consumption  2 AA batteries Expansion  51 pin I/O Connector 1 inch

5 MTS300CA Sensor Board

6 Programming Board (MIB510)

7 Hardware Setup Overview

8 Lecture Overview 1. Hardware Primer 2. Introduction to TinyOS 3. Programming TinyOS 4. Network Communication

9 What is TinyOS? An operation system An open-source development environment Not an operation system for general purpose, it is designed for wireless embedded sensor network.  Official website: Programming language: NesC (an extension of C) It features a component-based architecture. Supported platforms include Linux, Windows 2000/XP with Cygwin.

10 Install TinyOS and the ‘make’ Download  Directory Structure /apps /Blink /Forwarder /contrib /doc /tools /java /tos /interfaces /lib /platform /mica /mica2 /mica2dot /sensorboard /micasb /system /types From within the application’s directory:  make (re)install. is an integer between 0 and 255 may be mica2, mica2dot, or all Example: make install.0 mica2  make pc Generates an executable that can be run a pc for

11 Build Tool Chain Convert NesC into C and compile to exec Modify exec with platform-specific options Set the mote ID Reprogram the mote

12 Lecture Overview 1. Hardware Primer 2. Introduction to TinyOS 3. Programming TinyOS 4. Network Communication

13 Characteristics of Network Sensors Small physical size and low power consumption Concurrency-intensive operation  multiple flows, not wait-command-respond Limited Physical Parallelism and Controller Hierarchy  primitive direct-to-device interface Diversity in Design and Usage  application specific, not general purpose  huge device variation => efficient modularity => migration across HW/SW boundary Robust Operation  numerous, unattended, critical => narrow interfaces sensors actuators network storage

14 A Operating System for Tiny Devices? Main Concept  HURRY UP AND SLEEP!! Sleep as often as possible to save power  provide framework for concurrency and modularity Commands, events, tasks  interleaving flows, events - never poll, never block Separation of construction and composition Programs are built out of components  Libraries and components are written in nesC.  Applications are too -- just additional components composed with the OS components Each component is specified by interfaces  Provides “hooks” for wiring components together Components are statically wired together based on their interfaces  Increases runtime efficiency

15 Programming TinyOs There are two types of components in nesC:  Modules. It implements application code.  Configurations. It assemble other components together, called wiring A component does not care if another component is a module or configuration A component may be composed of other components via configurations A component provides and uses interfaces. A interface defines a logically related set of commands and events. Components implement the events they use and the commands they provide: ComponentCommandsEvents UseCan callMust implement ProvideMust implementCan signal

16 Component Syntax - Module A component specifies a set of interfaces by which it is connected to other components  provides a set of interfaces to others  uses a set of interfaces provided by others module identifier specification module-implementation module ForwarderM { provides { interface StdControl; } uses { interface StdControl as CommControl; interface ReceiveMsg; interface SendMsg; interface Leds; } implementation { …// code implementing all provided commands and used events } ForwarderM StdControl ReceiveMsg provides uses CommControl SendMsg Leds = interface X as X interface X as Y

17 Component Syntax - Configuration configuration Forwarder { } implementation { components Main, LedsC; components GenericComm as Comm; components ForwarderM; Main.StdControl -> ForwarderM.StdControl; ForwarderM.CommControl -> Comm; ForwarderM.SendMsg -> Comm.SendMsg[AM_INTMSG]; ForwarderM.ReceiveMsg -> Comm.ReceiveMsg[AM_INTMSG]; ForwarderM.Leds -> LedsC; } Component Selection Wiring the Components together configuration identifier specification configuration-implementation

18 Component Syntax - Configuration configuration Forwarder { } implementation { components Main, LedsC; components GenericComm as Comm; components ForwarderM; Main.StdControl -> ForwarderM.StdControl; ForwarderM.CommControl -> Comm; ForwarderM.SendMsg -> Comm.SendMsg[AM_INTMSG]; ForwarderM.ReceiveMsg -> Comm.ReceiveMsg[AM_INTMSG]; ForwarderM.Leds -> LedsC; } Component Selection Wiring the Components together ForwarderM StdControl ReceiveMsg provides uses CommControl SendMsg Leds Main StdControl LedsC Leds GenericComm SendMsg ReceiveMsg StdControl Forwarder

19 Interface Syntax- interface StdControl Look in /tos/interfaces/StdControl.nc Multiple components may provide and use this interface Every component should provide this interface  This is good programming technique, it is not a language specification  To understand how an application works, start from reading the implementation of StdControl.init(), StdControl.start(). interface StdControl { // Initialize the component and its subcomponents. command result_t init(); // Start the component and its subcomponents. command result_t start(); // Stop the component and pertinent subcomponents command result_t stop(); }

20 Interface Syntax- interface SendMsg Look in /tos/interfaces/SendMsg.nc Includes both command and event. Split the task of sending a message into two parts, send and sendDone. includes AM; // includes AM.h located in \tos\types\ interface SendMsg { // send a message command result_t send(uint16_t address, uint8_t length, TOS_MsgPtr msg); // an event indicating the previous message was sent event result_t sendDone(TOS_MsgPtr msg, result_t success); }

21 Configuration Wires A configuration can bind an interface user to a provider using -> or <-  User.interface -> Provider.interface  Provider.interface <- User.interface Bounce responsibilities using =  User1.interface = User2.interface  Provider1.interface = Provider2.interface The interface may be implicit if there is no ambiguity  e.g., User.interface -> Provider  User.interface -> Provider.interface

22 Component implementation module ForwarderM { //interface declaration } implementation { command result_t StdControl.init() { call CommControl.init(); call Leds.init(); return SUCCESS; } command result_t StdControl.start() {…} command result_t StdControl.stop() {…} event TOS_MsgPtr ReceiveMsg.receive(TOS_MsgPtr m) { call Leds.yellowToggle(); call SendMsg.send(TOS_BCAST_ADDR, sizeof(IntMsg), m); return m; } event result_t SendMsg.sendDone(TOS_MsgPtr msg, bool success) { call Leds.greenToggle(); return success; } Command implementation (interface provided) Event implementation (interface used) ForwarderM StdControl ReceiveMsg provides uses CommControl SendMsg Leds

23 {... status = call interfaceName.CmdName(args)... } command CmdName(args) {... return status; } {... status = signal interfaceName.EvtName(args)... } event EvtName(args) {... return status; } TinyOS Commands and Events Commands “call down” towards the hardware components Event “call up” towards application components Interface provider Interface user

24 TinyOs Concurrency Model TinyOS executes only one program consisting of a set of components. Two type concurrency:  Task  Hardware event handler Tasks:  Time flexible  Longer background processing jobs  Atomic with respect to other tasks (single threaded)  Preempted by event Hardware event handlers  Time critical  Shorter duration (hand off to task if need be)  Interrupts task and other hardware handler.  Last-in first-out semantics (no priority among events)  executed in response to a hardware interrupt

25 Tasks Provide concurrency internal to a component  longer running operations Scheduling:  Currently simple FIFO scheduler  Bounded number of pending tasks  When idle, shuts down node except clock  Uses non-blocking task queue data structure  Simple event-driven structure + control over complete application/system graph instead of complex task priorities and IPC {... post TaskName();... } task void TaskName() {... }

26 TinyOS Execution Contexts Events generated by interrupts preempt tasks Tasks do not preempt tasks Both essential process state transitions Hardware Interrupts event 1 Task B Task ATask B Task C event 2 event 3 … Task queue …

27 Syntax summary Command:  Define: command CmdName(args) {…}  Call: call interfaceName.commandName(arg); Event:  Define: event EvtName(args) {...}  Signal: signal interfaceName.EvtName(args) Task:  Define: task void TaskName(){…}  Call: post TaskName(); File name convention:  Filenames should be the name of the type contained within;  all nesC files have ".nc" as a suffix.  Example: ‘genericComm’ is defined in genericComm.nc How to read the code?  Find the top level application file, e.g. Forward.nc  Find the components used, find the component definition file.  Inside the component file, read from function: StdControl.init(), StdControl.start()

28 Event-Driven Sensor Access Pattern clock event handler initiates data collection sensor signals data ready event data event handler calls output command device sleeps or handles other activity while waiting conservative send/ack at component boundary command result_t StdControl.start() { return call Timer.start(TIMER_REPEAT, 200); } event result_t Timer.fired() { return call sensor.getData(); } event result_t sensor.dataReady(uint16_t data) { display(data) return SUCCESS; } SENSE Timer Photo LED

29 Lecture Overview 1. Hardware Primer 2. Introduction to TinyOS 3. Programming TinyOS 4. Network Communication

30 Do Your Homework!

31 Further Reading Go through the on-line tutorial:  Search the help archive:  NesC language reference manual:  Getting started guide  Hardware manual:  MIB_Series_Users_Manual.pdf MIB_Series_Users_Manual.pdf