Heterogeneous Wireless Sensor Networks (HWSN) are basically decentralized and distributed systems that playing a crucial role in numerous Internet of Things (IoT) applications, enabling efficient monitoring and data collection. However, these networks often suffer from high latency, routing overheads, and energy consumption. To meet these challenges effectively, This article proposes an enhanced CSMA/CA protocol based on an Optimal Robust Dynamic Query-Driven Clustering Protocol (ECODQC) model. The enhanced model includes two key components: the improved CSMA/CA protocol, which reduces network collisions, lowering delay and overhead during communication, and the Optimal Robust Dynamic Query-Driven Clustering (ODQC) protocol, which efficiently reduces energy consumption among sensors. In the first phase, the modified CSMA/CA protocol focuses on analyzing communication delays, defining dynamic data transmission, and evaluating data delivery beyond predefined times. In the second phase, the ODQC protocol addresses optimal load balancing and the dynamic process of cluster head selection, aiming to reduce energy consumption during sensor communication. The proposed techniques demonstrate superiority over conventional protocols and are recommended for enhancing the overall quality of service in decentralized, distributed HWSN-based IoT networks. The ECODQC model is compared against existing methods using the NS2 simulation platform in two scenarios: the varying numbers of nodes and varying speeds. The performance parameters of this proposed model are analyzed in terms of energy efficiency, cluster head efficiency, data success rate, computational delay, and node throughput. The Results demonstrate that ECODQC proves to be superior compared to existing techniques in terms of energy efficiency of 432.23 J, low latency of 85.23 ms, and increased throughput of 813.77 Kbits/s. With these observations, the possibility of using ECODQC with a high level of applicability in real-time IoT scenarios is evident