## 3 Materials and Methods
### LoRaWAN Protocol  
LoRa is a wireless modulation for long-range, low-power, and low-data rate applications developed by Semtech. LoRaWAN is a network protocol that belongs to the set of LPWANs specified in [13] by the LoRa Alliance, which uses LoRa modulation in its physical layer. In the new specification (version 1.1), a join Server (JS) was added in order to make communications more reliable and secure, being responsible for storing several keys. LoRa devices (nodes) are located around the different gateways. Gateways then connect to servers (to the network) using IP connections, bridging the devices and the network (backend). The devices use different channels and binary rhythms depending the request. By LoRa modulation, the change in this binary rhythm is promoted through an Adaptive Data Rate (ADR) scheme specific to the LoRaWAN network. A representation of the LoRaWAN stack can be seen in Figure 2.  
The LoRa application layer is composed of data from various actuators and sensors on the device. The LoRa Medium Access Control (MAC) layer is responsible for managing the network. This management obeys the type of device class used. Medium Access Control (MAC) commands allow us to make changes or check the status from the web. The LoRa Modulation layer concerns the type of modulation used, which is usually modulation LoRa. LoRaWAN also provides the use of frequency-shift keying (FSK) modulation. The Industrial, Scientific and Medical (ISM) band concerns a set of specifications of the frequency band of a given region, namely the frequencies and bandwidth of the transmission channels and a set  
Figure 1: LoRaWAN architecture (adapted from [62]). Figure 2: Stack LoRaWAN (adapted from [13]). of rules to be respected. Among these rules are the duty cycle allowed per channel and the timing of entry into sleep and active modes. EU863-870 MHz is an example of a European ISM band. The gateway bridges the device and the network and translates LoRa messages from the physical layer to IP protocol messages. Before an end device (LoRa Node) can communicate on the LoRaWAN network, it must be activated and the following information is required [13]:  
* **Device Address (DevAddr):** This is a 32-bit identifier that is unique within the network, present in each data frame and shared between the end device, network server, and application server. This differentiates nodes within the network, allowing the network to use the correct encryption keys and properly interpret the data. * **Network Session Key (NwkSSKey):** This is a 128-bit AES encryption key that is unique per end device and is shared between the end device and network server. This provides message integrity for communications and provides security for end device to network server communication. * **Application Session Key (AppSKey):** This is a 128-bit AES encryption key that is unique per end device and is shared between the end device and application server. This is used to encrypt/decrypt application data messages and to provide security for application payload. The LoRaWAN protocol defines three classes of devices (A, B and C) with different functionalities. The LoRaWAN network must be prepared to handle devices of all classes. * **Class A:** All devices on the LoRaWAN network need to implement the functions described by this class, even those of class B and class C. Class A devices send information at their discretion (ALOHA). ALOHA is a specific type of MAC that is characterized by sending packets through the terminals when there is information to send from higher layers. As such, collisions can occur when there are simultaneous transmissions, since the medium is shared and not dedicated. In the case of not receiving a message, this type of MAC waits a certain time, called backoff, in order to retransmit the packet. * **Class B:** In addition to the capacity of class A devices, these devices are characterized by opening windows of extra time (ping slots) at defined time intervals. So, more data from the servers can be forwarded to devices in this class.