Connect local Mosquitto MQTT broker to Google Cloud IoT - mqtt

In my current setup i read data using ebusd from my heating system which works perfectly fine. In the next step i'd like to send this data to a Google IoT Core Device. Unfortunately ebusd does not support setting the clientid externally.
To circumvent this i installed a local Mosquitto Broker which accepts unsecured messages in my Raspberry Pi and shall bridge them to the Google IoT Core Broker. Here is how i configured my local Mosquitto Broker:
# 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
pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_type all
log_dest file /var/log/mosquitto/mosquitto.log
# Goolge IoT Core Configuration
connection bridge-to-gcp
address mqtt.googleapis.com:8883
bridge_attempt_unsubscribe false
bridge_certfile /home/pi/certificates/rsa_cert.pem
bridge_keyfile /home/pi/certificates/rsa_private.pem
bridge_cafile /home/pi/certificates/roots.pem
bridge_protocol_version mqttv311
bridge_insecure false
tls_version tlsv1.2
try_private true
start_type automatic
cleansession true
notifications false
local_clientid local-to-remote-gcp-bridge
remote_username unused
remote_password <JWT Token generated using jwt.io>
remote_clientid projects/project-251313/locations/europe-west1/registries/prot/devices/ebusd12345
topic # both
include_dir /etc/mosquitto/conf.d
Although this setup works with AWS IoT with Google Cloud IoT i get
1542622526: Connecting bridge bridge-to-gcp (mqtt.googleapis.com:8883)
1542622526: Bridge projects/project-251313/locations/europe-west1/registries/prot/devices/ebusd12345 sending CONNECT
1542622526: Socket error on client local.projects/project-251313/locations/europe-west1/registries/prot/devices/ebusd12345, disconnecting.
After googling some time i found this blog (see http://community.onion.io/topic/2858/omega-onion-connecting-to-cloud-cloud-iot/2) which states that Google Cloud IoT Core does not support connections by "sub-brokers" but i didn't find a second statement claiming the same.
Can anybody either confirm that i am trying to do something impossible or please help with with configuring the broker properly?

I reached out to the author of that blog and other people who work on Cloud IoT Core and unfortunately it seems like MQTT bridging indeed is currently not supported. In the meantime, it seems like you're in contact with the ebusd owner on Github to add a configurable clientid feature, which would be a good temporary fix.
With that said, we have a feature that will be going into beta soon that will help you address this kind of issue specifically, so stay tuned!

Related

Nucleus emitter outbound rules

I am new to green-grass and working on nucleus emitter.I have gone through the documentation but found nothing about the nucleus emitter outbound rules. I want to know the outbound rules of the nucleus emitter if they exist.
The Greengrass Telemetry emitter publishes telemetry data on local pub/sub or/and to AWS IoT Core MQTT topic.
When deploying this component to your greengrass core device, you can specify on which AWS IoT Core topic greengrass publishes telemetry. The configuration parameter is mqttTopic. By default it is empty.
Now, the outbound rules you mentioned is based on your greengrass configuration. By default, the port used by Greengrass for MQTT operation is 8883. Again, you can modify this port to 443 by configuring the greengrass nucleus component. (See mqtt section).

Looking for a working example of a non-secure bridge between a local Mosquitto instance and the Watson IoT platform

I'm trying to establish a non-secure bridge from Mosquitto running on Home Assistant (home-assistant.io) to the MQTT broker on the Watson IoT platform. Why non-secure? To take out additional complexity as I can't connect. Once this step is successful I'll move on to secure the connection.
Firstly I have setup the Watson IoT platform and created a gateway device type ('ha-iotp-gateway') and device ('ha'). No other changes to the IoT platform.
I then created a bridge config file to connect Mosquitto with the Watson IoT platform broker by adopting the conf shared in this post and now have the following:
connection bridge-to-watsoniot
address xxxxxx.messaging.internetofthings.ibmcloud.com:1883
cleansession true
try_private false
bridge_attempt_unsubscribe false
notifications false
notification_topic iot-2/type/ha-iotp-gateway/id/ha/evt/status/fmt/raw
remote_username use-token-auth
remote_password <token>
remote_clientid g:xxxxxx:ha-iotp-gateway:ha
topic iot-2/type/+/id/+/cmd/+/fmt/+ in iot-2/type/+/id/+/cmd/+/fmt/+
topic iot-2/type/+/id/+/evt/+/fmt/+ out iot-2/type/+/id/+/evt/+/fmt/+
connection_messages true
The Mosquitto log file shows a connection attempt
1606909705: Connecting bridge bridge-to-watsoniot (xxxxxx.messaging.internetofthings.ibmcloud.com:1883)
1606909706: Socket error on client local.g:xxxxxx:ha-iotp-gateway:ha, disconnecting.
1606909707: New connection from 172.30.32.1 on port 1883.
[INFO] found homeassistant on local database
1606909707: New client connected from 172.30.32.1 as auto-BD9CD1CE-BE73-6CBA-196D-C02E83268AEB (p2, c1, k60, u'homeassistant').
1606909712: Connecting bridge bridge-to-watsoniot (xxxxxx.messaging.internetofthings.ibmcloud.com:1883)
1606909723: Connection Refused: not authorised
1606909723: Socket error on client local.g:xxxxxx:ha-iotp-gateway:ha, disconnecting.
The gateway device on the Watson IoT platform (created earlier) shows connected and the connection log shows
Closed connection. The operation is not authorized.
Has anyone been successful in establishing a non-secure connection to Watson IoT? I'm not sure whether the IoT platform is correctly configured or my bridge config has issues - or both.

Is it possible to bridge MQTT broker mosquitto to Cloud PubSub?

I have a local mosquitto broker that I would like to connect to Google Cloud pubsub queue.
I looked into Google Cloud IOT core but with no luck, I cannot seem to connect to it
Here is my mosquitto configuration
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example
pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
# Goolge IoT Core Configuration
connection bridge-to-gcp
address mqtt.googleapis.com:8883
bridge_attempt_unsubscribe false
bridge_certfile /Downloads/rsa_cert.pem
bridge_keyfile /Downloads/rsa_private.pem
bridge_cafile /Downloads/roots.pem
bridge_protocol_version mqttv311
bridge_insecure false
tls_version tlsv1.2
try_private true
start_type automatic
cleansession true
notifications false
local_clientid local-to-remote-gcp-bridge
remote_clientid projects/toolsense-dev/locations/europe-west1/registries/test-registry/devices/test-device
topic # both
Is there a way to forward all the messages received from edge devices to Google Cloud Pubsub?
After deeper research, it is not possible without the existence of a gateway device either virtually or physically. It could even be client code running on same machine as the one running the broker.
This usecase is however possible in AWS Iot
https://wiki.seeedstudio.com/Arduino-AWS-IOT-Bridge/

Linking cloud based MQTT Broker and local MQTT Broker

I am quite new to MQTT implementations. I am managing to connect popular cloud based MQTT Brokers such thingsboard.io, Azure and AWS to send Sensor information to create dashboards for monitoring devices.
Problem
I have installed a local things-board broker to my local computer. But it is unable to reach other dashboards on the internet. Is it possible? Or is it only accessible within the local network?
It seems your doubt is more related to network connections. An MQTT broker will work in the same way, regardless it is working locally, in a fog server or in a cloud server. Obviously you will have to deal with access means: your clients/devices/applications must access the MQTT broker no matter where it is running. If you are running a local MQTT broker and it does not communicate directly with some cloud server, you can develop a specie of "gateway" only to send these data to the cloud or search for some tool that performs this task for you.
Below, you have some references regarding the working of MQTT and how to use it:
MQTT IoT Protocol complete tutorial - How it works with a demo
Using local MQTT broker for cloud and interprocess communication
MQTT Brokers/Servers and Cloud Hosting Guide
Creating an MQTT Broker With CloudMQTT
How to setup your own MQTT Broker

How paho client can know status of bridge connections?

I have one remote broker (cloudmqtt) and one local broker on my board. Both are connected as bridge. I have one paho client connected to local broker. I want to know the status of bridge in order to publish message. I know I can publish message to local broker without knowing status and broker will take care. But I want to design my application like I will Publish message only if bridge is Up.
I am using paho client library in C and mosquitto broker v1.6.
Below is my conifg file :
pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
log_timestamp true
log_timestamp_format %Y-%m-%dT%H:%M:%S
log_type all
user root
connection cloudmqtt
address xxxx.cloudmqtt.com:13287
remote_username xxxxxxx
start_type automatic
try_private true
remote_password xxxxxx
notifications true
notification_topic /broker/connection/state
restart_timeout 20
max_queued_messages 0
topic # both 2
The short answer is you can't at a pure MQTT protocol level or specific to the Paho client (and you shouldn't care for the reasons you mentioned).
Now having said all that you can actually get messages about the bridge status from the $SYS/broker/connection/<remote-clientid>/# topic tree on mosquitto. To enable this you need to set the notification true flag in the bridge config. The doc for configuring bridges is here

Resources