ESP32 LoRa two way radio communication
Posted: Mon Feb 01, 2021 1:07 am
Hello everyone,
I have recently been exploring LoRa communication system and, inspired by the Meshtastic project to which I contributed in the early days, I decided to create a very basic two-way radio using a commercial LoRa module based on the ESP32.
Leveraging the two cores of the ESP32, I separated the logic into two threads, one responsible for sending messages and another for receiving. The TX thread also takes care of displaying the user interface via WiFi.
Now, going to the debug part, messages are correctly sent, I can see their spectral trace using a SDR dongle at 433MHz. However, somehow the receiving logic doesn't work. The RX thread is correctly working, there are no errors. I tried to replace with callbacks without success.
What can I do to find out the cause?
Here's the project files: https://github.com/grcasanova/Talker
Thank you
Here is the RX task code
I have recently been exploring LoRa communication system and, inspired by the Meshtastic project to which I contributed in the early days, I decided to create a very basic two-way radio using a commercial LoRa module based on the ESP32.
Leveraging the two cores of the ESP32, I separated the logic into two threads, one responsible for sending messages and another for receiving. The TX thread also takes care of displaying the user interface via WiFi.
Now, going to the debug part, messages are correctly sent, I can see their spectral trace using a SDR dongle at 433MHz. However, somehow the receiving logic doesn't work. The RX thread is correctly working, there are no errors. I tried to replace with callbacks without success.
What can I do to find out the cause?
Here's the project files: https://github.com/grcasanova/Talker
Thank you
Here is the RX task code
Code: Select all
[Codebox=c file=Untitled.c]
while(true) {
// try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize) {
// received a packet
Serial.print("Received packet");
// read packet header bytes:
int recipient = LoRa.read(); // recipient address
byte sender = LoRa.read(); // sender address
byte incomingMsgId = LoRa.read(); // incoming msg ID
byte incomingLength = LoRa.read(); // incoming msg length
String incoming = "";
while (LoRa.available()) {
incoming += (char)LoRa.read();
}
if (incomingLength != incoming.length()) { // check length for error
Serial.println("error: message length does not match length");
continue; // skip rest of the cycle
}
// if the recipient isn't this device or broadcast,
if (recipient != FROM_ADDR && recipient != ALL) {
Serial.println("This message is not for me.");
continue; // skip rest of the cycle
}
// Save msg
String temp = "<li class='you'>"+incoming+"</li>";
appendFile(SPIFFS, FILENAME, temp.c_str());
// if message is for this device, or broadcast, print details:
Serial.println("Message: " + incoming);
Serial.println("RSSI: " + String(LoRa.packetRssi()));
Serial.println("SNR: " + String(LoRa.packetSnr()));
Serial.println();
screen.clear();
screen.setTextAlignment(TEXT_ALIGN_LEFT);
screen.setFont(ArialMT_Plain_10);
screen.drawString(0, 0, "Received Message:");
screen.drawString(0, 15, incoming);
screen.display();
}
vTaskDelay(10);
}
}[/Codebox]