MQTT Client

Questions and comments specific to a particular plugin should go here.

MQTT Client

Postby krambriw » Sun Oct 20, 2013 8:37 am

Latest version always here:
http://plugins.krambriw.net/index.html

Hi, maybe you have heard about MQTT ?

"MQTT is a machine-to-machine (M2M)/"Internet of Things" connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport. It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium. For example, it has been used in sensors communicating to a broker via satellite link, over occasional dial-up connections with healthcare providers, and in a range of home automation and small device scenarios. It is also ideal for mobile applications because of its small size, low power usage, minimised data packets, and efficient distribution of information to one or many receivers (more...)"

Read more here: http://mqtt.org/

I have created a plugin for a MQTT client that allows you to
- subscribe to multiple brokers and multiple topics
- publish messages for different topics on multiple brokers of your choice

The plugin is based on the Mosquitto python module, kindly provided by Mr Roger Light <roger@atchoo.org>. If you are interested in the details, see here: http://mosquitto.org/documentation/python/

Subscriptions are handled in separate threads for each and publishing of messages are performed via actions that can be triggered by any event in EG.

For testing, there are several public MQTT brokers on the net if you can accept using one of those. Like [url]test.mosquitto.org[/url] or [url]m2m.eclipse.org[/url].

If you preferre a private solution, run your own broker inside your network. I personally run one (Mosquitto) in the Raspberry Pi and it works excellent.

In the following I will describe how to setup and configure the MQTT Client
Last edited by krambriw on Thu Jun 02, 2016 5:37 pm, edited 5 times in total.
My latest plugins
http://plugins.krambriw.net/index.html

Two men in front of a huge excavator...
- that beast steels work from 100 men with shovels
- well, a 1000 men could do the same using teaspoons
krambriw
Plugin Developer
 
Posts: 2559
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden

Re: MQTT Client

Postby krambriw » Sun Oct 20, 2013 8:37 am

Once you add the plugin "MQTT Client", you will see this dialog on the screen (there will however be no entries in the list to start, they have first to be configured as described below).
Image2.jpg

You may close this dialog and now instead add an action under "Autostart". Select "Start a new MQTT subscription".
This dialog will be shown and here you can fill in the details. As soon as you are done and clicked OK, the subscription will start.
Image4.jpg
Last edited by krambriw on Sun Oct 20, 2013 8:54 am, edited 1 time in total.
My latest plugins
http://plugins.krambriw.net/index.html

Two men in front of a huge excavator...
- that beast steels work from 100 men with shovels
- well, a 1000 men could do the same using teaspoons
krambriw
Plugin Developer
 
Posts: 2559
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden

Re: MQTT Client

Postby krambriw » Sun Oct 20, 2013 8:38 am

To publish a message to the broker, you need to configure a macro with a publishing action. Select the action "Publish a MQTT message" and the following dialog will appear:
Image6.jpg


The first part of the configuration like name of the action, broker host name or ip and port number is self explanatory I think.

When you define the topic, it is important that it is the same as the one clients are subscribed to, otherwise they will not receive the messages.

The message itself can be any fixed string or it can also be dynamic using {eg.event.string} or {eg.event.payload} like in this example:
Image8.jpg

The 'QOS' (Quality Of Service) can be selectable 0,1 or 2.

The 'Retain' can be set either True(checked) or False(unchecked)

So what is the use of this stuff ???

Well, we could expect more "Internet of Things" being MQTT connected to the internet (or intranet for privacy) in the future. Another usage I just realize is the integration of various software solutions (like in this case EventGhost and SwitchKing). Or why not just integrate multiple instances of EventGhost running on their different computers...

Best regards & enjoy,
Walter
My latest plugins
http://plugins.krambriw.net/index.html

Two men in front of a huge excavator...
- that beast steels work from 100 men with shovels
- well, a 1000 men could do the same using teaspoons
krambriw
Plugin Developer
 
Posts: 2559
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden

Re: MQTT Client

Postby blaher » Mon Oct 21, 2013 5:02 am

I thought I'd try it to replace the webserver plugin, but I'm getting: error: [Errno 10061] No connection could be made because the target machine actively refused it
I'm using XP on one PC & Win 7 on the other, both have firewalls off.

I'm just looking to send a message from 1 PC with EventGhost to another, so I may have misunderstood the settings.
blaher
Experienced User
 
Posts: 440
Joined: Thu Nov 17, 2011 1:27 am

Re: MQTT Client

Postby krambriw » Mon Oct 21, 2013 3:32 pm

Hello, that error indicates a connection problem with the broker.

Did you try to configure a MQTT subscription with the defaults? For me it works without problem...

Also you could eventually try the other broker, the m2m.eclipse.org

Best regards, Walter
My latest plugins
http://plugins.krambriw.net/index.html

Two men in front of a huge excavator...
- that beast steels work from 100 men with shovels
- well, a 1000 men could do the same using teaspoons
krambriw
Plugin Developer
 
Posts: 2559
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden

Re: MQTT Client

Postby blaher » Tue Oct 22, 2013 1:49 am

Sorry, I must've screwed up the configuration, but I just realised I need the webserver anyway, to receive messages from my Z-Wave Vera, so I won't persist.

Thanks all the same, I'm sure others will find it beneficial!
blaher
Experienced User
 
Posts: 440
Joined: Thu Nov 17, 2011 1:27 am

Re: MQTT Client

Postby krambriw » Sat Jul 19, 2014 6:11 pm

Alright, this is how you can integrate EG with OwnTracks

We do the following, just basics so we see it starts working

1) In the settings of OwnTracks, configure the following
- Host: test.mosquitto.org
- Port: 1883
- Topic: /mytracks (or something more unique like /shaggy79 )

Then tap 'Check' and you should get 'connected'

2) In EG,
- into EG plugin folder, unzip the MQTT Client plugin found here:
- restart EG and add the MQTT plugin
- add 'Start a new MQTT Subscription'
- configure it like in this picture

Image2.jpg

Click Test and OK and you should get connected.

In OwnTracks, tap on the symbol > or >> on top of the screen, select 'Puublish Now' and you should see an event in EG looking similar to this:
Code: Select all
20:09:32   Main./shaggy79 '{"t":"u","tst":"1405791920","acc":"10","lon":"18.0051","_type":"location","lat":"59.4288","batt":"65"}'


In OwnTracks, configure your Region Monitoring and Waypoints, see how to here:
https://github.com/owntracks/owntracks/wiki/iOS

Once you start to move ioutside and back into your defined radiusis (Geo Fences) you will receive new events for those.
My latest plugins
http://plugins.krambriw.net/index.html

Two men in front of a huge excavator...
- that beast steels work from 100 men with shovels
- well, a 1000 men could do the same using teaspoons
krambriw
Plugin Developer
 
Posts: 2559
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden

Re: MQTT Client

Postby krambriw » Sun Jul 20, 2014 6:33 am

To get a secure connection between the broker and client, you need to work with TLS and certificates. I tried but failed partly so far. There are tons of descriptions 'how to' but I must have missed something...

I have managed to generate and add certificates & keys to my local brooker so that it starts up correctly but I am not able to connect with the client...yet

Anyway, right now, if you are using a public MQTT broker on test.mosquitto.org, the next could be to set up your own private one because as you know, look at the friends list and you can see many other people using OwnTracks on the very same server.

As example, you can install a MQTT Mosquitto broker in a cheap Raspberry Pi in your home network.

1) In OwnTracks you can configure the 'host' to the local ip of the Raspberry Pi. In this case you will of course only recieve notifications when your smartphone is connected to your local network as well, basically when you are 'home'. If you configure a Waypoint region monitoring radius (geo fence) well within the coverage of your wifi network, this should give you home/away events when moving in and out. And it is pretty private if you use internal ip's like 192.168.... (those are never routed on internet)

2) If you define a virtual server for TCP port 1883 in your firewall and use a service like No-IP, you will get updates also if you are further away (but still without TLS)

3) Once we figure it out, it should be possible to add certificates and keys to our local Raspberry Pi MQTT broker and clients...to get a secure connection...
My latest plugins
http://plugins.krambriw.net/index.html

Two men in front of a huge excavator...
- that beast steels work from 100 men with shovels
- well, a 1000 men could do the same using teaspoons
krambriw
Plugin Developer
 
Posts: 2559
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden

Re: MQTT Client

Postby Pako » Sun Jul 20, 2014 8:09 am

Just two comments:
1) There's no need to use RaspberryPi.
You can install the windows version of the mosquitto on the same machine that is running EventGhost. It then runs as a service.
In the settings MQTT Client plugin / subscription then use 127.0.0.1 as the "Host ip or name".

2) I do not know if I correctly understand how the application "OwnTracks" actually works, but I'm afraid it will often turn on GPS and so it will have an impact on energy consumption and thus the battery life.
Moreover, it seems to me unnecessary to use this system only for me to know that the phone is at home. For example, Nmap plugin seems to be much better for it. And you do not need to install an application to your phone.
But I do not know how Nmap works reliably when you have the iPhone. I have no opportunity to try it.

Pako
User avatar
Pako
Plugin Developer
 
Posts: 2245
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic

Re: MQTT Client

Postby krambriw » Sun Jul 20, 2014 10:40 am

"it will have an impact on energy consumption and thus the battery life"


Yes, of course, I am noticing it, it leaks now like a sinking ship...

It was just for fun and for test but maybe not the most optimum from battery perspective
My latest plugins
http://plugins.krambriw.net/index.html

Two men in front of a huge excavator...
- that beast steels work from 100 men with shovels
- well, a 1000 men could do the same using teaspoons
krambriw
Plugin Developer
 
Posts: 2559
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden

Re: MQTT Client

Postby Pako » Sun Jul 20, 2014 11:33 am

Dear Walter !
krambriw wrote:... it leaks now like a sinking ship...
It looks like an English phrase, but I could not find it, so I do not understand.
Can you please explain in other words? :D

I know that you have the iPhone.
I would like to ask you to try Nmap plugin.
Can you please do this for me?
I suppose it behaves like a smartphone with Android, but it would be good to know for sure.

Thanks and best regards,
Pako
User avatar
Pako
Plugin Developer
 
Posts: 2245
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic

Re: MQTT Client

Postby krambriw » Sun Jul 20, 2014 1:33 pm

Hello Pako,

Sure, I will try the Nmap plugin, but it will be the week after next since I will be away for a couple of days

'Sinking ship...' I was just making the comparison, suppose you drill a hole in the ship...water will leak in

With the battery, is like a hole in it as well, but energy leaking out very quickly

I can say that my iPhone battery was 100% charged this morning and now it is around 30 % only (OwnTracks has been on all the time with very frequent updates via wifi...so is not so useful if the battery empties that rapidly)


My best regards, Walter
My latest plugins
http://plugins.krambriw.net/index.html

Two men in front of a huge excavator...
- that beast steels work from 100 men with shovels
- well, a 1000 men could do the same using teaspoons
krambriw
Plugin Developer
 
Posts: 2559
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden

Re: MQTT Client

Postby shaggy79 » Sun Jul 20, 2014 3:30 pm

Krambriw
Thanks for the help I will look into it. But it sounds abit out of my skillset lol. :oops:

Pako
I will also look into what you said, I tried "NMS" but I couldn't get it to work properly with what I want to do? Probably my fault as I'm new to all this stuff but am trying to learn. :oops:

My Goal:-

When I leave my house perform an action (A).
When I return perform an action (B).

I tried with "PING", But kept getting random actions due to phone in 'idle' mode. (when the phone was locked would give me incorrect response).

I was looking into it all night and found 'iBeacon', Don't really understand it but would iBeacon work?
If so what exactly would I need Hardware & software. And roughly how much will it cost ?

Cheers Paul.
shaggy79
Experienced User
 
Posts: 129
Joined: Sun Jul 13, 2014 4:57 pm

Re: MQTT Client

Postby Pako » Sun Jul 20, 2014 4:15 pm

shaggy79 wrote:Pako
I will also look into what you said, I tried "NMS" but I couldn't get it to work properly with what I want to do? Probably my fault as I'm new to all this stuff but am trying to learn.
I do not understand why you are trying NMS plugin.
It should be instead of Ping ?
If so, you probably have in mind Nmap plugin.
shaggy79 wrote:My Goal:-
When I leave my house perform an action (A).
When I return perform an action (B).
This is an easy task for Nmap plugin (but I tested it only for Android).

Pako
User avatar
Pako
Plugin Developer
 
Posts: 2245
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic

Re: MQTT Client

Postby shaggy79 » Sun Jul 20, 2014 5:09 pm

Pako

I tried PING it didn't work as I wanted, so deleted it. Then tried NMS with the same outcome.
I deleted PING & NMS.
Now I am trying to use Nmap but like I said I'm new to all this and very out my depth :oops:
I have installed the plugin but I have no idea how to "set it up" ? :oops:

Paul.
shaggy79
Experienced User
 
Posts: 129
Joined: Sun Jul 13, 2014 4:57 pm

Next

Return to Plugin Support

Who is online

Users browsing this forum: No registered users and 4 guests