-1

I'm trying to publish a MQTT message via javascript using the Paho MQTT js client:

gClient = new Paho.Client("192.168.178.34", 9001, "clientId");
gClient.send("mytopic", "myvalue", 1, true);

As I can see in another MQTT client, the message is actually sent. But strangely the QOS is 0 (not 1) and the message is NOT retained.

According to the documentation https://www.eclipse.org/paho/files/jsdoc/Paho.MQTT.Client.html it should work. Why doesn't it?

hardillb
  • 54,545
  • 11
  • 67
  • 105
Boris
  • 8,551
  • 25
  • 67
  • 120

1 Answers1

1

Firstly the QOS is only between the a client and the broker, not between the 2 clients, so even if the message is published at QOS 1, if the client has subscribed at QOS 0 that is what the the client will see.

Secondly I'm 99% sure you will only see the retained bit set in the other client when the message is delivered as part of the response to a new subscription, e.g. if you publish the message with the retained bit set, then subscribe a new client to that topic. If a client is already connected then they won't see the retained bit set as it's just a normal delivery at that point.

hardillb
  • 54,545
  • 11
  • 67
  • 105
  • Thanks for that info, good to know. But I still think that there's something wrong. E.g. newly connecting clients receive old values. This leads me to believe that the retained flag on my new messages was actually not set. – Boris Feb 11 '19 at 08:03
  • What do you mean by old value? A new client will always receive the last message published with the retained bit set – hardillb Feb 11 '19 at 08:15