Hi shramik,
this is the Sender code :
if (LoRa.beginPacket())
{
LoRa.write(lpp.getBuffer(), lpp.getSize());
if (LoRa.endPacket())
{
Serial.println("Lora Transmission OK");
}
else
{
Serial.println("Lora Transmission Error");
}
}
else
{
Serial.println("Lora Transmission Error");
}
Serial.print("Bytes sent : ");
Serial.println(lpp.getSize());
uint8_t *payload = lpp.getBuffer();
for (unsigned char i = 0; i < lpp.getSize(); i++)
{
Serial.print("0x");
Serial.print(payload[i], HEX);
Serial.print(" ");
}
// print checkmark
Serial.println();
Serial.print("LoRa message sent \u2714\r\n");
// DECODE
// uint8_t *payload = lpp.getBuffer();
StaticJsonDocument<512> jsonBuffer;
JsonArray root = jsonBuffer.to<JsonArray>();
lpp.decode(lpp.getBuffer(), lpp.getSize(), root);
serializeJsonPretty(root, Serial);
Serial.println();
…
This is the sender code result
Bytes sent : 11
0x1 0x67 0x0 0xD4 0x2 0x68 0x4A 0x3 0x74 0x1 0xF6
LoRa message sent ✔
[
{
"channel": 1,
"type": 103,
"name": "temperature",
"value": 21.2
},
{
"channel": 2,
"type": 104,
"name": "humidity",
"value": 37
},
{
"channel": 3,
"type": 116,
"name": "voltage",
"value": 5.02
}
]
Then, the receiver code
…
uint8_t *payload;
int packetSize = LoRa.parsePacket();
if (packetSize)
{
// received a packet
Serial.printf("Received %i bytes, RSSI : %i ", packetSize, LoRa.packetRssi());
while (LoRa.available())
{
payload += (uint8_t)LoRa.read();
}
// print checkmark
Serial.printf(" \u2714\r\n");
for (unsigned char i = 0; i < packetSize; i++)
{
Serial.print("0x");
Serial.print(payload[i], HEX);
Serial.print(" ");
}
Serial.println();
Serial.print("|");
for (unsigned int i = 0; i < packetSize; i++)
{
Serial.print(payload[i] >> 4, HEX);
Serial.print(payload[i] & 0xF, HEX);
}
Serial.print("|");
Serial.println();
The received message is
Received 11 bytes, RSSI : -62 ✔
0x45 0x3E 0x0 0x42 0x7F 0x40 0x0 0x72 0x49 0x49 0x49
|453E00427F400072494949|
Received 11 bytes, RSSI : -62 ✔
0xF 0x38 0x44 0x44 0x38 0x44 0xFC 0x4A 0x4A 0x4A 0x34
|0F3844443844FC4A4A4A34|
Received 11 bytes, RSSI : -62 ✔
0xF0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x1F 0xF8 0x7F
|F0000000000000001FF87F|
My question are :
#1. How to read correcty data on this case
#2. How to print on serial correctly data for debugging (there are two temptatives, are correct there ?)
#3. How to decode CayennLPP message from a payload
#4. How to extract a single value (e.g. temperature, or voltage) from received message
Many thanks to all.