Openhab not sending to MQTT (New user)

Hi,

I am a beginner, and have been struggling with MQTT. I setup Mosquitto as a broker, and tested using MQTT.fx that it is working well (arduino sending and receiving using the broker).
I added MQTT and set it up in the mqtt.cfg
then added in .items of the demo a switch:
Switch lamp2 “Office Lamp” (Garden, Lights) {mqtt=">[broker:/arduino/garden/com:command:ON:1],>[broker:/arduino/garden/com:command:OFF:0]"}

but it is not connecting to the mqtt broker

I am sure I am missing something basic, just can’t find what it is. any ideas or guidance would be welcome

Thanks

sam

Post mqtt.cfg

Post anything you see in the logs related to mqtt

i am also facing the same problem

on first look, I don’t believe you need the leading / after the broker: part… other than that:

have you checked to ensure the mqtt broker is started?

is the name of your MQTT broker in /etc/openhab2/mqtt.cfg called “broker” ?

is the openhab topic correct with no typo’s?

have you run ‘mosquitto_pub’ from command line and published an ON or OFF message to the topic to see if the broker is getting that message and switching the bulb? (I assume so, since you used mqtt.fx instead)

have you checked /var/log/mosquitto/mosquitto.log file for log entries?

is mqtt on the same server as openhab or elsewhere? if elsewhere, any firewall blocking tcp1883?

is mqtt authentication setup? if so, is the correct username/password combo set with no typos?

Thank you for the help. Details:
MQTT.CFG file:

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

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

# 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

# Optional. User id to authenticate with the broker.
broker:mosquitto.user=openhabian

# Optional. Password to authenticate with the broker.
broker:mosquitto.pwd=openhabian

# 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:<broker>.retain=true

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

Log files:

openhab log
2017-09-04 10:45:06.871 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2017-09-04 10:45:06.872 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto'
2017-09-04 10:45:07.449 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection '<broker>'

event log
2017-09-04 10:45:39.420 [ItemCommandEvent          ] - Item 'lamp2' received command ON
2017-09-04 10:45:39.432 [ItemStateChangedEvent     ] - lamp2 changed from OFF to ON
2017-09-04 10:45:41.348 [ItemCommandEvent          ] - Item 'lamp2' received command OFF
2017-09-04 10:45:41.359 [ItemStateChangedEvent     ] - lamp2 changed from ON to OFF

also just noted in the log this. maybe it is related?


2017-09-04 10:45:07.799 [WARN ] [.rule.jvmmodel.RulesJvmModelInferrer] - Duplicate field: 'lamp2'. Ignoring 'org.eclipse.smarthome.core.library.items.SwitchItem'.

Answers to other questions:
Mosquitto is on the same server (raspberry pi).
yes, i tested the broker with other ways (mainly MQTT.fx on a PC and a arduino with wireless. can transmit and receive using the broker.

Thanks again everyone

Make sure mosquito this configured to also listen on localhost or change your broker connection to use the Pi’s IP address.

Get rid of the “broker:” from all of your config lines. It should just be “mosquitto”.

The line broker:<broker>. retain=true I’d just completely wrong. It should match the rest of your configs:

mosquitto.retain=true

Or just commented out.

Your item binding config will need to change from “broker” to “mosquitto”.

You may need to clear out the old configs by deleting /var/lib/openhab2/config/org/openHAB/mqtt.cfg

Interestingly, I did an apt-get update and upgrade today, and MQTT stopped working completely - even after a reboot. Nothing I did would make it work (yet it worked publishing using mosquitto command line tools, just nothing worked out of the OH GUI) No config changes were made whatsoever either. Only solution I found to this was to uninstall then reinstall the MQTT ACTION and bingo, it started working again.

Thank you. sorry for my ignorance, but how do I uninstall then reinstall the MQTT ACTION and bingo?

from paper UI

my mqtt server is running perfectly and my clients are also working but i am just not able to send mqtt messages from my openhab’s items file. if any one can connect me through Teamviewer and help me. that would be really appreciated. i have tried a lot but i am just not able to fix it

Perhaps you could, I don’t know, make the changes to your mqtt.cfg file that I told you to make above.

Your problem is your mqtt.cfg file is completely broken.

1 Like

Rich, thanks again for the help.
I removed the broker:, cleaned up the mqtt config file, made sure that it points to the IP address, changed in .items file to mosquitto, cleared out teh old config. nothing changed. even tried to reinstall mosquitto. no change.

found this in the events log, not sure if it means much. not clear to me why it is still trying to open another session with . i combed through all files and could not find anywhere that still calls

2017-09-05 20:24:25.338 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto'
2017-09-05 20:24:25.836 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection '<broker>'
2017-09-05 20:24:29.202 [WARN ] [etty.util.internal.ThreadLocalRandom] - Failed to generate a seed from SecureRandom within 3 seconds. Not enough entrophy?

thinking of just doing a complete new install of OH on the Pi

And you tried my suggestion? I suspect your issue is different to the OP’s and similar to the issue I experienced, where uninstalling the mqtt action resolved. Its a 2 minute job, so worth a shot to see.

If you are still seeing that started <broker> message either you didn’t delete the config in the /var/lib/openhab2 … Folder or you didn’t do that last thing of all.

And please try chimera’s suggestion

Then post your cfg and item as they are now.

Yes. I tried that, thanks

Thanks for the help and pointers guys.
The solution for me was a fresh install, NOT using the demo house, but instead starting from scratch a new sitemap and things. After that, everything worked smoothly.