TinyOS Manual Ver 1
TinyOS Manual Ver 1
Tiny OS Installation
Installation of TinyOS using Virtual Machine.
Requirements:
https://my.vmware.com/en/web/vmware/free#desktop_end_user_computing/vmware_workst
ation_player/14_0
• Collect Ubuntu virtual disk from the instructor and copy it in your system.
• Open VMware workstation and add the virtual disk.
• Power ON the Ubuntu virtual machine.
Select next
Check in the box and click next
Click next
Enter the password: z.
• AppC.nc
• C.nc
• Makefile.
The programming language used in TinyOS is nesC (extension of C language. A nesC program is built
out of components, which are assembled (“wired”) to form whole programs. Components define
two scopes, one for their specification (containing the names of their interfaces) and one for their
implementation. The provided interfaces are intended to represent the functionality that the
component provides to its user, the used interfaces represent the functionality the component
needs to perform its job.
Interfaces are bidirectional: they specify a set of functions to be implemented by the interface’s
provider (commands) and a set to be implemented by the interface’s user (events). This allows a
single interface to represent a complex interaction between components (e.g., registration of
interest in some event, followed by a callback when that event happens). This is critical because all
lengthy commands in TinyOS (e.g. send packet) are non-blocking; their completion is signaled
through an event (send packet done). The interface forces a component that calls the “send packet”
command to provide an implementation for the “send packet done” event.
• Enter “sudo chmod 777 /dev/ttyUSB0” to enable read, write, execute permission for
the device. Enter password as ‘z’ (without quotes).
• Lets take a look inside the 1_Blink folder, you find three files, BlinkAppC.nc, BlinkC.nc and
Makefile. The application constructed using these three files toggles three LEDs (red, green
and blue) on the telosb board with a time interval of 1s, 2s and 4s. Blink application is
composed of two components: a module, called "BlinkC.nc", and a configuration, called
"BlinkAppC.nc". All applications require a top-level configuration file, which is typically
named after the application itself. In this case BlinkC.nc is the configuration for the Blink
application and the source file that the nesC compiler uses to generate an executable file.
BlinkAppC.nc, on the other hand, actually provides the implementation of the Blink
application. Lets take a look at each file:
BlinkAppC.nc:
configuration BlinkAppC
{
//Making use of standard functionality so keep it blank
}
implementation
{
//Define components for the application
//Wiring
#include "Timer.h"
module BlinkC
{
uses interface Timer<TMilli> as Timer0;
uses interface Timer<TMilli> as Timer1;
uses interface Timer<TMilli> as Timer2;
uses interface Leds;
uses interface Boot;
}
implementation
{
event void Boot.booted()
{
call Timer0.startPeriodic( 1000 );
call Timer1.startPeriodic( 2000 );
call Timer2.startPeriodic( 4000 );
}
The first part of the code states that this is a module called BlinkC and declares the interfaces it uses.
The BlinkC module also uses five interfaces: 3 interfaces of TimerMilli , Leds and Timer. This means
that BlinkC may call any command declared in the interfaces it uses and must also implement any
events declared in those interfaces. The Leds interface defines several commands like led1On( ),
led1Off( ), led2Toggle( ) and so forth, which turn the different LEDs (red, green, or yellow) on the
mote on and off. Because BlinkC uses the Leds interface, it can invoke any of these commands. Keep
in mind, however, that Leds is just an interface: the implementation is specified in the Blink.nc
configuration file.
Under implementation, the first line event void Boot.booted is executed after successful
initialization of telosb mote. The “call” commands imolementedd in the event schedules various
events in the telosb mote. IN this case, they are timers and are triggered at time intervals of 1s, 2s
and 4s.
How does an application know that its timer has expired? The answer is when it receives an event.
The Timer interface provides an event:
An event is a function that the implementation of an interface will signal when a certain event takes
place. In this case, the fired() event is signalled when the specified interval has passed. This is an
example of a bi-directional interface: an interface not only provides commands that can be called by
users of the interface, but also signals events that call handlers in the user. Think of an event as a
call-back function that the implementation of an interface will invoke. A module that uses an
interface must implement the events that this interface uses.
What you observer on the board would be three LEDs toggling at intervals of led 0 --1s, led1 -- 2s
and led2 -- 4s.
Makefile
Click ok.
At the end of this program, we see current time since the board was booted on serial terminal.
When reset button on the mote is pressed – the timer will start again.
Task 3: Implementing packet broadcast
The aim of this experiment is to setup mote-to-mote communication using wireless transceiver. Go
to folder 3_BlinktoRadio. Please go through all the three files and understand the logic. Insert the
first board, compile and program the board. Remove the first board. Insert the second board,
compile and program it. Power up both the boards now. Observe the outputs on the LEDs. If both
boards are communicating then the LEDs on both the boards should toggle in the same sequence.