Programming Wireless Sensor Networks with Logical Neighborhoods