Author Topic: MQTT QoS and Retain  (Read 9528 times)

plains203

  • Newbie
  • *
  • Posts: 48
    • View Profile
MQTT QoS and Retain
« on: June 23, 2016, 01:16:00 am »
I am having trouble working out how to set the QoS on my Mqtt messages and also the retain option. Can someone point me in the right direction please?
So far I have this line which I know doesn't work but not sure what should either.
Lplan.Publish("TempC/Lounge", payload, QoS, True)

Thanks
McGateway 0.6-360, 0.7-405
McModules 0.7-358
McStudio 0.7-894

Share on Facebook Share on Twitter


kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: MQTT QoS and Retain
« Reply #1 on: June 23, 2016, 02:05:56 am »
Hello.

When you say it does not work, what do you mean by that?
Does mcStudio gives you a error message?
Is the MQTT message delivered but with wrong QOS?
Is the MQTT message delivered with false retain?

plains203

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: MQTT QoS and Retain
« Reply #2 on: June 23, 2016, 03:02:20 am »
With the string above McStudio doesn't report an error but I don't believe the QoS part is correct as I want to specify a level. My broker recieves the message without qos or retain though.
McGateway 0.6-360, 0.7-405
McModules 0.7-358
McStudio 0.7-894

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: MQTT QoS and Retain
« Reply #3 on: June 23, 2016, 09:56:53 am »
I have now tried this myself and it seems that QoS is working as it should but it seems that it ignores the retain parameter.

In your code you have to change to a QoS Constant like this

QoS.AtMostOnce
QoS.AtLeastOnce
QoS.ExactlyOnce

Try one of the above and see if you could get the QOS to work.

mc-John

  • Global Moderator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: MQTT QoS and Retain
« Reply #4 on: June 23, 2016, 12:36:14 pm »
The code was changed to ignore the retain parameter because we had problems with devices that travel between gateways. We have to think how we, if possible, can implement this with multiple gateways without problems.
Like Like x 1 View List

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: MQTT QoS and Retain
« Reply #5 on: June 23, 2016, 12:59:00 pm »
Ahh that explains why it does not "work" thanks for information.

plains203

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: MQTT QoS and Retain
« Reply #6 on: June 23, 2016, 09:59:02 pm »
I have now tried this myself and it seems that QoS is working as it should but it seems that it ignores the retain parameter.

In your code you have to change to a QoS Constant like this

QoS.AtMostOnce
QoS.AtLeastOnce
QoS.ExactlyOnce

Try one of the above and see if you could get the QOS to work.


Thanks for this. Curious as to how you knew what code to use? Is there something I am missing in the script guide or something?
I know with some IDE's it will show you the options once you start typing the code.
McGateway 0.6-360, 0.7-405
McModules 0.7-358
McStudio 0.7-894

mc-Abe

  • Full Member
  • ***
  • Posts: 167
    • View Profile
    • mc-Things
Re: MQTT QoS and Retain
« Reply #7 on: June 23, 2016, 10:50:17 pm »
If you use Ctrl+Space, in most cases you will get a suggestions for what to type in. The feature is not bulletproof but we are working on making it better.
Like Like x 1 View List

plains203

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: MQTT QoS and Retain
« Reply #8 on: June 23, 2016, 11:06:16 pm »
Once I set the QoS type it no longer passed the MQTT messages through. I tried with the retain flag removed although without the QoS flag being correct and retain set as true in the ide it would pass message with no QoS. So it looks like a bug to me. I would like to use the QoS flag. Retain is not important at this point for what I am doing.
McGateway 0.6-360, 0.7-405
McModules 0.7-358
McStudio 0.7-894

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: MQTT QoS and Retain
« Reply #9 on: June 24, 2016, 01:22:33 am »
Please post the that you currently use then I could verify the code on one of my modules.

plains203

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: MQTT QoS and Retain
« Reply #10 on: June 24, 2016, 04:07:25 am »
This doesn't post anything,

Class Temperature
    Shared Event GetTemp() RaiseEvent Every 30 Seconds
       
        Dim TempC As Float = TempSensor.GetTemp
        Dim TempF As Float = TempSensor.ToFarenheit(TempC)
        Dim payload As ListOfByte = New ListOfByte
        Dim payString As String = ""
       
        payString = TempC.ToString()
       
        payload.Add(payString)
        Lplan.Publish("MC/TempC/Lounge", payload, QoS.ExactlyOnce)
       
    End Event
   
End Class

_________

This does post but no QoS settings

Class Temperature
    Shared Event GetTemp() RaiseEvent Every 30 Seconds
       
        Dim TempC As Float = TempSensor.GetTemp
        Dim TempF As Float = TempSensor.ToFarenheit(TempC)
        Dim payload As ListOfByte = New ListOfByte
        Dim payString As String = ""
       
        payString = TempC.ToString()
       
        payload.Add(payString)
        Lplan.Publish("MC/TempC/Lounge", payload, QoS)
       
    End Event
   
End Class
________________

This posts fine no QoS

Class Temperature
    Shared Event GetTemp() RaiseEvent Every 30 Seconds
       
        Dim TempC As Float = TempSensor.GetTemp
        Dim TempF As Float = TempSensor.ToFarenheit(TempC)
        Dim payload As ListOfByte = New ListOfByte
        Dim payString As String = ""
       
        payString = TempC.ToString()
       
        payload.Add(payString)
        Lplan.Publish("MC/TempC/Lounge", payload)
       
    End Event
   
End Class

_______

I have double checked this with reboots, different modules etc.
« Last Edit: June 24, 2016, 04:13:06 am by plains203 »
McGateway 0.6-360, 0.7-405
McModules 0.7-358
McStudio 0.7-894

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: MQTT QoS and Retain
« Reply #11 on: June 24, 2016, 04:40:04 am »
Here is a simple code that publish to my broker without any issues

Code: [Select]
Class Temperature
    Shared Event GetTemp() RaiseEvent Every 30 Seconds
       
        Dim payload As ListOfByte = New ListOfByte
       
        payload.Add("test")
        Lplan.Publish("MC/TempC/Lounge", payload, QoS.ExactlyOnce)
       
    End Event
   
End Class

As you could see on the image from my broker you could see that Q was 2 so it is working.
Please try the above code and if it is not working then verify that your broker handles QoS as it should.


[ Guests cannot view attachments ]

plains203

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: MQTT QoS and Retain
« Reply #12 on: June 24, 2016, 06:13:10 am »
I tried that. I am using Mosquitto 3.1 as a broker and confirmed it will support QoS levels because I have sent some messages and seen in the diagnostic output that the QoS flag is set correctly. I used mqtt-spy to Publish the message. I am not seeing any messages from the device I used the test code on or my own code. If I remove the QoS reference then it works fine, just no QoS setting.
McGateway 0.6-360, 0.7-405
McModules 0.7-358
McStudio 0.7-894

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: MQTT QoS and Retain
« Reply #13 on: June 24, 2016, 06:19:08 am »
That sounds strange. I send you a private message with information how you could connect to my MQTT broker just to verify this strange behavior.
Like Like x 1 View List

plains203

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: MQTT QoS and Retain
« Reply #14 on: June 24, 2016, 06:28:54 am »
Thanks for helping. I have reconfigured for your broker and have setup the test. It will be interesting to see the results.
McGateway 0.6-360, 0.7-405
McModules 0.7-358
McStudio 0.7-894