I am using the LMIC-node example for a node I created. Everything was going smoothly sensing bytes down. I decided I wanted to send downlink in JSON format. I am using the ArduinoJson library in Platform IO to parse the JSON message. However, I am having some issues getting my JSON message to print in the terminal.
Here is my ProcessDownlink function
void processDownlink(ostime_t txCompleteTimestamp, uint8_t fPort, uint8_t *data, uint8_t dataLength)
{
char holder[] = {data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11], data[12],
data[13], data[14], data[15], data[16], data[17], data[18], data[19], data[20], data[21], data[22], data[23], data[24],
data[25], data[26], data[27], data[28], data[29], data[30], data[31], data[32], data[33], data[34], data[35], data[36],
data[37], data[38], data[39], data[40], data[41], data[42], data[43], data[44], data[45], data[46]};
String message;
message = String(holder);
serial.println(message);
StaticJsonDocument<200> doc;
// Check for NUL characters in the JSON string.
char *nullCharacter = static_cast<char *>(memchr(holder, 0, dataLength));
if (nullCharacter)
{
Serial.print("There is a NUL character in the JSON string.");
*nullCharacter = ' ';
return;
}
DeserializationError error = deserializeJson(doc, holder, dataLength);
if (error)
{
Serial.print("deserializeJson() failed: ");
Serial.println(error.c_str());
return;
}
long Sensitivity = doc["Sensitivity"]; // "750"
const char *Light = doc["Light"]; // "OFF"
const char *Mode = doc["Mode"]; // "C"
Serial.println(Sensitivity);
Serial.println(Light);
Serial.println(Mode);
}
Here is the JSON message
{
"Sensitivity": "750",
"Light": "OFF",
"Mode": "C"
}
And here is my Downlink payload formatter for encoding.
function encodeDownlink(input) {
return {
bytes: [input.data.Sensitivity, input.data.Light, input.data.Mode],
fPort: 10,
};
}
Can anyone help me resolve this issue.