Page 3 of 4

Re: MQTT support in OpenNetHome

Posted: Fri Aug 19, 2016 9:48 pm
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 ;)

Re: MQTT support in OpenNetHome

Posted: Sat Aug 20, 2016 8:20 am
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

Re: MQTT support in OpenNetHome

Posted: Sun Aug 21, 2016 7:51 pm
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.

Re: MQTT support in OpenNetHome

Posted: Tue Aug 23, 2016 2:55 pm
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?

Re: MQTT support in OpenNetHome

Posted: Tue Aug 23, 2016 7:35 pm
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"

Re: MQTT support in OpenNetHome

Posted: Wed Aug 24, 2016 7:19 am
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**

Re: MQTT support in OpenNetHome

Posted: Wed Aug 24, 2016 11:32 am
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

Re: MQTT support in OpenNetHome

Posted: Fri Aug 26, 2016 8:57 pm
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.

Re: MQTT support in OpenNetHome

Posted: Sat Aug 27, 2016 3:28 pm
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

Re: MQTT support in OpenNetHome

Posted: Sun Aug 28, 2016 8:50 am
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.