I am working on a MQTT program but need some help with a function block. I have the Client block connected to the broker with the Topics communicating but i can't figure out how to publish or subscribe. I am not sure what to put in to the pbPayload? I am expecting a string value but it looks like it is a Pointer_TO_Byte?? I am still pretty new with Codesys and haven't used this data type before.
Pointer means that you need to get the memory address that stores the data. This can be done using the ADR instruction, so in your case you could do things like:
1) reading from a string variable like pbPayload := ADR(_sMyTestString)
2) reading from a static string variable like pbPayload := ADR('My Test String')
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You are probably still missing the udiMaxPayloadSize parameter. From the screenshot, it is set to 0, so it is expecting an empty string. You could do something like:
1) udiMaxPayloadSize := SIZEOF(_sMyTestString);
2) udiMaxPayloadSize := 35; // some fixed string length that would cover your test case
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I am working on a MQTT program but need some help with a function block. I have the Client block connected to the broker with the Topics communicating but i can't figure out how to publish or subscribe. I am not sure what to put in to the pbPayload? I am expecting a string value but it looks like it is a Pointer_TO_Byte?? I am still pretty new with Codesys and haven't used this data type before.
Last edit: jebates31 2021-07-15
@jebates31,
Pointer means that you need to get the memory address that stores the data. This can be done using the ADR instruction, so in your case you could do things like:
1) reading from a string variable like pbPayload := ADR(_sMyTestString)
2) reading from a static string variable like pbPayload := ADR('My Test String')
Thank you, I originally tried to do this and I keep getting an error showing the Allocated Payload size has been exceeded.
Thank you, I originally tried to do this and I keep getting an error showing the Allocated Payload size has been exceeded.
please see the example project at C:\Users\user-who-installed-package\MQTT Client SL\1.0.2.0
@jebates31,
You are probably still missing the udiMaxPayloadSize parameter. From the screenshot, it is set to 0, so it is expecting an empty string. You could do something like:
1) udiMaxPayloadSize := SIZEOF(_sMyTestString);
2) udiMaxPayloadSize := 35; // some fixed string length that would cover your test case