... so I'm looking forward to the pull request on this oneJocke.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
MQTT support in OpenNetHome
-
- Site Admin
- Posts: 313
- Joined: Sun Nov 30, 2014 2:16 pm
Re: MQTT support in OpenNetHome
I won't have much coding time this weekend...
Re: MQTT support in OpenNetHome
Excellent, this solves my concern1) 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.
When I test this, it is still fixed to 60 seconds3) Fixed the timer so you can change it without having to restart the Item
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
-
- Site Admin
- Posts: 313
- Joined: Sun Nov 30, 2014 2:16 pm
Re: MQTT support in OpenNetHome
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.
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
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/#)?
- are topics/feeds created automatically at adafruit or do they have to be created up front?
- 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/#)?
- are using the AIO-Key as password?I tried it out with http://io.adafruit.com
- are topics/feeds created automatically at adafruit or do they have to be created up front?
-
- Site Admin
- Posts: 313
- Joined: Sun Nov 30, 2014 2:16 pm
Re: MQTT support in OpenNetHome
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"
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
Yeah, all of those came up at once
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
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)The only thing to think about is that all MQTT-Events you send will be sent to all MQTT brokers
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
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
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
-
- Site Admin
- Posts: 313
- Joined: Sun Nov 30, 2014 2:16 pm
Re: MQTT support in OpenNetHome
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.
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
Perfect, this works fine!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.
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
-
- Site Admin
- Posts: 313
- Joined: Sun Nov 30, 2014 2:16 pm
Re: MQTT support in OpenNetHome
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.
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.