Introduction
Data logging to MQTT broker allows you to log your machine data directly to a 3rd party MQTT broker instead of the CloudVPN Portal. As such, it's an alternative to the feature Historical data, where the machine data is logged to the CloudVPN Portal.
The MQTT broker can either be self-hosted or it can be run at an online service like Azure or Amazon Web Services (AWS). In this application note we will be focusing on the cloud based MQTT broker from HiveMQ Cloud. To learn more about this feature check out out article regarding it.
In this application note, we will be sending our data from a CloudVPN router to a HiveMQ Cloud broker and then subscribe from a MQTT Client (MQTT Explorer).
Overview
- HiveMQ Cloud Broker
- Setting up HiveMQ MQTT Client Credential for CloudVPN Router
- Setting up HiveMQ MQTT Client Credential for MQTT Explorer
- Downlad CA Cert for HiveMQ
- CloudVPN Portal
- Connecting your MQTT Client on the laptop
- Verifying the connection
HiveMQ Cloud Broker
One you have logged into you HiveMQ Cloud Broker, click on "manage cluster".
Next look for Access Management.
Create 2 new credentials, one of the new credential is for the MQTT Client that is on the laptop, the other is for CloudVPN Router. For the CloudVPN router's credential, it is a required that it matches the CloudVPN Public ID.
Field | Entry | Remarks |
Client ID | Meaningful name / Router Public ID | ID for Router must match router's public ID |
Password | Provide a complex password for security | |
Permission | Publish / Subscribe / Both |
For this application note: |
CloudVPN Portal
Getting the router's public ID
The MQTT Client ID in the MQTT broker (sometimes called Device ID) needs to be equal to the CloudVPN router's public ID. You can find the CloudVPN router's public ID in the URL by going to the device in the CloudVPN Portal Fleet Manager. For example: cloudvpn.acirroplus.com/fleet-manager/device-configurator/mxLCEyXfR5Lx/...
..
Setting up of MQTT Broker (admin)
Go to Admin > MQTT and add a custom broker,
Field | Entry | Remarks |
Name | Meaningful name for the broker | |
Host | URL for the MQTT broker eg. examplehere.s1.eu.hivemq.cloud |
Can be found in Cluster Details in HiveMQ Cloud Console. |
Port | MQTT Broker port, typically it is 8883 | Can be found in Cluster Details in HiveMQ Cloud Console. |
CA Cert |
HiveMQ broker provider also provides a CA certificate you can upload it here. |
Download the cert here. |
Message Format |
JSON / Sparkplug B |
Choose what is applicable. |
Add the Client next
Field | Entry | Remarks |
Name | Meaningful name for the Client, eg name of the router you plan to connect it with. | |
Username | Username created in HiveMQ for the router, which is the Router's public ID. | Must match with router's public ID and entry in HiveMQ. |
Password | Password entered in HiveMQ for the router. | Must match with entry in HiveMQ. |
Certificate | Not used in this example | |
Key File | Not used in this example |
Setting up of MQTT Broker (fleet-manager)
Once you are done setting it up in the Admin page, you need to move over the Fleet Manager > Devices and click on the device name you wish to apply the it to.
Once you have selected the router, select the existing Service (Data Source) that you wish to link to the HiveMQ broker.
Check the "Use custom broker" and select the MQTT Client you have connected and create a meaningful topic.
Connecting your MQTT Client on the laptop
Setting up the MQTT Client
Once you have download MQTT Explorer, launch the software and setup a new connection and enter the fields accordingly. Once you are done you can click on connect.
Field | Entry | Remarks |
Name | Meaningful name for the connection. | |
Host | URL of the MQTT Broker | Can be found in the HiveMQ Console |
Port | Port of the MQTT Broker, default Port: 8883 | Can be found in the HiveMQ Console |
Username | Client ID created for the MQTT Client in HiveMQ Access Management page | |
Password |
Passwored entered for the MQTT Client in HiveMQ Access Management page |
Verifying the connection
Once you have set everything up you can connect the MQTT Client on your laptop (MQTT Explorer). If everything is setup correctly you will be able to see the MQTT messages coming though.
Comments
0 comments
Please sign in to leave a comment.