2025-01-13 01:05 AM
Hi everyone,
I am using the LoRaWAN_AT_Slave example code on an STM32WL-based device, and I am operating in OTAA mode with the ChirpStack server to monitor the data. I am successfully sending sensor data to the server at the specified intervals.
I have checked the ChirpStack server, and I can confirm that both uplink and downlink data are being successfully received and transmitted. Now, I want to send a downlink from the ChirpStack server. There are two options for sending the downlink: either in base64 format or in JSON format.
When I send the downlink in base64 format, I am successfully receiving the downlink. I am attaching a picture below for reference; please check it out.
Below is the logs printed on the serial monitor.
Now I am trying to send the downlink in JSON Object. Below is the picture of sending the JSON Object:
This JSON Object is successfully transmitted from chirpstack server to my device. But, on my device I am not getting the data which i have sent from the server. Below is the log output in serial monitor.
In conclusion , i am getting data when i sent it in base64 format but not getting data when i sent it in json format.
My Questions:
1. Can I send JSON payloads with different parameters like the one above, or is this not supported by the LoRaWAN system or the STM32WL firmware?
2. Do I need to modify the LoRaWAN_AT_Slave example code to properly handle such payloads?
I’d appreciate any insights or suggestions on how to resolve this issue.
I would appreciate further guidance on verifying whether the STM32WL-based device supports downlink payloads with nested JSON objects or if additional modifications are required in the firmware.
Thanks in advance!
Regards,
Anupam
2025-01-13 03:11 AM
2025-01-13 03:14 AM
@anupam1511 wrote:This JSON Object is successfully transmitted from chirpstack server to my device. But, on my device I am not getting the data which i have sent from the server. Below is the log output in serial monitor.
How do you know that?
A lot happens between you entering that on your console, and the data actually reaching the device - how do you know that it isn't getting lost/removed somewhere before your device?
2025-02-02 10:12 PM
Hi @anupam1511,
The information in your Json Object like fport, confirmed, deveui is not necessary because those are available fields on Chirpstack server. You just need to add the correct data that you want to send to the device in Json form, then do the necessary conversion from Json Object to bytes array in Encode function in Codec of device-profiles. That is exactly what I did with my app.
Ex:
Json Object:
{"GPIO5": 1}
// Encode encodes the given object into an array of bytes.
// - fPort contains the LoRaWAN fPort number
// - obj is an object, e.g. {"temperature": 22.5}
// - variables contains the device variables e.g. {"calibration": "3.5"} (both the key // value are of type string)
// The function must return an array of bytes, e.g. [225, 230, 255, 0]
function Encode(fPort, obj, variables) {
var bytes = [];
// Encode obj values
var jsonString = JSON.stringify(obj);
// Encode the entire JSON string including quotes
for (var i = 0; i < jsonString.length; i++) {
bytes.push(jsonString.charCodeAt(i)); // ASCII value of each character
}
return bytes;
}
*Note: In Encode function you can convert all data to json and send to device then parse OR convert value by specific key in Json object depending on your application.