Chapter 6
Programming in NesC
Low-level programming is good for the programmer’s soul.
—John Carmack
6.1 NesC PROGRAMMING
Because of the highly resource-constrained nature and unpredictability associated with wireless sensor networks, traditional programming techniques cannot be used in the development of programs intended for use in these networks. Unlike conventional programming techniques in which most resources are available locally and remote resources could be accessed through persistent connections, sensor applications have to contend with several factors that may lead to degradation in performance of the sensor network, ranging from energy depletion, to limited or no connectivity, to physical damage of the sensor hardware in hostile environments. In TinyOS-based sensor networks a C-based language called nesC has been developed with several constructs built in to mitigate some of these undesirable properties of sensor networks. NesC shares a similar syntax with C but runs only on the TinyOS operating system. The language is simple so that it can be used for programming embedded systems, wireless sensor nodes, and similar applications, where efficiency in terms of speed and memory is of utmost importance. The nesC language has features borrowed from computer hardware such as the notion of components and subcomponents, each interacting with the other via clearly defined interfaces, and the concept of split-phase operation. We will present concepts in the nesC language using ...