Wireless Sensor Networks (WSNs), enablers of the Internet of Things (IoT) technology, are typically used en-masse in widely physically distributed applications to monitor the dynamic conditions of the environment. They collect raw sensor data that is processed centrally. With the current traditional techniques of state-of-art WSN programmed for specific tasks, it is hard to react to any dynamic change in the conditions of the environment beyond the scope of the intended task. Cooperation between Software-Defined Networking (SDN) and WSN has been proposed. The parameter of network life and reduction of energy consumption is one of the most critical challenges of software-based wireless sensor networks. There are many ways to reduce energy consumption in wireless sensor networks, each with advantages and disadvantages. Given that the network we are looking at is software-defined, it allows us to differentiate network traffic, and this traffic separation allows us to differentiate between traffic and routing to reduce consumption. Energy Benefit from the difference between traffic and assign a route to it based on the type of traffic. To differentiate the type of traffic, we will also use machine learning to do this in the best possible way and have better results than the methods previously used to reduce energy consumption. The present study integrates terms of SDWSN and machine learning (ML), known as ML-SDWSNs. ML-SDWSN ensures a resource-aware, smart, centralized framework for obtaining developed network performance and also solves issues recognized in applicable SDWSNs’ performance. The results show that the accuracy of the proposed method achieved 98 %, which has improved by 11% compared to the other methods.