mc-Things
mc-Platform => MQTT => Topic started by: plains203 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
-
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?
-
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.
-
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.
-
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.
-
Ahh that explains why it does not "work" thanks for information.
-
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.
-
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.
-
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.
-
Please post the that you currently use then I could verify the code on one of my modules.
-
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.
-
Here is a simple code that publish to my broker without any issues
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.
[attachment deleted by admin]
-
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.
-
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.
-
Thanks for helping. I have reconfigured for your broker and have setup the test. It will be interesting to see the results.
-
I see no connection yet from your mcGateway, maybe you need to reboot it for the new connection to take place.
-
Now i see that you are connected and i also see that you are publishing with QoS2
Example this:
Received PUBLISH from plains203 (d0, q2, r0, m1, 'MC/TempC/Bedroom
So everything seems to be working ok.
-
Ok now it's strange because I have received 27.625 on MC/TempC/Lounge with QoS 1 so your setup works and mine is not showing me anything when I sue that QoS tag. I don't get it. I will need to update my gateway firmware to the newest version and test again I guess.
-
I recieved a good number of messages and most were tagged but occasionally the tag seemed to be missing on a couple of them.
[attachment deleted by admin]
-
With Tag you mean the QoS?
That I did on purpose.
But what i have seen is that QoS 0 and 1 is working on my client on my pc and 0, 1 and 2 is working on the mqtt broker, but if i publish a message with q2 from mcModule then the broker gets it but not my client.
I dont know what happening here but i will make some more tests.
For now, upgrade your mcGateway to latest firmware and make some test with QoS 0 and QoS 1 and verify if that is working.
-
I believe there might be some issues here with the way the QoS is handled by the gateway I will do some testing today and keep you informed.
-
Thanks, yes I agree there is something strange going on with the QoS.
-
A few of your messages came through with retain flags Kristofferis. Did you send though through the modules or just using a MQTT Client?
-
0 and 1 worked from my modules but not 2.
The 2 that you did see was a test from my client to verify that the broker worked with 2.
-
I received a retain flag on 3 messages as per this screenshot.
[attachment deleted by admin]
-
Ahh, my answer will be better if I actually reads the question :)
Yes all the messages with retain was from my client not mcGateway.
-
Ok thanks that clears that up for me then. I will try on the weekend with the qos 1 option but now it is late. Thanks for your help & I'll be interested to hear from you mc-Abe. Also I think I noticed a debug log option in mcStudio, I should try that.
-
There are definitely some issues around the QoS. I am investigating and will have a solution soon.
-
Good work Abe, and as always just let me know if you need a hand.
-
Just wanted to let you know that I have resolved this issue but need to do a lot more testing as it was a big change. We will have an update at some point next week that will fix this.
The issue I discovered explains why no QoS2 (Exactly One) MQTT messages get to the subscriber. It was also not honoring proper operation for QoS1 (At Least Once) and messages could have ended up not being delivered.
-
Thanks heaps for letting us know. This should be a nice improvement for my device that has flakey connectivity with the gateway.
-
We just uploaded a new version of the mc-Gateway. This should have resolved the QoS issue. Note that we are still not supporting the Retain feature.
-
Perfect, thanks.
-
I am having another issue now that I have added a second event to my I am finding that some of my modules aren't sending messages but are still sending beacons. I changed one string value between modules and some are working some are not. They all sent out one message after programming. I also attempted to connect to one module in mcSudio and had it connect to a different one about 5 different times. This only started after I had 6 instead of 3 talking. I had to restart mcStudio a few times to get the connection to work. I will paste my messy code below so you can see it.
Class Temperature
Const area As String = "Outside"
Shared Event GetTemp() RaiseEvent Every 2 Minutes
Dim TempC As Float = TempSensor.GetTemp
//Dim TempF As Float = TempSensor.ToFarenheit(TempC)
Dim payload As ListOfByte = New ListOfByte
Dim payString As String = ""
Dim decpos As Integer
Dim topic As String
topic = "MC/TempC/" + area
//TempC = (TempC * 10).ToInteger() / 10
payString = TempC.ToString
decpos = payString.IndexOf(46, 0)
payString = payString.SubString(0, (decpos + 2))
payload.Add(payString)
Lplan.Publish(topic, payload)
End Event
Shared Event CheckVoltage() RaiseEvent Every 6 Hours
Dim BattVolt As Short = Device.BatteryVoltage
Dim voltpayload As ListOfByte = New ListOfByte
Dim voltstring As String
Dim topic As String
topic = "MC/Voltage/" + area
voltstring = BattVolt.ToString
voltpayload.Add(voltstring)
Lplan.Publish(topic, voltpayload)
End Event
End Class
-
And the problem started when you added the CheckVoltage() event?
If you delete that part of the code and upload to all your modules then they all are sending as they should?
-
Been out all day and night but to answer a few of them worked perfectly with this code and others only published 3 or 4 updates. I changed the battery voltage to report every 2 minutes and then the rest of the modules report correctly although they occasionally only publish the temperature and not the voltage. It seems like there is something going wrong with the build function in mcStudio because I rebuilt and re flashed the code on one of the modules that had the 6 hour voltage publish and it worked properly after that, with the same code it was failing with. I have since updated the gateway firmware to the next revision.