openHAB 1.7.0 and MQTT: some questions

I have the following situation I’m currently trying out:

  • Raspberry Pi:

  • IP address: 192.168.123.155

  • Running Mosquitto version 1.4.2 (MQTT v3.1 broker)

  • Running Mosquitto publisher:
    mosquitto_pub -d -i publisher -h 192.168.123.155 -t -m
    Example:
    mosquitto_pub -d -i publisher -h 192.168.123.155 -t testsw/1 -m 1

  • Running Mosquitto subscriber:
    mosquitto_sub -d -i subscriber -h 192.168.123.155 -t
    Example:
    mosquitto_sub -d -i subscriber -h 192.168.123.155 -t testsw/+

  • Windows XP machine:

  • IP address: 192.168.123.145

  • Running the openHAB runtime executable with the default demo application as starting point

  • Added the following items to the end of the file demo.items:
    Switch mqttsw1 “Switch 1” (all) {mqtt=">[geertvc_winxp:testsw/1:command:on:default],>[geertvc_winxp:testsw/1:command:off:default],<[geertvc_winxp:testsw/1:command:MAP(1on0off.map)]"}
    Switch mqttsw2 “Switch 2” (all) {mqtt=">[geertvc_winxp:testsw/2:command:on:default],>[geertvc_winxp:testsw/2:command:off:default],<[geertvc_winxp:testsw/2:command:MAP(1on0off.map)]"}

  • Added the following items to the end of the file demo.sitemap:
    Frame label=“MQTT” {
    Switch item=mqttsw1 label="MQTT Switch 1"
    Switch item=mqttsw2 label="MQTT Switch 2"
    }

  • Added geertvc_winxp as replacement in the file openhab.cfg

  • Added WinXP as client ID in the file openhab.cfg

  • No other changes to any of the above files.

  • Added the 1on0off.map to the transform directory with the following content:
    1=ON
    0=OFF
    ON=1
    OFF=0

When I publish a message on the Raspberry Pi through mosquitto_pub to the topics testsw/1 or testsw/2 (values 1 or 0), then I see the items change in the web UI => OK!
When I change the position of the switches in the webUI for the items MQTT Switch 1 or MQTT Switch 2, I receive the message on the Raspberry Pi through mosquitto_sub => OK!

So far, so good.

Then, I run the openHAB runtime on a Win8.1 machine, next to the one already running on the WinXP machine.

  • IP address of the Win8.1 machine: 192.168.123.170.
  • The content of the file demo.items on the Win8.1 machine is exactly the same as the content of the same file on the WinXP machine.
  • The content of the file demo.sitemap on the Win8.1 machine is exactly the same as the content of the same file on the WinXP machine, apart from the broker name (see next item below)
  • The content of the file openhab.cfg on the Win8.1 machine is exactly the same as the content of the same file on the WinXP machine, apart from the following items:
  • broker is called geertvc_win81 in stead of geertvc_winxp
  • cliendId is Win8_1 in stead of WinXP

Now, when I have the two web interfaces running together (on the Win8.1 as well as on the WinXP machine), I see something I currently can’t explain:

  • When I publish something from the Raspberry Pi through mosquitto_pub, then the web UI for the switches on both machines is following equally, which I understand => OK.
    Next to this, the mosquitto_sub that still runs on the Raspberry Pi also see that change.
  • However, when I change the position of one of the switches on the web UI of the Win8.1 machine, the corresponding switch on the web UI of the WinXP machine is not changing accordingly!
    And vice versa: when I change the state of one of the switches on the web UI of the WinXP machine, the corresponding switch on the web UI of the Win8.1 machine is also not changing.
    This, while in both cases the mosquitto_sub catches both changes => How can this be explained???
    The strange thing is that, when I change one of the switches on the web UI of, say, the WinXP machine, I do see the changes on the openHAB runtime logs of the Win8.1 machine and vice versa. Only, in both cases the web UI is not changing accordingly.
    I hope someone can explain this behaviour to me.

I assume it should be possible to have two openHAB runtimes running on different machines, talking to one and the same MQTT broker, right?

Do the state changes show up in the UI if you refresh the page? I have had a lot of problems with both the Web and HABDriod sometimes missing some changes in an item’s state. If you see the changes in the logs than openHAB got the message, the UI may just be stale.

Rich

Yes, I do see the state changes in both the openHAB runtime logs. If I for instance change a switch position on the web UI running on my Win8.1 machine, then I see it reflected in the openHAB runtime logs on my WinXP machine. And vice versa (and of course also on the own openHAB runtime logs of the machines where the changes originated from).

If you see the state changes in both logs the message is successfully being received and processed in both places. It isn’t an MQTT problem. The problem is the UI is not refreshing to reflect the update.

I have the exact same problem and I don’t know if there is a way to fix it. However, I have found that Contact type items on the Sitemap as Text seem to update, on HABDroid at least, nearly instantly. However, switches tend to not refresh at all until I leave the frame and come back or reload the entire sitemap. I’ve not experimented as much with the web interface but I have seen similar behavior there as well. I always assumed the problem was has because I was using the visibility attribute but now I wonder if the problem is more general.

Rich