Cannot seem to get MQTT working fully N00B

Hi all,

OpenHab noob here trying to get this working but not having much luck.

I think I must have read nearly all the tutorials online on setting up openhab and configuring but I cannot seem to get MQTT fully working.

My plan is to have OpenHAB running on a raspberry pi, with either Arduino+Ethernet shield+relay or ESP8266(running Arduino code)+relay to control lights in the house.

Currently I have set up the following –

  • OpenHab running
  • .Sitemap and .items configured for 2 switches
  • Openhab.cfg configured for the MQTT binding
  • Mosquitto running
    If I open another terminal and use the command mosquito_sub –d –v –t /# , then flick a switch using the openhab.app website I can see the commands coming through.
    I haven’t tried putting a Arduino in subscribe mode and waiting for the data yet (new house and waiting for broadband to be activated so im doing everything over a 4g wifi hotspot), but I am trying to mosquito_pub messages to the openhab but nothing is showing on the /start.sh console window, even though the messages look exactly the same on the mosquito_sub terminal as they do when the openhab sends the messages by toggling in the GUI.

Am I confused? I expected the messages to be routed into the openhab and toggle the switch?

So after 4 more hours of playing, i have managed to publish on off commands from a windows CMD terminal to show up on the openhab/start.sh console.

What i was missing on the .items file is 3 sets of [broker: …], first one to turn the light on (> outgoing), second to turn the light off (> outgoing), and a third to show the state (< incoming).

Now i need to get an arduino programmed, fingers crossed!!

What do your Item definitions that subscribe to the MQTT message queues look like? One common and easy to overlook error is getting the direction wrong in your binding config. For example:

Inbound (i.e. openHAB reads the messages, changing this switch will not be sent to Mosquitto)
{mqtt="<…

Outbound (i.e. openHAB writes the messages, messages sent to this switch will not be read by openHAB)
{mqtt=">…

I think I’ve read that you can have a bidirectional Switch but the wiki doesn’t seem to document it.

Another common error is a typo in the topic in your item definition. Make double sure that they match.

Without seeing the specifics of what your Items are and what topic you are publishing to using mosquitto_pub I can’t help more.

Rich

I can speak and receive mqtt commands between my MacBook and the raspberry pi running openhab.
Also I have a arduino uno running some code, and it will connect to my MacBook and commands work fine, but it will not connect to the raspberry pi when I change the server ip to the raspberry pi’s

It feels like I have missed something,and it is blocking connection from the uno, perhaps because I have been using shh from the MacBook the raspberry pi allows the commands but will not allow them from anything else.

Could it be something in the openhab.cfg?

I have just ran openhab on my mac, and the ardunio functions perfectly with it. (im so relieved that i was doing something right all along)

I just dont know why the raspberry pi will not accept its connection!??