# Collision Avoidance Resource Allocation for LoRaWAN
## 7 Proof-of-Concept  
As a proof of concept, we implemented CARA in an experimental testbed, part of the demonstrator developed for project A-TIC-241-UGR18 \"Architecture for IoT networks oriented to environmental sustainability\", funded by the Andalusian Knowledge Agency. Our testbed consists of 30 nodes connected to one LoRaWAN gateway, which in turn is also connected to the corresponding LoRaWAN network and application servers. The nodes are based on the Pycom's FiPy development board [21], which is a multi-technology board (supporting Wi-Fi, BLE, LoRaWAN, SigFox and LTE-M/NB-IoT) with an ESP32 SoC. The LoRaWAN gateway is an IMST Lite Gateway [22], which contains a Raspberry Pi connected to an IMST ic880A LoRaWAN concentrator for the ISM 868 MHz band. We employed the Chirpstack platform [23], which provides open-source components for the LoRaWAN networks (network server, application server, gateway bridge, among others). Figure 13 presents the network architecture for our proof-of-concept. As shown, a LoRaWAN network was deployed using the aforementioned nodes, gateway and servers. On top of this network, we implemented a CARA server, which is responsible of assigning the initial resource blocks for each node that joins the system. In addition, we also modified the firmware of the nodes in order to include the signaling handling and the resource block selection for each transmission. Since we do not have access to the source code of the MAC layer in the nodes, we implemented the required signaling at the application layer. The CARA server is programmed using Python 3, and implements:  
* An **MQTT listener** (subscriber) for messages from the application server. This allows the CARA server to receive signaling from nodes, that is, the Join-Request messages. * A **signaling handler** which generates Join-Accept messages as a response for the received Join-Request frames. For that purpose, it uses the Chirpstack network server  
Figure 12: PER comparison coexistence LoRaWAN vs. C.A.R.A. RESTful API [24]. This handler communicates with the resource assignment logic to obtain the available spreading factors (\(\overline{SF_{i}}\)) and the initial resource block (\(RB_{i}\)) for the node, parameters included in the Join-Accept. * A **database client** to store and retrieve the current status of the CARA algorithm from a Postgresql database. In this database we store, for each node, its identifier (DevEUI), the initial resource block, the spreading factors that the node has available (in the form of a binary SF mask, in which 1 means that the SF can be used, 0 otherwise), and the time when the node was last seen (in order to remove that node from the CARA calculations after a configurable time without receiving data from that node). * The **CARA resource assignment logic**, which checks which is the resource block with lowest assignments to be employed for the next node, considering which SFs are available. Nodes are programmable using Micropython with the Pycom's LoRa API [25]. We modified the devices' firmware to include the following functionality (source code available at [26]):  
* Since we do not have access to the source code of the MAC layer in order to include DeviceTime MAC commands, **node synchronization** is achieved by using the NTP protocol through a Wi-Fi connection. * **Experiment parameters** are also sent over Wi-Fi to customize the testbed nodes. * Nodes connect to the network using Over the Air Activation (**OTAA**). Activation By Personalization (ABP) has also been successfully tested. * **CARA signaling** has been implemented on the node's side. As soon as the node joins the network, it sends a Join-Request message to the application server. After this, it waits the reception of a Join-Accept message with the initial RB and the available SFs. Both messages are sent as application frames. If a Join-Accept is not received after a configurable time, the Join-Request is retransmitted. * After this signaling, we assume a random time between packets for **traffic generation**.