# Routing Algorithm for Sensor Network Monitoring the Condition of Mining Equipment
## 6 Subsequent Modifications to Implement the Developed Algorithm  
In a further step, the Algorithm 1 (SSAM--sensory swarm autonomous monitoring) was implemented into the extended sensor network. The algorithm is based on the pso algorithm and uses elements of the ant algorithm. Figures 8 and 9 show the first step of the algorithm, which will allow each node (Figure 8) to select its best neighbour (Figure 9), according to the objective function. In the first stage of network initialisation, NODE-type nodes send broadcast messages informing about their state to neighbouring nodes (i.e., nodes within their radio range). Information is transmitted about the state of the battery, the number of hops to the SINK node and the RSSI signal power level. At the same time, each node receives information about its neighbours and transmits it to the SINK node. The SINK node, analysing information about all nodes in the network and their neighbours, carries out the various procedures involved in the swarm algorithm. In the first phase, the position and velocity are randomly determined in the range from 0 to 1. Depending on the new position calculated according to  
Figure 8: Example network structure. Figure 9: Paths taken by packets after the first iteration of the routing algorithm. the routing algorithm, the neighbouring node to which the data will be sent is determined (see Figure 9). Initialisation:  
1. Initialise the parameters of the PSO algorithm, such as number of particles, number of iterations, weighting co-factors, etc. 2. Initialise the pheromone values for each node in the sensory network. 3. Randomly initialise the positions of Pi particles in a D-dimensional space, where D is the number of nodes in the sensory network. For each iteration until the stop condition is reached:  
4. For each Pi particle:  
a. Calculate the objective function for the current position of the Pi particle based on the sensory network. b. If the objective function is better than the best value found so far, update the particle's best position. c. For each neighbouring node with a Pi particle, update the pheromone weights based on the ACO algorithm. 5. For each Pi particle:  
a. Update the particle's velocity and position according to the equations of the PSO algorithm. 6. For a SINK node:  
a. Calculate for each neighbouring node the index of the target node based on its number of neighbours and the position of the Pi particle. b. Select a suitable neighbour based on the calculated index. c. Pass the information about the selected neighbour to the NODE nodes that send data to the respective SINK node. Stop condition:  
7. Check the stop condition, e.g., reaching the maximum number of iterations or the set value of the objective function. Return the best particle position found, which corresponds to the optimal sensory network configuration. **Algorithm 1. ** SSAM: The Pseudocode of the algorithm is as follows  
In step 6a, for a SINK node, we calculate the index of the target node based on the number of its neighbours and the position of the Pi particle. Then, in step 6b, we select the appropriate neighbour based on the calculated index. In step 6c, we pass the information about the selected neighbour to the NODE-type nodes, which then send the data to the respective SINK node. This procedure ensures that the information about the selected neighbour is passed to the NODE-type nodes. Currently, the network data path determination procedure is activated at specific time intervals, which are configurable. The main algorithmic calculations are performed in a SINK node, which can be connected to the mains power supply (and therefore has a high computing power). **7. Implementation in the Extended Network**  
Figure 10 illustrates a test bed designed for a network with an increased number of nodes. Tests are planned for a network of 30 nodes.