After activate MQTT integration to external MQTT broker, failed to receive payload from device

Appreciate if someone could guide me on what am I missing.
after activated MQTT integration to external MQTT broker, I can see data send out from Chirpstack to my external MQTT broker but Chipstack failed to receive payload from device.


You have got a page called “CODEC” in your device profile. In order to use MQTT external broker, you need to CODE and DECODE the messages going UP and DOWN.

I mean, you need to create a proper CODE function which sends the data to your external MQTT broker in a way is readable for it.

On the other hand, you need to input a DECODE function, so that the data coming from your external MQTT is readable and useful for Chirpstack. (Otherwise, the downlink would not work properly).

Whish I helped you,


Leave you here an example on the CODE function:

function Decode(fPort, bytes) {

result = {};

if(bytes[0] == 2) // Command code = 2
	result.address = byteArrayToInt(bytes,1,4);
	result.volumen = byteArrayToInt(bytes,5,4);
	result.batteryLevel = byteArrayToInt(bytes,15,2);

return result;


function byteArrayToInt(byteArray,n,m)
var val = 0;

for(var i = 0; i < m-1; i++)
  val += byteArray[i+n] << i * 7;

return val;


Hi Nicolas,
Thanks for your guidance, however, i’m still little confuse. Do I still need to fill in the broker address for connect to external broker? on below configuration?

Currently, my problem is whenever I replace the below address to with login credential username and password, Chirpstack will not able to let device to join and receive data.
if I put the address back to localhost, without any login credential, then Chirpstack back to normal and let device to join and receive payload from device. So i was wonder how would this affect Chirpstack to receive data from device if after fill the external broker address with login details.

Generic MQTT authentication.


MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws)


Connect with the given username (optional)


Connect with the given password (optional)


If things goes fine using localhost as tcp address, I think you may be doing something wrong using your own name. What I did to have my Chirpstack server working on any http address I wanted to, is entering the Gateway configuration (via UI), then change the http address and fix it in a free domain (ex:

Generic MQTT authentication.


MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws)


I had try to fill in like the above, and it still same, after fill with external broker address, the gateway became inactive in Chirpstack.
I saw you mentioned "entering the gateway configuration (via UI)? I can’t find where I can change this configuration via UI, my Chirpstack version is 4.0.2, would like to seek for your advise.

I am using version 4 of chirpstack and also I have generated all the certificates, provided path in the toml file of chirpstack and also tried using gateway.toml file but still in the MQTT Integration I am recieving an error
''read mqtt ca_cert" how did you fixed it?

1 Like

Hi all,

I meant to enter your gateway user interface (UI) via http. For example if your gateway has got the address then you should enter in any browser: “” and then you can do your gateway configuration.

Inside it, you can fix a tcp address for your server. (In other words you are setting your “localhost” to work on another address different from (default)).