tinyos course 01: basic programming

15
WSN Programming Course TinyOS Lab: Basic Programming Manuel Fernández UAH, 18th September 2013

Upload: manuel-fernandez-santo-tomas

Post on 15-Dec-2014

487 views

Category:

Education


2 download

DESCRIPTION

Lesson 01 slides for one day introductory course on wireless sensor networks and TinyOS, that took place at the University of Alcalá de Henares in Madrid Spain the 18th of September 2013. This course was jointly designed by the Electronics Department of the university and Advanticsys. Find source code for the lessons here: http://www.advanticsys.com/wiki/index.php?title=TinyOS%C2%AE_Course_at_UAH_18th_September_2013

TRANSCRIPT

Page 1: TinyOS Course 01: Basic Programming

WSN Programming Course

TinyOS Lab: Basic Programming

Manuel Fernández

UAH, 18th September 2013

Page 2: TinyOS Course 01: Basic Programming

• Introduction to nesC • Components • File Types • Basic program: NullC • How to compile • NesC variables • Eclipse IDE • Exercises

2

Contents

Page 3: TinyOS Course 01: Basic Programming

• 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)

Page 4: TinyOS Course 01: Basic Programming

• 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)

Page 5: TinyOS Course 01: Basic Programming

• 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)

Page 6: TinyOS Course 01: Basic Programming

• 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

Page 7: TinyOS Course 01: Basic Programming

• Naming conventions are as follows:

CONFIGURATION

MODULE

COMPONENTS

INTERFACE

Makefile Only in main app

7

File Types

CONFIGURATION

MODULE

Page 8: TinyOS Course 01: Basic Programming

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

Page 9: TinyOS Course 01: Basic Programming

NullApp.nc :

SPECIFICATION

IMPLEMENTATION

9

Basic program: NullC

SPECIFICATION

IMPLEMENTATION

NullC.nc :

Page 10: TinyOS Course 01: Basic Programming

• 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

Page 11: TinyOS Course 01: Basic Programming

• Open terminal in the folder

• Type:

make telosb docs

• Check the created folders

Platform

11

Fun Stuff

Page 12: TinyOS Course 01: Basic Programming

• Commonly used units:

• int is NOT used • bool is also used

12

NesC variables

Page 13: TinyOS Course 01: Basic Programming

• 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

Page 14: TinyOS Course 01: Basic Programming

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

Page 15: TinyOS Course 01: Basic Programming

Contact Info: Manuel Fernández

[email protected]

15