MQTT enqueue downlink payload issues

Hello every body,

I am working on setting up an MC-EDGE plc as a LoraWan gateway. The device I am connecting to is a Dragino LT-22222-L. I am programming the PLC via CODESYS.

I can have the device connected successfully and can get digital outputs to turn on using the Enqueue Downlink Payload under Applications/Mc-edge/Devices/Dragino
But this only works when I send the payload in the based 64 encoded format.


Above encoded payload that turns on the Dragino’s DO1 and DO0


the highlighted area shows that the payload took successfully.

However when I try to do this using the JSON object the payload does not take.


the above photo shows the JSON message I am sending - which I got from the MQTT format in the documentation.


The above photo shows that the payload is blank.

when sending the payload via JSON I can see the downlink and ack uplink show up in my LoraWan frames tab, so the gateway and the device are talking back and forth.

So my question is pretty much what is the difference between sending just the encoded payload compared to the JSON and why is the data field not functioning the way I am intending?

Additionally I am having problems with my CODESYS MQTT publish function - I am sure this is not the correct place to ask about this problem but hey maybe someone will know!

My client and subscriber are functioning perfectly, I am able to get analog and digital values out of my device and into my CODESYS program. When using the Publisher command It returns the status’ “done” and “No_errors” yet when looking inside the LoraWan Frames in chirpstack the GW never sends a downlink.

Here is my code:

PROGRAM PLC_PRG
VAR
	xTurnON: BOOL;
	client : MQTT.MQTTClient;
	publisher : MQTT.MQTTPublish;
	subscriber : MQTT.MQTTSubscribe;
	
	GO: BOOL;
	data_sub   : ARRAY [0..1000] OF BYTE;

	pub_sub   : ARRAY [0..91] OF BYTE := [	123,34,99,111,110,102,105,114,109,101,100,
											34,123,34,99,111,110,102,105,114,109,101,
											100,34,58,116,114,117,101,44,34,102,80,111,
											114,116,34,58,49,44,34,100,97,116,97,34,58,
										34,65,103,69,66,69,81,61,61,34,125,58,116,114,
											117,101,44,34,102,80,111,114,116,34,58,49,44,
											34,100,97,116,97,34,58,34,65,103,69,66,69,81,
											61,61,34,125];
	errorcode: MQTT.MQTT_ERROR;
	errorcode2: MQTT.MQTT_ERROR;
	errorcode3: MQTT.MQTT_ERROR;
	active: BOOL;
	_ClientDone: BOOL;
	_ClientBusy: BOOL;
	_ClientError: BOOL;
	
	topicfilter : WSTRING(1024) := "application/2/device/a84041931187ebc6/rx";
	pubfilter   : WSTRING(1024) := "application/2/device/a84041931187ebc6/tx";
	size: UDINT := 92;
	DONE: BOOL;
	BUSY: BOOL;
	j: INT;
	payloadStart: INT;
	i: INT;
END_VAR

xTurnON := TRUE;

client(
	xEnable:= xTurnON, 
	xDone=> _ClientDone, 
	xBusy=> _ClientBusy, 
	xError=> _ClientError, 
	uiPort:= 1883, 
	xUseTLS:= FALSE, 
	uiKeepAlive:= , 
	pbWillMessage:= , 
	uiWillMessageSize:= , 
	xWillRetain:= , 
	eWillQoS:= , 
	xCleanSession:= FALSE, 
	wsUsername:= , 
	wsPassword:= , 
	wsWillTopic:= , 
	sClientId:= , 
	tPingInterval:= , 
	hCert:= , 
	itfTLSContext:= , 
	itfAsyncProperty:= , 
	sHostname:= '127.0.0.1', 
	eMQTTError=> errorcode , 
	xConnectedToBroker=> );

subscriber(
	xEnable:= client.xConnectedToBroker, 
	eSubscribeQoS:= MQTT.MQTT_QOS.QoS1, 
	pbPayload:= ADR(data_sub), 
	udiMaxPayloadSize:= SIZEOF(data_sub), 
	eFilterMode:= MQTT.FILTER_MODE.FILTER_OFF, 
	mqttClient:= client, 
	wsTopicFilter:= topicfilter, 
	xDone=> , 
	xBusy=> , 
	xError=> , 
	eMQTTError=>errorcode2, 
	xReceived=> , 
	udiPayloadSize=> , 
	xSubscribeActive=> active , 
	wsLastTopic=> );
	

publisher(
	xExecute:= GO,
	udiTimeOut:= ,
	eQoS:= MQTT.MQTT_QOS.QoS1,
	xReDelivery:= ,
	xRetain:= ,
	pbPayload:= ADR(pub_sub),
	udiPayloadSize:= size,
	mqttClient:= client,
	wsTopicName:= pubfilter,
	xDone=> DONE ,
	xBusy=> BUSY,
	xError=>  ,
	eMQTTError=> errorcode3 );


IF j = 0 THEN
	FOR i := 0 TO 999 DO
		IF data_sub[i] = 34 AND data_sub[i+1] = 100 AND data_sub[i+2] = 97 AND data_sub[i+3] = 116 AND data_sub[i+4] = 97 AND data_sub[i+5] = 34 AND data_sub[i+6] = 58 AND data_sub[i+7] = 34 THEN
			payloadStart := i + 8;
		END_IF
	END_FOR
END_IF

j := payloadStart;

you will notice the:
pub_sub : ARRAY [0…91] OF BYTE
is the array that I intend to publish. The values that I populated this array with are the direct conversion of the above JSON to Hex and then to base 10.

I am unsure why my CODESYS MQTT subscriber was so easily set up to receive uplinks but its seeming impossible to make the publisher send a Downlink.

I would really appreciate some insight on either of the issues I have explained above! I will totally cooperate so if you need additional files, pictures, or explanation please feel free to let me know!
Thank you for your time :slight_smile:

Note: Sorry for making this post in a bunch of replies, I could only put one photo per (which I think is a little silly because the description of a problem like this requires many screenshots to be thorough)

The JSON object is parsed by your codec encoder function. It is not the same as the enqueue payload that you would publish over MQTT. E.g. the

{
    "confirmed": true,
    ...
   "data": "..."
}

object is passed through the codec and then it is up to your codec function to encode this to a slice of bytes.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.