Mosquitto can not work with OH2, please help!

As the title said, I want to get communication between raspberry pi 3 running OH2 and arduino via nrf24l01 module.
Here is the .item file:

Switch Light_GF_Living_Ceiling 		"Living room Ceiling [MAP(switch.map):%s]"		(GF_Living, Lights){mqtt=">[mymosquitto:livingroomceil:command:default]"}
Number Temperature_GF_Living 	"Living room Temperature [%.1f °C]"	<temperature>	(Temperature, GF_Living){mqtt="<[mymosquitto:livingroomtemp:state:default]"}

The switch.map:

OFF=OFF
ON=ON
undefined=Unknown
 

And .sitemap file;

Switch item=Light_GF_Living_Ceiling 
Text item=Temperature_GF_Living 

When I used OH1.8.3, there was so easy to set up mqtt configuration inside openhab.cfg and then use 2 sets of commands below to play around:

mosquitto_sub -d -i subcriber -h raspberrypi.mshome.net -t livingroomtemp
mosquitto_pub -d -i publisher -h raspberrypi.mshome.net -t livingroomceil -m ON

And the result was perfect, I received the value of livingroomtemp when I used mosquitto_sub and also I could control livingroomceil by using mosquitto_pub
But when I migrate to OH2, I amend the mqtt.cfg file like this:

#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.
#

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
mymosquitto.url=tcp://localhost:1883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a default one is generated.
mymosquitto.clientId=openHAB

# Optional. User id to authenticate with the broker.
#<broker>.user=<user>

# Optional. Password to authenticate with the broker.
#<broker>.pwd=<password>

# Optional. Set the quality of service level for sending messages to this broker.
# Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2
# (Deliver exactly once). Defaults to 0.
mymosquitto.qos=0

# Optional. True or false. Defines if the broker should retain the messages sent to
# it. Defaults to false.
mymosquitto.retain=true

# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to true.
mymosquitto.async=true

# Optional. Defines the last will and testament that is sent when this client goes offline
# Format: topic:message:qos:retained <br/>
#<broker>.lwt=<last will definition>

when I use the commands above, I only get the respond:

Unable to connect (Lookup error.).

here is the output of log file:

==> /var/log/openhab2/openhab.log <==
2017-01-18 23:29:48.363 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'demo.items'
2017-01-18 23:29:48.395 [ERROR] [arthome.core.items.dto.ItemDTOMapper] - Group function 'AND' requires two arguments. Using Equality instead.
2017-01-18 23:29:48.400 [ERROR] [el.item.internal.GenericItemProvider] - Binding configuration of type 'mqtt' of item 'Light_GF_Living_Ceiling' could not be parsed correctly.
org.eclipse.smarthome.model.item.BindingConfigParseException: Configuration 'mymosquitto:livingroomceil:command:default' is not a valid outbound configuration: Configuration requires 5 parameters separated by ':'
        at org.openhab.core.binding.internal.BindingConfigReaderDelegate.processBindingConfiguration(BindingConfigReaderDelegate.java:50)[176:org.openhab.core.compat1x:2.0.0.201701091302]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:312)[123:org.eclipse.smarthome.model.item:0.9.0.201701090931]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:284)[123:org.eclipse.smarthome.model.item:0.9.0.201701090931]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.processBindingConfigsFromModel(GenericItemProvider.java:167)[123:org.eclipse.smarthome.model.item:0.9.0.201701090931]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.modelChanged(GenericItemProvider.java:347)[123:org.eclipse.smarthome.model.item:0.9.0.201701090931]
        at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.notifyListeners(ModelRepositoryImpl.java:207)[122:org.eclipse.smarthome.model.core:0.9.0.201701090931]
        at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:120)[122:org.eclipse.smarthome.model.core:0.9.0.201701090931]
        at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile(FolderObserver.java:270)[122:org.eclipse.smarthome.model.core:0.9.0.201701090931]
        at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.access$1(FolderObserver.java:264)[122:org.eclipse.smarthome.model.core:0.9.0.201701090931]
        at org.eclipse.smarthome.model.core.internal.folder.FolderObserver$WatchQueueReader.processWatchEvent(FolderObserver.java:145)[122:org.eclipse.smarthome.model.core:0.9.0.201701090931]
        at org.eclipse.smarthome.core.service.AbstractWatchQueueReader.run(AbstractWatchQueueReader.java:122)[98:org.eclipse.smarthome.core:0.9.0.201701090931]
        at java.lang.Thread.run(Thread.java:745)[:1.8.0_111]
2017-01-18 23:29:48.411 [ERROR] [arthome.core.items.dto.ItemDTOMapper] - Group function 'AND' requires two arguments. Using Equality instead.
2017-01-18 23:29:48.426 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'demo.items'
2017-01-18 23:29:48.455 [ERROR] [arthome.core.items.dto.ItemDTOMapper] - Group function 'AND' requires two arguments. Using Equality instead.
2017-01-18 23:29:48.459 [ERROR] [el.item.internal.GenericItemProvider] - Binding configuration of type 'mqtt' of item 'Light_GF_Living_Ceiling' could not be parsed correctly.
org.eclipse.smarthome.model.item.BindingConfigParseException: Configuration 'mymosquitto:livingroomceil:command:default' is not a valid outbound configuration: Configuration requires 5 parameters separated by ':'
        at org.openhab.core.binding.internal.BindingConfigReaderDelegate.processBindingConfiguration(BindingConfigReaderDelegate.java:50)[176:org.openhab.core.compat1x:2.0.0.201701091302]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:312)[123:org.eclipse.smarthome.model.item:0.9.0.201701090931]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:284)[123:org.eclipse.smarthome.model.item:0.9.0.201701090931]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.processBindingConfigsFromModel(GenericItemProvider.java:167)[123:org.eclipse.smarthome.model.item:0.9.0.201701090931]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.modelChanged(GenericItemProvider.java:347)[123:org.eclipse.smarthome.model.item:0.9.0.201701090931]
        at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.notifyListeners(ModelRepositoryImpl.java:207)[122:org.eclipse.smarthome.model.core:0.9.0.201701090931]
        at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:120)[122:org.eclipse.smarthome.model.core:0.9.0.201701090931]
        at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile(FolderObserver.java:270)[122:org.eclipse.smarthome.model.core:0.9.0.201701090931]
        at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.access$1(FolderObserver.java:264)[122:org.eclipse.smarthome.model.core:0.9.0.201701090931]
        at org.eclipse.smarthome.model.core.internal.folder.FolderObserver$WatchQueueReader.processWatchEvent(FolderObserver.java:145)[122:org.eclipse.smarthome.model.core:0.9.0.201701090931]
        at org.eclipse.smarthome.core.service.AbstractWatchQueueReader.run(AbstractWatchQueueReader.java:122)[98:org.eclipse.smarthome.core:0.9.0.201701090931]
        at java.lang.Thread.run(Thread.java:745)[:1.8.0_111]
2017-01-18 23:29:48.471 [ERROR] [arthome.core.items.dto.ItemDTOMapper] - Group function 'AND' requires two arguments. Using Equality instead.

Anybody please help!!!1

The error message states what is wrong. It needs 5 parameters where you provide 4. See https://github.com/openhab/openhab1-addons/wiki/MQTT-Binding

Regarding the connection problem: why do you use different hostnames in the OH configuration and the command line?

Best regards

-jnk

1 Like

I believe your switch item needs to send a command (ON or OFF) instead of default.

Try this:
Switch Light_GF_Living_Ceiling "Living room Ceiling [MAP(switch.map):%s]" (GF_Living, Lights){mqtt=">[mymosquitto:livingroomceil:command:*]"}

from the docs:
Use * to indicate that any command or state should trigger the sending.

1 Like

Thanks for your both quick answers
@J-N-K: In the old version of OH, localhost and raspberrypi.mshome.net actually is the same hostname. I was successfully test by using those commands
@david : As your suggestion, I’ve changed my items to (I followed the example from the docs):

Switch Light_GF_Living_Ceiling 		"Living room Ceiling [MAP(switch.map):%s]"		(GF_Living, Lights){mqtt=">[mymosquitto:livingroomceil:command:ON:1],>[mymosquitto:livingroomceil:command:OFF:0]"}

but still no progress when I used these two commands:

mosquitto_sub -d -i subcriber -h raspberrypi.mshome.net -t livingroomtemp
mosquitto_pub -d -i publisher -h raspberrypi.mshome.net -t livingroomceil -m ON

The result is:

Unable to connect (Lookup error.).

So I think the command syntax in OH2 might be different from OH1.8.3
Please help me!!!

mosquitto_sub -d -i subcriber -h raspberrypi.mshome.net -t livingroomtemp
mosquitto_pub -d -i publisher -h raspberrypi.mshome.net -t livingroomceil -m ON

are mosquitto commands and have no relationship to OH or OH2, i.e. if they aren’t working then either mosquitto isn’t running on your raspberrypi or the syntax of instructions is wrong.

Not sure why you need the -i publisher / -i subscriber. To monitor MQTT on my RPI I use mosquitto_sub -t +/#. I also don’t need the -h option as mosquitto is running on the same RPI.

Try mosquitto_sub -t ‘#’ and see if this works.

1 Like

also make sure the hostname is resolving correctly. or try using the IP address.

Woah, what a quick reply, thank you guys!
@WayneStronach
Oh indeed it works, now I can see the state changes of my items, something like this:

OFF
100
OFF
ƠN
ƠN
OFF
OFF
ƠN
OFF

So how about publishing value to a specific item? And how to subcribe to only one particular item?
@david: oh thanks, I believe the hostname is just right

That’s great - if you add the -v to the mosquitto_sub you will see the full item name. To subscribe to only one item, just change -t ‘#’ to - t itemname

And then to publish to single item you should only need

mosquitto_pub - t itemname -m ‘value’

Note generally the publishing would be done via openhab - e.g. from my OH2

Number RailOn1Time88 “Towel Rail Time On 1[%.0f :00]” (Node88,log) {mqtt=">[OH2MQTT:home/rfm_gw/sb/node88/dev81:state:*:default]"}

writes a value from RailOn1Time88 to home/rfm_gw/sb/node88/dev81 on mosquitto OH2MQTT (as per MQTT.cfg)

How about publishing? I want to control switches from my terminal
Thanks for your support, I’m veryyy appreciated!

and for output/switch an example is:

Switch DO_70_2 “Allow Automatic Humidity Control [MAP(EnDis.map):%s]” (Node70,log) {mqtt=">[OH2MQTT:home/rfm_gw/sb/node70/dev17:command:ON:ON],>[OH2MQTT:home/rfm_gw/sb/node70/dev17:command:OFF:OFF]",autoupdate=“true”}

This writes value (ON/OFF) from tag DO_70_2 to home/rfm_gw/sb/node70/dev17.

:slight_smile:

Note the MAP section is just to change the words in OH from ON/OFF to enabled/disabled.

1 Like

EDIT: Oh I figured out by myseft already, thanks for your help!!!

Oh yes I do understand that but my question is what exactly is my command to send on/off command to a switch, not reading its state. For example, I want to use mosquitto_pub command to send ON/OFF value from my terminal so that the corresponding item in OH2 can be changed.
anyway thanks for your example, it’s good to know

so

mosquitto_pub -t livingroomceil -m ‘ON’

should work

1 Like