[SOLVED] Can't get my MQTT Binding to work (still connected but it does nothing)

Tags: #<Tag:0x00007f2fbb496aa0>

Hello,
i have problems to get my mqtt binding working proberbly.
MQTT binding is installed, nothing else.
In config i tried all you can find in www, now it has only “mosquitto.url=tcp://192.168.178.95:8888” and the connection is established.

Mosquito broker is working under this address and the openhab2 log gives me no error

2018-07-14 22:59:04.115 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
LOG
--------------------------
2018-07-14 22:59:04.117 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto'
==> /var/log/openhab2/events.log <==
2018-07-14 22:59:48.553 [ome.event.ItemCommandEvent] - Item 'MQTT_Switch_Command' received command ON
2018-07-14 22:59:48.616 [vent.ItemStateChangedEvent] - MQTT_Switch_Command changed from NULL to ON
-----------------------------

Here you can see, that Openhab recognize if i triggered the switch, but didnt send anything through mqtt.
The MQTT broker (Mosquitto) is tested with an esp8266 and worked. I tested it with MQTT.fx

My Command item looks like:

Switch MQTT_Switch_Command "Lichtschalter" {mqtt=">[mosquitto:esp/station001:command:ON:1],>[mosquitto:esp/station001:command:OFF:0]"}

I’ve been trying to get that working for the past 3 days, but I definitely need help !!

Sorry for my bad english!
best regards,
Marc

update

Mosquito log =>
1531601944: New connection from 192.168.178.95 on port 8888.
1531601944: New client connected from 192.168.178.95 as paho89601675222578 (c1, k60).

installed:

  • clean install with the openhab2 image for raspi ==> I used a raspi 3 b +
  • installed mosquitto => config anonymous connection allowed => on port 8888
  • install mqtt binding in openhab (nothing else)
  • in services/mqtt.conf added the following line “mosquitto.url=tcp://192.168.178.95:8888”
  • create item and sitemap i listed below
  • tested the mosquitto mqtt broker with esp8266 and all worked fine (but openhab2 did nothing over mqtt => tested with mqtt.fx => subscribed # to see all postings, also esp/station001 )

status now => not working mqtt binding

Can you publish your mqtt.cfg file, please

Use the code fences:

Here is my mqtt.cfg
it has only the .url
but i tried all … rly all other things

If active…MQTT Event Bus Binding works perfect!

#
# 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
#<broker>.url=tcp://<host>:1883

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

# Optional. True or false. If set to true, allows the use of clientId values
# up to 65535 characters long. Defaults to false.
# NOTE: clientId values longer than 23 characters may not be supported by all
# MQTT servers. Check the server documentation.
#<broker>.allowLongerClientIds=false
mosquitto.url=tcp://192.168.178.95:8888

# 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.
#<broker>.qos=<qos>

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

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

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

And how do you know nothing is published when you trigger the switch?
Do you you an mqtt tool like mqtt-fx or mqtt-spy?

Also try adding a space at the begining and end of your binding.

Switch MQTT_Switch_Command "Lichtschalter" { mqtt=">[mosquitto:esp/station001:command:ON:1],>[mosquitto:esp/station001:command:OFF:0]" }

Thanks for your reply.

Yes, i use MQTT.fy and subscribed # to get all messages and i also subscribed “esp/station001”
The broker was tested with an esp8266 on esp/station001 and worked.
If i activate the mqtt event bus, i got those mqtt messages from openhab.

I added the space at the begining and end, but mqtt still wont work, sry.
mybe important, all i write in config and items/sitemaps, i type in nano in/over ssh on raspi 3b+

If i restart mosquitto, then i have the following log entry in Openhab.The reconnect did fine.

2018-07-15 00:25:48.763 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to 'mosquitto' was lost: Connection lost : ReasonCode 32109 : Cause : null

2018-07-15 00:25:48.767 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting connection helper to periodically try restore connection to broker 'mosquitto'

2018-07-15 00:25:58.776 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto'

Is 8888 the correct port?

Yes the port is 8888
You can see in first post under update => mosquitto log.

Sorry let me clarify. Are all the services set to 8888 because if my memory serves me correctly that is not the default port setting.

use this method:

Dim i tried this after reading 2 days ago but still no mqtt messages (openhab cache and temp cleared after changes).
I set the pid in the first line in mqtt.cfg

Thedannymullen:
All other ports are default, i changed only the mosquitto broker to 8888 and set it right in the mqtt.conf. Do you know, it has to be changed in other places too?

I don’t think that this is the problem, but: try to use the default port if possible 1883 to see if it works.

I see that OH is reporting that is trying to connect to the broker but I didn’t see any connection attempt in your mosquitto.log

did you get any log entry related to this? (something like “explicit configuration”)

no MQTT Action Add-On installed I hope :slight_smile: (there is an issue when both the MQTT binding and the MQTT action are installed)

1 Like

Thanks for your reply.
Openhab still connects to the broker, you can see in first reply/message i will update this with all i try to get mqtt working. The mosquitto get connection from openhab2. If i restart mosquitto then openhab reconnects by itself.

I have no log from this but i had no errors, still broker connection but no mqtt messages from item.
Mqtt eventbus works perfect, but i need the item messages.
But yes, mqtt action wasnt installed.

try this for mqtt.cfg: (only these 2 lines)

pid:org.openhab.mqtt
mosquitto.url=tcp://127.0.0.1:8888

and this for the item config:

Switch MQTT_Switch_Command "Lichtschalter" { mqtt=">[mosquitto:esp/station001:command:*:default]" }

I don’t know what could be wrong… your configs seem ok to me

can you post your mqtt-eventbus.cfg also?

This is strange… the MQTT-EventBUS is working but not the Item lines… I have never seen this before :slight_smile:
This points to the direction of a syntax error in the Item config (although I don’t see any errors in your stuff)

Here is the eventbus.cfg, i only copied the example from Doc, when i changed my item-Switch i got the mqtt messages for command and state, also i can change the switch state with mqtt.fx, when publishing the right message.

broker=mosquitto
commandPublishTopic=/openHAB/out/${item}/command
commandSubscribeTopic=/openHAB/in/${item}/command
stateSubscribeTopic=/openHAB/in/${item}/state
statePublishTopic=/openHAB/out/${item}/state

i will try this later.

Following you get my item and sitemap config, maybe you can find any syntax error.

MQTT_Command_Switch

Switch MQTT_Switch_Command "Lichtschalter" { mqtt=">[mosquitto:esp/station001:command:ON:1],>[mosquitto:esp/station001:command:OFF:0]" }

Sitemap

sitemap Eingang label="My home" {
Frame {
Switch item=MQTT_Switch_Command
}
}

and the item config in basicUI

is the sitemap file named Eingang.sitemap ?

I don’t see any errors in your configs…

try the simplified Item configuration also:

Switch MQTT_Switch_Command "Lichtschalter" { mqtt=">[mosquitto:esp/station001:command:*:default]" }

Make another simple test.items file and enter this Item alone in there…
Try to increase the log levels for the MQTT Binding also to see if more useful info come up

log:set TRACE org.openhab.binding.mqtt
log:set TRACE org.openhab.io.transport.mqtt
1 Like

Yes it is named “Eingang.sitemap”
image

I will try this @ home later and give a reply then.

@iMarc92 yes if you change in one place you will need everything to be on port 8888.

Here is a simple example the best way I know to explain. Openhab2 runs its web service on port 8080. If you go to a browser an try to communicate on port 5020 you will get a blank screen. This is because you have to have two components to see the openhab2 website the IP address and the port. Mosquito works much the same way. You need the broker and openhab2 to be talking to the same port and ip combination or else you will get nothing.

I would also ask one question in the end. Is there a reason you changed the port? Why not just leave it the same, it will make things a little less error prone.

I know how it works and i know how to configure tcp/ip websoc etc, i developed some other programs in the past, but this here I just can not get it to work. And you can see in this thread, that the connection is not the problem. MQTT broker and openhab can communicate (the mqtt eventbus work well) only the item did nothing.
I changed the port, because i have learned that you shouldn`t use standard ports (security :wink: ).
But thank you for your reply.

I found the problem, i thought.
It was an syntax error… maybe the linending in nano editor or something else. If i created the test.items in editor on windows and copy them over to the PI, it works !! …
I created my items again and it works too…

Thank you all for your help :), have a nice day!

1 Like