In this tutorial, we will check how to connect the UART OBLOQ to a MQTT broker. As a broker, we will use CloudMQTT, which allows to create a free account for testing.
We will be using a serial to USB converter to connect the UART OBLOQ to a computer, so we can send all the commands needed without the need to write code. Please check this previous post for the connection diagram.
We will use the Arduino IDE serial monitor to connect to the device and send the commands. Nonetheless, you may test with other serial software of you choice.
As mentioned, we will use CloudMQTT as MQTT broker. Cloud MQTT is a cloud based broker for the Internet of Things . You can sign up with a free testing account, as can be seen here in the pricing plans.
After signing up, we need to setup a broker instance, so later we can connect to it. You can check all the steps to setup a broker instance on this guide provided by CloudMQTT. Setting up a broker instance is really simple and achieved with a couple of clicks.
After setting up the instance, simply click on it to access the details page. There, you will need 4 parameters:
You can check at figure 1 where these parameters are located in the details page of the instance.
Figure 1 – Broker instance details.
We will need the 4 mentioned parameters later, when sending the command to the OBLOQ to connect to the MQTT broker.
In order to be able to connect to a MQTT broker, we will first need to connect the OBLOQ to a WiFi network. The procedure was covered in detail on this previous tutorial.
Basically, we need to send the following command, which includes the credentials of the WiFi network:
Upon sending the command, the OBLOQ will start connecting to the WiFi network. During the procedure, it will periodically print |2|2|, which allows us to know that it is still trying to connect.
After the connection is successfully established, then it will print an IP address, which corresponds to the IP assigned to the OBLOQ on the network. You can check the result of the command in figure 2.
Figure 2 – Connection of the OBLOQ to the WiFi network.
Now that the device is connect to the WiFi network, we can connect it to the MQTT broker. To do it, we need to send the command shown below, where we need to change the parameters indicated by the ones from the CloudMQTT details page:
Upon sending the command, the OBLOQ should connect to the broker and return a |4|1|1|1| to the serial monitor, indicating success, as shown in figure 2.
Figure 2 – Connecting the OBLOQ to the MQTT broker.
After this, the OBLOQ should now be connected to the broker. You can confirm this by going to the “Connections” tab of the CloudMQTT broker instance. As indicated in figure 3, a connection should be listed.
Figure 3 – OBLOQ connection listed in the MQTT broker instance connections.
Note that the IP that will listed there is not the IP assigned to the device after the connection to the WiFi network, since that is the private IP of the OBLOQ in the local network. Here, in the list of connections, what will appear is the public IP address of the router that is hosting that WiFi network.
UART OBLOQ module Tutorials: