Implementation of LORa
Implementation of LORa
ABSTRACT LoRa is a popular communication technology in the Internet of Things (IoT) domain, providing
low-power and long-range communications. Most LoRa IoT applications use the LoRaWAN architecture,
which builds a star topology between LoRa end nodes and the gateway they connect to. However, LoRa
can also be used for the communication between end nodes themselves, forming a mesh network topology.
In this paper, we present a library that allows to integrate LoRa end nodes into a LoRa mesh network,
in which a routing protocol is used. Thus, an IoT application running on these nodes can use the library to
send and receive data packets to and from other nodes in the LoRa mesh network. The designed routing
protocol is proactive, and maintains the routing table at each node updated by sending routing messages
between neighboring nodes. The implemented library has been tested on embedded boards featuring an
ESP32 microcontroller and a LoRa single-channel radio. By using our LoRa mesh library, nodes do not need
to connect to a LoRaWAN gateway, but among themselves. This opens the possibility for new, distributed
applications solely built upon tiny IoT nodes.
This work is licensed under a Creative Commons Attribution 4.0 License. For more information, see https://creativecommons.org/licenses/by/4.0/
113158 VOLUME 10, 2022
J. M. Solé et al.: Implementation of a LoRa Mesh Library
a problem in scenarios where the geographic scale of the In this paper, we aim to make a significant step forward
end nodes is large and the density of gateways is low. While in the public availability of ready to use code that allows to
increasing the number of gateways can be considered as a deploy LoRa mesh networks. In particular, we present our
solution to the problem, it is not always possible due to the library code-named LoraMesher, which we have developed
economic cost or the geographic conditions. in order to deploy LoRa mesh networks operating a rout-
Devices used for event-based or periodic data transmission ing protocol as proposed in [7]. The library is implemented
to the gateway are categorized as class A end node [4]. There- in C++ and is conceived to be a part of an application
fore, the LoRa traffic from applications using devices of such code that runs on an IoT node consisting of an embedded
class is mostly on the uplink channel, i.e., LoRa packets from microcontroller and a LoRa radio. Having the LoRaMesher
the data sources (end nodes) sent via radio to the LoRaWAN library integrated within the IoT code running on such a node,
gateway and, from there, over the Internet towards the cloud. an application is able to connect to a LoRa mesh network and
After sending a LoRa packet, these end nodes open two short send, route and receive LoRa packets from the nodes within
reception windows to get any downlink messages from the the network.
gateway, which are optional. Since in LoRaWAN the down- The main contributions of this paper are:
link messages from the gateway are linked to the uplink mes- • We describe the design and implementation of the
sage from the sensor, instantaneous pushes of notifications to LoRaMesher library for deploying LoRa mesh networks
the sensor node are not immediately available. Also, the fact which include a routing protocol.
that in LoRaWAN the field for the Cyclic Redundancy Check • We evaluate the library performance in experiments with
(CRC) of the payload is only available in the uplink LoRa different topologies using real hardware nodes.
packet makes the downlink packet less of a reliable element The main potential of this library, which is freely available
in the data transmission. IoT application based on LoRaWAN as open source code,2 is to enable a new class of distributed
often aim at centralized decision-making, with the purpose applications that can run only at the IoT layer using LoRa
of the sensor nodes solely being to send data to cloud-based interconnected nodes.
services. Decisions are taken after the cloud-based processing
of the sensor data. Other application scenarios, however, con- II. DESIGN AND IMPLEMENTATION
ceive more autonomous IoT nodes where decisions need to be A. OVERVIEW
taken at the device. Indeed, the current trend in performing
The LoRaMesher library is a C++ implementation of a
machine learning on low capacity devices only increases this
proactive distance-vector routing protocol for enabling the
need [5]. For such autonomous IoT nodes, a certain asyn-
communication among LoRa nodes that form a mesh net-
chronous communication capacity is needed, e.g., for being
work, as proposed in [7]. The target hardware for which the
able to inform a node about a current application context to
library is compiled is an embedded board with a System
be taken into account for local decision-making. LoRa point
on a Chip (SoC) and a single-channel LoRa radio, like the
to point communications between end nodes, as delivered by
popular ESP32 SoC-based development boards featuring an
a LoRa mesh networks, can be a solution. However, this type
SX1276 LoRa transceiver. LoRaMesher uses FreeRTOS3 to
of communication is not considered in LoRaWAN.
implement the task handlers of the receiver, sender, packet
The energy consumption of ICT applications has become
processing, routing protocol and application data bidirec-
a raising concern [6]. LoRaWAN-based IoT applications
tional transmission.
address a full software and hardware stack that covers from
For the interaction with the LoRa radio chip, LoRaMesher
the IoT device to the cloud. Therefore, it involves the oper-
leverage RadioLib,4 a versatile communication library which
ation of a huge software and hardware infrastructure, which
supports the SX1276 LoRa series radio available on the hard-
translates in significant environmental costs due to the bill of
ware we use. Features of RadioLib include an easy configura-
materials and the energy consumption. Nonetheless, most ser-
tion of LoRa parameters, and the addition of CRC verification
vices forming an IoT application can be obtained from shared
of the LoRa payload, if enabled. Moreover, LoRaMesher uses
cloud-based computing infrastructures, which reduces the
RadioLib to define an Interrupt Service Routine (ISR) which
operational cost per application. IoT applications can lever-
is executed every time a LoRa packet is detected.
age the already deployed components for LoRaWAN-based
In the following section, we describe in detail the design of
solutions, where providers often offer enterprise and com-
the LoRaMesher library.
munity partnerships, such as The Things Network,1 among
others. Still, we can envision applications of interconnected
B. PACKET STRUCTURE
LoRa devices which only use the computing infrastructure
LoRa belongs to IoT communication technologies for build-
available on the devices themselves. Such gateway-less IoT
ing Low Power Wide Area Networks (LPWANs). LoRa
applications, in terms of infrastructure costs, are much more
targets applications in which remote sensors communicate
affordable in regard to the needed hardware and their energy
consumption. 2 https://github.com/LoRaMesher/LoRaMesher
3 https://www.freertos.org/
1 https://www.thethingsnetwork.org/ 4 https://github.com/jgromes/RadioLib
FIGURE 6. Packet Process Task diagram. When the Receiver task notifies
the Packet Process task, then this task processes the first packet inside
the Q_RP queue.
FIGURE 10. Queues diagram. The Receive task adds to the Q_RP queue,
the Process Packet task gets from the Q_RP queue and adds to the Q_SP
and Q_URP queue. The Routing Protocol task and User Send task add to FIGURE 11. LoRaMesher task sequence example when receiving a data
the Q_SP queue, the Send task gets from the Q_SP queue and finally the message whose destination is the application of this node.
User Receive task gets from the Q_URP queue.
FIGURE 14. Topology of the first experiment, where all ten nodes are
interconnected by one hop, as illustrated for node 0 × C5FC.
the first node 0 × 5728, at one end of the chain, creates data
messages that are sent to the last node 0 × C5FC at the other
end of the chain. The experimental settings are described in
Table 3. It needs to be mentioned that, before node 0 × 5728
can start sending data messages, it needs to wait for at least
nine routing message exchanges between the neighboring
nodes in order to have in its routing table the entry of the last
node 0 × C5FC. With the configured periodicity of 300s for
FIGURE 15. PDR by payload (experiment 1).
routing table exchanges, it adds 45 minutes to the experiment
for the routing table updates to travel through the 9 hops of
the middle nodes.
size. The larger packets have a larger time on air, which In Figure 19 it can be seen that, similar to the first experi-
increases the EED. ment, the PDR is lower for the larger packets, which can be
Since all the nodes send the same amount of data, both in attributed to a higher number of collisions. Different to the
terms of routing and data messages, all nodes have the same first experiment, however, the number of data messages sent
Control Overhead, which is 19% in this experiment. in the second experiment is lower since only the first node
creates data messages. The reduced number of packets sent
2) EXPERIMENT 2 results in a higher PDR for the different payloads.
We experiment a topology in which the nodes form a chain Figure 20 shows the obtained EED. The dependence
(Figure 18). This experiment aims to assess whether the rout- between the payload size and the EED can be observed,
ing tables built represent the given topology and that the rout- where the time of the packet in the network increases with the
ing of data messages at each node performs correctly. Only payload size. In the configuration used in this experiment, the
FIGURE 25. Number of packets inside the Q_SP to be sent to each node
in the third experiment.
Hester and several other contributors work on Meshtas- library to route in the mesh network application layer pay-
tic [20], a project for using inexpensive development boards loads beyond the size of LoRa packets. Having such capac-
with GPS, battery and a LoRa chip as secure mesh communi- ities would allow the LoRaMesher library to become a
cators. Meshtastic is intended for outdoor sport activities or communication substrate for distributed embedded machine
any other situation with no Internet access. Users create a pri- learning applications.
vate mesh to exchange their location and send text messages
to a group chat. Devices forward packets using a flooding REFERENCES
algorithm to reach the furthest member. [1] M. A. M. Almuhaya, W. A. Jabbar, N. Sulaiman, and S. Abdulmalek,
Pycom provides commercial development boards and ‘‘A survey on LoRaWAN technology: Recent trends, opportunities,
OEM products for IoT projects in the Python language. These simulation tools and future directions,’’ Electronics, vol. 11, no. 1,
p. 164, Jan. 2022. [Online]. Available: https://www.mdpi.com/2079-
devices can run Pymesh, a firmware for flexible LoRa mesh 9292/11/1/164
networking [21]. It provides encrypted ad-hoc communica- [2] J. Haxhibeqiri, E. De Poorter, I. Moerman, and J. Hoebeke,
tion over raw LoRa, implements Listen-before-talk (LBT) ‘‘A survey of LoRaWAN for IoT: From technology to application,’’
Sensors, vol. 18, no. 11, p. 3995, Nov. 2018. [Online]. Available:
MAC, and supports multiple node roles (leader, router, child, https://www.mdpi.com/1424-8220/18/11/3995
and border router). The firmware also has some routing [3] J. R. Cotrim and J. H. Kleinschmidt, ‘‘LoRaWAN mesh networks: A review
capabilities, as it claims to forward packets via the best link and classification of multihop communication,’’ Sensors, vol. 20, no. 15,
p. 4273, Jul. 2020. [Online]. Available: https://www.mdpi.com/1424-
available. Unfortunately, Pymesh can only run on Pycom’s 8220/20/15/4273
products, making it incompatible with other vendors. [4] N. Sornin, M. Luis, T. Eirich, T. Kramp, O. Hersent. (2016). LoRaWAN
NiceRF commercially offers the SV-Mesh and LoRaS- Specification; Version V1.0.2. LoRa Alliance. Beaverton, OR, USA.
tar range of LoRa transceivers. These products, available Accessed: Oct. 20, 2022. [Online]. Available: https://lora-alliance.org/wp-
content/uploads/2020/11/what-is-lorawan.pdf
as embedded boards or packaged devices, provide serial [5] F. Sakr, F. Bellotti, R. Berta, and A. De Gloria, ‘‘Machine learning on
TTL, RS232, or RS482 communication over LoRa links. mainstream microcontrollers,’’ Sensors, vol. 20, no. 9, p. 2638, May 2020.
They consist of a low power microcontroller and a regular [Online]. Available: https://www.mdpi.com/1424-8220/20/9/2638
[6] E. Ahvar, A.-C. Orgerie, and A. Lebre, ‘‘Estimating energy consumption
LoRa transceiver. The manufacturer developed the propri- of cloud, fog, and edge computing infrastructures,’’ IEEE Trans. Sustain.
etary LoRa-Pro mesh networking protocol, which defines a Comput., vol. 7, no. 2, pp. 277–288, Apr. 2022.
2 byte addressing scheme, three network roles (node, router, [7] R. P. Centelles, ‘‘Towards LoRa mesh networks for the IoT,’’ Ph.D. dis-
node plus router), and a virtually unlimited number of routes. sertation, Dept. Comput. Archit., Universitat Politècnica de Catalunya,
Barcelona, Spain, Nov. 2021.
Based on this review of related works, we can conclude [8] LoRa Core sx1276/77/78/79 Documentation. Accessed: Oct. 20, 2022.
that most of the works that propose a LoRa mesh network do [Online]. Available: https://www.semtech.com/products/wireless-rf/lora-
not implement it, they are limited to simulations or analytical core/sx1276#documentation
[9] R. P. Centelles, F. Freitag, R. Meseguer, and L. Navarro, ‘‘Beyond the star
calculations. The few works that implement a network focus of stars: An introduction to multihop and mesh for LoRa and LoRaWAN,’’
on addressing very specific and particular use cases. They do IEEE Pervasive Comput., vol. 20, no. 2, pp. 63–72, Apr. 2021.
not perform a general implementation as the one done in this [10] A. Osorio, M. Calle, J. D. Soto, and J. E. Candelo-Becerra, ‘‘Routing in
LoRaWAN: Overview and challenges,’’ IEEE Commun. Mag., vol. 58,
paper. no. 6, pp. 72–76, Jun. 2020.
[11] C. Ebi, F. Schaltegger, A. Rust, and F. Blumensaat, ‘‘Synchronous LoRa
V. CONCLUSION mesh network to monitor processes in underground infrastructure,’’ IEEE
This paper presented the development of the LoRaMesher Access, vol. 7, pp. 57663–57677, 2019.
[12] R. P. Centelles, R. Meseguer, F. Freitag, L. Navarro, S. F. Ochoa,
library, which implements a routing distance-vector protocol and R. M. Santos, ‘‘LoRaMoto: A communication system to provide
for the communication of nodes in a LoRa mesh network. safety awareness among civilians after an earthquake,’’ Future Gener.
The design of the library is explained in detail. The imple- Comput. Syst., vol. 115, pp. 150–170, Feb. 2021. [Online]. Available:
https://www.sciencedirect.com/science/article/pii/S0167739X20306063
mentation is deployed on real devices, showing the library as [13] A. Osorio, M. Calle, J. Soto, and J. E. Candelo-Becerra, ‘‘Routing
ready to use code. The experimentation with LoRaMesher is in LoRa for smart cities: A gossip study,’’ Future Gener. Comput.
done with different topologies and payloads and evaluates the Syst., vol. 136, pp. 84–92, Nov. 2022. [Online]. Available:
https://www.sciencedirect.com/science/article/pii/S0167739X22001996
packet delivery ratio, end-to-end delay and control overhead.
[14] B. Sartori, S. Thielemans, M. Bezunartea, A. Braeken, and K. Steenhaut,
The implementation of LoRaMesher is open source. ‘‘Enabling RPL multihop communications based on LoRa,’’ in Proc.
The results obtained from the experimentation showed that IEEE 13th Int. Conf. Wireless Mobile Comput., Netw. Commun. (WiMob),
the LoRaMesher library worked correctly in the different Oct. 2017, pp. 1–8.
[15] H.-C. Lee and K.-H. Ke, ‘‘Monitoring of large-area IoT sensors using a
topologies and for small, medium and large sizes of payloads. LoRa wireless mesh network system: Design and evaluation,’’ IEEE Trans.
Configuration parameters such as the periodicity of data and Instrum. Meas., vol. 67, no. 9, pp. 2177–2187, Sep. 2018.
routing messages allow the user of the library to adapt its [16] G. Zhu, C.-H. Liao, T. Sakdejayont, I.-W. Lai, Y. Narusue, and
H. Morikawa, ‘‘Improving the capacity of a mesh LoRa network
operation to the specific application requirements. The library by spreading-factor-based network clustering,’’ IEEE Access, vol. 7,
can be included in an IoT application code with a few steps, pp. 21584–21596, 2019.
which can lead to distributed LoRa mesh-based applications [17] D. L. Mai and M. K. Kim, ‘‘Multi-hop LoRa network protocol with
minimized latency,’’ Energies, vol. 13, no. 6, p. 1368, Mar. 2020. [Online].
at the IoT layer.
Available: https://www.mdpi.com/1996-1073/13/6/1368
Future work will include extending the implemented pro- [18] C. T. Duong and M. K. Kim, ‘‘Multi-hop linear network based on LoRa,’’
tocols with reliable LoRa packet delivery and enabling the Adv. Sci. Technol. Lett., vol. 150, pp. 29–33, Apr. 2018.
[19] A. Abrardo and A. Pozzebon, ‘‘A multi-hop LoRa linear sensor network FELIX FREITAG is currently an Associate Profes-
for the monitoring of underground environments: The case of the medieval sor with the Department of Computer Architec-
aqueducts in Siena, Italy,’’ Sensors, vol. 19, no. 2, p. 402, Jan. 2019. ture, Universitat Politècnica de Catalunya (UPC).
[20] Meshtastic: Open Source Hiking, Pilot, Skiing and Secure GPS His research interests include edge computing and
Mesh Communicator. Accessed: Oct. 20, 2022. [Online]. Available: federated machine learning.
https://meshtastic.org/
[21] Pycom PyMesh. Accessed: Oct. 20, 2022. [Online]. Available:
https://docs.pycom.io/pymesh/
ROGER PUEYO CENTELLES received the ROC MESEGUER is currently an Associate Pro-
Ph.D. degree from the Universitat Politècnica de fessor with the Department of Computer Architec-
Catalunya (UPC), in 2021. He is currently working ture, Universitat Politècnica de Catalunya (UPC).
as a Senior Researcher with the i2CAT Founda- His research interests include resource alloca-
tion. His research interests include community tion for large-scale systems, decentralized systems
networks, mesh and ad-hoc networks, and the IoT. applied to ambient intelligence, and bottom-up
networks.