bridge local mosquitto to cloud broker

笑着哭i 提交于 2019-12-10 18:25:38

问题


I'm trying to bridge local mosquitto (on raspberry pi) to some cloud broker so I can send data and control some devices using that data. I tried with Cloudmqtt and dioty, but with no success. In case of cloudmqtt I've been told that everything is ok with mosquitto.conf file and for dioty I've been told that it uses Mosca broker which doesn't support bridging (with I've been told I refer to cloudmqtt and dioty support service). Does anybody knows some remote broker that can be bridged to local mosquitto and did somebody already tried that?

I considered using some IOT platform to do this, but I have read that platform like that use pricing, I'm doing this for learning and hobbie purposes, so before I learn how to use it I would like to stay on free account.

EDITED: I'm using mosquitto 1.4.5, mosquitto.conf file like this:

#Place your local configuration in /etc/mosquitto/conf.d/
#
#A full description of the configuration file is at
#/usr/share/doc/mosquitto/examples/mosquitto.conf.example

connection cloudmqtt
address mnumber.cloudmqtt.com:port
topic zaESP8266 in 0
topic ESP8266 out 0
try_private true
notifications false
start_type automatic
remote_usename username_of_the_user_on_cloudmqtt
remote_password password_of the_user_on_cloudmqtt

pid_file /var/run/mosquitto.pid

persistance true
persistance_location /var/lib/mosquitto/

The reason I have choose Cloudmqtt for online mosquitto broker is because I tought that local mosquitto <--> remote mosquitto bridge should work. And that I could use clients like laptop or phone, and use them to publish and subsccribe messages with local broker. This way even when I lose internet access I can have local broker to interact with local clients.

EDITED: I configured mosquitto.conf file so I can bridge with test.mosquitto.org, I added these lines:

connection test
address test.mosquitto.org
topic in_topic in 0
topic out_topic out 0
try_private false
notifications false
bridge_attempt_unsubscribe true

Now, in one terminal I can use mosquitto_sub -t in_topic and in other terminal I use mosquitto_pub -h test.mosquitto.org -t in_topic -m message. I get that message in first terminal where I used mosquitto_sub command. So after this I am right to assume that bridge works well. But I can't figure out what seems to be the problem with bridging to cloudmqtt.

Cloudmqtt uses mosquitto mqtt brokers, dioty crossed from mosquitto to Mosca mqtt broker which doesn't support bridging but apparently have better scalability (this information has been provided to me by dioty customer service)

EDITED: I solved this bridgig problem using Node-RED. Just added one mqqt input and configure it for local mosquitto broker (PORT 1883) and two mqtt outputs, for cloudmqtt and DIoTY.

On cloudmqtt, after you made an account (cute cat is free), go to control panel and add cloudmqtt instance and username and password will be provided to you by cloudmqtt. In Node-RED configure one of the mqtt outputs for cloudmqtt instance by adding server, username, password and port.

On DIoTY you also need to make account or sign in with google, or some other account. When you log in you will be provided by username which will be your mail account and other informations like host and port, password which will be sent to the e-mail account. So to use this in Node-RED you need to add host(server), username, password and port to the mqtt output. And when you subscribe or publish message keep in mind that you have root topic, in example:

/your_mail_account/topic

and no matter are subscribing to some topic or publishing some messages you need to add root topic as some kind prefix.

After you have done this configuration you need to deploy changes, and that is. So for this kind of I used Node-RED.


回答1:


I am using windows and c9.io linux console tested.


I find out that https://www.cloudmqtt.com/docs-faq.html#TLS_SSL

cloudmqtt.com server cert is signed by Comodo, which has the AddTrust CA as root. Most OSs comes with it by default, so can you point to your default trust/CA store.

Methods to get AddTrust CA cert

Method 01

  1. Click Start, click Start Search, type mmc, and then press ENTER.

  2. On the File menu, click Add/Remove Snap-in.

  3. Under Available snap-ins, click Certificates,and then click Add.

  4. Under This snap-in will always manage certificates for, click Computer account, and then click Next.

  5. Click Local computer, and click Finish.

  6. If you have no more snap-ins to add to the console, click OK.

  7. In the console tree, double-click Certificates.

  8. Click to Trusted Root Certification Authorities > Certificates store.

  9. Right-click AddTrust External CA Root

  10. Click Export to Export the certificates and follow the steps in the Certificate Export Wizard, Export File Format choose Base-64 encoded X.509(CER).

  11. Save the ca.cer to **C:\Program Files\mosquitto**

Method 02

I get the cert here : www.tbs-certificates.co.uk/FAQ/en/357.html

AddTrust CA Root cert : http://www.tbs-x509.com/AddTrustExternalCARoot.crt

  1. Copy AddTrustExternalCARoot.crt to C:\Program Files\mosquitto\
  2. Double click AddTrustExternalCARoot.crt, Install Certificate...

Bridge Mosquitto to CloudMQTT

Windows

I'm using mosquitto 1.4.11, windows, mosquitto.conf file I use difference name(cloud.conf), It look like this:

connection cloudmqtt
address xxx.cloudmqtt.com:<ssl-port>
remote_username <username_of_the_user_on_cloudmqtt>
remote_password <password_of the_user_on_cloudmqtt>
remote_clientid cloud.mqtt
bridge_protocol_version mqttv311
try_private true
notifications false
start_type automatic
topic # both 2
# Method 01
bridge_cafile ca.cer
# Method 02
#bridge_cafile AddTrustExternalCARoot.crt
bridge_insecure false
cleansession false
local_clientid local.mosquitto

Run cmd.exe

C:\Program Files\mosquitto> mosquitto.exe -c cloud.conf -v

1490627692: mosquitto version 1.4.11 (build date 20/02/2017 23:24:29.40) starting
1490627692: Config loaded from cloud.conf.
1490627692: Opening ipv6 listen socket on port 1883.
1490627692: Opening ipv4 listen socket on port 1883.
1490627692: Bridge local.mosquitto doing local SUBSCRIBE on topic #
1490627692: Connecting bridge cloudmqtt (xxx.cloudmqtt.com:<ssl-port>)
1490627692: Bridge cloud.mqtt sending CONNECT
1490627693: Received CONNACK on connection local.mosquitto.
1490627693: Bridge local.mosquitto sending SUBSCRIBE (Mid: 1, Topic: #, QoS: 2)
1490627693: Received SUBACK from local.mosquitto
...

Now, my local mosquitto broker bridged cloudmqtt.com in 2 way communication.


Linux

Simple try at c9.io linux console using method 02 (AddTrustExternalCARoot.crt), the output as below.

$ mosquitto -c cloud.conf -v -p 8080
1490634446: mosquitto version 1.4.11 (build date Fri, 03 Mar 2017 15:11:39 +0000) starting
1490634446: Config loaded from cloud.conf.
1490634446: Opening ipv4 listen socket on port 8080.
1490634446: Opening ipv6 listen socket on port 8080.
1490634446: Bridge c9.mosquitto doing local SUBSCRIBE on topic #
1490634446: Connecting bridge cloudmqtt2c9 (xxx.cloudmqtt.com:<ssl-port>)
1490634446: Connecting bridge cloudmqtt2c9 (xxx.cloudmqtt.com:<ssl-port>)
1490634446: Bridge cloud.mqtt.c9 sending CONNECT
1490634446: Received CONNACK on connection c9.mosquitto.
1490634446: Bridge c9.mosquitto sending SUBSCRIBE (Mid: 1, Topic: #, QoS: 2)
1490634447: Received SUBACK from c9.mosquitto
...

Raspberry Pi

Copy AddTrustExternalCARoot.crt to same directory with cloud.conf

connection pi2cloudmqtt
address xxx.cloudmqtt.com:<ssl-port>
remote_username <username_of_the_user_on_cloudmqtt>
remote_password <password_of the_user_on_cloudmqtt>
remote_clientid cloud.mqtt.pi
bridge_protocol_version mqttv311
try_private true
notifications false
start_type automatic
topic # both 2
# Method 01
#bridge_cafile ca.cer
# Method 02
bridge_cafile AddTrustExternalCARoot.crt
bridge_insecure false
cleansession false
local_clientid pi.mosquitto

$ mosquitto -c cloud.conf -v




回答2:


You could try test.mosquitto.org as the remote broker.

To improve your question, please give details of which version of mosquitto you are using and post the exact mosquitto.conf settings you use - with credentials removed of course.



来源:https://stackoverflow.com/questions/34255907/bridge-local-mosquitto-to-cloud-broker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!