Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial import of mqqt code from Neil #488

Merged
merged 5 commits into from
Nov 15, 2015
Merged

Initial import of mqqt code from Neil #488

merged 5 commits into from
Nov 15, 2015

Conversation

hollie
Copy link
Owner

@hollie hollie commented Mar 15, 2015

Code was submitted on the mailing list. Moving it here so multiple people can work on the same codebase.

@hollie
Copy link
Owner Author

hollie commented Mar 15, 2015

Input from Neil in the mail:

Right now the first design decision is that I'll use wild cards instead
of a socket for each device. We can map the topic into the device when
I get to that part. No ssl or tls is supported and no Websocket.

So you'll need to add this to the mh.private.ini:

       mqtt_host=test.mosquitto.org
       mqtt_server_port=1883
       mqtt_topic=home/#
       mqtt_user=user                  # (optional)
       mqtt_password=password          # (optional)
       mqtt_keepalive=120              # (optional)

You don't need the user or password as there's no code for it yet.

When you start up MH you will get a ton of data and I may have left
a Dumper or 2 in the code.

To test the mqtt, I send data from the command line:

mosquitto_pub -d -h test.mosquitto.org -q 0 -t home/ha/test/x10/A1 -m "A1AON"

I'm modeling my code after Jason Sharpee's UPB modules. I made a mistake
and didn't setup the mqtt.pm for multiple instances so I'm currently
back tracking to fix that. I'm also trying to figure out how the data gets
from the check_for_data function to the mh objects. I found this bit of
code in Jason's UPBPIM.pm (the interface pm, like the mqtt.pm):

   for my $obj (@{$$self{objects}}) {
    $obj->set($msg,$self);
   }

Which seems to say that I use the objects set method to do that work.

@hollie
Copy link
Owner Author

hollie commented Mar 15, 2015

[copy of a message I sent on the mailing list, I think it is better to continue the discussion here].

Would it make sense to have an object that takes care of the connection to the MQTT server (kind of a gateway) and then have objects per instance that connect to the MQTT server through that gateway object.

I implemented such structure for the Squeezebox client interface:
https://github.com/hollie/misterhouse/blob/master/lib/SqueezeboxCLI.pm

What is your opinion on this?

@linuxha
Copy link
Contributor

linuxha commented Mar 20, 2015

Actually the _server method does the same thing but I like the method SqueezeboxCLI.pm uses so I've switched over to it. I'll post that code later, I think I have the multiple subscriptions to the same host/port working now and I have some of the set partially working to and from mqtt. Lots and lots of print_logs going on so I can trace the flow. MH is maddeningly frustrating with examples that are understandable

@hollie
Copy link
Owner Author

hollie commented Mar 20, 2015

Hey Neil,

feel free to push the changes to this branch on your clone, then everybody can easily access them and I can pull them in this branch.

@linuxha
Copy link
Contributor

linuxha commented Mar 20, 2015

On 03/20/2015 02:54 AM, Lieven Hollevoet wrote:

Hey Neil,

feel free to push the changes to this branch on your clone, then everybody can easily
access them and I can pull them in this branch.

I will in a couple of days (sorry) a bit busy at the moment. But I think
I have the mqtt to MH work us to the point where I can set the MH object
from Perl $mqtt_obj->set("On") or from the command line:

mosquitto_pub -d -h 127.0.0.1 -q 0 -t path/to/topic -m "Off"

That occurred at the last minute. I need to remove a lot of the
Data::Dumper code that's sitting there.

Linux Home Automation Neil Cherry [email protected]
http://www.linuxha.com/ Main site
http://linuxha.blogspot.com/ My HA Blog
Author of: Linux Smart Homes For Dummies

hollie and others added 4 commits March 21, 2015 16:48
I've made a number of changes to allow more than one mqtt instance. This is
meant to provide support for multiple hosts and ports pairs. I noticed that
using the same host:port would cause the second request to be disconnected. So I
reused the first host:port instance (I really only wanted the socket). So I
reused the instance and issued a new subscription. This has man side effects
that need to be worked out.

There are a number of other fix "me"s and todos (listed in the source).
Reconnect handleing among the top issues.

See Usage and Example in the source file for changes to instanctiation.
Further work on the mqtt module
@hollie hollie added this to the Next stable 4.0 milestone Nov 15, 2015
hollie added a commit that referenced this pull request Nov 15, 2015
Initial import of mqqt code from Neil
@hollie hollie merged commit aca1397 into master Nov 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants