Can not send downlink

I try to send downlink with mosquitto_pub -h “192.168.153.251” -p “1883” -t “application/9/device/72b1d27eg3017316/command/down” -m ‘{“confirmed”:true,“fPort”:1,“data”:“1234”, “obj”:{“status”: “on”}}’

My encode function in chirpstack API:
function Encode(fPort, obj, variables) {

var statuss = [“off”, “on”];
var bytes = ;

//obj = JSON.parse(obj);
//console.log("JSON parsed OBJ is "+obj);
bytes.push(0x00);
//bytes.push(statuss.indexOf(obj.status));

return bytes;
return fPort;

My Decode Function in Chirpstack API:
function Decode(fPort, bytes, variables) {
var statuss = [“off”, “on”];
var data ={};
data.pressure=((bytes[1] << 8) + bytes[2])/10;
data.temperature=((bytes[3]<<8)+bytes[4])/100;
data.humidity=((bytes[5]<<8)+bytes[6])/100;
data.battery=bytes[7];
voltageFromArduino_string=String.fromCharCode(bytes[13])+String.fromCharCode(bytes[14])+String.fromCharCode(bytes[15])+String.fromCharCode(bytes[16]);
data.voltageFromArduino=Number(voltageFromArduino_string);
if(fPort==1) {
data.status=statuss[0];
return {
data: data,
warnings: ,
errors:
};
}

return {
data: data,
warnings: ,
errors:
};

}

Then i receive this log from network server:

Aug 14 12:39:12 pi chirpstack-network-server[1241]: time=“2024-08-14T12:39:12.590555457+02:00” level=error msg=“backend/gateway: unmarshal downlink tx ack error” data_base64=“eyJnYXRld2F5SUQiOiJKT0VrLy83NDRmQT0iLCJ0b2tlbiI6Mjc4OTMsIml0ZW1zIjpbeyJzdGF0dXMiOiIxIn1dfQ==” error=“unknown value "\"1\"" for enum gw.TxAckStatus”

I receive this error in “Device data” from chirpstack API:

  • error:“json: unsupported value: NaN”

I can receive uplink from my lora-e5 dev board, but downlink not working. I can not see the bytes array, which should send for my device.
What could be wrong in my set up. What can i do ?

As you can see in my pics. txack and ack=true from device and from gateway, but data still null and i don’t have any bytes HEX send to my LoRa-e5 dev board.
I try return simple bytes[0]=0x00 in encode function from chirpstack. Still same problem.
What i understand: After mosquitto_pub, my raspi send message for network server(chirpstack), network server use my encode function, send bytes array for gateway and gateway send to device. What i missunderstanding ?

Second pic is LoRaFrame from gateway, prove that, fPort1 have been use for my mosquitto_pub, which correct to my message send with mosquitto_pub

Can anyone help me, i stuck here for a week ?
Thank you all
Minh Thong Pham

You need to format you code so we can see.
Show us your input data.
And show us how you send the data (MQTT Topics/MQTT payload/REST API URL/REST API data)…

This is a sample basic encoder.

// Encode downlink function.
//
// Input is an object with the following fields:
// - data = Object representing the payload that must be encoded.
// - variables = Object containing the configured device variables.
//
// Output must be an object with the following fields:
// - bytes = Byte array containing the downlink payload.
function encodeDownlink(input) {
  var obj=input.data;
  return {bytes: [0x02,0x11,0x00,0x11]};
}

Looks like your missing DEV EUI in your MQTT command, look at the example payload:

{
    "devEui": "0102030405060708",             // this must match the DEV_EUI of the MQTT topic
    "confirmed": true,                        // whether the payload must be sent as confirmed data down or not
    "fPort": 10,                              // FPort to use (must be > 0)
    "data": "...."                            // base64 encoded data (plaintext, will be encrypted by ChirpStack)
    "object": {                               // decoded object (when application coded has been configured)
        "temperatureSensor": {"1": 25},       // when providing the 'object', you can omit 'data'
        "humiditySensor": {"1": 32}
    }
}
2 Likes