[LORA] Fix message without json not being transmitted (#1875)

Fix LoRa not processing message that are not JSON
Add also a non-JSON-message to the example
This commit is contained in:
Florian authored and GitHub committed 2024-01-21 19:28:23 -06:00
1 parent b2dbc2d581
commit 71389438d3
4 files changed
+22 -5

No files matched your search

+1
View File
@@ -1,5 +1,6 @@
# OpenMQTTGateway LoRa Node Example
This repository contains an example of a LoRa node program designed for the ESP32 platform. The program reads the internal temperature of the ESP32, packages the data into a JSON format, and sends it over LoRa.
It also sends a constant raw string simulating a Makerfab Soil sensor payload.
## Features:
* Uses an SX12XX LoRa module.
+1 -1
View File
@@ -27,7 +27,7 @@ lib_deps =
monitor_speed = 115200
[env:heltec-wifi-lora-32] ; Heltec ESP32 Board with SSD1306 display
platform = ${com.esp32_platform}
platform = espressif32
board = heltec_wifi_lora_32
framework = arduino
lib_deps =
+12 -1
View File
@@ -90,13 +90,24 @@ void loop() {
LoRa.print(msg);
LoRa.endPacket();
Serial.println(String(msg));
Serial.println(msg);
display.drawString(0, 15, String(NodeId));
display.drawString(0, 30, "tempc: " + String(temp) + " C");
display.display();
delay(5000);
// Send makerfab soil sensor example packet
LoRa.beginPacket();
String msg2 = "ID010770 REPLY : SOIL INEDX:5862 H:100.00 T:1.77 ADC:624 BAT:857";
LoRa.print(msg2);
LoRa.endPacket();
Serial.println(msg2);
counter++;
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
+8 -3
View File
@@ -428,9 +428,13 @@ void LORAtoMQTT() {
} else {
// ascii payload
std::string packetStrStd = (char*)packet;
auto error = deserializeJson(LORAdataBuffer, packetStrStd);
if (error) {
Log.error(F("LORA packet deserialization failed: %s, buffer capacity: %u" CR), error.c_str(), LORAdataBuffer.capacity());
auto result = deserializeJson(LORAdataBuffer, packetStrStd);
if (result) {
Log.notice(F("LORA packet deserialization failed, not a json, sending raw message" CR));
LORAdata = LORAdataBuffer.to<JsonObject>();
LORAdata["message"] = (char*)packet;
} else {
Log.trace(F("LORA packet deserialization OK" CR));
}
}
@@ -453,6 +457,7 @@ void LORAtoMQTT() {
} else {
LORAdataBuffer["origin"] = subjectLORAtoMQTT;
}
handleJsonEnqueue(LORAdata);
if (repeatLORAwMQTT) {
Log.trace(F("Pub LORA for rpt" CR));