## 4 Proposed SDN-Based Energy-Aware Routing Protocol  
In recent years, Industry 4.0 has gained great popularity in the manufacturing field. Nodes are a primary technology in this industry due to the central role of data exchange. In general, nodes relay and forward data to other nodes in the sector; thus, energy is spent on both transmitting and receiving data. Since wireless mobile nodes depend on the batteries equipped within, the life of these batteries is critical. In particular, it affectsthe energy consumption of the whole wireless network as well as the duration of the data transmission. Traditionally, routing strategies have been based on the shortest-path criterion, which uses optimal (shortest) paths no matter the nature (or state) of the nodes. Consequently, nodes used large amounts of their energy to exchange huge amounts of data, and the batteries of the mobile, wireless nodes become exhausted. In order to solve this issue, we have developed a SDN-based energy-aware routing protocol for WSNs that allows the SDN controller to estimate the energy level of critical nodes in the WSN and decide the best routing path based on their energy consumption and battery state rather than on the shortest-path criterion. In the proposed routing approach, the battery level is the primary factor in deciding the path. At the beginning of transmission, the battery is assumed to be fully charged for all the access points. During transmission, the access points' battery levels decrease as the amount of traffic is transmitted through them. If any access point reaches a critical battery level, the SDN controller will decide to change the routing path. The proposed method distinguishes itself from the traditionally used routing techniques since it can be used in access points and stations in the industry without turning off the devices with low batteries. It is important to highlight that the proposed routing strategy takes care of the energy of access points, not the data center, within a wifi environment. Figure 5 shows the components of the proposed approach, which works as follows. The sensor senses the data, processes them, and proceeds to the access point to transmit them. In order to transmit the data, the access point needs to know the appropriate path according to the energy level of the other components in the network. To this end, the SDN controller estimates the amount of energy consumed in each node based on the number of bytes sent and received and assigns the right path to deliver data traffic based on the estimated battery level. In the proposed algorithm, the battery level of WSN is considered to change the path. The amount of battery consumed affects the energy consumption. This assignment is focused on making the node live longer to reach the following objectives:  
* Prevent the waste of energy and sources, thus improving the efficiency in terms of energy consumption;
* Make the transmission time last longer;
* Avoid the need to replace batteries, which are usually difficult to access. Figure 5: Components of the proposed SDN-based energy-aware routing protocol. The pseudocode of the algorithm developed to implement the proposed routing protocol is provided in Algorithm 1. Algorithm 1 has four functions: TopologyDiscovery(), TrafficGenerator(), EnergyEstimation(Power,Byte), and PathSelection(AP,Path). It works as follows. Initially, TopologyDiscovery() determines the network topology; the function result sets the number of access points and stations. Subsequently, TrafficGenerator() generates user datagram protocol (UDP) traffic from the first node in the network to the last one, independently of the chosen path. The energy at each access point is estimated by EnergyEstimation (byte, time) based on the number of transmitted bytes and the power consumption. If an access point's power reaches its maximum level (denoted as \(MaxEnergy\) in Algorithm 1), the PathSelection() function will choose the path depending on the energy consumption. ```
Functions: TopologyDiscovery(): determines the network topology.