Wireless sensor networks are being developed for a variety of applications. With the continuing advances in network and application design, appropriate middleware is needed to provide both standardized and portable system abstractions, and the capability to support and coordinate concurrent applications on sensor networks. In this article, we first identify several design principles for such middleware. These principles motivate a cluster-based lightweight middleware framework that separates application semantics from the underlying hardware, operating system, and network infrastructure. We propose a layered architecture for each cluster that consists of a cluster control layer and a resource management layer. Key design issues and related challenges within this framework that deserve further investigation are outlined. Finally, we discuss a technique for energy-efficient resource allocation in a single-hop cluster, which serves as a basic primitive for the development of the resource management layer.