Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/LoraTemperature/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion examples/LoraTemperature/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
13 changes: 12 additions & 1 deletion examples/LoraTemperature/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions main/ZgatewayLORA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand All @@ -453,6 +457,7 @@ void LORAtoMQTT() {
} else {
LORAdataBuffer["origin"] = subjectLORAtoMQTT;
}

handleJsonEnqueue(LORAdata);
if (repeatLORAwMQTT) {
Log.trace(F("Pub LORA for rpt" CR));
Expand Down
Loading