Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Bridging local MQTT broker to io.adafruit.com broker
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Bridging local MQTT broker to io.adafruit.com broker

by tdack on Sun Jan 17, 2016 6:15 pm

Has anyone successfully managed to bridge their local (or any other) MQTT broker to the Adafruit IO one?

I've been trying with Mosquitto and haven't had much luck.

Relevant section of mosquitto.conf:
Code: Select all | TOGGLE FULL SIZE
connection adafruit
address io.adafruit.com:1883
clientid my_client_id
remote_username <username>
remote_password <aio key>
try_private false
cleansession true
start_type automatic

topic ambient out 0 temperature/ <username>/feeds/temperature_
topic fridge out 0 temperature/ <username>/feeds/temperature_
topic freezer out 0 temperature/ <username>/feeds/temperature_
topic fermenter out 0 temperature/ <username>/feeds/temperature_

Initially things appear to be working, but I end up with a disconnection error and no messages are published to the Adafruit IO broker.

mosquitto.log
Code: Select all | TOGGLE FULL SIZE
1453066709: mosquitto version 1.4.5 (build date Mon, 09 Nov 2015 15:00:46 +0000) starting
1453066709: Config loaded from /etc/mosquitto/mosquitto.conf.
1453066709: Opening websockets listen socket on port 8080.
1453066709: Opening ipv4 listen socket on port 1883.
1453066709: Opening ipv6 listen socket on port 1883.
1453066709: Bridge local.my_client_id doing local SUBSCRIBE on topic temperature/ambient
1453066709: Bridge local.my_client_id doing local SUBSCRIBE on topic temperature/fridge
1453066709: Bridge local.my_client_id doing local SUBSCRIBE on topic temperature/freezer
1453066709: Bridge local.my_client_id doing local SUBSCRIBE on topic temperature/fermenter
1453066709: Connecting bridge adafruit (io.adafruit.com:1883)
1453066709: Bridge my_client_id sending CONNECT
1453066710: Received CONNACK on connection local.my_client_id.
1453066710: Bridge local.my_client_id sending UNSUBSCRIBE (Mid: 4, Topic: <username>/feeds/temperature_ambient)
1453066710: Bridge local.my_client_id sending UNSUBSCRIBE (Mid: 5, Topic: <username>/feeds/temperature_fridge)
1453066710: Bridge local.my_client_id sending UNSUBSCRIBE (Mid: 6, Topic: <username>/feeds/temperature_freezer)
1453066710: Bridge local.my_client_id sending UNSUBSCRIBE (Mid: 7, Topic: <username>/feeds/temperature_fermenter)
1453066710: Socket error on client local.my_client_id, disconnecting.


Mosquitto V1.4.5 is running on Ubuntu 15.04 installed from http://ppa.launchpad.net/mosquitto-dev/mosquitto-ppa

Any suggestions on how to proceed would be appreciated.

tdack
 
Posts: 6
Joined: Sun Jan 17, 2016 5:38 pm

Re: Bridging local MQTT broker to io.adafruit.com broker

by tdack on Sun Jan 17, 2016 7:16 pm

So it seems the mosquitto.conf setting that makes everything work is:

Code: Select all | TOGGLE FULL SIZE
notifications false

I now have my local MQTT broker forwarding selected topics to the io.adafruit.com broker and they display in the feeds.

The config above maps my topics as follows:
Code: Select all | TOGGLE FULL SIZE
Local                  ->  Remote
-------------------------------------------------------------------
temperature/fridge     ->  <username>/feeds/temperature_fridge
temperature/freezer    ->  <username>/feeds/temperature_freezer
temperature/fermenter  ->  <username>/feeds/temperature_fermenter
temperature/ambient    ->  <username>/feeds/temperature_ambient

Also, if you want a secure connection for your bridge add/change your mosquitto.conf with this (at least on Ubuntu):
Code: Select all | TOGGLE FULL SIZE
address io.adafruit.com:8883
bridge_capath /etc/ssl/certs


Thanks to https://developer.ibm.com/answers/quest ... wer-170240 for pointing me in the right direction regarding the disconnection error.

tdack
 
Posts: 6
Joined: Sun Jan 17, 2016 5:38 pm

Re: Bridging local MQTT broker to io.adafruit.com broker

by tdack on Sun Jan 17, 2016 8:34 pm

More bad form replying to myself, but it might help others later.

Sample mosquitto.conf with examples that can be used to bridge your local broker to Adafruit.io

https://gist.github.com/tdack/45dd356d9271a87914ce

Example dashboard that is updated using bridged MQTT https://io.adafruit.com/tdack/temperatures

tdack
 
Posts: 6
Joined: Sun Jan 17, 2016 5:38 pm

Re: Bridging local MQTT broker to io.adafruit.com broker

by jwcooper on Mon Jan 18, 2016 12:22 pm

Thank you for following up your questions with a working solution! This will almost certainly help others in the future.

jwcooper
 
Posts: 679
Joined: Tue May 01, 2012 9:08 pm

Re: Bridging local MQTT broker to io.adafruit.com broker

by tdack on Wed Jan 27, 2016 12:45 am

Well it looks like something may have changed on the Adafruit end and my bridge is no longer working.

Connections fail with:
Code: Select all | TOGGLE FULL SIZE
Connection Refused, identifier rejected


(see: http://docs.oasis-open.org/mqtt/mqtt/v3 ... able_3.1_-)

It doesn't seem to matter what I set the client ID to it is rejected. Although pub/sub from the command line works OK, so I'm not sure what is going on here.

tdack
 
Posts: 6
Joined: Sun Jan 17, 2016 5:38 pm

Re: Bridging local MQTT broker to io.adafruit.com broker

by hukuzatuna on Wed Jan 27, 2016 1:56 pm

Let us know if you get it working again, please. I'd like to try this out with my home Rasberry Pi network.

Unfortunately, I have my rover configured to publish science data as a CSV string. I then have a subscriber running on a different RPi that reads the data, parses it, does "other stuff" with it, and then updates my adafruit.io feeds with individual data fields. If I have a single feed for each sensor reading I need to track, my supporting code is going to be lengthy. I'd much rather use the CSV->MQTT->parser->adafruit.io method since it seems cleaner.

For my weather station, however, the bridged MQTT approach seems desirable. I'm going to start testing with your bridge configuration and see if I can get it to work from my end, too.

Cheers,
Phil

hukuzatuna
 
Posts: 113
Joined: Wed Aug 14, 2013 11:40 pm

Re: Bridging local MQTT broker to io.adafruit.com broker

by tdack on Thu Feb 04, 2016 6:33 am

After reading through the mosquitto.conf man page for what seems like the hundredth time I came across the try_private option (again). This option is meant to make the remote broker aware of the fact that the connection is a bridge and not just an ordinary client. The man page does state that not all brokers support this.

It seems the broker Adafruit is using doesn't support (or doesn't have support enabled) the try_private option. Setting this to false and then restarting Mosquitto resulted in my bridge connecting to io.adafruit.com and forwarding topics.

Yippee!!!

I've updated the gist linked above.

tdack
 
Posts: 6
Joined: Sun Jan 17, 2016 5:38 pm

Please be positive and constructive with your questions and comments.