[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:
1 parent
b2dbc2d581
commit
71389438d3
4 files changed
+22
-5
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
# OpenMQTTGateway LoRa Node Example
|
# 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.
|
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:
|
## Features:
|
||||||
* Uses an SX12XX LoRa module.
|
* Uses an SX12XX LoRa module.
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ lib_deps =
|
|||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
|
|
||||||
[env:heltec-wifi-lora-32] ; Heltec ESP32 Board with SSD1306 display
|
[env:heltec-wifi-lora-32] ; Heltec ESP32 Board with SSD1306 display
|
||||||
platform = ${com.esp32_platform}
|
platform = espressif32
|
||||||
board = heltec_wifi_lora_32
|
board = heltec_wifi_lora_32
|
||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps =
|
lib_deps =
|
||||||
|
|||||||
@@ -90,13 +90,24 @@ void loop() {
|
|||||||
LoRa.print(msg);
|
LoRa.print(msg);
|
||||||
LoRa.endPacket();
|
LoRa.endPacket();
|
||||||
|
|
||||||
Serial.println(String(msg));
|
Serial.println(msg);
|
||||||
|
|
||||||
display.drawString(0, 15, String(NodeId));
|
display.drawString(0, 15, String(NodeId));
|
||||||
display.drawString(0, 30, "tempc: " + String(temp) + " C");
|
display.drawString(0, 30, "tempc: " + String(temp) + " C");
|
||||||
display.display();
|
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++;
|
counter++;
|
||||||
|
|
||||||
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
|
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
|
||||||
delay(1000); // wait for a second
|
delay(1000); // wait for a second
|
||||||
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
|
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
|
||||||
|
|||||||
@@ -428,9 +428,13 @@ void LORAtoMQTT() {
|
|||||||
} else {
|
} else {
|
||||||
// ascii payload
|
// ascii payload
|
||||||
std::string packetStrStd = (char*)packet;
|
std::string packetStrStd = (char*)packet;
|
||||||
auto error = deserializeJson(LORAdataBuffer, packetStrStd);
|
auto result = deserializeJson(LORAdataBuffer, packetStrStd);
|
||||||
if (error) {
|
if (result) {
|
||||||
Log.error(F("LORA packet deserialization failed: %s, buffer capacity: %u" CR), error.c_str(), LORAdataBuffer.capacity());
|
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 {
|
} else {
|
||||||
LORAdataBuffer["origin"] = subjectLORAtoMQTT;
|
LORAdataBuffer["origin"] = subjectLORAtoMQTT;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleJsonEnqueue(LORAdata);
|
handleJsonEnqueue(LORAdata);
|
||||||
if (repeatLORAwMQTT) {
|
if (repeatLORAwMQTT) {
|
||||||
Log.trace(F("Pub LORA for rpt" CR));
|
Log.trace(F("Pub LORA for rpt" CR));
|
||||||
|
|||||||
Reference in new issue
Block a user