Using local and global knowledge in wireless sensor networks