Great write up, but he is using openHAB2 where you don’t have the prefix “mqtt:” anymore.
http://docs.openhab.org/tutorials/migration.html#configure-add-ons
But he should definitely perform all other suggestions …
No to the log edit - well, saying that i forced OH/Mosquitto to create new logs so i could see what was going on.
You may well be right, i can’t see OH connecting to the MQTT broker in the logs so its probably misconfigured somewhere, I’ll try testing it some more.
Thanks Sihui
Hi @Jamesb4uk, I was trying to look at your config file but it’s kind of hard to tell what is going on because of the uncommented comments. You should be able to show the full contents of that file by putting three ` (backticks) characters at the beginning of the line before the file contents, and then end it with three more after the last line of the file. That’s how I’m doing the file contents below.
I think I might see a problem with your mqtt config anyways, but I’ll let you confirm. In my config below, the line where I define the url begins with “mqtt:” You do not have the same part of that line in your file. That’s the part that lets openHAB know to get the configuration to the correct binding, so it’s very important.
After that, the next important step is to make sure the name of the broker in your items file matches the name you gave the broker in your config file. So if your config says
mqtt:mymosquitto.url=tcp://localhost:1883
, then you need to make sure that the start of the binding config in your items file matches the “mymosquitto” part like this:{mqtt="<[mymosquitto:/Node2...
.# # 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 mqtt:mosquitto.url=tcp://mqtt:1883 # Optional. Client id (max 23 chars) to use when connecting to the broker. # If not provided a default one is generated. #<broker>.clientId=<clientId> # 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>
If modifying your mqtt config doesn’t fix it, then it will be good for you to learn more about how to track what is happening in openhab. To track down anything, you usually want to turn on the DEBUG logs for the binding. So in your case, you’d turn the mqtt logging to DEBUG. You can read about how to do that here: http://docs.openhab.org/administration/logging.html
Then you want to watch the logs. There are various ways to do this. Instead of rebooting to see what happens, I usually like to have 3 terminal windows open for the server. On the first one, I run
tail -f openhab.log
in the openhab logs directory. On the second one I runtail -f events.log
in the openhab logs directory. These two logs usually give you pretty much anything you need to know, unless you configure a binding’s logging to go to its own separate file. In the third terminal I run other commands, like editing config files and restarting the service. Depending on the distro, you can usually restart openhab by runningsudo systemctl restart openhab
orsudo service restart openhab
. You may not need the sudo and the command may be slightly different, but that’s the gist of it. The benefit of doing it this way is that you can just keep the tails running and you never have to reconnect your windows to the server.Hope this helps!
Very helpful write up there Jonny i copied the config file with the # in the line but i think that turns it to a heading in the forum,
I’ll try your Tail command, many thanks for that - t like to think i know my way around Linux but there are always commands you forget!
Thanks for everyone’s help - hopefully i’ll figure it out early in the new year - Have a good one all!
James
I’m not sure what to say to that. I posted my working openhab 2 config. Maybe if it is the 1.9 binding like you said above, it still uses the old style config statements? I think it would be worth a try since it’s just a matter of typing 5 characters and restarting the openhab.
Maybe if it is the 1.9 binding like you said above, it still uses the old style config statements?
I don’t think so because it is working on my system without the leading “mqtt:”.
I think it would be worth a try since it’s just a matter of typing 5 characters and restarting the openhab.
Why not. openHAB is full of surprises …
@Jamesb4uk, the forum doesn’t change # characters into headings if you use the backticks like I described. See how it works in my first post. There’s actually a little “code” button in the editor that does the backticks for you.
Another thought on your problem: I vaguely remember that mqtt didn’t like host names in some instances. Try changing localhost to 127.0.0.1 and see if that helps.
OK, lets see if this works.
#
# 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
mymosquitto.url=tcp://192.168.1.201:1883
# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a default one is generated.
mymosquitto.clientId=OphenHAB2
# Optional. User id to authenticate with the broker.
mymosquitto.user=odroid
# Optional. Password to authenticate with the broker.
mymosquitto.pwd=odroid
# 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.
mymosquitto.qos=1
# Optional. True or false. Defines if the broker should retain the messages sent to
# it. Defaults to false.
mymosquitto.retain=true
# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to true.
mymosquitto.async=true
# 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>
Most recent changes i had the same thought over the local host so actually changed it to the machines IP address.
I’ll take out the my in the broker name now so it will read mosquitto.url=tcp://192.168.1.201:1883
Back shortly with results
James
OK i still haven’t seen any change in output on the Odroid machine, i think there is something I’ve missed/messed up.
I’m now trying another image, openhabian to be precise and on that i’m now seeing the MQTT broker starting up in the logs so already an improvement.
I also see the link in from OH2 to mosquitto now - result!
1483200880: mosquitto version 1.4.10 (build date Thu, 25 Aug 2016 10:12:09 +0100) starting
1483200880: Config loaded from /etc/mosquitto/mosquitto.conf.
1483200880: Opening ipv4 listen socket on port 1883.
1483200880: Opening ipv6 listen socket on port 1883.
1483200934: New connection from 192.168.1.105 on port 1883.
1483200934: New client connected from 192.168.1.105 as ESPClient2 (c1, k15, u'pi').
1483200979: New connection from 127.0.0.1 on port 1883.
A quick recreation of the items & sitemap
Thanks again for everyones advice - its tought me a lot
Have a good New Year’s Eve all.
James