# LaRaWAPS: A Wide-Area Positioning System Based on LoRa Mesh
## 4 System Design
### LoRa Ranging and Localization
#### 4.3.1 Positioning Workflow  
It is important to note that standard LoRa hardware has only one RF channel. To carry out the ranging operation, the packet-type parameter of SX1280 should be set from LoRato LoRa Ranging. This means that nodes cannot communicate during ranging. If the workflow of the system is not correct, some nodes in a path that is transmitting data may be in ranging mode, which will cause the data transfer to fail. Therefore, the positioning workflow of the system is very important.  
We have taken mode switching of LoRa into consideration and designed the workflow of system positioning, as shown in Figure 7. The gateway sends the positioning instruction, and the anchor points in the network broadcast and forward the positioning instruction after receiving it. The target is usually in a standby state to save energy consumption. After receiving the positioning instruction, it will record the anchor information of the surrounding forwarding positioning instruction and apply it for joining the network. In the next stage, the target initiates ranging to the surrounding anchor points, until all the surrounding anchor points complete ranging, all the results are sent to the gateway, and the target returns to the standby mode.  
Since the target may be moving, they need to find the anchor node currently around before each ranging. Therefore, the authors broadcast location instructions to the node. When the target receives a broadcast location instruction for the first time, it updates the routing table and collects all broadcast instruction packets from the neighbor node. If the number of nodes around is enough to obtain location results, the label responds to the gateway and starts its ranging work.  
Figure 7: Positioning workflow.  
Figure 7 also shows that, during ranging, the target acts as the master role, and the other anchors act as the slave role. This is because only the target knows the link status information of all surrounding anchors. The target records the corresponding RSSI value when receiving broadcast packets from surrounding anchors and sorts the anchors in order of RSSI value. The target will preferentially range anchors with good signal quality (high RSSI value). At the beginning of ranging with one anchor, the target sends a ranging request to the anchor and waits for the reply. If no reply is received within the resend interval time, the target will resend the packet. For anchors, if it receives a ranging request from the target and is ready for the ranging, it replies to the target directly and waits for a resend interval time to listen if a ranging request comes again, which avoids the loss of reply. If target receives the right reply to the request, it switches to the ranging master mode, and will take an extra resend interval time for the anchor to switch to ranging slave mode. Both the master mode and slave mode have a timeout exit mechanism if no action takes place.  
For anchors that are far away from the target, communication or positioning of other targets can be carried out as usual, so that the whole system can carry out both communication and positioning tasks at the same time.