TinyOS and NesC

35
MANJUNATH D, CS 4222 SEMESTER II, 2011/2012 TinyOS and NesC

description

TinyOS and NesC. Manjunath D, Cs 4222 Semester II, 2011/2012. Hardware: Motes and Sensors. Configuration of a typical mote. Sensors. TelosB. 16-bit 8 MHz processor. 10 KB RAM. Microcontroller (TIMSP430). 12-bit ADC. 48 KB internal flash. Smart dust. Radio transceiver of 250 Kbps. - PowerPoint PPT Presentation

Transcript of TinyOS and NesC

Page 1: TinyOS and NesC

MANJUNATH D, CS 4222 SEMESTER I I , 2011 /2012

TinyOS and NesC

Page 2: TinyOS and NesC

Hardware: Motes and Sensors

TelosB

SBT30 sensor

Smart dust

Microcontroller (TIMSP430)

10 KB RAM16-bit 8 MHz processor

48 KB internal flash

Radio transceiver of 250 Kbps

Configuration of a typical mote

12-bit ADC

2 AA batteries

Sensors

Page 3: TinyOS and NesC

TinyOS and NesC: Installation

An overview of the steps involved in using TinyOS and NesC

PC-side Install TinyOS and NesC Write and compile your programs Test your executables in a simulation environment Finally, executables are loaded on to the mote devices

Mote-side Loaded executables are executed on the mote devices

Page 4: TinyOS and NesC

TinyOS and NesC: PC-Side Installation

On the PC-side, we encourage you to use Ubuntu Linux: http://www.ubuntu.com/

A three-step process for installation Edit the file “/etc/apt/sources.list” to include the

following line “deb http://tinyos.stanford.edu/tinyos/dists/ubuntu <version_name> main” Command “lsb_release –a” will tell you the <version_name>

Execute commands “apt-get update” and “apt-get install tinyos-2.1.1”

Set environment variables Add the line “source /opt/tinyos-2.1.1/tinyos.sh” to

“/home/xxx/.bashrc”

Page 5: TinyOS and NesC

TinyOS and NesC: PC-Side Installation (Contd..)

Installation is somewhat painful on other OSs

Every package has to be installed manually Details for Windows, Redhat Linux, and MAC can be found

here http://docs.tinyos.net/index.php/Getting_started

Learning Unix commands is inevitable as Cygwin is mandatory on Windows so why not Ubuntu Linux ?

You can use Ubuntu Linux’s virtual image containing TinyOS and NesC on Windows http://docs.tinyos.net/index.php/Getting_started

Page 6: TinyOS and NesC

TinyOS and NesC: PC-Side Installation (Contd..)

Directory structure Parent directory

/opt/tinyos-2.1.1/ Applications

/opt/tinyos-2.1.1/apps/ System libraries

/opt/tinyos-2.1.1/tos/ Supporting tools

/opt/tinyos-2.1.1/support/

Page 7: TinyOS and NesC

TinyOS: Design

Process management Application plus OS is a single program and a single process

Main() { }

func1(){ }func2(){ }func3(){ }func4(){ }

funcN(){ }

Application+OS

Image of a TinyOS Program

Page 8: TinyOS and NesC

TinyOS: Design

Process management Multiprocessing is expensive in terms of memory

Process 1

stack

Process 2

stack

Process 3

stack

Process N

stack

Each process has to be allocated with a separate stack memory

Only interrupts are allowed to preempt the execution

Global variables (BSS)

Stack

RAM0X00000

TinyOS’s single stack

Page 9: TinyOS and NesC

TinyOS: Design

Memory management Virtual memory is not supported Memory is not protected

File systems Proposed file systems are not popular

Page 10: TinyOS and NesC

TinyOS: Components

TinyOS is a library of components A specific component implements a specific set of services A component in turn can be a collection of sub-components

Network Sensors

LedsUSB Flash

Routing

MAC

Temperature

LightMicrophon

eRadio

TinyOS

Page 11: TinyOS and NesC

TinyOS: Components (Contd..)

Building an application over TinyOS

AppC

Sensors

LedsUSB Flash

Temperature

LightMicrophon

e

Network

Routing

MAC

Radio

TinyOS

Page 12: TinyOS and NesC

TinyOS: Components (Contd..)

Component interfaces Component services are accessed via interfaces

Network

Send

Receive

Page 13: TinyOS and NesC

TinyOS: Components (Contd..)

Interface commands Instruct components to perform its specific tasks

Sensors SampleSensors

getTemperature

getLightgetMagnetomet

ergetAccelerometer

Page 14: TinyOS and NesC

TinyOS: Components (Contd..)

Interface events Applications are responsible for specifying an action on an

occurrence of an event

Events are also essential as system calls in TinyOS are non-blocking

Network ReceiveApplication

PacketReceive

ApplicationSend sendDone

Page 15: TinyOS and NesC

TinyOS: Components (Contd..)

A few commonly used TinyOS components LedsC TimerC ActiveMessageC Some components to sample sensors

Page 16: TinyOS and NesC

TinyOS: Components (Contd..)

LedsC Allows to control the 3 LEDS on the motes Provided interfaces

Leds Commands

• led0Toggle()• led1Toggle()• led2Toggle()• ledoOn• led0Off• ………

Page 17: TinyOS and NesC

TinyOS: Components (Contd..)

TimerC Lets to carryout a task after a specified interval or

periodically Provided interfaces

Timer Commands

• startPeriodic(int period_millisec)• startOneShot(int period_millisec)• stop()• ……

Events• fired()

Page 18: TinyOS and NesC

TinyOS: Components (Contd..)

ActiveMessageC (TinyOS’s Network component) Allows to communicate over the radio Provided interfaces

AMSend Commands

• send(destination, packet, size) Events

• sendDone(packet, error) Receive

Events• receive(packet, payload, size)

Page 19: TinyOS and NesC

NesC: Design

NesC is designed to implement TinyOS components

NesC is a pre-processor to the C compiler

NesC preprocessor

C program

NesC program

C compiler (gcc)

Binary for the mote platform

NesC Compilation Process

Page 20: TinyOS and NesC

NesC Programs over TinyOS

The best way to learn NesC is to dig into a few examples of NesC programs over TinyOS

Hello-world program A simple application that toggles (blinks) the red LED

on a mote once in every 2 seconds

Page 21: TinyOS and NesC

Configuration component Module component

components TimerC, LedsC,MainC;

uses {interface Leds; interface Timer; interface Boot; }

implementation {event Boot.booted(){ }event Timer.fired(){

}

}

components BlinkC;implementation {BlinkC.Leds -> LedsC;BlinkC.Timer -> TimerC;BlinkC.Boot -> MainC;}

LedsC interfaces: Leds commands: led0Toggle() led1Toggle()…..

TimerC interfaces: Timer commands: startPeriodic() events: fired()

call Timer.startPeriodic(2000) ;

(BlinkC)

call Leds.led0Toggle() ;

Page 22: TinyOS and NesC

NesC Programs over TinyOS (Contd..)

Compile and upload the Blink application Include a Makefile containing the following two lines

COMPONENT=BlinkAppCinclude $(MAKERULES)

Compilation Type make telosb in the same directory where the

Makefile and your application components are located Uploading an exe image on to a mote

Type make telosb reinstall.NODEID bsl,addr_usb_port in the same directory

Command “motelist” will give you the addr_usb_porte.g., make telosb reinstall.1 bsl,/dev/ttyUSB0

Page 23: TinyOS and NesC

NesC Programs over TinyOS (Contd..)

A simple networking example A packet is communicated from a sender to a receiver

with the sender turning ON the red LED after transmission and the receiver switches ON the green LED on receiving the packet

Page 24: TinyOS and NesC

Configuration component Module componentcomponentsLedsC,

ActiveMessageC,MainC;

uses {interface AMSend; interface Receive; interface SplitControl; }implementation {

event Boot.booted(){

}

interface Boot;

message_t packet;

event SplitControl.startDone(){

}

LedsC interfaces: Leds commands: led0Toggle() led1Toggle()…..

ActiveMessageC interface: AMSend commands: send() events: sendDone() interface: Receive events: receive () interface: SplitControl commands: start() events: startDone()

call SplitControl.start()

call AMSend.send(2, &packet, 10);

Page 25: TinyOS and NesC

event AMSend.sendDone(packet, error){ if(error == SUCCESS) { call Leds.led0On(); } else { // Retransmit if you need } }event Receive.recevie(packet, payload, size){ call Leds.led1On(); }

}

componentsLedsC,

ActiveMessageC,MainC;

LedsC interfaces: Leds commands: led0Toggle() led1Toggle()…..

ActiveMessageC interface: AMSend commands: send() events: sendDone() interface: Receive events: receive () interface: SplitControl commands: start() events: startDone()

Configuration component Module component

Page 26: TinyOS and NesC

componentsLedsC,

ActiveMessageC,MainC;

components NetC;implementation {NetC.AMSend -> ActiveMessageC.AMSend;

NetC.SplitControl -> ActiveMessageC;

}NetC.Boot -> MainC;

NetC.Receive -> ActiveMessageC.Receive;

Module component

uses {interface AMSend; interface Receive; interface SplitControl; }implementation {

event Boot.booted(){

}

interface Boot;

message_t packet;

event SplitControl.startDone(){

}

call SplitControl.start()

call AMSend.send(2, &packet, 10);

(NetC)Configuration component

Page 27: TinyOS and NesC

componentsLedsC,

ActiveMessageC,MainC;

components NetC;implementation {NetC.AMSend -> ActiveMessageC.AMSend;

NetC.SplitControl -> ActiveMessageC;

}NetC.Boot -> MainC;

NetC.Receive -> ActiveMessageC.Receive;

uses {interface AMSend; interface Receive; interface SplitControl; }interface Boot;

Configuration component

event Receive.recevie(packet, payload, size){ call Leds.led1On(); }

Module component

(NetC)

Page 28: TinyOS and NesC

uses {interface AMSend; interface Receive; interface SplitControl; }interface Boot;

Configuration component

componentsLedsC,

MainC; components NetC;implementation {NetC.AMSend -> ActiveMessageC.AMSend [240];

}NetC.Boot -> MainC;

NetC.Receive -> ActiveMessageC.Receive[240];NetC.SplitControl -> ActiveMessageC;

ActiveMessageC,

event Receive.recevie(packet, payload, size){ call Leds.led1On(); }

Module component

(NetC)

Page 29: TinyOS and NesC

NesC Programs over TinyOS (Contd..)

An example of serial communication over USB Send a command from a PC to a mote that triggers the mote

to send a packet back to the PC (PC mote communication)

PC

moteSF

SF-client

TCP

TCP

SF-client

SF protocol

Required set-up for serial communication

Page 30: TinyOS and NesC

NesC Programs over TinyOS (Contd..)

Executing serial communication programs on the PC-side SF is a gateway program that lets multiple clients to

communicate with a mote./sf tcp_port_num usb_dev_addr telosb

Two programs constituting the SF-client./send host_addr sf_port_num input_values./receive host_addr sf_port_num

These programs are available in C, Python, and Java You do not have to learn any of these languages –

knowing to execute their programs is sufficient !!!!

Page 31: TinyOS and NesC

NesC Programs over TinyOS (Contd..)

TinyOS component to be used on the mote-side SerialActiveMessageC (Very similar to the

ActiveMessageC) Provided interfaces

AMSend Receive SplitControl

Page 32: TinyOS and NesC

event AMSend.sendDone(packet, error){ if(error == SUCCESS) { call Leds.led0On(); } else { // Retransmit if you need } }

Configuration component Module component (SerialC)

components

LedsC, SerialActiveMessageC,

MainC;

uses { interface

AMSend; interface Receive; interface SplitControl;

}

implementation {

event Boot.booted(){ call SplitControl.start();}

}

components SerialC, implementation {SerialC.AMSend ->

SerailActiveMessageC.AMSend[240];SerialC.Receive -> SerialActiveMessageC.Receive[240];

SerialC.SplitControl -> SerialActiveMessageC;

}

interface Boot;

message_t packet;

event SplitControl.startDone(){}

event Receive.recevie(packet, payload, size){ call Leds.led1On(); call AMSend.send(addr, &packet, 10); }

SerialC.Boot -> MainC;

Page 33: TinyOS and NesC

Programming Assignment 1

A simple application aimed to warm you up for more programming on TinyOS/NesC Students mainly learn

Basic architecture of TinyOS/NesC Compilation and downloading of TinyOS code on to

motes PC<->Mote communication

Application is to turn a desired LED(s) ON/OFF for a desired duration of time

Application involves programming on both PC- and mote-side

Page 34: TinyOS and NesC

Programming Assignment 1 (Contd..)

PC-side Design a client that communicates a few parameters

to the mote and displays messages received from the mote

A command line interface is sufficient, no need for GUI

Mote-side Program should receive the parameters that the client

transmits and send an ACK back to the client LEDS must be controlled as instructed by the input

parameters

Page 35: TinyOS and NesC

Programming Assignment 1 (Contd..)

Submission Submit your code zipped/tarred to IVLE workbin The code should be compilable and include a

README file explaining how to compile and how the program works

Grading 25 points – Correct choice of components and

compilation 25 points – PC to mote communication 25 points – Mote to PC communication 25 Points – Desired control of LEDS

Weightage towards final assessment is 5%