Title: TinyOS Tutorial, Part I
1TinyOS Tutorial, Part I
- Phil Levis et al.
- MobiSys 2003
2Goals
- Deploy a (small) sensor network
- See, modify, and install some nesC code
- Write a simple application
3TinyOS Applications
- Application specific images
- Top-level configuration
- tinyos-1.x/apps/
4TinyDB
- Data collection and aggregation
- SQL-like queries
- Ad-hoc multi-hop routing
5Two Steps
- Prepare PC-side application
- Install TinyDB on two or more motes
6Building Java Tools
- cd tinyos-1.x/tools/java
- make
7TinyDB Java Application
- cd tinyos-1.x/tools/java
- cd net/tinyos/tinydb
- java jar tinydb.jar
- After you run this, close it
8Installing TinyDB
- cd tinyos-1.x/apps/tinydb
- make mica
- Make sure application builds properly
- Plug in programming board
- make mica install.1
- Installs application with mote ID 1
9Build a TinyDB Base Station
- Plug in a new mote
- cd apps/TinyDB
- make mica install.0
- Make sure serial cable is connected
10Running the Application
- Plug in (and turn on) base station
- Turn on TinyDB mote
- Run TinyDB PC application
11A Simple Query
- Report light at one Hz
- Look at data output
12Multi-Mote Network
- Close TinyDB PC application
- Turn off motes
- Install TinyDB on more motes
- make install.2
- make install.3
- Run TinyDB PC application
- Send query again
13Applications
- TinyOS applications have a top-level
configuration - Wires application components to boot sequence,
etc. - Some applications have no app-specific modules
14Example Configuration
15A Simple App CntToLeds
- CntToLeds
- Displays bottom 3 bits of a counter on LEDs
- apps/CntToLeds
16CntToLeds Configuration(apps/CntToLeds/CntToLeds.
nc)
configuration CntToLeds implementation
components Main, Counter, IntToLeds, TimerC
Main.StdControl -gt IntToLeds.StdControl
Main.StdControl -gt Counter.StdControl
Main.StdControl -gt TimerC.StdControl
Counter.Timer -gt TimerC.Timerunique("Timer")
Counter.IntOutput -gt IntToLeds.IntOutput
17Step By Step(apps/CntToLeds/CntToLeds.nc)
configuration CntToLeds
- This is a configuration (wiring)
- Named CntToLeds (CntToLeds.nc)
18Step By Step(apps/CntToLeds/CntToLeds.nc)
implementation components Main, Counter,
IntToLeds, TimerC
- This is the implementation block
- As this is a configuration, implementation is
wiring - This wiring uses these components
- There can be more than one components statement
- Component order unimportant
19Step By Step(apps/CntToLeds/CntToLeds.nc)
Main.StdControl -gt IntToLeds.StdControl
Main.StdControl -gt Counter.StdControl
Main.StdControl -gt TimerC.StdControl
- Connect Mains StdControl (uses) to the
StdControl interfaces (provides) of three
components - In the boot sequence, Main will call these
components init() and start()
20Step By Step(apps/CntToLeds/CntToLeds.nc)
Counter.Timer -gt TimerC.Timerunique("Timer")
- Wire counter to a unique TimerC timer
- Counter.Timer.startTimer() will call
TimerC.Timerx.startTimer - TimerC.Timerx.fired() will call
Counter.Timer.fired()
21Finally.(apps/CntToLeds/CntToLeds.nc)
Counter.IntOutput -gt IntToLeds.IntOutput
- Wire the counter output to the LEDs
22CntToLeds, Revisited(apps/CntToLeds/CntToLeds.nc)
configuration CntToLeds implementation
components Main, Counter, IntToLeds, TimerC
Main.StdControl -gt IntToLeds.StdControl
Main.StdControl -gt Counter.StdControl
Main.StdControl -gt TimerC.StdControl
Counter.Timer -gt TimerC.Timerunique("Timer")
Counter.IntOutput -gt IntToLeds.IntOutput
23How it Works
- On boot, Main initializes components
- When Counter starts, it starts its Timer
- When Timer fires, Counter increments is value,
then calls IntToLeds - IntToLeds displays bottom three bits
24Install CntToLeds
- cd apps/CntToLeds
- make mica install
- Watch the mote blink
25Simulation
- TinyOS has a simulator, TOSSIM
- Builds directly from TinyOS code
- make pc
- build/pc/main.exe h
- Configurable output
- export DBGled
- Scalable to thousands of nodes
26Simulating CntToLeds
- Syntax main.exe ltnumber of nodesgt
- Sample command line options
- -h help
- -x ltfloating pointgt Scale simulated time to real
world time (2.0 twice as fast) - -r ltsimplestaticlossygt Radio models
- Running CntToLeds
- build/pc/main.exe x 1.0 1
27TinyViz
- GUI for visualization and actuation
- Connects directly to TOSSIM
- build/pc/main.exe gui 4
- cd tinyos-1.x/tools/java/
- java net.tinyos.sim.TinyViz
28TinyViz Screenshot
29Adding Debugging Output
- tinyos-1.x/tos/lib/Counter.nc
- export dbgled,usr3
- make pc
- build/pc/main.exe x 1.0 1
event result_t Timer.fired() state
dbg(DBG_USR3, Counter i.\n, state)
return call IntOutput.output(state)
30Simple Messaging
- Build a CntToRfm mote
- Build a RfmToLeds mote
- One mote displays the others counter
31CntToRfm (apps/CntToRfm/CntToRfm.nc)
configuration CntToRfm implementation
components Main, Counter, IntToRfm, TimerC
Main.StdControl -gt Counter.StdControl
Main.StdControl -gt IntToRfm.StdControl
Counter.Timer -gt TimerC.Timerunique("Timer")
Counter.IntOutput -gt IntToRfm.IntOutput
32RfmToLeds (apps/RfmToLeds/RfmToLeds.nc)
configuration RfmToLeds implementation
components Main, RfmToInt, IntToLeds
Main.StdControl -gt IntToLeds.StdControl
Main.StdControl -gt RfmToInt.StdControl
RfmToInt.IntOutput -gt IntToLeds.IntOutput
33Sensing
- Instead of a counter, display sensor reading on
LEDs - See what sensing code looks like
- Install SenseToRfm on CntToRfm node
34Sensing SenseToRfm (apps/SenseToRfm/SenseToRfm.nc
)
configuration SenseToRfm // this module does
not provide any interfaceimplementation
components Main, SenseToInt, IntToRfm, ClockC,
Photo Main.StdControl -gt SenseToInt
Main.StdControl -gt IntToRfm SenseToInt.Clock
-gt ClockC SenseToInt.ADC -gt Photo
SenseToInt.ADCControl -gt Photo
SenseToInt.IntOutput -gt IntToRfm
35Sensing, Continued
- Build a new application
- Goals
- Have two motes sense
- Each displays others reading on LEDs
- Starting blocks
- SenseToRfm
- RfmToLeds
36Making a New Application
- Create a new application directory
- Create the Makefile
- Write the code
37Directory
- mkdir tinyos-1.x/apps/SenseExchange
- cd tinyos-1.x/apps/SenseExchange
38Makefile
COMPONENTSenseExchangeinclude ../Makerules
39Application File
- What components do we need?
- Main
- Photo
- SenseToInt
- IntToRfm
- RfmToInt
- IntToLeds
- ClockC
40Wiring It Up The Components (apps/SenseExchange/
SenseExchange.nc)
configuration SenseExchange // this module does
not provide any interfacesimplementation
components Main // The output part
components SenseToInt, IntToRfm, ClockC, Photo
// The input part components RfmToInt,
IntToLeds
41Wiring It Up Output Connections
(apps/SenseExchange/SenseExchange.nc)
Main.StdControl -gt SenseToInt
Main.StdControl -gt IntToRfm SenseToInt.Clock
-gt ClockC SenseToInt.ADC -gt Photo
SenseToInt.ADCControl -gt Photo
SenseToInt.IntOutput -gt IntToRfm
42Wiring It Up Input Connections
(apps/SenseExchange/SenseExchange.nc)
Main.StdControl -gt IntToLeds.StdControl
Main.StdControl -gt RfmToInt.StdControl
RfmToInt.IntOutput -gt IntToLeds.IntOutput
43Wiring It Up Result (apps/SenseExchange/SenseExc
hange.nc)
configuration SenseExchange // this module does
not provide any interfacesimplementation
components Main components SenseToInt,
IntToRfm, ClockC, Photo components RfmToInt,
IntToLeds Main.StdControl -gt SenseToInt
Main.StdControl -gt IntToRfm SenseToInt.Clock
-gt ClockC SenseToInt.ADC -gt Photo
SenseToInt.ADCControl -gt Photo
SenseToInt.IntOutput -gt IntToRfm
Main.StdControl -gt IntToLeds.StdControl
Main.StdControl -gt RfmToInt.StdControl
RfmToInt.IntOutput -gt IntToLeds.IntOutput
44Running SenseExchange
- Compile and run on two motes
- Cover one light sensor
- Cover the other
45Conclusion of Part I
- Deployed a small sensor network
- Installed simple applications
- Used TOSSIM
- Wrote SenseExchange
- Part II Communication, actuation
46Questions
47SerialForwarder
- Sensor network proxy
- Connects to serial port
- Provides TCP socket interface
java net.tinyos.sf.SerialForward