Newbie tries to get MQTT broker to work

  • Platform information:
    • Hardware: Game PC
    • OS: Windows 10 Pro
    • openHAB version: 2.5.11

I think that I need some advices now. I have tried to get some functionality to work in openHAB in order to collect data from my Arduinos. I think Arduino codes are pretty much ready but cant get openHAB to work. It’s because the concept is still a little confusing to me. Even that I have tried several days now.

I bet this is a very basic and common questions for beginners, yet I couldnt find help from search. Believe me, I have tried.

I have some images here if it helps you to figure out my situation? Does it look right? And if not, should I just remove bindings and brokers and could some one walk me through to show what I would need to do better. The first problem in current situation is that MQTT broker is offline.

Screen shots tend to be not all that helpful.

To work with MQTT you need to do the following:

  1. Install an MQTT Broker, Mosquitto is popular
  2. In openHAB install the MQTT binding
  3. Create an MQTT Broker Thing and configure it with the connection information the MQTT Broker expects. The host, port, username/password, etc.
  4. Create a Generic MQTT Thing for each device.
  5. Create Channels on that Generic MQTT Thing for each sensor and actuator to publish/subscribe and transform the messages as necessary
  6. Create and link Items to those Channels

If the Broker thing is showing as offline that means there is something wrong with the broker connection settings.

Always look in the logs for errors.

Thank you rlkoshak for your attempt to help me.

I installed the Mosquitto. Do I need to tell it somehow to openHab?

I can find this from my log (192.168.1.109 is the machine where the openHab is installed.

2021-02-05 18:54:01.760 [ERROR] [org.openhab.binding.mqtt ] - bundle org.openhab.binding.mqtt:2.5.12 (242)[org.openhab.binding.mqtt.internal.discovery.MqttServiceDiscoveryService(215)] : The activate method has thrown an exception
java.lang.IllegalArgumentException: ID segment ‘192.168.1.109:1883’ contains invalid characters. Each segment of the ID must match the pattern [A-Za-z0-9_-]*.

Steps 2 and 3 above.

The IP address and port are two separate fields. You’ve combined them into one field.

I didnt find an IP field that contained also the port number, but doesn’t show in log any more. Now the log looks like this:

2021-02-05 20:01:36.357 [INFO ] [thome.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2021-02-05 20:01:37.874 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at http://192.168.1.109:8080
2021-02-05 20:01:37.876 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at https://192.168.1.109:8443
2021-02-05 20:01:38.702 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2021-02-05 20:01:38.781 [INFO ] [ebuilder.internal.HomeBuilderServlet] - Started Home Builder at /homebuilder
2021-02-05 20:01:39.004 [INFO ] [openhab.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2021-02-05 20:01:41.269 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to ‘192.168.1.109’ with clientid 579472d1-4420-4894-900d-fe0dfddddf23
2021-02-05 20:01:53.561 [INFO ] [.reconnect.PeriodicReconnectStrategy] - Try to restore connection to ‘192.168.1.109’. Next attempt in 60000ms
2021-02-05 20:01:53.599 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to ‘192.168.1.109’ with clientid 579472d1-4420-4894-900d-fe0dfddddf23
2021-02-05 20:02:53.618 [INFO ] [.reconnect.PeriodicReconnectStrategy] - Try to restore connection to ‘192.168.1.109’. Next attempt in 60000ms
2021-02-05 20:02:53.629 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to ‘192.168.1.109’ with clientid 579472d1-4420-4894-900d-fe0dfddddf23

Mosquitto should be ok?

C:\Program Files (x86)\mosquitto>mosquitto.exe -c mosquitto.conf
1612545712: mosquitto version 2.0.7 starting
1612545712: Config loaded from mosquitto.conf.
1612545712: Starting in local only mode. Connections will only be possible from clients running on this machine.
1612545712: Create a configuration file which defines a listener to allow remote access.
1612545712: Opening ipv4 listen socket on port 1883.
1612545712: Opening ipv6 listen socket on port 1883.
1612545712: mosquitto version 2.0.7 running

There is something wrong with the configuration of your Broker Thing. It does not have the right configuration to successfully connect to Mosquitto.

There is no such thing as 1883.0 as a port. Ports are always an integer. 1883

Noticed that too, but isn’t this the place where it is set? Should I try some other browser instead…

It’s again that “192.168.1.109:1883 contains invalid character” thing in the log. Im sure that they are not on the same field in the setup.

Also there is now:
2021-02-05 20:43:51.335 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to ‘192.168.1.109’ with clientid e347b6c1-d65d-4a8e-af76-1e3e33f340f9
2021-02-05 20:43:51.408 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to ‘192.168.1.109’ with clientid 4ba576bf-fee4-4455-924a-62ace0bb50e1

Is it ok that there is two different clientid?

That sounds as if you have setup two broker connections .