I try to get the MQTT Bindung to talk to some other Raspberry Pis. Previously I used the MQTT Action Binding with some rules to send specific text values to the berries.
With the new released openHAB 2.5 I want to implement the MQTT Binding using switches and channels. Even If I tried several guides and the official description of the binding, I cant receive any messages on other berries.
I am using the embedded broker, created a MQTT generic thing and connected to a Switch Channel (“MQTT command topic” is “test”). Changing the state of the switch to ON or OFF shall send “ON” or “OFF”.
No error messages are at the log files and the broker and generic thing are ONLINE / INITIALIZED.
With the other PI I subscribe to the topic “test” (like I did with the MQTT Action binding) :
mosquitto_sub –t test
Switching the MQTT-Switch doesn’t give me any response at the subscribed topic.
I really don’t know my mistake – Could be the subscription to the topic “test” by the mosquitto client the wrong approach?
Simplify and make changes gradually. Presumably if you had this working with the MQTT v1 binding working using the MQTT Action, you have Mosquitto or some other external broker running. Keep using that. Honestly, the embedded broker is no longer maintained and probably shouldn’t be used anyway, but you definitely don’t want to move from a solid broker like Mosquitto to that.
Keep your Rules the same. Once you have your Broker Thing connected and Online, you can publish messages using
actions.getAction("mqtt", "broker:thing:id").publishMQTT("topic", "message", false) // last argument is the retained flag
Once that works, then move to creating the Generic MQTT Things and Channels to replace your Rules.
Minimize your changes to make it easier to find where it went wrong.
It doesn’t matter what the broker is. If the configuration is correct it will work. You configure the connection to the Broker in the MQTT Broker Thing.
So do you see errors in the logs? Get MQTT Explorer and monitor all of the messages on your broker instead of just mosquitto-sub.
without curly bracket Bridge mqtt: .... Thing mqtt: ...
Nevertheless, using your code doens’t work at my side.
Where is the connection to the embedded mqtt broker? Shall the bridge make this connection and how do I see this in the code?
@rlkoshak
When I connect to my openhabserver 192.168.222.10:1883 with the following settings I don’t get any message (no error logs, no $SYS or something else)
The MQTT-Client ID is jsut a name not the connected MQTT Server ID, isn’t it?
This is based on how mosquitto was set up in the first place. If you never set up a username and password, how did you know what username and password to use to get it to work?