# A Resilient LoRa-Based Solution to Support Pervasive Sensing
## 4 Our Proposed Solution
### Synchronization among Nodes  
As previously noted, our network possesses self-management capabilities, eliminating the need for external initialization. Initially, when a device is powered up, it retrieves vital initialization information to guide its operational parameters, essentially configuring  
Figure 2: Flow chart of our solution.  
settings that influence its behavior. These data are derived from the configuration file, which dictates subsequent actions, instructing nodes on whether or not they need to establish a Bluetooth connection with a sensor device or initialize the GPS to obtain geographical coordinates. In an effort to conserve energy, the device is designed to automatically deactivate non-essential features, such as the LED light and Wi-Fi antenna, if they are not in use.  
After the initial setup is finished, the node starts listening for advertisements from an existing mesh network for some time. If one is received, the node requests to join the network. Otherwise, if no advertisement is received in that window of time, the node creates a new mesh network, with itself as the only node present.  
After the node is in a mesh network, it enters an endless loop running the main code of the device. Every action the nodes execute is preceded by a check on the time reported by the real-time clock (RTC) internal to the device. This clock is initialized when the node enters the mesh network: it uses an arbitrary value if the node is creating the mesh or it is sent over by the node that is bringing the device onto the existing network. Since the clock is shared with other nodes, every network device reports more or less simultaneously. This allows us to have a well-defined receive window, meaning that a node will send out a message only when it knows the receiver is listening. This synchronization allows nodes to save power by avoiding retransmitting packets that have not been received due to the other node not listening. To ensure the clock's consistency, some nodes broadcast their clock value and keep all nodes in sync. The node that creates the network initializes its internal clock with an arbitrary time and date since, in our solution, we did not focus on connecting the network to the Internet. Our implementation can easily be extended to have a node connected to the Internet and communicating with a server or a cloud infrastructure to exchange data and commands, as well as to retrieve the current time.  
Inside the endless loop, each node will perform many actions, but it will mainly accomplish the following:  
* Advertise the mesh network and bring in new nodes;
* Retrieve data from the connected sensor;
* Listen for messages.  
Other actions a node can perform are generally tied to the ones listed above, controlled by what is in the config file, or performed to maintain the mesh network alive and reliable. For example, a node may respond to a message containing sensor data since it requires an acknowledgment, forward a message to the correct node, or retrieve its GPS coordinates. Every action requiring interaction with other nodes is performed after checking the current time in order to exchange messages only during the scheduled receive window.