Tutorials: Connect to an MQTT Broker

Send data using MQTT with TLS Security to a designated MQTT Broker

G3 with Antenna 3.jpg



Send JSON data using MQTT with TLS Security to a MQTT Broker

In this tutorial, we will explain the simple steps to modify our standard Ubidots MQTT script to send your Modbus or CAN bus device data (in JSON) to a MQTT broker with TLS security. We will be using the Mosquitto test server in this article, from there you can implement the same with your own MQTT broker.

SSH over to your FATBOX and modify the following in the scripts/ubidots/ubidots_client.py file, 

BROKER_ENDPOINT = "test.mosquitto.org" #mosquitto test server TLS_PORT = 8883 # Secure port

TOPIC = "your_topic" #we use “fatbox” in our example
TLS_CERT_PATH = "/scripts/ubidots/mosquitto.org.crt" #you will need to copy and paste *

You can download the certificate from https://test.mosquitto.org/, please try to leave a donation to show appreciation of the nice job done by team Mosquitto!

As we are using the existing framework of our Ubidots client, you will need to ‘Enabled’ Ubidots in the ‘IoT Client’ tab of your gateway.

You can leave both Device Token and Name empty as it’s not used in this mode.

TLS Security Config.png
After saving the modifications to the client file and also copied over the certificate file, you are ready to go after a reboot.

If your Modbus or CAN bus settings are already working, you should be able to subscribe to your MQTT publisher topic and receive the JSON device data like in the following screen-shots.

MQTT with TLS Security to Mosquitto.png

Ask Us Your Questions

Get a prompt response to your query.