0

[SOLVED] Bridging Mosquitto MQTT to io.Adafruilt.com
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

[SOLVED] Bridging Mosquitto MQTT to io.Adafruilt.com

by st2000 on Thu Aug 29, 2019 8:54 am

Has anyone gotten the Mosquitto MQTT Bridge to pass data to io.Adafruit.com? This web page (https://learn.adafruit.com/manually-bri ... o?view=all) actually uses a Python program to send data to io.Adafrult.com. Not Mosquitto's Bridge feature. I have searched for a solution and have tried several different Mosquitto.conf configurations. I still have not found one that works. I think this is partly due to the constant evolution of Mosquitto. Any help appreciated. Thanks.
Last edited by brubell on Tue Sep 03, 2019 1:58 pm, edited 1 time in total.
Reason: add solved

st2000
 
Posts: 54
Joined: Fri Oct 28, 2011 7:08 pm

Re: Bridging Mosquitto MQTT to io.Adafruilt.com

by brubell on Thu Aug 29, 2019 1:47 pm

One of the issues may be that Mosquitto uses user/topic/topicname and adafruit io uses user/feed/topicname (http://www.steves-internet-guide.com/mo ... iguration/).

You may want to look at using Paho-Python-MQTT to bridge data, instead.

brubell
 
Posts: 496
Joined: Fri Jul 17, 2015 10:33 pm

Re: Bridging Mosquitto MQTT to io.Adafruilt.com

by st2000 on Fri Aug 30, 2019 3:08 pm

Thank you brubell for the feed back. What I (believe I) did to get around this was to publish a corrected topic locally (I am using Tasmota and had Tasmota send out io.adafruit.com friendly topic & data). On my local Mosquitto broker I was able to confirm this by subscribing to the topic in question:

mosquitto_sub -v -t st2000/feeds/sensor
st2000/feeds/sensor 39.0
st2000/feeds/sensor 39.2


So, the sensor was sending data to my MQTT broker & I could subscribe to it verifying that bit works. Now I want to Bridge this topic to io.Adafruit.com.

I am using the instructions from this set of web pages:
https://learn.adafruit.com/manually-bri ... spberry-pi

...and came up with this mosquitto.conf file:

Code: Select all | TOGGLE FULL SIZE
# Config file for mosquitto
#
# See mosquitto.conf(5) for more information.

user mosquitto
max_queued_messages 200
message_size_limit 0
allow_zero_length_clientid true
allow_duplicate_messages false

listener 1883
autosave_interval 900
autosave_on_changes false
persistence true
persistence_file mosquitto.db
allow_anonymous true
#password_file /etc/mosquitto/passwd

#
# Bridge to Adafruit.IO
#
connection adafruit-light-sensor
address io.adafruit.com:1883
bridge_atetempt_unsubscribe false
cleansession false
notifications false
remote_username st2000
remote_password beeeeeeeeeeeeeeeeeeeeeeeep
start_type automatic
#topic /sensors/lightsensor  out 0 lightsensor
topic st2000/feeds/sensor out 0
topic st2000/feeds/sensor in 0


...but so far, no luck. I do not see anything getting added to the data at io.adafruit.com for this feed.

Going on, just to verify I can get data to io.Adafruilt.com I tried the following commands on the same computer that is running mosquitto:

mosquitto_pub -h io.adafruit.com -t st2000/feeds/sensor -m "321" -u st2000 -P beeeeeeeeeeeeeeeeeep -p 1883


...and that worked! So, it would appear the "broken" bit here is likely the way the local Mosquitto's mosquitto.conf file has been written. Any help would be appreciated.

-thanks

st2000
 
Posts: 54
Joined: Fri Oct 28, 2011 7:08 pm

Re: Bridging Mosquitto MQTT to io.Adafruilt.com

by st2000 on Fri Aug 30, 2019 6:02 pm

I decided to press on. I moved the MQTT Mosquitto Broker to a machine where I could run WireShark. I set everything up to monitor packets going to io.adafruit.com (52.7.124.212) and saw nothing. I then simplified the /etc/mosquitto/conf.d/mosquitto.conf file to only the following:

connection dehumidifier
address 52.7.124.212:1883
topic # out 0
topic # in 0


I did not expect to connect to io.adafruit.com but I did expect to see packets while monitoring traffic for 52.7.124.212. I saw nothing.

Finally I executed a manual mosquitto_pub command:

mosquitto_pub -h 52.7.124.212 -t st2000/feeds/sensor -m "100"


...and WireShark recorded the event. Of course nothing happened at io.adafruit.com because of the lack of a user name and password. But, bottom line, the Bridge feature of Mosquitto is definitely not working as expected.

(I'm using mosquitto version 1.6.4.)

st2000
 
Posts: 54
Joined: Fri Oct 28, 2011 7:08 pm

Re: Bridging Mosquitto MQTT to io.Adafruilt.com

by st2000 on Fri Aug 30, 2019 8:00 pm

Well, to answer part of my own post, I assumed the file /etc/mosquitto/conf.d/mosquitto.conf would be read each time mosquitto started up. Guess I was wrong. I do not know if this is a bug. But I now explicitly use this configuration file using the start up command:

mosquitto -v -c /etc/mosquitto/conf.d/mosquitto.conf


...at least now I'm seeing attempts to connect to io.adafruit.com. Unfortunately I see the following error:

1567208596: Bridge local.raspberrypi.adafruit doing local SUBSCRIBE on topic st2000/feeds/sensors
1567208596: Connecting bridge (step 1) adafruit (io.adafruit.com:8883)
1567208596: Connecting bridge (step 2) adafruit (io.adafruit.com:8883)
1567208596: Bridge raspberrypi.adafruit sending CONNECT
1567208596: Socket error on client local.raspberrypi.adafruit, disconnecting.

st2000
 
Posts: 54
Joined: Fri Oct 28, 2011 7:08 pm

Re: Bridging Mosquitto MQTT to io.Adafruilt.com

by st2000 on Sat Aug 31, 2019 2:41 pm

Today I finally got Mosquitto version 1.6.4 running on a RaspberryPi to Bridge to io.Adafruit.com! Here is what I have found out:

1. Do not believe the Mosquitto README files scattered around. Files ending in .conf in the directory /etc/mosquitto/conf.d/ are not used by Mosquitto. Instead, add any io.Adafruilt.com / Mosquitto adjustments to the end of the /etc/mosquitto/mosquitto.conf file.

2. Here are the (edited) io.Adafruilt.com / Mosquitto adjustments that have been working for me for the past 10 hours:

Code: Select all | TOGGLE FULL SIZE
connection adafruit
address io.adafruit.com:1883
cleansession true
notifications false
username st2000
password Beeeeeeeeeeeeeeeeeeeeeeeep
try_private false
topic st2000/feeds/temperature-attic out 0


...Use your own Adafruit username and password. And of course change the topic to match what you want to send to io.Adafruit.com. As you can see from the above, I formed my topic to match the format used by io.Adafruit.com before I published it. So there is no translation at the end of the "topic" line necessary.

---

This is great to have data show up at io.Adafruit.com. But as you can see from the Mosquitto.conf file, I am using port 1883. I would much rather use the encrypted port 8883 at io.Adafruit.com. But I have not been able to create a Mosquitto.conf file to do this. Does anyone have an idea as to how to do this?

-thanks

st2000
 
Posts: 54
Joined: Fri Oct 28, 2011 7:08 pm

Re: Bridging Mosquitto MQTT to io.Adafruilt.com

by st2000 on Sat Aug 31, 2019 3:50 pm

So close...

Adafruit author Philip Moyer said here
https://learn.adafruit.com/manually-bridging-mqtt-mosquitto-to-adafruit-io/the-right-way-to-have-built-this
the following:

As I noted, I have NOT tried these two techniques yet, though I plan to do so.


In short, he was trying to do what I have been trying to do in this question. He was about to make a secure connection from an MQTT Broker over that Broker's Bridge to io.Adafruit.com!

Philip - if you are there, did you get it to work?

st2000
 
Posts: 54
Joined: Fri Oct 28, 2011 7:08 pm

Re: Bridging Mosquitto MQTT to io.Adafruilt.com

by st2000 on Sat Aug 31, 2019 4:59 pm

Ug, I can't believe this happened. I altered my mosquitto.conf file to make a bid at using secure port 8883 at io.adafrult.com. That didn't work. So I reverted the mosquitto.conf file. Now I can not connect to io.adafrult.com!!!! Is there an Adafrult Lock Out mechanism that I triggered? Maybe there were sooo many failed SSL attempts something snapped at Adafruit and now my account is frozen?

Either I've had a boat load of bad luck. Or IoT is really hard to do.

st2000
 
Posts: 54
Joined: Fri Oct 28, 2011 7:08 pm

Re: Bridging Mosquitto MQTT to io.Adafruilt.com

by st2000 on Sat Aug 31, 2019 6:59 pm

So, I'm noticing errors in my local Mosquitto log file even though data from 4 different topics appear to be getting to io.adafruit.com. These are the things I tried to get my Adafruit io.adafruit.com account free of errors:
1. Deleted my local mosquitto.db file.
2. Rebuilt my local mosquitto.conf file from scratch.
3. Purged my installation of Mosquitto from the RaspberryPi and reinstalled it from scratch.
4. Generated a new AIO key and restarted my instance of Mosquitto with the new key.
5. Deleted my Adafruit io.adafruit.com account and all of its data.
6. Recreated one of my feed for the Adafruit io.adafruit.com account.

Still getting this in my local MQTT Mosquitto log file:

1567291988: Connecting bridge (step 1) adafruit (io.adafruit.com:1883)
1567291989: Connecting bridge (step 2) adafruit (io.adafruit.com:1883)
1567291999: Socket error on client local.raspberrypi.adafruit, disconnecting.


Anyone got any other ideas?

st2000
 
Posts: 54
Joined: Fri Oct 28, 2011 7:08 pm

Re: Bridging Mosquitto MQTT to io.Adafruilt.com

by st2000 on Sat Aug 31, 2019 7:51 pm

Hallelujah. I used the mosquitto.conf file listed in this thread over at github.com:
https://github.com/eclipse/mosquitto/issues/1343

connection mybridge
bridge_capath /etc/ssl/certs/
try_private false
bridge_attempt_unsubscribe false
cleansession false
notifications false
start_type automatic
notifications false
remote_username secretuser
remote_password secretkey
address io.adafruit.com:8883
topic test out 0


And I'm finally connected error free on secure port 8883!

This sure does seam like the long way to success. Hopefully any one else w/similar problems can use this information to figure things out.

st2000
 
Posts: 54
Joined: Fri Oct 28, 2011 7:08 pm

Re: Bridging Mosquitto MQTT to io.Adafruilt.com

by brubell on Tue Sep 03, 2019 1:57 pm

Glad you solved it!

If you are interested - you can submit the bridging config example to the Adafruit IO API Cookbook (https://io.adafruit.com/api/docs/cookbo ... i-cookbook).

brubell
 
Posts: 496
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.