WSN Programming Course
TinyOS Lab:
Basic Programming
Manuel Fernández
UAH, 18th September 2013
• Introduction to nesC
• Components
• FileTypes
• Basic program: NullC
• How to compile
• NesC variables
• Eclipse IDE
• Exercises
2
Contents
• A nesC application consists of one or more components assembled, or
wired, to form an application executable.
• Components define two scopes:
• one for their specification which contains the names of their
interfaces, and
• a second scope for their implementation.
COMPONENT A
SPECIFICATION
IMPLEMENTATION
3
NesC (I)
•A component provides and uses interfaces.
•The provided interfaces are intended to represent the
functionality that the component provides to its user in its
specification.
•The used interfaces represent the functionality the component
needs to perform its job in its implementation.
4
NesC (II)
• Interfaces are bidirectional: they specify a set of commands, which
are functions to be implemented by the interface's provider, and a set
of events, which are functions to be implemented by the interface's
user. For a component to call the commands in an interface, it must
implement the events of that interface.
•The set of interfaces which a component provides together with the
set of interfaces that a component uses is considered that
component's signature.
5
NesC (III)
•There are 2 types of components in nesC:
- Modules: provide the implementations of one or more
interfaces.
- Configurations: used to assemble other components together,
connecting interfaces used by components to interfaces provided
by others.
6
Components
• Naming conventions are as follows:
CONFIGURATIO
N
MODULE
COMPONENTS
INTERFACE
Makefile Only in main app
7
File Types
CONFIGURATION
MODULE
TinyOS Lab: Lesson 01 – Basic Programming
© 2012 Manuel Fernández
Makefile
NullAppC.nc
NullC.nc
Configuration
Module
Makefile:
COMPONENT=NullAppC
include $(MAKERULES)
Name of configuration file
8
Basic program: NullC
NullApp.nc :
SPECIFICATION
IMPLEMENTATION
9
Basic program: NullC
SPECIFICATION
IMPLEMENTATION
NullC.nc :
• Open terminal in the folder
•Type:
make telosb
• Insert mote in USB port and type:
make telosb reinstall.1 bsl,/dev/ttyUSB0
Platform
MoteID USB port (type motelist
to find which one it is
10
How to compile
• Open terminal in the folder
• Type:
make telosb docs
• Check the created folders
Platform
11
Fun Stuff
• Commonly used units:
• int is NOT used
• bool is also used
12
NesC variables
• An alternative to console programming is using a TinyOS plug-in
for the Eclipse IDE.
• In this IDE it is possible to compile and install programs in motes
•We will use this IDE to speed up the lessons.
13
Eclipse IDE
1. Interface Leds has commands to control the 3 leds on the mote.
(led0, led1, led2).Try each of them and install them on the mote
2. Add a Timer to blink the Leds periodically, showing a binary timer
using the 3 leds.
3. Configure the User Button to do a complete routine with the Leds
4. Pack the previous subroutine in a new component with your own
interface.
14
Exercises
Contact Info:
Manuel Fernández
manuel.fernandez@advanticsys.com
15

TinyOS Course 01: Basic Programming

  • 1.
    WSN Programming Course TinyOSLab: Basic Programming Manuel Fernández UAH, 18th September 2013
  • 2.
    • Introduction tonesC • Components • FileTypes • Basic program: NullC • How to compile • NesC variables • Eclipse IDE • Exercises 2 Contents
  • 3.
    • A nesCapplication consists of one or more components assembled, or wired, to form an application executable. • Components define two scopes: • one for their specification which contains the names of their interfaces, and • a second scope for their implementation. COMPONENT A SPECIFICATION IMPLEMENTATION 3 NesC (I)
  • 4.
    •A component providesand uses interfaces. •The provided interfaces are intended to represent the functionality that the component provides to its user in its specification. •The used interfaces represent the functionality the component needs to perform its job in its implementation. 4 NesC (II)
  • 5.
    • Interfaces arebidirectional: they specify a set of commands, which are functions to be implemented by the interface's provider, and a set of events, which are functions to be implemented by the interface's user. For a component to call the commands in an interface, it must implement the events of that interface. •The set of interfaces which a component provides together with the set of interfaces that a component uses is considered that component's signature. 5 NesC (III)
  • 6.
    •There are 2types of components in nesC: - Modules: provide the implementations of one or more interfaces. - Configurations: used to assemble other components together, connecting interfaces used by components to interfaces provided by others. 6 Components
  • 7.
    • Naming conventionsare as follows: CONFIGURATIO N MODULE COMPONENTS INTERFACE Makefile Only in main app 7 File Types CONFIGURATION MODULE
  • 8.
    TinyOS Lab: Lesson01 – Basic Programming © 2012 Manuel Fernández Makefile NullAppC.nc NullC.nc Configuration Module Makefile: COMPONENT=NullAppC include $(MAKERULES) Name of configuration file 8 Basic program: NullC
  • 9.
    NullApp.nc : SPECIFICATION IMPLEMENTATION 9 Basic program:NullC SPECIFICATION IMPLEMENTATION NullC.nc :
  • 10.
    • Open terminalin the folder •Type: make telosb • Insert mote in USB port and type: make telosb reinstall.1 bsl,/dev/ttyUSB0 Platform MoteID USB port (type motelist to find which one it is 10 How to compile
  • 11.
    • Open terminalin the folder • Type: make telosb docs • Check the created folders Platform 11 Fun Stuff
  • 12.
    • Commonly usedunits: • int is NOT used • bool is also used 12 NesC variables
  • 13.
    • An alternativeto console programming is using a TinyOS plug-in for the Eclipse IDE. • In this IDE it is possible to compile and install programs in motes •We will use this IDE to speed up the lessons. 13 Eclipse IDE
  • 14.
    1. Interface Ledshas commands to control the 3 leds on the mote. (led0, led1, led2).Try each of them and install them on the mote 2. Add a Timer to blink the Leds periodically, showing a binary timer using the 3 leds. 3. Configure the User Button to do a complete routine with the Leds 4. Pack the previous subroutine in a new component with your own interface. 14 Exercises
  • 15.