more G-Labs products

Author Topic: MQTT Broker  (Read 12192 times)

June 03, 2015, 03:39:27 PM
Reply #15

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I was searching for that thread the other day, thanks for the link.

I was able to get communication from the broker last night.  I reviewed the MQTT code in the Interconnects automation group and found the issue.  The code is looking for a message with a topic split into several parts (4 are called out) delineated by '/'.  My messages are only using a single word at the moment, so they failed the check.  I added a Program.Notify to see what traffic was coming in and saw every message the Arduino published.

At this point, I need to make sensor items to store the incoming data and get plotting set up.  I was originally thinking of uploading the data to WU or Pachube, but they appear flakey so I'm not sure it's worth the effort.

June 03, 2015, 04:07:11 PM
Reply #16

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Perhaps the mosquitto MQTT broker service is not configured properly to accept remote connections.
See http://manpages.ubuntu.com/manpages/trusty/man5/mosquitto.conf.5.html (bind_address and  allow_anonymous).

What I would also suggest is to uninstall the mosquitto server and use HomeGenie MQTT Service plugin instead:

- download the add-on from https://github.com/genielabs/MIG-MqttBroker/raw/master/MIG-MqttBroker.zip
- load the add-on from the "install add-on" screen in homegenie (see attacched screenshot)

Cheers,
g.
« Last Edit: June 03, 2015, 04:10:46 PM by Gene »

June 03, 2015, 04:51:34 PM
Reply #17

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I can give that a try.  Was this the result of the work Wibo put in a few months ago as far as determining the best MQTT broker for HG on RPi?  I thought Mosquitto was what he suggested which is why I went that route thus far.

June 03, 2015, 07:30:22 PM
Reply #18

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
I've not experienced any problem using mosquitto as broker for hg clients under Ubuntu. Never tried it on a raspberry pi.
Few months ago hg was not providing any "add-on" funcionality, so the purpose of this plugin is to provide an easy integrated way for adding MQTT broker  to HG.

Cheers,
g.


June 04, 2015, 06:54:17 AM
Reply #19

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I was able to get HG to receive MQTT data from my Arduino using the Mosquitto broker by copying the built in script from the Interconnect group.  I'll have to spend some time figuring out the best method to use the data, but I think the hard part is done.  Thanks!

June 05, 2015, 09:23:04 PM
Reply #20

Wibo

  • ***
  • Information
  • Full Member
  • Posts: 95
Hi bkenobi,

I used mosquitto broker because it seemed a good broker and it proofed to be an extreme stable broker under windows, that's the only platform I tested.

My search was not about a broker, a stable dotNet library to communicate with the broker was my problem.

My search ended up with RabbitMQ which also has an extremely stable broker.
It also has a very stable dotNet library for accessing the broker, that's why I'm using it.

Really busy building hardware and software at home and at work, so that's why I'm not posting very often.

Regards,
Wibo.

June 06, 2015, 12:30:45 AM
Reply #21

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Thanks for clarifying.

I think the issue I was having is that the Interconnect script uses a different call than the code posted by Gene in this topic.  It appears that "Net.Subscribe" does not work in the code provided for whatever reason.  However, using "MqttClient.Subscribe" does work.

June 07, 2015, 04:53:16 PM
Reply #22

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525

Does this thread help:
http://www.homegenie.it/forum/index.php?topic=758.0

If not, what is the difference between the MQTT broker and what is done in this other thread?  I have an Adafruit Huzzah ESP8266 WiFi board coming in the mail and need to figure out how to communicate with it via HG.


Thanks for posting that link.  I hadn't looked at the code before, but it pretty much confirms what I thought.  I just need to create a virtual module to save the incoming data to.  Then, I use the built-in plotting capability to track different items (temp, rain, etc) as needed.

June 07, 2015, 05:26:56 PM
Reply #23

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I now have my power meter and weather station sending data that HG receives via the MQTT broker I have running on the RPi (Mosquitto).  I have data saved to virtual module sensors (thanks to CptJack's script) and I can see the data if I look at the parameters under the module settings.  I now have 2 questions:
  • The data doesn't display on the sensor, so I just see the "status.level" stored value and not the temperature, energy used, wind, etc.  How do I get things to show up like in the following link?
  • I have never used the statistics page to track data.  I think I actually turned it off at some point in the old UI.  Now I'm trying to get it running and I don't see anything that looks familiar.  Any suggestions?

http://www.homegenie.it/forum/index.php?topic=758.msg4497#msg4497

June 09, 2015, 09:53:11 PM
Reply #24

sintei

  • *
  • Information
  • Newbie
  • Posts: 8
Hello,

So I tried downloading the latest homegenie.
Went into Programs, interconnections and enabled mqtt network.
Set the parameters:
Unique ID for this client: Hometest
MQTT server address: broker.mqtt-dashboard.com  (this is a free test broker over the internet)
Serverport: 1883
Topic: /mqttspy/test/

Homegenie says it is connected.
In Eventghost and another subsription/publishing software I can see stuff that I publish between Eventghost and the other software.
but from Homegenie, nothing happens.
I have enabled Publish over MQTT at the device in the homegenie dashboard.
Do you guys have any things I can do to troubleshoot?

June 10, 2015, 01:32:59 AM
Reply #25

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I just went though this.  The code is probably set up and working correctly, but the script is designed to connect one HG installation to another.  So, the script is looking for a specific topic/message combination.  I modified the code slightly (added a Program.Notify) to post any messages that it saw come in on the subscribed topic and found it was connecting as it said.  Next, just add some code to parse the topic/message as you need.

June 10, 2015, 12:18:56 PM
Reply #26

sintei

  • *
  • Information
  • Newbie
  • Posts: 8
Yes, but firstly I want to publish using mqtt from HG.
Do the HG need to subscribe to a specific topic if it wants to publish to one?
I mean, basic setttings should mean the devices publish to selected topic.
I apologize for not really understanding. I just learned some python to be able to write scripts in Eventghost and to tackle a new software (HG) is making my learning curve very steep as I do not know where to look instantly.
I'll go in HG later tonight and see if I can begin to understand what happens in the background.

If you could, could you please publish your code for interconnections/mqtt broker?
Cheers.

June 10, 2015, 03:44:39 PM
Reply #27

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
When I started liiokking into MQTT (only 2 weeks ago now, so I'm no expert), the first thing I tried was to set HG to publish the status of a couple test switches.  I subscribed to all topics with a RPi client and changed the state of the switches.  I was never able to get traffic to the broker.  But, that was not a goal for me so I didn't try for very long and did no other debugging.

My code for receiving is derived from the MySensors code that was shared earlier in this topic.  The only difference is specific to my sensors really and wouldn't help over what was posted there.

June 10, 2015, 11:10:10 PM
Reply #28

sintei

  • *
  • Information
  • Newbie
  • Posts: 8
Gene, is the broker only supposed to work with other HG boxes?
I looked at the code in the mqtt script (from what I understand) and i can't figure out why it won't publish info to the brokers.
What is the topic set by HG?
cheers.

June 11, 2015, 05:20:55 PM
Reply #29

sintei

  • *
  • Information
  • Newbie
  • Posts: 8
OK, so I set up an own broker and could now see that HG changes the topic depending on the event.
So for instance if I turn on lights in one room this is the topic:
hometest/HomeAutomation.ZWave/5/event

And for another light/room:
hometest/HomeAutomation.ZWave/4/event

The first "hometest" is HG identifier in the line and the "5" or "4" is the ID of the z-wave switch.
the datapayload given from HG:
{"Name":"Status.Level","Value":"0","Description":"","FieldType":"","UpdateTime":"2015-06-11T15:09:53.8443472Z","NeedsUpdate":false}

Basically, it does not matter what topic you input in HG, it does nothing and HG selects according to above rule and only uses HG Identifier.

Now.. I have to understand how you guys got HG to act when you send a mqtt message into HG and make the switch turn on /off.
Will check your codes later and see if I can work it out.