MQTT support in OpenNetHome

Functionality and usage of the OpenNethome Server
stefangsbb
Site Admin
Posts: 313
Joined: Sun Nov 30, 2014 2:16 pm

Re: MQTT support in OpenNetHome

Post by stefangsbb »

I won't have much coding time this weekend...
Jocke.g wrote: And also, there should be authentication in MqttClient. Here is how to do it:
http://www.hivemq.com/blog/mqtt-client- ... -paho-java
... so I'm looking forward to the pull request on this one ;)
krambriw
Posts: 86
Joined: Sun Jan 04, 2015 8:48 am

Re: MQTT support in OpenNetHome

Post by krambriw »

1) You can now specify a ValuePrefix, which is a string that is added in front of the value that is sent in the MQTT-Message.
Excellent, this solves my concern
3) Fixed the timer so you can change it without having to restart the Item
When I test this, it is still fixed to 60 seconds

Besides, a minor but I guess wishful, when you define a new MqttValueLogger it is found as a "Port". Once configured it is shown as a "Gauge"

BR Walter
stefangsbb
Site Admin
Posts: 313
Joined: Sun Nov 30, 2014 2:16 pm

Re: MQTT support in OpenNetHome

Post by stefangsbb »

Ok, so I got some time to code after all and I have implemented username/password in the MqttClient. I tried it out with http://io.adafruit.com and it seems to work just fine! It seems to be a lot of interesting stuff you can do there, so I have to explore that a bit more.

I also fixed the category issue, it is now a gauge everywhere.

Regarding the log interval, it seems to work fine for me to change the interval. It does however only send a MQTT-message if the value has changed since last interval, so if you log a thermometer for example that only get new values every 60 seconds, you will only see messages logged every 60 seconds even if you ser the interval to 5 seconds.
krambriw
Posts: 86
Joined: Sun Jan 04, 2015 8:48 am

Re: MQTT support in OpenNetHome

Post by krambriw »

I have some questions
- is it necessary to restart ONH if you change the port settings for the MqttClient connection?
- is it necessary to restart ONH if you change settings for the MqttRemapButtons?
- is it possible to have multiple number of MQTT Clients (assume connections to several MQTT brokers)?
- can I name topics or are they hardcoded (like MyHome/#)?
I tried it out with http://io.adafruit.com
- are using the AIO-Key as password?
- are topics/feeds created automatically at adafruit or do they have to be created up front?
stefangsbb
Site Admin
Posts: 313
Joined: Sun Nov 30, 2014 2:16 pm

Re: MQTT support in OpenNetHome

Post by stefangsbb »

Wow, that was a lot of questions at once... ok, here we go:

When you change port name or address, the client automatically reconnects - you don't have to restart. I am fixing the same for username and password now, so that will soon work as well.

If you change things in remap button, you do not have to restart.

You can have multiple MqttClients connected at the same time to different servers and receive events from all. The only thing to think about is that all MQTT-Events you send will be sent to all MQTT brokers.

You can name the topics as you like.

In io.adafruit.com you use the key (the long hex string) as password.
In io.adafruit.com the topic seems to be hardcoded by them. If your username there is "krambriw", then the base topic is: "krambriw/feeds", so in the MqttClient you configure the topic as: "krambriw/feeds/+" and if you configure a feed with a graph called "utetemperatur", you set the topic name in the MqttValueLogger to: "krambriw/feeds/utetemperatur"
krambriw
Posts: 86
Joined: Sun Jan 04, 2015 8:48 am

Re: MQTT support in OpenNetHome

Post by krambriw »

Yeah, all of those came up at once ;)
The only thing to think about is that all MQTT-Events you send will be sent to all MQTT brokers
Well, I recommend to change that. Adding a setting in the MqttValueLogger to select the broker/port would not be bad (or multiple selections if someone finds use for it)

I do have a problem with the io.adafruit connection. It seems I have a problem publishing/subscribing and disconnecting. However, I can see that a message is successfully sent first time after restart but then consecutive attempts fails. Also subscription seems not work in the MqttRemapButton but that could be a consequence of the previous problem.

Running your latest nightly build

Best regards, Walter

See the log below

Code: Select all

	Time	Source	Message
	16.08.24 07:08:00	MqttClient	MQTT refused to disconnect
	16.08.24 07:07:00	MqttClient	MQTT refused to disconnect
	16.08.24 07:06:00	MqttClient	MQTT refused to disconnect
	16.08.24 07:05:01	MqttClient	Failed to send MQTT-message
	16.08.24 07:05:00	MqttClient	MQTT refused to disconnect
	16.08.24 07:04:00	MqttClient	MQTT refused to disconnect
	16.08.24 07:03:00	MqttClient	MQTT refused to disconnect
	16.08.24 07:02:00	MqttClient	MQTT refused to disconnect
	16.08.24 07:01:00	MqttClient	MQTT refused to disconnect
	16.08.24 07:00:01	MqttClient	Failed to send MQTT-message
	16.08.24 07:00:00	ValueItemLoggerFactory	Enabled global logging of type: LoggerComponentFileBased with descriptor: /etc/opt/nethome/log.txt
	16.08.24 07:00:00	MqttClient	MQTT refused to disconnect
	16.08.24 06:59:07	HomeServer	Activated 21 of 21 Items
	16.08.24 06:59:05	ResteasyDeployment	Adding provider singleton nu.nethome.home.items.web.rest.exceptions.ExecutionFailureMapper from Application class nu.nethome.home.items.web.rest.HomeServices
	16.08.24 06:59:05	ResteasyDeployment	Adding provider singleton nu.nethome.home.items.web.rest.exceptions.RestExceptionMapper from Application class nu.nethome.home.items.web.rest.HomeServices
	16.08.24 06:59:05	ResteasyDeployment	Adding singleton resource nu.nethome.home.items.web.rest.HomeItemsResource from Application class nu.nethome.home.items.web.rest.HomeServices
	16.08.24 06:59:05	ResteasyDeployment	Deploying javax.ws.rs.core.Application: class nu.nethome.home.items.web.rest.HomeServices
	16.08.24 06:58:53	TrayBarIcon	SystemTray is not supported on this system
	16.08.24 06:58:53	MqttClient	Failed to send MQTT-message
	16.08.24 06:57:38	HomeItemFileLoader	Loading Items from /etc/opt/nethome/config.xml
	16.08.24 06:57:38	HomeManagerStarter	Logging to: /var/log/nethome/HomeManager%g.log
	16.08.24 06:57:38	HomeManagerStarter	**Starting HomeManager 2.1-SNAPSHOT-bf7a1**
krambriw
Posts: 86
Joined: Sun Jan 04, 2015 8:48 am

Re: MQTT support in OpenNetHome

Post by krambriw »

So I think I have found out the reason to my problem!

It is verified by adding two MqttValueLoggers; one is pointing to io.adafruit and correctly configured to a topic structure that really exists, one is pointing to another structure that does not exists at io.adafruit BUT exists at another broker.

As example, I configure one to use existing structure 'krambriw/feeds/xxx' at io.adafruit, I configure the other to use 'MyHome/yyy' at another 'standard' mqtt broker in my network. With this configuration, the io.adafruit connection will not work properly since a message is published to a structure at io.adafruit that does not exist. And this causes the connection with io.adafruit to be disconnected.

So it boils down that you up front need to define ALL possible structures you might use on other brokers also at io.adafruit .

Adding a setting in the MqttValueLogger to select brokers/ports seems necessary to have a multi-broker configuration if you cannot have identical structures on all brokers. It is anyway always important to check that the structure at io.adafruit really is prepared before you connect with ONH.

Best regards, Walter
stefangsbb
Site Admin
Posts: 313
Joined: Sun Nov 30, 2014 2:16 pm

Re: MQTT support in OpenNetHome

Post by stefangsbb »

Thanks Walter. I have now added a parameter in the MqttValueLogger called MqttClient, where you can specify a specific client where the MQTT events should be sent. If you don't specify a client it will send to all.

I have also added a new Item called MqttCommandPort. It turns all Items and attributes in the server into MQTT-Topics. If you have an Item called HallLamp, and send a MQTT event to the subject "HallLamp" with the message "on", then the on-method is invoked. If you send a message to the subject "HallLamp_OnDimLevel" with the message "56", then the attribute OnDimLevel is set to 56 and the lamp will dim to that level.
krambriw
Posts: 86
Joined: Sun Jan 04, 2015 8:48 am

Re: MQTT support in OpenNetHome

Post by krambriw »

Thanks Walter. I have now added a parameter in the MqttValueLogger called MqttClient, where you can specify a specific client where the MQTT events should be sent. If you don't specify a client it will send to all.
Perfect, this works fine!

Just fyi: I get these kind of lines in the log every minute, is it because io.adafruit is terminating the connection???

Code: Select all

        16.08.27 15:17:41	MqttClient$SubscribeCallback	Lost connection to MQTT server tcp://io.adafruit.com: Connection lost
	16.08.27 15:16:41	MqttClient$SubscribeCallback	Lost connection to MQTT server tcp://io.adafruit.com: Connection lost
	16.08.27 15:15:41	MqttClient$SubscribeCallback	Lost connection to MQTT server tcp://io.adafruit.com: Connection lost
stefangsbb
Site Admin
Posts: 313
Joined: Sun Nov 30, 2014 2:16 pm

Re: MQTT support in OpenNetHome

Post by stefangsbb »

I have seen exactly the same thing with io.adafruit.com, it seems to drop the connection after 20 seconds and I have not been able to figure out why yet. Actually yesterday at 22.25 it stopped dropping the connection and has stayed connected since.

According to some documentation I have seen there they want some kind of heart beat/ping, but that seems to be every five minutes, so I can't really understand why they would drop the connection after 20 seconds.
Post Reply