A distributed algorithm for network-wide clock synchronization in wireless sensor networks