Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

MQTT Pointer to Byte Help

jebates31
2021-07-15
2021-07-19
  • jebates31 - 2021-07-15

    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
  • nothinrandom - 2021-07-19

    @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')

     
  • jebates31 - 2021-07-19

    Thank you, I originally tried to do this and I keep getting an error showing the Allocated Payload size has been exceeded.

     
  • jebates31 - 2021-07-19

    Thank you, I originally tried to do this and I keep getting an error showing the Allocated Payload size has been exceeded.

     
  • i-campbell

    i-campbell - 2021-07-19

    please see the example project at C:\Users\user-who-installed-package\MQTT Client SL\1.0.2.0

     
  • nothinrandom - 2021-07-19

    @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

     

Log in to post a comment.