The evolution of agriculture towards a modern, intelligent system is crucial for achieving sustainable development and ensuring food security. In this context, leveraging the Internet of Things (IoT) stands as a pivotal strategy to enhance both crop quantity and quality while effectively managing natural resources such as water and fertilizer. Wireless sensor networks, the backbone of IoT-based smart agricultural infrastructure, gather ecosystem data and transmit them to sinks and drones. However, challenges persist, notably in network connectivity, energy consumption, and network lifetime, particularly when facing supernode and relay node failures. This paper introduces an innovative approach to address these challenges within heterogeneous wireless sensor network-based smart agriculture. The proposed solution comprises a novel connectivity management scheme and a dynamic clustering method facilitated by five distributed algorithms. The first and second algorithms focus on path collection, establishing connections between each node and m-supernodes via k-disjoint paths to ensure network robustness. The third and fourth algorithms provide sustained network connectivity during node and supernode failures by adjusting transmission powers and dynamically clustering agriculture sensors based on residual energy. In the fifth algorithm, an optimization algorithm is implemented on the dominating set problem to strategically position a subset of relay nodes as migration points for mobile supernodes to balance the network’s energy depletion. The suggested solution demonstrates superior performance in addressing connectivity, failure tolerance, load balancing, and network lifetime, ensuring optimal agricultural outcomes.