MQTT Gateway Plugin

Posted on
Thu Dec 10, 2015 2:36 pm
afulki offline
Posts: 15
Joined: Jun 01, 2015

Re: MQTT Gateway Plugin

Thanks I will check it out, been hard at work using MQTT and a number of other technologies :) I just re-created OpenSprinker in Node-Red to use Indigo to control my sprinklers using a Raspberry PI :D

Posted on
Tue Jan 05, 2016 8:32 am
rlust offline
Posts: 93
Joined: Jan 12, 2009
Location: Ohio

Re: MQTT Gateway Plugin

Checking to see if anyone else is having issues with MQTT gateway stopping capturing events?
Every day or two I have needed to reload the gateway and all is well.

Is there a way to schedule the plugin to restart?

Posted on
Tue Jan 05, 2016 9:08 am
jeremyjjr offline
Posts: 104
Joined: Sep 10, 2013
Location: St Albans, UK

Re: MQTT Gateway Plugin

Interesting! On my main install here, all of the listeners have been running non-stop for about three weeks.

Is it one particular listener or do they all stop receiving events?

First port of call would be to open up a terminal window and manually execute the 'mosquitto_sub' command subscribed to one of your commonly updated topics. If that stops receiving messages at roughly the same time as the MQTT Gateway plugin, then I'd suggest it's an environment issue with the Mosquitto install and will need to be investigated.

If only the Indigo plugin stops receiving the events, then we can pull out some of the debug log information. If you turn debugging on at the same time as you set up the terminal window, then we should have all we need to dig deeper!

J.

Posted on
Sat Jan 09, 2016 11:06 am
bluenoise offline
Posts: 143
Joined: Aug 23, 2008

Re: MQTT Gateway Plugin

This looks like exactly what I need for my ESP8266 garage door project. Thank you for creating this!

When I install Mosquitto, do I need to also install the Python Eclipse library as described on the setup page linked in the original post?

Posted on
Sat Jan 09, 2016 1:35 pm
jeremyjjr offline
Posts: 104
Joined: Sep 10, 2013
Location: St Albans, UK

Re: MQTT Gateway Plugin

You could start by not installing it. The library was originally used in a pre- release version that used a separate Python 3 listener. For simplicity, I elected to not use this and just created the sub process based listeners instead.

J.

Posted on
Sat Jan 09, 2016 6:05 pm
bluenoise offline
Posts: 143
Joined: Aug 23, 2008

Re: MQTT Gateway Plugin

I have some Arduino MQTT example code running on another ESP8266, but I'm stuck coming up with the setting for "server." I tried using the IP address and default port number of my Mac running Indigo and Mosquitto, but that didn't work. How do I get or set the name of my Mosquitto server?

Edit: As always seems to be the case, after considerable time trying to figure things out, I punt and post the question. Moments later, I find the answer myself. I had added the port number to my IP address without seeing that the example code also added it. :oops:

Posted on
Sun Jan 10, 2016 12:24 pm
bluenoise offline
Posts: 143
Joined: Aug 23, 2008

Re: MQTT Gateway Plugin

I've got the MQTT Gateway receiving updates from my ESP8266 perfectly, but I'm having trouble figuring out how to send messages back to the ESP8266. I tried adding a button to a control page that triggers MQTT Gateway to send a message, but all that seems to happen is this log output:

Code: Select all
  mqttGateway                     sent "a MQTT Test" message
  mqttGateway                     a MQTT Test received mqtt message from garageDoor


My device is called "a MQTT Test" and the topic is "garageDoor."

When I click "Send Status Request" from the "a MQTT Test," My ESP8266 receives it perfectly.

How do I send custom messages to my ESP8266? In other words, how do I publish messages to my broker?

Thank you in advance!

Posted on
Sun Jan 10, 2016 3:12 pm
jeremyjjr offline
Posts: 104
Joined: Sep 10, 2013
Location: St Albans, UK

Re: MQTT Gateway Plugin

Hi,

Thanks for the info. Would appear that there was a bug in 1.0.4 that prevented the message being sent. I've just updated the download link to 1.0.5 with a fix. Try downloading and upgrading - should work okay.

In summary, follow these instructions ...

1. In the device config page, tick the 'Enable Status Request' check box and enter the Status Topic you want to allow Indigo to broadcast to the Broker on. You can leave the status message blank in this dialog for now. For example, if you've configured your plugin to listen to the topic called myDevice/toIndigo, you might configure the Status Request as myDevice/fromIndigo

2. Create an mqttGateway action with type 'Send Message'. Select the Indigo device and then click the 'Edit Action Settings' button to define the actual message you want to send.

When you execute the action, it is effectively running the following command ...

mosquito_pub -h <broker> -t 'myDevice/fromIndigo' -m 'myMessage'

Don't forget, you will have to implement a listener on your device or broker that is specifically coded to react to the incoming message.

Hope that helps, and let me know how you get on!

J.

Posted on
Sun Jan 10, 2016 4:08 pm
bluenoise offline
Posts: 143
Joined: Aug 23, 2008

Re: MQTT Gateway Plugin

Thank you for your prompt attention.

I got it working with 1.0.5 after tweaking a few settings.

I get this in the log, too:

Code: Select all
  Started plugin "mqttGateway 1.0.5"
  mqttGateway Debug               startup called
  mqttGateway Debug               resetting device states to OFF
  Error                           device "Garage Door" state key onOffState not defined (ignoring update request)
  Error                           device "Garage Door" state key onOffState not defined (ignoring update request)

Posted on
Mon Jan 11, 2016 6:20 am
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: MQTT Gateway Plugin

Hi Jeremy,
Just started to have a play with this and stumbled at the first hurdle :wink:

There is a typo on the install mosquito page: the line
Code: Select all
brew install mosquito
should be
Code: Select all
brew install mosquitto
two t's in mosquito otherwise you get an error No available formula with the name "mosquito" :)

It proves I am reading through the documentation :D

EDIT: Another minor correction: The line
Code: Select all
mosquitto_pub -t topic/state -m “Hello World”
should be
Code: Select all
mosquitto_pub -t topic/state -m "Hello World"
Note the use of ordinary quotes otherwise you get an error Unknown option 'World”'.

Posted on
Mon Jan 11, 2016 12:43 pm
jeremyjjr offline
Posts: 104
Joined: Sep 10, 2013
Location: St Albans, UK

Re: MQTT Gateway Plugin

Thanks Jon! Got to love Wordpress's spelling checker! All sorted now - hope you have success with everything and please share how you use the plugin!

J.

Posted on
Sun Jan 31, 2016 2:26 pm
bluenoise offline
Posts: 143
Joined: Aug 23, 2008

Re: MQTT Gateway Plugin

Hello!

I've added another MQTT device to my setup and am struggling with a scripting issue. How do I read the topicMessage of my custom device? This device shows my pool's temperature and the MQTT Gateway device is correctly showing the proper temperature in Indigo and on my control page. I'd like to add a Trigger whenever the temperature changes so that I can update my dailyMaxTemp variable. The script would be something like this, though this doesn't work:

Code: Select all
poolMax = indigo.variables[1141597781] # "pool_temp_max"

poolTemp = indigo.devices[102542860] # "Pool Temperature"

if poolMax.value < poolTemp.topicMessage:
   indigo.variable.updateValue(poolMax, poolTemp)


Thanks in advance!

Posted on
Sun Jan 31, 2016 3:32 pm
jeremyjjr offline
Posts: 104
Joined: Sep 10, 2013
Location: St Albans, UK

Re: MQTT Gateway Plugin

Can I ask why you're not just using a standard Trigger action to load a variable with a device value?

Posted on
Sun Jan 31, 2016 3:47 pm
bluenoise offline
Posts: 143
Joined: Aug 23, 2008

Re: MQTT Gateway Plugin

I think that's what I'm trying to do. ;)

I want to set the variable for my max temperature from the value of my pool temperature mqtt device. I just don't know how to read that value from the device as it's in the form of the device's topic message.

Posted on
Sun Jan 31, 2016 7:25 pm
bluenoise offline
Posts: 143
Joined: Aug 23, 2008

Re: MQTT Gateway Plugin

So, I've come up with a rather inelegant and assuming way to pull the message payload out of my device from within a Python script. This is the embedded script within a trigger that fires when the message from my MQTT device changes:

Code: Select all
poolMax = indigo.variables[1141597781] # "pool_temp_max"

poolTemp = indigo.devices[102542860] # "Pool Temperature" # This is my MQTT Gateway device that is receiving from a temperature sensor

#indigo.server.log(poolTemp.name + ": \n" + str(poolTemp))

poolStr = str(poolTemp) # Fetch entire text dump of mqtt device

# Find lines containing "topicMessage"
matched_lines = [line for line in poolStr.split('\n') if "topicMessage : " in line]

#indigo.server.log(str(matched_lines))

# Split the first matched line into separate items
splitStr = matched_lines[0].split()
#indigo.server.log(str(splitStr))

# The message payload is the third item in the splitStr
message = splitStr[2]
#indigo.server.log(str(message))

# If the daily maximum temperature is less than our new temperature, update the daily max to the new value
if float(poolMax.value) < float(message):
   indigo.variable.updateValue(poolMax, message)


Of course, this could break very easily if formats change, but it's working for now. Is there a much better way that I'm just not figuring out , such as direct access through a plugin method?

Who is online

Users browsing this forum: No registered users and 11 guests