A Practical Introduction To Sensor Network Programming: Wireless Communication and Networked Embedded Systems, VT 2011
A Practical Introduction To Sensor Network Programming: Wireless Communication and Networked Embedded Systems, VT 2011
Frederik Hermans,
Communication Research, Uppsala Universitet
Overview
● Sensor node hardware: Zolertia Z1
● TinyOS & nesC
● Components & Interfaces
● A first TinyOS program: Blink
● Networking in TinyOS: Active messages
● Contiki
● Protothreads
● A first Contiki program: Blink
● Networking in Contiki: The Rime stack
● Wrap-up
Zolertia Z1
● General purpose sensor node for research
● Low power consumption
● Months to years on two AA batteries
● Specs
● 16 MHz, 8 kB RAM
● Radio: 250 kbps @ 2.4 GHz
● Three LEDs
● Accelerometer
● Temperature sensor
Some perspective on the specs
RAM 8 kB 8 kB 589824 kB
Timer
BlinkC TimerC
nesC: Interfaces
● An interface describes a behavior (cf. Java)
● It specifies commands and events
● Example:
interface Timer {
command void start(uint32_t dt);
event void fired();
}
0
1
2
3
4
5
4 2 1
Timer Timer-
MilliC
Boot
BlinkC MainC
Leds
LedsC
Genericity
configuration BlinkAppC { }
implementation {
components MainC, BlinkC, LedsC, new TimerMilliC();
●
AMSenderC and AMReceiverC are generic
● Need to be instantiated
● Constructor takes on argument: An active message type
● E.g., component new AMReceiveC(42)
Active messages: Starting the radio
● ActiveMessageC provides SplitControl to turn
on/off radio
● Signals events startDone(err) and stopDone(err)
module ClickerClientC { uses interface SplitControl; ... }
implementation {
event void Boot.booted() {
call SplitControl.start(); Start the radio
}
Notify User-
ButtonC
do {
PROCESS_WAIT_UNTIL(data_to_send());
send(pkt);
timer_start();
PROCESS_WAIT_UNTIL((ack_received() || timer_expired());
} while (!ack_received());
PROCESS_THREAD_END();
}
...
route
discovery
Rime: Packet buffer
● Packets are stored in the so-called packetbuf
● There is one single packetbuf
● API
●
broadcast_open(...) - Initialize a broadcast handle
●
broadcast_close(...) - Close a broadcast handle
●
broadcast_send(...) - Send a packet
Rime: Broadcast module initialization
● Need to setup a handle before sending/receiving
● broadcast_open(con, channel, callback)
●
con – Handle to be created
●
channel – 16-bit integer for multiplexing
●
callback – Pointer to receive function