Chapter 12: Sensor Network Programming
Chapter 12: Sensor Network Programming
Programming
Chapter 12: Roadmap
Challenges
Node-centric programming
Macroprogramming
Dynamic reprogramming
Sensor network simulators
interface StdControl {
command result_t init ();
}
interface Timer {
command result_t start (char type, uint32_t interval);
command result_t stop ();
event result_t fired ();
}
interface Send {
command result_t send (TOS_Msg *msg, uint16_t length);
event result_t sendDone (TOS_Msg *msg, result_t success);
}
interface ADC {
command result_t getData ();
event result_t dataReady (uint16_t data);
}
configuration TimerC {
provides {
interface StdControl;
interface Timer;
}
}
implementation {
components TimerModule, HWClock;
StdControl = TimerModule.StdControl;
Timer = TimerModule.Timer;
COMPONENT DownSample
ACCEPTS {
void init (void);
void fire (int in);
};
USES {
void fireOut (int out);
};
void init () {
_active = true;
}
void fire (int in) {
if (_active) {
CALL_COMMAND (fireOut) (in);
_active = false;
} else {
_active = true;
}
}
M=(COMPONENTSM,INITM,INPORTSM,OUTPORTSM,PARAMETERSM,LINK
SM)
COMPONENTSM … set of components of M
INITM … list of methods of M’s components
INPORTSM … inputs of the module
OUTPORTSM … outputs of the module
PARAMETERSM … set of variables external to the components
LINKSM … relationship between the method call interfaces and the
inputs and outputs of the module
SNACK library
variety of components for sensing, aggregation, transmission,
routing, and data processing
several core components supported
Network: receives/sends messages from/to TinyOS radio stack
MsgSink: ends inbound call chains and destroys received buffers
MsgSrc: generates periodic empty SNACK messages and passes
them to outbound interface
Timing:
– TimeSrc: generates a timestamp signal sent over signal
interface at specified minimum rate
– TimeSink: consumes such signals
Storage: implemented by components such as Node-Store64M,
which implements an associative array of eight-byte values
keyed by node ID
Service: variety of services (e.g., RoutingTree implements a tree
designed to send data up to some root)
Similar projects
Cougar: resource-efficient database appraoch
SINA: models WSN as collection of distributed objects;
supports SQTL scripts in SQL queries
MiLAN: sensor applications can specify QoS needs
Fundamentals of Wireless Sensor Networks: Theory and Practice
Waltenegus Dargie and Christian Poellabauer © 2010
31
Dynamic Reprogramming
Sometimes necessary to disseminate code to all or some sensor
nodes
Virtual machines
Maté
small VM on top of TinyOS
capsules (sequence of 24 instructions) inside a single
TinyOS packet
every capsule includes type and version information
– message send capsules
– message receive capsules
– timer capsules
– subroutine capsules
programs execute in response to events (e.g., timer firing,
packet being sent/received)
each event has a capsule and an execution context
Fundamentals of Wireless Sensor Networks: Theory and Practice
Waltenegus Dargie and Christian Poellabauer © 2010
32
Dynamic Reprogramming
Virtual machines (contd.)
Maté (contd.)
jumps to first instruction of capsule and executes until halt
instruction
when subroutine called, return address is pushed onto a return
address stack; upon return, address is taken from the stack
Trickle
controlled flooding protocol for disseminating small pieces of code
uses metadata to describe code (allows node to determine if code
update needed)
metadata is exchanged among neighbors via broadcast
periodic time intervals, each node randomly selects broadcast
time during each interval
when a node hears outdated metadata, it broadcasts its own code,
giving outdated node chance to update
when a node overhears newer metadata, it broadcasts its own
metadata, triggering the neighbor to broadcast newer code