In the recent years, the advance wireless networks and Internet of Things (IoT) are becoming very prominent in assorted domains. In the traffic system, the problem of congestion control is very common, and it is classically handled by the global positioning systems by the drivers as well as traffic administrative authorities. But as the traffic density is increasing day by day, it is becoming difficult to handle and view all the possibilities in the prospective traffic area where the driver is willing to move. Moreover, the problem of security and integrity is also increasing rapidly as there are number of attacks in VANET and GPS systems being used by the crackers by sending the malicious code or fake packets. Ubiquitous computing is one of the recent technologies that is in the phase of implementation under Internet of Things (IoT). In this research manuscript, the approach to integrate the dynamic key exchange with the Elephant Herd Optimization (EHO) is presented to achieve the higher degree of energy optimization and overall lifetime of the network communication. The key concept of the cluster head shuffling using EHO and inner modules of key exchange are simulated in Contiki-Cooja that is open source simulator for advance wireless networks.