TinyOS Laboratorio di Sistemi Wireless Ing. Telematica Università Kore Enna Ing. A. Leonardi Wireless Sensor Networks The number of nodes can be very high Nodes are densely deployed Low cost, low power devices Limited in power, computational capacities, memory Prone to failures Maintenance free Implicit data redundancy Focus on energetic consumption 1
8MHz Processor RAM 4K ISM band 40 Kbit/sec numerous sensor boards Motes Motes Evolution 2
Mica2 Mica2 Mica dot 3
MicaZ IEEE 80.15.4/ZigBee compliant RF transceiver 2.4 GHz ISM band DSSS radio (resistant to RF interference) up to 250 Kbps data rate tinyos 1.7 and higher plug & play with numerous sensor boards 4
Sensorboards Crossbow MTS310 sensorboard Programming board Crossbow MIB510 5
Environment Cygwin TinyOS nesc AVR Tools Cygwin A linux like environment for MS Windows User interface for compiling and downloading Mote applications Many open source programs on Unix have been ported to Cygwin, including: X Window System, KDE, Gnome, Apache, TeX, and others 6
TinyOS Open source operating system designed for wireless embedded sensor networks Developed by UC Berkeley Designed in nesc Event driven Implement concurrency model Component based Hardware/software cross design http://www.tinyos.net/tinyos 1.x/doc/tutorial TinyOS: Characteristics and Challenges Application specific Only the hardware actually needed for the application Only the software components strictly required by the application Unusual degree of software modularity A generic development environment is needed which allows specialized applications to be constructed from a spectrum of devices without heavyweight interfaces It should be natural to migrate components across the hardware/software boundary as technology evolves 7
TinyOS Design To facilitate modularity, each component also declares the commands it uses and the events it signals These declarations are used to compose the modular components in a per application configuration The composition process creates layers of components where: higher level components issue commands to lower level components lower level components signal events to the higher level components Physical hardware represents the lowest level of components The fixed size frames are statically allocated the memory requirements of a component is known at compile time. nesc (New) structured component based language C like syntax (extension of C language) TinyOS operating system, libraries and applications are written in nesc Supports the TinyOS concurrency model Goal: build components that can be easily composed into complete, concurrent systems 8
AVR tools Suite of software development tools for Atmel s AVR processors (AVR...8 bit RISC microcontroller [μc], developed by ATMEL in 1996) TinyOS programming architecture/concept a TinyOS application consists of one or more nesc components components are linked together via configurations to get a run time executable 9
nesc Components Basic building blocks for nesc applications Two types: Modules & Configurations Can provide and use interfaces (bidirectionality in contrast to unidirectionality in common programming languages like JAVA) Module A component that implements one or more interface Contains application code... Configuration A component that wires other components together nesc Interfaces Abstract definition of the interaction of two components nesc interfaces are bidirectional 10
TinyOS programming structure application Component D module Component B interface Component A Component C configuration make flow 11
Example application Blink /opt/tinyos 1.x/apps/Blink A simple test program causes the red LED on the mote to turn on and off at 1Hz two components a module called BlinkM.nc a configuration called Blink.nc BlinkM.nc provides the implementation of the Blink application 12
Blink.nc it is the configuration file for the Blink application and the source file that the nesc compiler uses to generate an executable file all the applications require a top level configuration file it is used to wire the BlinkM.nc module to other components that the Blink application requires Overview 13
Configuration Blink.nc this line specifies the set of components that this configuration references Interface StdControl.nc it a common interface used to initialize and start TinyOS components /tos/interfaces it defines 3 commands: must be implemented in BlinkM.nc 14
Interface Leds.nc it defines multiple commands Interface Timer.nc it defines 3 commands start() is used to specify the type of timer (REPEAT or ONE SHOT) and the interval at which the timer will expire stop() stops repeating timers applications receive fired() event if the timer has expired 15
Module BlinkM.nc It implements the StdControl interface it may call any command declared in the interfaces and must implement any events declared in those interfaces TinyOS SIMulator built with make pc TOSSIM the simulation runs natively on a desktop or laptop it can simulate thousand of nodes simultaneously 16
Exercise 1 /opt/tinyos 1.x/apps/Blink make pc a TOSSIM simulator executable is generated in build/pc/main.exe try main.exe help export DBG=led (display only messages concerning LED status) main 3 (run the simulator with 3 motes) main l=1 (it means real time) tinyviz run./main.exe 3 (simulation environment) Exercise 2 Copy the Blink folder contents to a new folder MyBlink Rename the files according to the new name Implementation: A counter variable hat increases every second by 1 A debug message of type led that tells the current counter value The 3 leds represent the 3 lower bits of the counter YELLOW LED on if bit 1 is set GREEN LED on if bit 2 is set RED LED on if bit 3 is set 17