Episode 10: Migrating to HiveMQ broker
-
NOTE: The following tutorial applies to IoT (MQTT) connection mode only.
By default, GUI-O application uses a MQTT test broker that is running on our own server. The broker listens on ports 1883 (unencrypted), 8883 (encrypted with client certificates) and 8884 (encrypted). This is perfect for testing and some smaller use cases, but some IoT scenarios require using a broker platform that gives you finer control over additional settings (e.g., managing credentials for different clients).
There are numerous platforms that offer managed cloud MQTT broker, such as HiveMQ, EMQX, CloudMQTT, etc. This episode focuses on migrating from GUI-O broker to HiveMQ broker using ESP32 board.
Software prerequisites:
-
Arduino IDE (https://www.arduino.cc/en/software)
-
ESP32 Arduino board support (see https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html)
-
Arduino Client for MQTT(https://github.com/knolleary/pubsubclient)
You can follow the setup instructions or directly download and include the PubSubClient.zip library within the Arduino IDE (Sketch -> Include Library -> Add .ZIP library) -
GUI-O application (https://play.google.com/store/apps/details?id=com.guio.guioapp)
Components needed:
- ESP32-WROOM-32 (or any other Arduino supported WiFi capable board; see https://github.com/knolleary/pubsubclient#compatible-hardware for compatible hardware)
The entire tutorial is split into various steps. All necessary information is given in each step.
1. SETUP HIVEMQ
-
Navigate to https://www.hivemq.com/downloads/ and signup to (free) HiveMQ cloud plan
-
Login to HiveMQ cloud console and navigate to "Clusters"
-
Create a new cluster selecting any cloud service provider
-
Select "MANAGE CLUSTER" (NOTE: The "Cluster URL" is required later)
-
Select "ACCESS MANAGEMENT" tab and add new credentials (at least one)
All steps are shown in the video below.
2. SETUP GUI-O FOR HIVEMQ
-
Open GUI-O application, open settings and navigate to "Connections -> IoT -> IoT Settings"
-
Set the "Server name" using the HiveMQ "Cluster URL" (see 1. SETUP HIVEMQ).
-
Set the "SSL port number" to 8883
-
Set the "User name" and "User password" based on the HiveMQ credentials (see 1. SETUP HIVEMQ)
-
Navigate to "Connections -> IoT" and press "Connect" to test the connection
All steps are shown in the video below.
3. SETUP ESP32 FOR HIVEMQ
-
Download BasicMQTT_HiveMQ.ino sketch and open it in Arduino IDE
-
Get the certificate of your HiveMQ broker (see video below)
- On Linux, open the terminal and enter command:
openssl s_client -connect <hivemq_url>:8883 -showcerts
replacing the <hivemq_url> with the "Cluster URL" (see 1. SETUP HIVEMQ)
-
You can alternatively use an online Linux terminal (e.g., https://www.tutorialspoint.com/linux_terminal_online.php) to execute the same command
-
After running the command, copy the last certificate displayed in the terminal and replace the one in the downloaded Arduino sketch (keep same certificate formatting)
-
Use the downloaded Arduino sketch (i.e., BasicMQTT_HiveMQ.ino) while referring to the video below. Make sure that the server url, user name and password are set according to HIVEMQ setup (see 1. SETUP HIVEMQ)
If you have any questions or run into any problems, please let me know!
Best regards,
kl3m3n -