21.08.2013 Views

A State-Based Programming Model for Wireless Sensor Networks

A State-Based Programming Model for Wireless Sensor Networks

A State-Based Programming Model for Wireless Sensor Networks

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

70 Chapter 4. Event-driven <strong>Programming</strong> in Practice<br />

SAMPLE phase in order to start sampling. In order to save power the<br />

sensor is generally switched off unless actually sampling. There<strong>for</strong>e<br />

the SAMPLE phase is initialized by switching on the sensor. When<br />

the data sample is available, which may considerable time (e.g., <strong>for</strong><br />

GPS sensors), the sensor is switched off again. Then the SEND phase<br />

is started. Similar to the SAMPLE phase the SEND phase first switches<br />

on the radio, waits until a connection to the dedicated sink node is<br />

established and then sends the data sample acquired in the previous<br />

SAMPLE phase. When the reception of the data has been acknowledged<br />

by the sink node, the radio is switched off again and the program<br />

moves to the IDLE phase. In this initial version of the program<br />

we ignore a failed send attempt (e.g, due to collisions or packet loss<br />

on a noisy channel) and move to IDLE anyway. The IDLE phase does<br />

nothing but wait <strong>for</strong> the start of the next interval, when the next cycle<br />

of sampling and sending is restarted, that is, the program moves to<br />

the SAMPLE phase again. In order to sleep <strong>for</strong> the specified time, a<br />

timer is initialized upon entering the IDLE phase and then the CPU is<br />

put into sleep mode. The node wakes up again when the timer fires<br />

and the program moves to the SAMPLE mode again. In our example,<br />

the sampling of the sensor in the SAMPLE state may need to be<br />

scheduled regularly. Since both the sample and the send operation<br />

may take varying amounts of time, the program needs to adjust the<br />

dwell period in the IDLE phase. ✷<br />

Start INIT SAMPLE SEND<br />

init_done sample_done<br />

(n)ack<br />

IDLE<br />

timeout<br />

Figure 4.1: A simple version of Surge with four program phases. In this version<br />

a failure while sending the data sample is ignored.<br />

Though this program is rather simple, it has many features of the complex<br />

algorithms used in current sensor-node programs.<br />

Sequential Composition<br />

The four phases of the Surge program are all scheduled strictly sequentially.<br />

From our analysis of sensor-node programs we conclude that typically the majority<br />

of logical operations (i.e., phases) are per<strong>for</strong>med sequentially (though<br />

there is a certain amount of concurrency, as we will discuss in Sect. 4.2.3).<br />

Whenever the application at hand permits, architects of sensor-node programs<br />

seem to be inclined to schedule these phases sequentially rather then<br />

concurrently. This holds true even <strong>for</strong> many fundamental system services, such<br />

as network management, routing, device management, etc. This is in contrast to<br />

traditional networks, where most of such services are per<strong>for</strong>med permanently in<br />

the background, often by dedicated programs or even on dedicated hardware.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!