## 3 Proposed Algorithmic Approach
### Operation of the Route Generator Application within the Network Prototype
* The controller updates the route periodically at times defined at the beginning. Obtaining the default route node default includes three stages: (i) the data collection stage of each node's battery and received signal strength levels; (ii) the execution stage of the Kruskal or Dijkstra algorithm in the controller; and (iii) the stage where the controller sends the default route to each node. Algorithm 1 defines the following variables and is executed in sensor nodes:  
* **ID_S:** Identifier of the node that sends the neighbor table to the controller. This identifier is also stored within IEEE802.15.4 frames. * **NB:** Node battery level. * **NS:** Frame receive power level. * **ID_D:** Identifier of the predefined route, located in each node. This identifier is also stored within IEEE802.15.4 frames. * **ID_DF:** Node identifier of the node to which the predefined route will be modified. This identifier is also stored within IEEE802.15.4 frames. * **SRC_ADDR:** Source node address. * **DST_ADDR:** Destination node address. * **Neighbor_table:** Stores NB, NS, and ID_S. This table is also stored within IEEE802.15.4 frames. * **Uplink_frame:** Indicates whether a frame travels on an uplink or downlink. ```
Data:\(NB,NS,ID\_D,ID\_DF,SRC\_ADDR,DST\_ADDR,neighbor\_table,\\ uplink\_frame\) Result: Update \(NB\), \(NS\), \(neighbor\_table,ID\_D,\) transmit and receive downlink frames, transmit and receive uplink frames. whiletruedo  node in receiving state; if\(uplink\_frame==false\)then  update \(NB\);  update \(NS\);  update \(neighbor\_table\); if\(ID\_DF==SRC\_ADDR\)then \(ID\_D\gets ID\_D\) of the received frame; else \(DST\_ADDR\leftarrow\)0 xFFFF(broadcast);  node in transmit state;  transmit downlink frame; elseif\(uplink\_frame\)then \(DST\_ADDR\gets ID\_D\) ;  node in transmit state;  transmit uplink frame; if\(generatedataforpc\)then \(DST\_ADDR\gets ID\_D\) ; \(ID\_S\gets SRC\_ADDR\) ;  generate frame using \(neighbor\_table\);  node in transmit state;  transmit uplink frame;
```  
**Algorithm 1**Sensor node pseudocode. Algorithm 2 is instead implemented in the controller and calculates the default routes for each node within the network. ```
Data:\(NB\), \(NS\), \(ID\_D\), \(ID\_DF\), \(SRC\_ADDR\), \(DST\_ADDR\), \(neighbor\_table\), \(uplink\) Result: Update \(NB\), \(NS\), \(neighbor\_table\), \(ID\_D\), transmit and receive downlink frames, receive uplink frames, send data to a computer, send new \(ID\_Ds\). while\(true\)do  node in receiving state; if\(uplink\_frame==false\)then  update \(NB\);  update \(NS\);  update \(neighbor\_table\); elseif\(uplink\_frame==true\)then  send \(neighbor\_table\) data to pc; ifgenerate data for nodesthen ifgenerate a broadcast\(frame\)then \(DST\_ADDR\leftarrow\) 0 XFFFF ; \(ID\_DF\leftarrow\) an address that is not part of the network ;  generate a frame with \(ID\_DF\) and any \(ID\_D\) in its payload;  node in transmit state;  transmit downlink frame(broadcast); ifcalculate new paththen  waiting for execution of the Kruskal or Dijkstra algorithm;  waiting for new \(ID\_D\) from each node; for each node and new \(ID\_D\)do \(ID\_DF\leftarrow\) source address of the node that will receive the information;  generate frame with \(ID\_DF\) and \(ID\_D\) in its payload;  node in transmit state;  transmit downlink frame;
```  
**Algorithm 2**Controller node pseudocode.