LoRa Network - Build a LoRa Network With Transceivers Only

date
Jun 4, 2024
type
Post
AI summary
slug
lora-network-protocol
status
Published
tags
ESP32
LoRa
summary
Learn the difference between LoRa and LoRaWAN and how to set up a cost-effective LoRa network with ESP32 devices and transceivers. This guide covers the limitations of a no-gateway setup and provides solutions for timing coordination, avoiding conflicts, and assigning unique identifiers. Includes practical examples and code snippets using the Arduino LoRa library to help you implement your own LoRa network.
Here you are, you have a bunch of sensors far apart, and you want to collect data from them over LoRa. But it seems like everybody on the internet talks about LoRaWAN. Simply put, LoRa is the radio, and LoRaWAN is a fancy protocol built over the LoRa physical layer. Typically, it requires a LoRa gateway to implement LoRaWAN. A LoRa gateway is essential in a LoRaWAN network because it acts as a bridge between the end devices and the network server. The gateway receives data from multiple LoRa end devices, which communicate using the LoRa radio protocol, and then forwards this data to a central network server over a standard IP connection, such as Ethernet or cellular. LoRa gateways are designed to support multiple channels and can decode multiple signals simultaneously, making them crucial for the scalability and robustness of a LoRaWAN network.
Gateway made by Rak (starting at $268)
Gateway made by Rak (starting at $268)
However, you don’t always want a LoRa gateway. It is an extra piece of hardware, more power hungry, more expensive (easily costs $200+), and you probably just want to manage a simple network. Can we make it work with only transceivers ($5 a piece)? You are gonna buy one for each node anyways!
$5 without breakout board
$5 without breakout board
Yes! We can build a custom LoRa network with only transceivers on each end device, and any one of them can be configured as either the master or node. Indeed, this setup comes with limitations, as these transceivers cannot listen and send data at the same time; they have to work under one mode. Also, they do not support simultaneous communications with multiple devices . As such, building such a system will need to ensure devices do not conflict with each other, and the timing needs to be coordinated.

Network Architecture

Let’s say we have 30 data collection nodes each with a ESP32 and a transceiver, how do they talk to each other, when do they speak up? If they can’t listen and speak at the same time, how do they make sure they are not missing out?
To solve these problems, we need to make rules for our LoRa devices!
  1. Timing Coordination:
    1. Option 1:
      • Use a simple time-division multiplexing (TDM) approach where each node has a specific time slot to transmit data.
      • Implement a synchronization mechanism, such as a common start signal or periodic sync messages from the gateway.
      Option 2:
      • Let the master node dictate everything (almost), a slave node can speak only if the master asks it to send packets. I think this is easier!
  1. Avoiding Conflicts:
      • Ensure that only one node transmits at a time.
      • Use acknowledgment messages to confirm successful data transmission and reception.
  1. Unique Identifier:
      • Each node should always attach their unique identifier (e.g., a name or MAC address) with their message.
      • The master can check where the message is from and discard any garbage messages or those from unauthorized nodes.
      • Nodes can check if the master is addressing them specifically or another node.

Understand the Arduino LoRa Library

Before implementing our own LoRa protocol (rules) or LoRa network, we need to understand the wonderful
arduino-LoRa
sandeepmistryUpdated Jul 9, 2024
library that allows us to interact with the transceiver hardware. The API of this library is very well document in LoRa API.

Hello World!

Here is an example of a simple sender and receiver sketch using the LoRa library.
Sender Code:
Receiver Code:
You can power one of the sender battery or USB, and inspect the receiver via your computer’s serial monitor. That simple! Hello, hello, hello from LoRa!

Continuous Receive & Send

Consider the following two scenarios:
  • Slave nodes should constantly listen for new packets, and only send data at the request of the master.
  • Master node should constantly listen for new packets, and only send data if it needs to contact the slave nodes.
Hey, they work in the same logic! How can we set this logic up using the Lora library? LoRa.onReceive is the answer! In the snippet below, it registers a callback also called onReceive, but you can name it anything you want.
Important! After sending the message, you have to put the LoRa module back into receive mode. That is why LoRa.receive() is called in the sendMessage function.

Conclusion

Now that you understand the basics of using LoRa to send and receive messages, we'll move on to discussing how to implement complex logic for a LoRa network without a gateway in the next post.
But hold on! While the onReceive example provided is a great starting point, it's important to note that this function can easily crash if not handled properly. Is this an issue with the library? Not quite. The delicacy of the onReceive method means you need to handle it with care to avoid potential crashes. Please read before it’s too late.
I’m working on an implementation of the custom LoRa protocol we discussed. You can check out my repository:
ESP32-Datalogger
qiweimaoUpdated Jul 8, 2024
. This project enables the ESP32 to transfer large files over LoRa and use addressing to control slave modules. More exciting features are currently in development.

About Me

Hi, I'm Qiwei Mao, a geotechnical engineer with a passion for IoT systems. I'm exploring low-power microcontrollers and LoRa communication systems to enable both hobbyist remote monitoring solutions and industrial-grade monitoring or control systems.
Qiwei Mao
Qiwei Mao

© Qiwei Mao 2024