Software-defined wireless sensor networking is an emerging networking architecture envisioned to play a critical role in the looming internet of things paradigm. Since energy is a scarce resource in wireless sensor networks, many energy-efficient routing algorithms were proposed to enhance the network lifetime. However, most of these algorithms lack network stability and reliability in the presence of dead nodes. This paper presents ESRA: Energy Soaring-based Routing Algorithm for IoT Applications in Software-Defined Wireless Sensor Networks, specifically for monitoring environment to address this shortcoming. The proposed ESRA algorithm efficiently selects the network cluster heads to be considered for solving the controller placement problem, intending to achieve network reliability and stability and enhance the network lifetime. The selection of controllers among the cluster heads is formulated as an NP-hard problem, considering the residual energy of the cluster heads, their spatial distance to the sink, and their load or density. To tackle this NP-hard problem, genetic algorithm is adopted to optimize the network lifetime, throughput, latency, and network reliability in the presence of different percentages of dead nodes. Simulation results showed that ESRA outperforms other three state-of-the art algorithms in terms of network lifetime and throughput by 15%, 20%, and 25%, in terms of energy savings by 10%, 20%, and 25%, and in terms of delay by 10%, 15%, and 20%. We also applied the proposed scheme on real networks adopted from the internet topology zoo, which showed promising results compared to other existing works.