Customizing the LoRa Protocol --- Enhancing Data Reliability
by makerfabs in Circuits > Arduino
72 Views, 0 Favorites, 0 Comments
Customizing the LoRa Protocol --- Enhancing Data Reliability


What is LoRa?
LoRa (Long Range) is a Low Power Wide Area Network (LPWAN) wireless communication technology developed by Semtech. Its core advantage lies in enabling communication over several kilometers—or even tens of kilometers—while consuming extremely low power, making it highly suitable for data transmission between Internet of Things (IoT) devices. It has the following features: Long-range transmission, Low power consumption, Low data rate, Strong penetration capability.
Problems with LoRa
Although LoRa technology has clear advantages in low power consumption and long-range communication, but it also faces some common issues in practical use:
- No confirmation of data reception: LoRa is connectionless by default, so the sender cannot confirm whether the receiver has successfully received the data.
- Low data transmission rate: The amount of data transmitted each time is limited, making it unsuitable for large-volume data communication.
- Data loss or corruption: In environments with multiple nodes or signal interference, data packets may be lost or received incompletely.
How to solve it?
To address the issue of data reliability, we have designed a communication mechanism:
1.CRC Validation Mechanism
When sending data, we introduce CRC (Cyclic Redundancy Check) to ensure data integrity:
- The sender appends a calculated CRC value to the end of the data before transmission.
- Upon receiving the data, the receiver recalculates the CRC and compares it with the appended CRC value.
- If they match, the data is considered intact; otherwise, the packet is discarded.
2.Data Acknowledgment Mechanism
We have introduced a bidirectional communication protocol:
- After sending the data, the sender waits for an acknowledgment from the receiver.
- If no acknowledgment is received within a timeout period, the sender automatically retransmits the data.
Supplies

We use the Makerfabs LoRa Soil Monitoring & Irrigation Kit, This Kit is based on ESP32 and Lora. The MaTouch 3.5 inch display is the console for the system:
- Receives the Lora message from Lora moisture sensors (Lora moisture sensors→MaTouch) and display on the screen.
- Send control commands to Lora 4-chnanel MOSFET (MaTouch→Lora 4-chnanel MOSFET).
LoRa Soil Monitoring & Irrigation Kit:
MaTouch_ESP32-S3 SPI TFT with Touch 3.5'' ILI9488 *1;
Lora Expansion for ESP32 Display *1;
Lora Moisture Sensor *1;
Lora 4 Channel MOSFET *1;
12V Power Supply *1;
Data Packet Format

We modified the LoRa transmission and reception part by adding a custom protocol, which includes CRC validation and data acknowledgment. On top of the original system, we added:
- CRC is appended to each data packet to verify data integrity and correctness during transmission and reception.
- An acknowledgment mechanism is implemented on both the LoRa transmitter and receiver sides to guarantee that the receiver has successfully received the transmitted data.
LoRa Communication Protocol From Lora Moisture Sensor to MaTouch

Lora Moisture Sensor→MaTouch
- Sensor Data Collection
We amplify the collected data by 10 times before transmission, preserves one decimal place while saving space.
- Data Packet Assembly
The data length is added to the packet to provide the receiver with a CRC calculation;
And the CRC value is calculated once locally to provide the receiver with a comparison.
- Send to MaTouch
- Wait for Response
Upon receiving an acknowledgment from MaTouch, the sensor enters sleep mode.
Otherwise, it will retry sending. If no acknowledgment is received after two retries, the sensor enters sleep mode.
MaTouch → LoRa moisture sensors
- Receive Data from LoRa Moisture Sensor
- CRC Validation
If the CRC check passes, a confirmation packet is sent back to the LoRa Moisture Sensor, and the soil moisture value is displayed on the screen.
If the CRC check fails, the system continues waiting to receive data.
LoRa Communication Protocol From MaTouch to MOSFET

MaTouch→Lora 4-channel MOSFET
- After pressing the Send button on the screen, the system starts building the data packet.
The packet includes the MOS value set on the screen, the data length (for CRC calculation on the receiver side), and a locally calculated CRC value for verification.
- Send to Lora 4-channel MOSFET
- Wait for a response
Upon receiving a reply from the LoRa 4-Channel MOSFET, the system performs a CRC check.
If CRC validation, verifies whether the actual MOS status matches the intended control state.
If status match pass, the system enters data-receiving mode.
Otherwise, the system resending the packet.
If the CRC check fails, the system resending the packet.
If retransmission fails twice, the UI displays "Send Error".
Lora 4-channel MOSFET→MaTouch
- Receive data from MaTouch
- Parse the data
Perform CRC validation.
If the CRC check passes, parse the MOS data and execute the corresponding switch control.
Then, build a response data packet containing the actual control status and send it back to MaTouch.
If the CRC check fails, remain in data-receiving mode.
Conclusion




- With CRC verification, data reception is 100% accurate and complete.
- With the acknowledgment mechanism, data communication achieves 100% success.
In addition to upgrading the LoRa protocol, we also enhanced the screen UI using SquareLine Studio and improved user interaction with LVGL. Come and experience it!
Code
For detailed code and implementation, please refer to the project on Github.