Abstract. Many applications operate in heterogeneous wireless sensor networks, which represent a challenging programming environment due to the wide range of device capabilities. Servilla addresses this difficulty in developing applications by offering a new middleware framework based on service provisioning. Using Servilla, developers can construct platform-independent applications over a dynamic and diverse set of devices. A salient feature of Servilla is its support for the discovery and binding to local and remote services, which enables flexible and energy-efficient in-network collaboration among heterogeneous devices. Furthermore, Servilla provides a modular middleware architecture that can be easily tailored to devices with a wide range of resources, allowing resource-constrained devices to provide services while leveraging the capabilities of more powerful devices. Servilla has been implemented on TinyOS for two representative hardware platforms (Imote2 and TelosB) with drastically different resources. Microbenchmarks demonstrate the efficiency of Servilla's implementation, while an application case study on structural health monitoring demonstrates the efficacy of its coordination model for integrating heterogeneous devices.