Adaptive Machine Learning-Driven Routing Framework for Secure and Energy-Efficient Wireless Sensor Networks
Abstract:
Predictable routing schemes in Wireless Sensor Networks (WSNs) often suffer from limited scalability, poor energy efficiency, and inadequate adaptability to dynamic network conditions. These limitations reduce the reliability of data transmission and shorten the network’s operational duration. To overcome these challenges, this study develops an adaptive routing framework driven by diverse machine learning (ML) techniques—including supervised learning, reinforcement learning, and regression models—to intelligently select energy-efficient, congestion-aware, and secure routing paths. By continuously learning from network feedback on topology changes, node energy levels, and traffic load, the routing algorithm dynamically optimizes path selection. Simulation experiments demonstrate that the proposed approach significantly outperforms traditional protocols in Packet Delivery Ratio, Energy Consumption, End-to-End Delay, Throughput, and Network Lifetime. Furthermore, the integration of anomaly detection mechanisms using behavioral analysis enhances security by identifying and isolating malicious nodes in real time. The results confirm the effectiveness and scalability of ML-driven routing for next-generation Internet of Things (IoT) and WSN infrastructures. Future work will explore real-world deployments and extended security features.1. Introduction
Wireless Sensor Networks (WSNs) are unstructured networks made up of sensor nodes connected in an ad hoc fashion, as shown in Figure 1. WSNs are employed to keep an eye on the system, the surroundings, and the physical world. Many modern Internet of Things (IoT) applications rely on WSNs [1]. They let you collect and look at data in a lot of different places, such smart cities, healthcare, environmental monitoring, and industrial automation. Several sensor nodes make up these networks. They operate together to see, evaluate, and transfer data to base stations or sinks that are all in one area. But it's really hard to create appropriate routing protocols for WSNs since the sensor nodes don't have a lot of power, the network topologies change, and the data has to be sent reliably.

Traditional routing protocols are effective under some circumstances, but in general do not consider the energy constraints, scalability and flexibility required by WSNs. Sensor networks are such that, their topologies change frequently and their node's energy reserves vary dynamically. This implies that routing policies have to be dynamically adjusted to the particular situation of a network at a given point in time. In order to meet these needs, ML methods were proposed that would enable sensor nodes to learn from their environment and use data -driven routing decisions.
Ad hoc On Demand Vector (AODV), RPL and Dynamic Source Routing (DSR) are all very common routing protocols that are suitable for most situations, but don’t work so well they are task specific to WSN. AODV has high control overhead and doesn’t scale well with the number of users, RPL load balances badly when the topology changes drastically, while DSR does not update itself as rapidly as network changes. Taken together, all of these issues drag the life and energy use of the networks down.
Routing approaches three subcategories under this approach in the past few years, a lot of machine learning-based routing schemes have been proposed that exploit neural networks, reinforcement learning, genetic algorithms (GA), fuzzy logic and some other heuristic in order to obtain optimal routes based on energy consumption. Congestion control and QoS or Quality of Service [2], by accounting for local state information, e.g., remaining energy, buffer status and network load, these techniques enable nodes to estimate the best paths. This minimizes overhead message and extends the life of the network. It also provides the ability to employ adaptive routing algorithms which can learn and bypass nodes occupied or low in energy. This in turn speeds up the bullets and reduces latency/loss packets.
However, WSN routing involves some challenges while using ML such as the need for labeled training data to train the model, limited computational power of sensor nodes [3] and a need for lightweight algorithms that balance accuracy with resource consumption. Nonetheless there are a number of ways machine learning can benefit the performance of WSNs. However, now researchers are more worrying about how to design routing protocols which should be scalable, efficient and reliable under the very large scale and highly non-uniform sensor networks.
Consequently, the objectives of this study are as follows: (i) to design an adaptive ML-driven routing protocol tailored for WSNs; (ii) use supervised, reinforcement and regression machine learning models in order improve routing decisions, thus leading to more efficient performance maximization; (iii) improve security by detecting anomalous behavior in the network and finally, and iv) confirm that performance improvements have been achieved over key metrics like data delivery reliability, delay, throughput and network lifetime through extensive simulation. We have designed a hybrid ML-based framework for routing, enabled continuous on-line learning for dynamic adaptation, and conducted rigorous benchmarking to show that we outperform state-of-the-art protocols. These are some of the main things that worked.
2. Related Work
Routing in WSN is a critical issue, due to the limited energy resources, dynamic topology and need for reliable data delivery. Traditional routing mechanisms can rarely achieve the maximum use of energy consumption and network lifetime. To address these challenges, the emerging works resort to machine learning (ML) techniques towards enabling adaptive and energy efficient routing protocols as well as improving network performance.
Routing in wireless networks (WSNs as well as other LPLN) is very difficult because of dynamic topology, constrained energy, congestion and QoS requirement variations [1].
Nayak et al. [1], also introduced the problems and challenges of using ML in WSNs routing. They argue that ML solutions (i.e., genetic algorithms, fuzzy logic and deep learning) can take into account congestion explicitly, load balance in a functional manner and deliver traffic at the pace desired by modifying network conditions. The authors mention that ML methods avoid the drawbacks of static routing as they operate decision process in an online manner based on the instantaneous state of the network.
Ding et al. [4] gave a broad visceral perspective of ML based energy efficient routing algorithms in WSNs. They show that reinforcement learning combined with neural networks and multi-agent decision can result in distributed collaborative routing decisions among sensor nodes, resulting in better energy consumption (lifetime) and quality of service metrics such as packet loss delay. These ML-based models take the local link status dependent parameters (i.e., remaining energy, packet error rate etc.) into account and discover the optimal dynamic routing alternatives dynamically. This prolongs the network since of life.
A study recently reported by Sattibabu et al. [5], they focused on energy-efficient routing protocols on more machine learning, and reminds that the primary job of wireless sensor networks (WSNs) routing is to try to save as much energy as possible. They push forward that ML-based mechanisms dynamically schedule routes by anticipating at which time nodes are running out of their energy and as an additional to when traffic becomes overloaded, in order to further extend the lifetime and robustness of the network.
In addition to energy efficient [6], ML for security, geolocation and anomaly detection have been employed in WSNs.
Another recent study [7] investigated the influence of ML-based routing protocols on data load overhead. It shows that supervised, unsupervised and reinforcement learning methods are pervious to environmental changes with less energy consumption and congestion.
Many classic routing algorithms aren’t smart or adaptable when it comes to these problems. Advanced information processing technologies, such as the ML based solution that nodes can learn from network states and deterministically prevent decision-making in routing combinations have been proposed. It improves energy efficiency, packet delivery ratio and delay minimize human intervention, network overhead [7], [8].
Issues encountered and solved by emphasizes ML methodologies embedded into routing protocols for WSNs such as energy save, conformation, congestion control or security are precisely elaborated. This one is for discussing and dissembling apps. The ML based adaptive routing method is grounded in the literature and necessary contributions.
Supervised Learning: In gradient boosted decision trees (like CatBoost) we learn what is the probability of a packet successfully being delivered over all possible paths. This allows nodes to select the most secure roads [9].
Reinforcement Learning (RL) Q-learning and Deep Q-Network (DQN) agents learn the optimal routing policy at a node by interacting with the network environment. They do so by learning to optimize long-term goals that are related to energy efficiency, latency, and throughput [10], [11].
Regression Models: Random Forest Regression (RFR) forecasts future bandwidth availability across many pathways to mitigate congestion and enhance flow allocation [12].
Hybrid Models: These are models that combine supervised and reinforcement learning approaches or include anomaly detection models to make routing and security more reliable [13], [14].
Alanazi et al. [15] investigated a machine learning-based routing methodology intended to improve energy efficiency in wireless sensor networks developed for 6G technologies. Their research is on refining routing choices to satisfy the rigorous energy demands of next-generation networks.
Akinola [16] described adaptive routing techniques that use location awareness for wireless sensor networks that function in changing urban cyber-physical settings. The suggested protocols use real-time contextual information to make routing work better in cities that are always changing and are very complicated.
Priya et al. [17] provided a comprehensive examination of energy-efficient routing algorithms in wireless sensor networks, classifying them by their processes and evaluating their advantages and disadvantages. They stress how important machine learning will be for making routing protocols better in the future.
Shokouhifar et al. [18] examined artificial intelligence applications in cluster-based routing for wireless sensor networks, including fuzzy logic, metaheuristic algorithms, and machine learning methodologies. The review elucidates the relative advantages and difficulties of several AI methodologies for route optimization.
Yang et al. [19] provided an intelligent routing system that integrates swarm intelligence with deep reinforcement learning. This hybrid approach seeks to dynamically adjust routing pathways to improve energy efficiency and the overall lifespan of the network.
Osamy et al. [20] analyzed contemporary research using artificial intelligence to address routing issues in wireless sensor networks. Their review talks on several machine learning methods that make networks more stable and energy-efficient by improving sensor grouping and routing choices.
The limited processing power of sensor nodes, the difficulty in getting enough training data, the complexity of the models, and the possibility of higher communication overhead are all reasons why ML-based techniques can't be used in WSNs, even though they would be very useful. For these reasons, there has to be ongoing research on ML algorithms that are efficient, scalable, and lightweight, and that can learn within networks while being aware of the resources that are available [1], [3].
3. Routing Protocol Design and Implementation
Dynamic Source Routing (DSR) and AODV are two example protocols using the real-time status information broadcasted by each node to discover potential paths for sending data. These techniques are used as a first step in route construction before ML driven evaluation and selection.
The routing protocol based on machine learning works in these steps:
Route Discovery: Use the updated state information from all the nodes to find the different possible pathways to the goal.
Route Evaluation: The machine learning algorithms look at these pathways and rate them based on how likely they are to deliver on time, how much energy they use, how congested they are, and how trustworthy they are.
Route Selection: Choosing the route that is most likely to be the most efficient and reliable for sending data.
Adaptive Data Recovery: Using the properties of ML-predicted channels, cyclic redundancy check (CRC) techniques are changed on the fly to get back lost data and cut down on retransmissions.
Security Integration: To make sure that routing is safe, anomaly detection models are utilized to find and isolate bad or malicious nodes.
Continuous Learning: Reinforcement learning agents alter routing strategies depending on how well transmissions go, how much energy is used, and how the network evolves.
We test the suggested strategy by running a lot of simulations using tools like NS-3 or MATLAB. The Performance measures include the Packet Delivery Ratio (PDR), the End-to-End Delay, the Energy Consumption and Network Lifetime, the Throughput and Congestion Levels, and Metrics for Security: Rate of detecting attacks and false positives
We compared our work with traditional routing protocols (such as RPL and AODV) and current ML-based methods. The results show that routing is more efficient, latency is lower, energy is saved, and the system is more resilient to network problems and assaults.
The method starts with putting out sensor nodes and setting up network settings. Each node then collects and shares important status information with its neighbors. After that, historical network data is combined and utilized to train different machine learning models, such as those that can forecast if packets will be delivered successfully, whether bandwidth is available, and whether there are any problems. After being trained, these models are used to help make routing choices in real time. This lets the system choose the best pathways, recover data on the fly, and keep an eye on security. The framework also has ways for the models to keep learning, so they can be updated with new data as it becomes available, and it makes sure that these changes are sent out quickly. To make the system even better, performance indicators like delivery ratio, latency, energy use, and security are always being watched. Figure 2 shows a complete process for utilizing machine learning to improve routing pathways in a sensor network.
Algorithmic
Step 1: Initialize network and collect node states
Step 2: Train ML models offline with historical data
Step 3: while network operational do
$\quad$for each data packet
$\quad$Discover candidate routes
$\quad$for each route
$\quad$Evaluate route using ML models end for
$\quad$Select optimal route based on composite score
$\quad$$\quad$Adjust CRC parameters adaptively
$\quad$$\quad$Forward packet along selected route
$\quad$$\quad$Update RL policies based on feedback
$\quad$$\quad$Detect and isolate malicious nodes
end for
$\quad$Periodically fine-tune ML models online
$\quad$Monitor network performance and optimize parameters
$\quad$end while.

4. Results and Discussions
The first step involves modeling the Wireless Sensor Network as a graph where nodes represent sensor devices and edges represent wireless communication links. Each node collects local state information such as residual energy, buffer occupancy, link quality (e.g., RSSI, SNR), node location, and traffic load. This data is continuously logged and forms the basis for training machine learning (ML) models. Environmental parameters, such as channel impulse response (CIR) and interference patterns, are also recorded to improve routing robustness and adaptive data recovery.
Using the collected network data, offline training of various ML models is performed. Supervised learning models like Gradient Boosted Decision Trees (e.g., CatBoost) are trained to predict the probability of successful packet delivery for candidate routes. Reinforcement learning agents (Q-learning or Deep Q-Networks) learn optimal routing policies by maximizing cumulative rewards based on energy efficiency, delay, and throughput. Regression models such as Random Forest Regression predict future bandwidth availability to avoid congestion. Additionally, anomaly detection classifiers are trained to identify and isolate malicious or faulty nodes, enhancing security. This multi-model training strategy follows the distributed and modular ML framework recommended in recent research and simulation toolkits.
Once trained, the ML models are integrated into the routing protocol within the simulation environment. For example, in NS-3, MAT LAB or OMNeT++, the routing agent queries the ML models during route discovery and evaluation phases. Nodes broadcast their current states, and the source node identifies multiple candidate paths to the destination. Each candidate path is scored based on ML model predictions, including delivery success probability, predicted bandwidth, energy availability, congestion level, and security trust scores. The path with the highest composite score is selected for packet forwarding. This integration is supported by frameworks that allow external ML models (Python, R) to interact with network simulators.
This adaptive data recovery cuts down on retransmissions and saves energy. At the same time, anomaly detection models keep an eye on how nodes behave all the time to find malicious actions or malfunctions. If a node is hacked, it is isolated to keep routing pathways safe. This dual emphasis on dependability and security is in line with recent improvements in ML-enhanced routing protocols that include adaptive error control and anomaly detection.
Reinforcement learning agents implemented at nodes dynamically adapt their routing strategies on-line based on feedback carried by packets, i.e., success or failure, energy, latency and congestion features. This continuous learning allows the routing protocol to adapt to the evolving network conditions such as topology, traffic and node failures. To ensure that ML models remain accurate and responsive, they are retrained or fine-tuned on a periodic basis. As advocated in MAS and SDN-oriented architectures, distributed learning and control can help make systems more scalable and faster to adapt.
Parameter | Value |
|---|---|
Number of nodes | 50-100 |
Simulation area | 500 m $\times$ 500 m |
Transmission range | 50 m |
Initial energy per node | 100 Joules |
Traffic type | Constant Bit Rate (CBR) |
Packet size | 512 bytes |
Simulation time | 1000 seconds |
Mobility model | Static or Random Waypoint |
Channel model | Log-distance path loss |
The entire ML-based routing protocol is evaluated through extensive simulations using NS-3, OMNeT++, or MATLAB and the simulation parameters in Table 1. Performance metrics such as Packet Delivery Ratio, End-to-End Delay, Energy Consumption, Network Lifetime, Throughput, and Security Detection Rate are collected and analyzed. Results typically show that ML-based routing outperforms traditional protocols by improving reliability, reducing latency, conserving energy, and extending network lifetime. The modular design allows benchmarking against standard protocols like AODV and RPL, validating the effectiveness of the ML integration.
Time dependent PDR comparison on ML-Based Routing and Traditional Routing in wireless network. Both approaches begin with the initial 50% PDR at time zero however the ML-Based Routing approach soon surpasses old school method, achieving a PDR of over 90% by 500 s. The old way, on the other hand, is resting at just about 80%. This indicates that ML-Based Routing critically improves data delivery over network operation. It is quickly responsive to the variations that can occur within a network and keeps a more harmonized and standard PDR over time, as compared with the previous routing protocol shown in Figure 3, Table 2. This is strong evidence of the capacity for machine learning to enhance wireless network routing both in performance and reliability.

Time (s) | PDR (%) ML-Based Routing | PDR (%) Traditional Routing |
|---|---|---|
0 | 50 | 50 |
100 | 85 | 75 |
200 | 90 | 78 |
300 | 92 | 80 |
400 | 93 | 81 |
500 | 94 | 82 |
The analysis of the evolution of energy consumption over time (Min) in ML-Based Routing and Traditional Routing for wireless. Both strategies begin with 0 usage of energy, but Traditional Routing drain energy much more quickly and at time stamp 500 seconds its energy reaches to 65 Joules. ML-Based Routing meanwhile consumes energy more slowly and efficiently, drawing only 38 Joules simultaneously. The significant improvements between them indicate that machine learning-based routing can route more efficaciously for energy saving, load balancing and lifetime extending, comparing with traditional routing protocols as shown in Figure 4 and Table 3.

| Time (s) | Energy Consumed (J) ML-Based | Energy Consumed (J) Traditional |
|---|---|---|
| 0 | 0 | 0 |
| 100 | 10 | 15 |
| 200 | 18 | 28 |
| 300 | 25 | 40 |
| 400 | 32 | 52 |
| 500 | 38 | 65 |
The relationship between end-to-end delay and the number of nodes in a wireless network for both ML-Based Routing and Traditional Routing protocols. As the number of nodes increases from 20 to 100, the end-to-end delay rises for both approaches; however, the increase is significantly steeper for Traditional Routing, which reaches over 100 milliseconds at 100 nodes. In contrast, ML-Based Routing maintains a much lower delay throughout, only reaching about 70 milliseconds at the same scale. This demonstrates that ML-Based Routing is more efficient at managing network congestion and optimizing data paths, resulting in consistently lower delays even as the network grows larger, thereby offering better scalability and performance compared to traditional routing methods as shown in Figure 5 and Table 4.

| Number of Nodes | Delay (ms) ML-Based | Delay (ms) Traditional |
|---|---|---|
| 20 | 15 | 20 |
| 40 | 25 | 35 |
| 60 | 40 | 60 |
| 80 | 55 | 85 |
| 100 | 70 | 110 |
The network lifetime is measured in hours, with traditional routing achieving a lifetime of 50 hours, while ML-based routing significantly extends the network lifetime to 75 hours. This 50% increase demonstrates the effectiveness of ML-based routing in optimizing resource utilization and improving the overall efficiency and sustainability of the network as shown in Figure 6 and Table 5.

| Protocol | Network Lifetime (hours) |
|---|---|
| Traditional routing | 50 |
| ML-Based routing | 75 |
It compares the performance of ML-based routing and traditional routing in terms of throughput under varying traffic loads in a WSN. Throughput, measured in packets per second, consistently increases with higher traffic loads for both methods. However, ML-based routing (blue line) significantly outperforms traditional routing (red dashed line) across all traffic levels. For instance, at a traffic load of 50 packets/sec, ML-based routing achieves a throughput of about 32 packets/sec, while traditional routing only reaches around 22 packets/sec. This clearly demonstrates that ML-based routing is more efficient and capable of handling higher traffic volumes, resulting in improved data transmission performance as shown in Figure 7 and Table 6.
In comparison to conventional protocols, which only manage an 82% Packet Delivery Ratio (PDR) after 500 seconds, ML-based routing reaches a whopping 94% (Table 2). Table 3 shows that energy usage drops to 38 Joules from 65 Joules after 500 seconds. Table 4 shows that conventional approaches reach 110ms for 100 nodes, but ML-based routing keeps it to 70ms. The lifespan of the network is increased from 50 to 75 hours, as shown in Table 5. Table 4 shows that throughput surpasses conventional routing's 22 packets/sec under heavy traffic loads, up to 32 packets/sec.

| Traffic Load (packets/sec) | Throughput ML-Based (packets/sec) | Throughput Traditional (packets/sec) |
|---|---|---|
| 10 | 9.5 | 8.0 |
| 20 | 18 | 14 |
| 30 | 25 | 18 |
| 40 | 30 | 20 |
| 50 | 32 | 22 |
5. Conclusion
In order to alleviate congestion, the suggested protocol employs supervised models to forecast the success of packet delivery, reinforcement learning agents (such as Deep Q-Networks) to optimize routes and dynamically update policies in response to changing traffic loads, and regression models to forecast the availability of bandwidth. By identifying and removing infected nodes, anomaly detection methods improve security and dependability even further. Adapting to changing network circumstances, these integrated ML techniques allow for the selection of routes that are energy efficient, dependable, and congestion aware. Further investigation into cross-layer optimization tactics, the creation of ultra-lightweight ML models for real-time deployment on sensor nodes with limited resources, and the incorporation of blockchain-based security mechanisms to enhance the reliability of WSN routing might be the subject of future study. Another factor that will push for the ML framework's practical acceptance is testing it in diverse and real-world settings.
The data used to support the findings of this study are available from the corresponding author upon request.
The authors declare that they have no conflicts of interest.
