Introduction to IDE and programming of TinyOS devices
Quratulain Taj
WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
Agenda Introduction to WSN
WSN architecture
--what are motes?
--what are base stations?
Challenges of WSN
Why a new OS design is needed?
TinyOS
TinyOS Architecture
Installations and configurations
NesC and TinyOS
--Modules
--Cofigurations
--Interfaces
--Commands and events
--Task scheduler
--Hardware event Handler
--Data race and atomic statement
IEEE 802.15.4 and TinyOS communication
Overview of Crossbow equipment
Some applications
WATCHNETs Lab 2
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
Introduction to WSN
WSNs are networks that consists of sensors which are distributed in an ad hoc manner.
These sensors work with each other to sense some physical phenomenon and then the information gathered is processed to get relevant results.
WSNs consists of protocols and algorithms with self-organizing and self healing capabilities.
3 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
Applications
Wireless Control that
Simply Works
RESIDENTIAL/
LIGHT
COMMERCIAL
CONTROL
CONSUMER
ELECTRONICS
TV
VCR
DVD/CD
remote
security
HVAC
lighting control
access control
lawn & garden irrigation
PC &
PERIPHERALS
INDUSTRIAL
CONTROL
asset mgt
process
control
environmental
energy mgt
PERSONAL
HEALTH CARE
BUILDING
AUTOMATION
security
HVAC
AMR
lighting control
access control
mouse
keyboard
joystick
patient
monitoring
fitness
monitoring
4 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
WATCHNETs Lab 5
Internet
WSN Architecture
Sensor nodes
Base station
Cell phone client PDA client
Desktop PC client Laptop client
WSNs can entertain
GSM, Bluetooth, Wired
and Wireless internet
clients.
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
What are motes or nodes?
Motes mainly consist of three parts: A low cost and power computer. Transceiver to connect with outside world with a radio link. One or more sensors( e.g. temperature, light, sound, position,
acceleration, vibration, stress, weight, pressure, humidity, etc. ) Size of the mote is at most 4x2 inches.
6 WATCHNETs Lab
ADC Power
source
Sensor A
Sensor B
Transceiver
(802.15.4 radio)
Micro-Controller
External memory
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
What are Base Stations?
WATCHNETs Lab 7
Base station is basically the same node connected with an interface board or programming board.
Interface board is connect with a server or PC via serial, USB or ethernet port.
All the sensed data is accumulated in this server or PC and processed to get relevant information.
This server maybe further connected with internet and GSM network to provide the information to all types of clients.
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
Challenges of Wireless Sensor
Networks
Energy Efficiency
Limited storage and computation
Low bandwidth and high error rates
Errors are common
Wireless communication
Noisy measurements
Node failure are expected
8 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
In embedded world of sensing , applications are tightly bound to particular hardware.
OS requirements for embedded system are different because of
I. limited hardware resources
II. highly specialized applications
While a WSN node is carrying out its normal data acquisition and processing steps, it also needs to service protocol events and packet transfers that arise asynchronously from the network.
Why a new OS design is needed?
12/23/2010 9 WATCHNETs LAB
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
TinyOS
Open Source System By UC, Berkeley
TinyOS has a component-based programming model, codified by the NesC language, a dialect of C.
TinyOS is not an OS in the traditional sense; it is a programming framework for embedded systems and set of components that enable building an application-specific OS into each application.
It supports microprocessors ranging from 8bit- architectures 2KB of RAM to 32-bit processors with 32 MB of RAM or more.
WATCHNETs Lab 10
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
Developed for resource constrained WSNs.
Features a task scheduler
Automatically puts the microcontroller to sleep when there is no code to execute.
Allows for concurrency
Lets execution be split-phase
Event-driven operating system
Concurrency model based on tasks , hardware event handlers and detection of data race.
A program is a set of components
Components can be replaced or reused
Components can be hardware or software
TinyOS Features
12/23/2010 11 WATCHNETs LAB
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
TinyOS Architecture
Sensing Comms
Hardware Abstractions (ADC, CLOCK, I2C, LEDS, PHOTO, UART, SPI) 12/23/2010 12 WATCHNETs LAB
Other Libraries
Application
Main (scheduler)
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
INSTALLATION AND CONFIGURATIONS
Download TinyOS from:
http://www.tinyos.net/download.html
Version release notes available here:
http://www.tinyos.net/tinyos-1.x/doc/
The default install puts TinyOS in
C:\tinyos\cygwin\opt\tinyps-1.x
Or install MoteWorks platform:
Low Power Operating System – TinyOS
Software Development Tools
13 WATCHNETs Lab
GCC
TinyOS
nesC
Compilation
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
NESC AND TINYOS
Component oriented programming Programming in nesC / TinyOS is like programming in a hardware description language.
3 file types in TinyOS:
Module (suffixed with P.nc)
Configuration (suffixed with C.nc)
Interface (suffixed with .nc)
Collectively, a Configuration and a Module are combined to create a Component.
14 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
NESC AND TINYOS
Modules
Define functionality that make your application run.
Provide interfaces to other modules.
Use interfaces from other modules.
Don’t care what’s behind the interface.
Modules are like the IC’s on a circuit board that actually do something.
15 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
NESC AND TINYOS
Configurations Wire interfaces from several modules together. May forward interfaces from external modules to internal modules. May contain sub-configurations. Configurations are like a Printed Circuit Board, laying out wiring that connects modules together.
16 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
NESC AND TINYOS
Interfaces
Define the interactions between modules
Commands Implemented by the module providing the interface
Called by the module using the interface
Events Signaled by the module providing the interface
Captured by the module using the interface
17 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
HELLO WORLD—COMPONENT DIAGRAM
HelloC CONFIGURATION
18 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
HELLOC CONFIGURATION
configuration HelloC {
}
implementation {
components HelloM;
}
19 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
COMPONENT DIAGRAM
HelloM
HelloC module
20 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
HELLOM MODULE
module HelloM {
}
implementation {
}
21 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
COMPONENT DIAGRAM
HelloM
HelloC functionality
Void
myFunction()
{……}
22 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
HELLOM MODULE
module HelloM {
uses {
interface Boot;
interface Leds;
}
}
implementation {
}
}
23 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
COMPONENT DIAGRAM
Boot
HelloM
HelloC functionality
Void
myFunction()
{……}
Leds
interface 24 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
HELLOM MODULE
module HelloM {
uses {
interface Boot;
interface Leds as MyLeds;
interface Leds as MySecondLeds;
}
}
implementation {
event void Boot.booted() {
call Leds.led0On();
}
}
25 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
COMPONENT DIAGRAM
Boot
HelloM
HelloC
interfaces
Void
myFunction()
{……}
Leds
LedsC
MainC
26 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
Tasks are functions that are queued up to run at a later time.
Provide split phase execution.
Task Rules:
Tasks do not take or return arguments.
Tasks cannot preempt other tasks.
Tasks run to completion.
Tasks are synchronous Interrupts are asynchronous
All tasks have the same priority.
Cannot post/queue the same task twice, but a task can post itself.
Task Scheduler
12/23/2010 27 WATCHNETs LAB
ComponentA ComponentB
call
Interface.doSomething();
return SUCCESS;
signal Interface.done();
return SUCCESS;
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
1. When you have a lot of processing to do that will take a long time to execute.
2. When your code can possibly form a recursive loop in execution.
3. When you want to use something that’s currently busy (i.e. the radio or flash file system).
When should you post a task?
12/23/2010 28 WATCHNETs LAB
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
Hardware event handler
Hardware event handlers are executed in response to a hardware interrupt
Also runs to completion
May preempt the execution of a task or other hardware event handler.
Commands and events that are executed as part of a hardware event handler must be declared with the async keyword.
WATCHNETs Lab 29
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
Data race and atomic statement
Because tasks and hardware event handlers may be preempted by other asynchronous code, nesC programs are susceptible to certain race conditions.
Races are avoided either by having all accesses within atomic statements.
The nesC compiler reports potential data races to the programmer at compile-time.
In this case a variable can be declared with the norace keyword.
WATCHNETs Lab 30
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
TinyOS communication
WSNs consist of low data rate and low power devices.
Multi channel split phase MAC protocol IEEE 802.15.4 is used for TinyOS communication. This protocol:
-reduces energy consumptions by introducing wake/ sleep cycles.
-provides collision avoidance
-provides overhearing avoidance
-provides topology maintenance
-provides guaranteed time slots
Send and Receive interfaces are used for data transmission and reception
SplitControl provides sharing of the half duplex transceiver.
WATCHNETs Lab 31
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
Features of IEEE 802.15.4
16 channels in the 2450 MHz band, 10 channels in the 915 MHz band, and 1 channel in the 868 MHz band
Over-the-air data rates of 250 kb/s, 40 kb/s, and 20 kb/s
Star or peer-to-peer operation
Allocated 16 bit short or 64 bit extended addresses
Allocation of guaranteed time slots (GTSs)
Carrier sense multiple access with collision avoidance (CSMA-CA) channel access
Fully acknowledged protocol for transfer reliability
Low power consumption
Energy detection (ED)
Link quality indication (LQI)
32 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
Topology Models
coordinator
Routers
End Devices
Star
Mesh
Cluster Tree
33 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
Protocol Stack Features
Microcontroller utilized
Full protocol stack <32 k
Simple node-only stack ~4k
Coordinators require extra RAM
Node device database
Transaction table
Pairing table
PHY LAYER 2.4 GHz 915MHz 868 MHz
MAC LAYER MAC LAYER
NETWORK LAYER Star/Cluster/Mesh
APPLICATION INTERFACE
APPLICATIONS
Silicon Application ZigBee Stack
Customer
IEEE 802.15.4
ZigBee
Alliance
SECURITY
34 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
SplitControl
Provided by ActiveMessageC and SerialActiveMessageC
AMSend
Provided by AMSenderC and SerialAMSenderC
Receive
Provided by AMReceiverC and SerialAMReceiverC
Main Radio and serial Interfaces
12/23/2010 35 WATCHNETs LAB
Radio Hardware
Transmit / Receive / Init
CSMA / Acknowledgements
ActiveMessage
Message Queue
Your Application
SplitControl AMSend
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
configuration MyAppC {
}
implementation {
components MyAppP,
MainC,
ActiveMessageC,
new AMSenderC(0), // send an AM type 0 message
new AMReceiverC(0); // receive an AM type 0 message
MyAppP.Boot -> MainC;
MyAppP.SplitControl -> ActiveMessageC;
MyAppP.AMSend -> AMSenderC;
MyAppP.Receiver -> AMReceiverC;
}
Setting up the Radio: Configuration
12/23/2010 36 WATCHNETs LAB
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
module MyAppP { uses { interface Boot; interface SplitControl; interface AMSend; interface Receive; } } implementation { … }
Setting up the Radio: Module and turning it on
12/23/2010 37 WATCHNETs LAB
event void Boot.booted() { call SplitControl.start(); } event void
SplitControl.startDone(error_t error) {
post sendMsg(); } event void
SplitControl.stopDone(error_t error) {
}
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
message_t myMsg;
task void sendMsg() {
if(call AMSend.send(AM_BROADCAST_ADDR,
&myMsg, 0) != SUCCESS) {
post sendMsg();
}
}
event void AMSend.sendDone(message_t *msg,
error_t error) {
post sendMsg();
}
Send and receive Messages
12/23/2010 38 WATCHNETs LAB
event message_t
*Receive.receive(mess
age_t *msg, void
*payload, uint8_t
length) {
call
Leds.led0Toggle();
return msg;
}
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
typedef nx_struct message_t {
nx_uint8_t
header[sizeof(message_header_t)];
nx_uint8_t data[TOSH_DATA_LENGTH];
nx_uint8_t
footer[sizeof(message_footer_t)];
nx_uint8_t
metadata[sizeof(message_metadata_t)];
} message_t;
Message structure message_t
12/23/2010 39 WATCHNETs LAB
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
OVERVIEW OF CROSSBOW WIRELESS SENSOR EQUIPMENT
Sensor Data Acquisition Boards
Processor/Radio Platforms or “Motes”
Gateways and Network Interfaces
40 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
SENSOR DATA ACQUISITION BOARDS
41 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
PROCESSOR/RADIO PLATFORMS OR “MOTES”
42 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
GATEWAYS AND NETWORK INTERFACES
43 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
A SIMPLE SENSING APPLICATION
Hardware Requirements
Two Motes: standard editions of MICA2 (MPR4x0), MICAz (MPR2400), IRIS (XM2110) or OEM editions MPR600, MPR2600, M2110
One sensor or data acquisition board: MDA100, MTS300 or MTS310
One gateway board: MIB510, MIB520, or MIB600 and the associated hardware (cables, power supply) for each
A Windows PC with MoteWorks installed
44 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
DEVELOPING AN APPLICATION Within the MoteWorks framework a minimum of five files will be placed in any application’s directory:
1. Makefile
2. Makefile.component
3. Application’s configuration written in nesC
4. Application’s module written in nesC
5. README (optional)
45 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
Hardware setup
Connect a mote on gateway load program in it, plug out that mote
and connect a sensor board on that mote. Connect another mote on
interface board.
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
Compile the application: Select Tools > make iris
Install in Mote: Select Tools>shell and type in
make iris install,1 mib510,com1 or Use MoteConfig
Remove Mote from the programming board, plug sensor
board on Mote and make sure it has battery and turn it on.
Install Xsniffer application onto another Mote that
remains plugged into board
Use Xsniffer to see the display of packets
47 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
CODE UPDATE ON LOGICAL GROUPS USING MULTIPLE GATEWAYS
Over the Air Programming
If a sensor node is already deployed in the network and code update is required without disturbing the network traffic.
Logical Group
A group of nodes running same application.
Multiple gateways
using more than one base stations
48 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
WATCHNETs Lab 49
Web s
erv
er
Ethernet cable
Selected nodes for Usecase A
5 4
3
2
1
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
The OTAP protocol reformats a large code image into pages and fragments in order to reduce the traffic required in downloading process.
A fragment is the amount of the image that can be transmitted in a single TOS packet, i.e. 19 bytes (29-byte TOS message with 7 byte XMesh header and 3 bytes OTAP header).
A page is a sequential set of fragments that are managed as an entity. There can be a maximum of 128 fragments per page.
Every Crossbow Mote has an external serial flash(512 kB) non-volatile memory interfaced to microprocessor.
OTAP divides the serial memory into 4 slots (0, 1, 2& 3).
Each slot can be a user-configured number of pages in 2k byte step.
By default each slot is 128 kB or 64 pages wide.
Unused slots are available to the user for data logging.
Slot zero always holds the OTAP image.
Crossbow mote and OTAP
3/19/2010 50 WATCHNETs LAB
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
Serial Flash Memory Slots
3/19/2010 51 WATCHNETs LAB
Reprogramming the
microprocessor from
serial flash requires that
bootloader code resides
in the top part of the
ATmega
microprocessor’s flash
memory. This code is
loaded once during the
initial programming of
the Mote via
UISP(universal in-
system programmer).
Message structure
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
CommonSense-sensing for all
Web based data visualization of WSN.
-Take raw data from sensor hardware.
-After parsing raw data into converted form, encode it into XML format.
-Passes XML encoded data through XML query.
-Provides real time query handling ,queuing, cashing and data retrieval from XML file.
-User can connect anytime with sensor network.
-Can be integrated with cellular networks.
WATCHNETs Lab 52
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
WATCHNETs Lab 53
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
References
1. Eschenauer, L., and V. Gligor, “A Key-Management Scheme for Distributed Sensor Networks,” Proceedings of ACM Conference on Computer and Communications Security (ACM CCS), Washington DC, pp. 41-47, 2002
2. http://www.xbow.com/products/Product_pdf_files/Wireless_pdf/MICA2_Datasheet.pdf
3. http://www.ece.osu.edu/~bibyk/ee582/telosMote.pdf
4. http://en.wikipedia.org/wiki/Wireless_Sensor_Networks
5. http://arri.uta.edu/acs/networks/WirelessSensorNetChap04.pdf
6. http://www.eecs.harvard.edu/~mdw/course/cs263/papers/jhill-thesis.pdf
7. http://www.polastre.com/papers/polastre-thesis-final.pdf 8. www.cse.fau.edu/~jie/teaching/fall_2004_files/sensorslides1.ppt 9. http://web2.uwindsor.ca/courses/cs/aggarwal/cs60520/SeminarMaterial/WSN-
future.ppt 10. http://web.cecs.pdx.edu/~nbulusu/talks/grace-hopper.ppt 11. http://galaxy.cs.lamar.edu/~bsun/wsn/wsn.html 12. www.dsc.ufcg.edu.br/~maspohn/katia/introduction.ppt 13. http://computer.howstuffworks.com/mote1.htm 14. “Mac protocols for sensor network” by Ki-Hyung Kim
54 WATCHNETs Lab
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010
Thank you!
Presented in Open Source Series Workshop 2010
22-24 December, 2010 © ICOSST 2010