TinyOS Tutorial
TinyOS Tutorial
1
Lecture Overview
1. Hardware Primer
2. Introduction to TinyOS.
3. Programming TinyOS.
4. Hands on section.
2
Sensor node(mote):
1. Node in a wireless sensor network
2. Capable of performing some processing
3. Gathers information from sensors
4. Communicates with other connected nodes
in the network.
3
Architecture of sensor node:
4
Sensor node:
Two main parts
1. Microcontroller
2. Transceiver
5
Basic controller architecture
6
Purpose of controller
Functions of a mote:
- Collecting data from various sensors
- Process data and extract useful information
- Transmitter controlling
- Local storage maintenance
7
Purpose of controller
Data collections:
- Collecting data from various sensors, simultaneously.
8
Purpose of controller
Data processing:
- Some applications require on board processing of
the collected data.
- Most of the adaptive sampling algorithms use on
board processing due to les delay.
Transceiver control:
- Controller can force transceiver into sleep mode
when it is not needed.
- Can wake up transmitter, when there is some data
to be transmitted.
9
Purpose of controller
Local storage maintenance:
- If the gateway is not in the range, then the data can
be stored on to the local storage.
- When the gateway comes into vicinity, it can transmit
the stored data and free up the local storage.
Power gating:
- Some of the functional blocks which are not necessary
at present can be switched off to conserve power and
can only be turned on when needed.
10
How to select a controller?
11
Simple controller example
ATMEGA128 uC
- 8 bit architecture
- 8 channel ADC (10 bit resolution)
- TWI
- 2 UART interfaces
- SPI interface (To interface additional memory)
- Can run TinyOS & Contiki.
12
Transceiver
AT86RF230:
Low Power 2.4 GHz Transceiver for ZigBee,
IEEE 802.15.4, 6LoWPAN, ISM
Applications.
13
IITH Mote(sensor node):
ADC/IO port
User button UART Power jumper
Microcontroller(ATMEGA1281V)
UART port
Transceiver(AT86RF230)
Reset button
Programming port
Programming jumper
Programmer
con.
15
UC Berkeley Family of Motes
16
Lecture Overview
1. Hardware Primer
2. Introduction to TinyOS
3. Programming TinyOS
4. Hands on section.
17
What is TinyOS?
An operation system
An open-source development environment
18
Now add this at the end of the file deb http://hinrg.cs.jhu.edu/tinyos hardy main
Install TinyOS
1.Install Ubuntu 12.04/13.04/14.04
or any higher versions.
2. Enable root user.
3. Switch to root user to install
TinyOS.
4. Open terminal (Ctrl+Alt+T).
19
Installation procedure:
1. gedit /etc/apt/source.list
Add this at end of the file
deb http://hinrg.cs.jhu.edu/tinyos hardy main
2. apt-get update
3. apt-get install tinyos-2.1.1
4. gedit ~/.bashrc
Add this at end of file
#Sourcing the tinyos environment variable
setup script source /opt/tinyos-
2.1.1/tinyos.sh
20
Compile and install program
Terminal view.
compile
install
21
Program installation view on terminal
22
Lecture Overview
1. Hardware Primer
2. Introduction to TinyOS
3. Programming TinyOS
4. Hands on section.
23
Program files
Every application needs 4 files
1. Make file (Makefile)
2. Configuration file (SensorAppC.nc)
3. Module file (SensorC.nc)
4. Header file (Sensor.h) (if application needs)
Sensor is application name.
check example application in TinyOS
cd /opt/tinyos-2.1.1/apps/ (path)
cd /opt/tinyos-2.1.1/apps/tutorials (path)
To develop application gedit or eclips IDE can be used
https://www.youtube.com/watch?v=IO5spZwKwRQ
24
Editors for writing a application
Gedit:
Create a folder with your application name.
Open terminal
Cntrl+Alt+T
Open a document by using gedit command
And save with your application name.
gedit documentname
create 4 files with mentioned extension in one
folder.
25
How to write a application
Programming structure:
27
How to write application
Makefile: compiler can compile program.
“COMPONENT= SensorAppC
include $(MAKERULES)”
28
Configuration file(SensorAppC.nc):
File contains components which provides
and uses interfaces.
1. Initialization of components.
2. Wiring of components with interfaces.
Components example:
MainC, LedsC, TimerMilliC.
http://www.tinyos.net/tinyos-2.1.0/doc/nesdoc/micaz/
29
Module file(SensorC.nc):
1.File contains Interfaces initialization and
using interfaces.
2.Interfaces contains commands and
events.
3.Commands and events are used to
develop algorithm.
30
Component Syntax - Configuration
configuration SensorAppC
{
}
implementation
{
components MainC, SensorC, LedsC;
Component components new TimerMilliC() as Timer0;
Selection components new TimerMilliC() as Timer1;
components new TimerMilliC() as Timer2;
SensorC -> SensorC.Boot;
31
Module syntax:
#include "Timer.h"
module SensorC()
interface X as Y
{
uses interface Timer<TMilli> as Timer0;
uses interface Timer<TMilli> as Timer1;
uses interface Timer<TMilli> as Timer2;
uses interface Leds;
uses interface Boot;
} = interface X as X
implementation
{
event void Boot.booted()
{
call Timer0.startPeriodic( 250 );
call Timer1.startPeriodic( 500 );
call Timer2.startPeriodic( 1000 );
commands
}
event void Timer0.fired()
{
call Leds.led0Toggle(); Event
}
event void Timer1.fired()
{
call Leds.led1Toggle();
}
event void Timer2.fired()
{
call Leds.led2Toggle();
}
}
32
Lecture Overview
1. Hardware Primer
2. Introduction to TinyOS
3. Programming TinyOS
4. Hands on section
33
Try new applications
34
Further Reading
35
Thank you.
36