# Mosquitto can not work with OH2, please help!

**URL:** <https://community.openhab.org/t/mosquitto-can-not-work-with-oh2-please-help/20584>\
**Category:** Runtime\
**Created:** [January 18, 2017, 4:46pm UTC](https://community.openhab.org/t/mosquitto-can-not-work-with-oh2-please-help/20584 "2017-01-18T16:46:55Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nguy\_n\_Phuc\_Anh\_D\_ng](https://community.openhab.org/letter_avatar_proxy/v4/letter/n/ccd318/32.png) [@Nguy\_n\_Phuc\_Anh\_D\_ng](https://community.openhab.org/u/Nguy_n_Phuc_Anh_D_ng)\
**Post date:** [January 18, 2017, 4:46pm UTC](https://community.openhab.org/t/mosquitto-can-not-work-with-oh2-please-help/20584/1 "2017-01-18T16:46:56Z")

</div>

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:

```php
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:

```csv
OFF=OFF
ON=ON
undefined=Unknown
 

```

And .sitemap file;

```php
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:

```php
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:

```csv
#
# 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:

```csv
Unable to connect (Lookup error.).

```

here is the output of log file:

```csv
==> /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

---

<div class="post-metadata">

**Author:** ![J-N-K](https://community.openhab.org/user_avatar/community.openhab.org/j-n-k/32/19276_2.png) [@J-N-K](https://community.openhab.org/u/J-N-K)\
**Post date:** [January 18, 2017, 5:10pm UTC](https://community.openhab.org/t/mosquitto-can-not-work-with-oh2-please-help/20584/2 "2017-01-18T17:10:03Z")

</div>

The error message states what is wrong. It needs 5 parameters where you provide 4. See [MQTT Binding · openhab/openhab1-addons Wiki · GitHub](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

---

<div class="post-metadata">

**Author:** ![david](https://community.openhab.org/user_avatar/community.openhab.org/david/32/37433_2.png) [@david](https://community.openhab.org/u/david)\
**Post date:** [January 18, 2017, 7:10pm UTC](https://community.openhab.org/t/mosquitto-can-not-work-with-oh2-please-help/20584/3 "2017-01-18T19:10:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Nguy\_n\_Phuc\_Anh\_D\_ng](https://community.openhab.org/letter_avatar_proxy/v4/letter/n/ccd318/32.png) [@Nguy\_n\_Phuc\_Anh\_D\_ng](https://community.openhab.org/u/Nguy_n_Phuc_Anh_D_ng)\
**Post date:** [January 19, 2017, 2:56am UTC](https://community.openhab.org/t/mosquitto-can-not-work-with-oh2-please-help/20584/4 "2017-01-19T02:56:18Z")

</div>

Thanks for your both quick answers  
@J-N-K: In the old version of OH, localhost and [raspberrypi.mshome.net](http://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):

```csv
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:

```csv
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:

```csv
Unable to connect (Lookup error.).

```

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

---

<div class="post-metadata">

**Author:** ![WayneStronach](https://community.openhab.org/user_avatar/community.openhab.org/waynestronach/32/5390_2.png) [@WayneStronach](https://community.openhab.org/u/WayneStronach)\
**Post date:** [January 19, 2017, 3:12am UTC](https://community.openhab.org/t/mosquitto-can-not-work-with-oh2-please-help/20584/5 "2017-01-19T03:12:55Z")

</div>

mosquitto\_sub -d -i subcriber -h [raspberrypi.mshome.net](http://raspberrypi.mshome.net) -t livingroomtemp  
mosquitto\_pub -d -i publisher -h [raspberrypi.mshome.net](http://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.

---

<div class="post-metadata">

**Author:** ![david](https://community.openhab.org/user_avatar/community.openhab.org/david/32/37433_2.png) [@david](https://community.openhab.org/u/david)\
**Post date:** [January 19, 2017, 3:17am UTC](https://community.openhab.org/t/mosquitto-can-not-work-with-oh2-please-help/20584/6 "2017-01-19T03:17:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nguy\_n\_Phuc\_Anh\_D\_ng](https://community.openhab.org/letter_avatar_proxy/v4/letter/n/ccd318/32.png) [@Nguy\_n\_Phuc\_Anh\_D\_ng](https://community.openhab.org/u/Nguy_n_Phuc_Anh_D_ng)\
**Post date:** [January 19, 2017, 3:21am UTC](https://community.openhab.org/t/mosquitto-can-not-work-with-oh2-please-help/20584/7 "2017-01-19T03:21:42Z")

</div>

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:

```csv
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

---

<div class="post-metadata">

**Author:** ![WayneStronach](https://community.openhab.org/user_avatar/community.openhab.org/waynestronach/32/5390_2.png) [@WayneStronach](https://community.openhab.org/u/WayneStronach)\
**Post date:** [January 19, 2017, 3:54am UTC](https://community.openhab.org/t/mosquitto-can-not-work-with-oh2-please-help/20584/8 "2017-01-19T03:54:12Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Nguy\_n\_Phuc\_Anh\_D\_ng](https://community.openhab.org/letter_avatar_proxy/v4/letter/n/ccd318/32.png) [@Nguy\_n\_Phuc\_Anh\_D\_ng](https://community.openhab.org/u/Nguy_n_Phuc_Anh_D_ng)\
**Post date:** [January 19, 2017, 3:58am UTC](https://community.openhab.org/t/mosquitto-can-not-work-with-oh2-please-help/20584/9 "2017-01-19T03:58:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![WayneStronach](https://community.openhab.org/user_avatar/community.openhab.org/waynestronach/32/5390_2.png) [@WayneStronach](https://community.openhab.org/u/WayneStronach)\
**Post date:** [January 19, 2017, 4:04am UTC](https://community.openhab.org/t/mosquitto-can-not-work-with-oh2-please-help/20584/10 "2017-01-19T04:04:44Z")

</div>

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.

🙂

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

---

<div class="post-metadata">

**Author:** ![Nguy\_n\_Phuc\_Anh\_D\_ng](https://community.openhab.org/letter_avatar_proxy/v4/letter/n/ccd318/32.png) [@Nguy\_n\_Phuc\_Anh\_D\_ng](https://community.openhab.org/u/Nguy_n_Phuc_Anh_D_ng)\
**Post date:** [January 19, 2017, 4:12am UTC](https://community.openhab.org/t/mosquitto-can-not-work-with-oh2-please-help/20584/11 "2017-01-19T04:12:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![WayneStronach](https://community.openhab.org/user_avatar/community.openhab.org/waynestronach/32/5390_2.png) [@WayneStronach](https://community.openhab.org/u/WayneStronach)\
**Post date:** [January 19, 2017, 5:26am UTC](https://community.openhab.org/t/mosquitto-can-not-work-with-oh2-please-help/20584/12 "2017-01-19T05:26:06Z")

</div>

so

mosquitto\_pub -t livingroomceil -m ‘ON’

should work
