MQTT 2.4.0 Binding qos is 1

I switched from mqtt1 binding to the new mqtt 2.4.0 binding but can’t set the qos. I don’t like the paperUI and prefer configuration via files.
Here is my config:
My mqtt.things looks like this (please note that I replaced credentials with dummy data or <placeholders>):

Bridge mqtt:broker:thingspeak [ host="mqtt.thingspeak.com", port=8883, secure=true, reconnectTime=1000, username="username", password="password", certificatepin=false, publickeypin=false, qos=0 ]{
    
    Thing topic motion {
    Channels:

       Type switch : MotionSwitch "Motion Switch" [ qos=0, retained=false, stateTopic="channels/<ID>/subscribe/fields/field1", commandTopic="channels/<ID>/publish/fields/field1/<KEY>", on="ON", off="OFF" ]
    
    }
}

And an according item:

Switch MQTT_Switch_Command "MQTT Command 1" {channel="mqtt:topic:thingspeak:motion:MotionSwitch"}

After setting the phao mqtt logger to DEBUG level (karaf: log:set DEBUG org.eclipse.paho.client.mqttv3) I can see some log entries when switching the MQTT_Switch_Command item (please note that qos is set to 1 but configured to be 0):

2019-11-21 11:19:33.169 [DEBUG] [mqttv3.internal.wire.MqttOutputStream] - null: Sent PUBLISH qos:1 msgId:10 retained:false dup:false topic:"channels/<ID>/publish/fields/field1/<KEY>" payload:[hex:4f4e utf8:"ON" length:2]
2019-11-21 11:19:33.380 [DEBUG] [mqttv3.internal.wire.MqttInputStream] - null: Automatic Reconnect Successful: PUBACK msgId 10

The update is not registered/showed by thingspeak so I guess it’s not accepted. (my channel on thingspeak shows 0 entries). I guess it’s rejected because of the qos.

The thingspeak mqtt docs state the following (requirements? or suggestions?)
https://de.mathworks.com/help/thingspeak/publishtoachannelfieldfeed.html

Set the PUBLISH messages to a QoS value of 0.
Set the connection RETAIN flag to 0.
Set the connection CleanSession flag to 1.

I cross-checked with MQTT.fx and published a new value successfully with qos 0. When I set the qos to 1 it does not work. Therefore I’m highly confident that the phao qos is the issue.

I cross-checked by using a public mqtt server that is not that picky regarding qos and the state changes where propagated successfully.

I restarted openhab2 multiple times because I red there is an issue with reloading the config. See Small problem with mqtt after model refresh

The relevant docs are here:

qos : Quality of Service. Can be 0, 1 or 2. Please read the MQTT specification for details. Defaults to 0.

I can’t observe a default of 0, neither setting this value to 0. It’s constantly 1. The same for the channel based configuration.

Does anyone have an idea what the problem is? Or other things I can try?

  • Platform information:
    • openHAB version: 2.4.0

What happens when you remove qos=0 from the thing topic and place retained=false at the end like below?

Bridge mqtt:broker:thingspeak [ host="mqtt.thingspeak.com", port=8883, secure=true, reconnectTime=1000, username="username", password="password", certificatepin=false, publickeypin=false, qos=0 ]{
    
    Thing topic motion {
    Channels:

       Type switch : MotionSwitch "Motion Switch" [ stateTopic="channels/<ID>/subscribe/fields/field1", commandTopic="channels/<ID>/publish/fields/field1/<KEY>", on="ON", off="OFF", retained=false ]
    
    }
}

The output is the same. The message is not published on thingspeak. Tested with restart of openhab:

2019-11-21 15:11:13.041 [DEBUG] [qttv3.internal.wire.MqttOutputStream] - null: Sent PUBLISH qos:1 msgId:5 retained:false dup:false topic:"channels/<ID>/publish/fields/field1/<KEY>" payload:[hex:4f4e utf8:"ON" length:2]

Also removing qos from the Bridge does not change anything.
Also reinstalled the binding without success.

There has been a years worth of bug fixes and improvements to the MQTT binding since 2.4 was released. Try it with at least version 2.5 M5 or the latest snapshot. If you still see this behavior, file an issue on the binding. See How to file an Issue. The issue goes on the openhab2-addons repo.

A work in progress -

Did you check with latest snapshot version? QoS should work. As a side note: IMO a broker that rejects other QoS than 0 is broken and should be fixed.

The problem with QoS 0 is that it‘s perfectly fine if the message is not delivered at all. The default should really be 1.

Thank you. I thought 2.4.0 would be stable enough for this.

After upgrading to 2.5.0.M5 the publish works fine… sometimes. I guess there is a rate limit on the thingspeak broker or something like this, because with MQTT.fx it also doesn’t publish sometimes.
Beside this

  • the subscribe does not work
  • the bridges goes offline
  • the thing has an error
  • everything is OK (connected) but states are not changed from the subscription

I can’t find a causality between my changes and the errors. So I cant give instructions to reproduce.
@rossko57 thanks I did not see this issue.

@J-N-K Thanks for confirming that the PR is merged and should be function. Upgrading to a snapshot release? I’m not sure I want to do this with my live system.

2.5 M5 was released 5 days ago and the PR was merged 3 days ago… I don’t understand why the publish is working now (sometimes).

The mqtt implementation changed and I can’t view the actual mqtt command with its params as in 2.4.0. Setting com.hivemq.client.mqtt, org.openhab.binding.mqtt and org.eclipse.smarthome.io.transport.mqtt to DEBUG does not show the messages Does someone know how to check the qos? Do i need to switch to an unsecure connection and record the mqtt packages?

PRs are not back ported. To get that PR, you need to run a snapshot from at least a day after the PR was merged.

I did not expect that the PR is back ported to 2.4.0 somehow.
Do you agree that the mentioned PR should be available in version > 2.5 M5? (Not “>=”)

M5 was released 5 days ago. The pr was merged 3 days ago. 3 days is after 5 days so the PR is not going to be in m5. PRs are not back ported.

Exactly. That’s why I don’t understand how publish is working now. (since I am on 2.5 M5 that does not include this PR).

But since there were so many changes internal on the mqtt module and I can’t confirm qos 0 is working now the reason might be something other than qos.

And again, also with 2.5 M5 and other broker and same config everything works fine. Publish, subscribe, state changes.

Bridge mqtt:broker:hive [ host="broker.hivemq.com", port=1883, reconnectTime=1000, certificatepin=false, publickeypin=false, qos=0 ]{
    
    Thing topic motion {
    Channels:
       Type switch : MotionSwitch "Motion Switch" [stateTopic="channels/<ID>/subscribe/fields/field1", commandTopic="channels/<ID>/publish/fields/field1", on="ON", off="OFF", retained=false]
    }
}

So there is something with thingspeak only.

The issue still exists. Does anybody have an idea?

If the issue is still present on the latest release (2.5.6-2 as of this posting) than file a new issue.

Yes, tested with 2.5.6-2.

Seems to be related to https://github.com/openhab/openhab-addons/issues/8056 and
Connecting OpenHab - TheThingsNetwork