MQTT on CentOS Stream 10 Configuration - Part 02

by AmruthKumarSala in Teachers > University+

29 Views, 0 Favorites, 0 Comments

MQTT on CentOS Stream 10 Configuration - Part 02

CoverImage.png

This is the continuation of the first article. In this article, we will understand suitable changes to the machine to install and configure MQTT.

Supplies

pngimg.com - laptop_PNG101835.png
VMware_Workstation_11.0_icon.png

We will make use of the same laptop/PC that is installed with CentOS Stream 10 OS.

Prerequisites - Configuration Changes to CentOS Stream 10

001-FirstBootWithIpv6MldQrvError.png
002-CheckingNetworkConnections.png
003-PermanentSolutionToIpv6MldQrvError.png
004-ConfigurationChangesAPermanentSolutionToIpv6MldQrvError.png
SuppressIPV6MLDQRVMessage.png
005-ConfigurationChangesToDisableAutoConfigurationOfENS32NetworkInterfaceFetchingIPV6AndIPV4Address.png
006-MessagesThatCanBeIgnoredForNow.png
007-ConfigurationChangesToSysctl.confMayNotWork.png
008-ExecutionOfCommandsToConfigureStaticIPAddressAndChangeTheInterfacesToBeManuallyConfigured.png
009-ObserveChanges.png
010-ObservationsAfterReboot.png
WhereDidIGetIPV6Address-01.png
WereDidIGetIPV6Address-02.png

Readers of this article are suggested to complete the following before starting the activities mentioned in these articles:

  1. https://www.instructables.com/Flashing-ESP32-With-Tasmota/
  2. https://www.instructables.com/Smart-Energy-Meter-Using-ESP32-PZEM004T-V30-Config/
  3. https://www.instructables.com/MQTT-on-CentOS-10-Stream-Installation-Part-01/

The first four screenshots will be important to suppress the error "IPV6: MLD: clamping QRV from 1 to 2!", and provide a permanent solution by editing the "/etc/sysctl.d/99-sysctl.conf" file. Towards the end of the file entering "net.ipv6.mld_qrv=1" will suppress the error on machine reboot.

All the servers in the office network are configured with Static IP addresses. By default, "CentOS Stream 10" provides auto-configuration of network adapter "ens32" and fetches IPV4 and IPV6 addresses from office/home DHCP servers. Disabling the Autoconf is done by mentioning "net.ipv4.conf.ens32.autoconf=0" and "net.ipv6.conf.ens32.autoconf=0" in "/etc/sysctl.d/99-sysctl.conf" file. This configuration to disable Autoconf is optional.

Reboot the machine after you are done with the above configuration changes.

For now, please ignore messages on reboot (Screenshot 06). We will handle them later in our articles. When you execute the command "cat /etc/NetworkManager/system-connections/ens32," you may be under the impression that the suggested changes did not affect the configuration changes (Screenshot 07).

Please do not get dejected, you may execute the following commands to set static IP addresses to the adaptor and set it to "manual" mode (Screenshot 08):

  1. "nmcli connection modify ens32 ipv4.address 192.168.29.150/24 ipv4.gateway 192.168.29.1"
  2. "nmcli connection modify ens32 ipv6.address 2405:201:c00f:f02a:20c:29ff:fe91:968e/64"
  3. "nmcli connection modify ens32 ipv4.method manual "
  4. "nmcli connection modify ens32 ipv6.method manual "

Commands mentioned in steps 1 & 3 are mandatory if you want to set IP Address Static and convert the adaptor from Autoconf to Manual mode. Please configure the IP address, subnet mask, and gateway to match your office/home network.

Commands mentioned in Steps 2 & 4 are optional.

Observe changes by executing "cat /etc/NetworkManager/system-connections/ens32.nmconnection" (Screenshot 09). It is better to reboot and recheck if the configuration changes remain unaltered.

Observe changes remain after the machine reboot (Screenshot 10).

Prerequisite Packages Installation for Mosquitto

011-CheckInternetConnectivityUsingPingCommand.png
012-TimeDateCTL.png
013-YumInstallEpelRelease.png
MQTTOnCentOSStream10-V3-2025-02-26-19-19-08.png
MQTTOnCentOSStream10-V3-2025-02-26-19-25-21.png
MQTTOnCentOSStream10-V3-2025-02-26-19-30-16.png

The first step before we install MQTT is to check Internet Connectivity with the "ping google.com" command.

Note: The command "ping google.com" will continue its output unless you press "CTRL + C". The command "ping google.com -c4" will continue its output four times. It is your choice to use either option (Screenshot 11).

Please also check the timezone with the "timedatectl" command (Screenshot 12). Note that the data received from the smart device to MQTT should match, avoiding any confusion.

Continue with the following steps:

  1. We can now download PuTTY from here. Downloading PuTTY and accessing the machine is optional. You may proceed if you are comfortable continuing with the CentOS Stream 10 console.
  2. Access the CentOS Stream 10 machine using PuTTY.
  3. Execute "yum install epel-release -y" (Screenshot 13)
  4. Execute "yum install wget -y"
  5. Execute "yum update -y". Please note this step may take some time to complete. Please allow the machine sufficient time. Around 80 packages get updated and installed.
  6. The last screenshot shows you the successful completion of "yum update -y"

Downloading and Installing Mosquitto Broker

MQTTOnCentOSStream10-V3-2025-02-26-19-37-15.png
MQTTOnCentOSStream10-V3-2025-02-26-19-43-57.png
MQTTOnCentOSStream10-V3-2025-02-26-19-48-22.png
MQTTOnCentOSStream10-V3-2025-02-26-19-51-41.png
MQTTOnCentOSStream10-V3-2025-02-26-19-52-34.png

A brief Introduction: A Mosquitto broker is an open-source message broker that implements the MQTT (Message Queuing Telemetry Transport) protocol, essentially acting as a central hub for devices to publish and subscribe to messages, making it particularly useful for Internet of Things (IoT) applications where devices with limited bandwidth need to communicate efficiently; it's known for being lightweight and suitable for low-power devices like single-board computers and microcontrollers

The following steps will explain the Downloading and Installing of "mosquitto broker"

  1. Execute "wget https://mosquitto.org/files/source/mosquitto-2.0.20.tar.gz" - This will download the file required to install mosquitto broker on CentOS Stream 10 VM.
  2. Execute "tar -xzvf mosquitto-2.0.20.tar.gz" - This will create a folder/directory "mosquitto-2.0.20". Navigate to the directory by executing "cd mosquitto-2.0.20".
  3. Execute "dnf install c-ares* cjson* libwebsockets* openssl* uthash* qt6-qtmqtt.x86_64 qt6-qtmqtt-devel.x86_64 -y --skip-broken" to install supporting packages for mosquitto broker to get installed. This will install around 180 packages. Please allow your machine some time to complete the execution of this command.
  4. Execute "make" and "make install". This completes the installation of the mosquitto broker on CentOS Stream 10.

Configuration of Mosquitto Broker & Starting It

MQTTOnCentOSStream10-V3-2025-02-26-19-59-37.png
MQTTOnCentOSStream10-V3-2025-02-26-20-03-54.png
MQTTOnCentOSStream10-V3-2025-02-26-20-04-56.png
MQTTOnCentOSStream10-V3-2025-02-26-20-13-52.png
MQTTOnCentOSStream10-V3-2025-02-26-20-21-01.png

Before we start the mosquitto broker there are a few configuration steps, we need to take care of.

  1. Create two users "mosquitto" and "ognngo". While mosquitto is mandatory, please choose a different name for the other user. I considered naming it ognngo. You can choose to name that suits your environment. You may configure a stronger password for both users to suppress the message: "The password fails the dictionary check - it is too simplistic/systematic".
  2. Execute "mosquitto_passwd -c /etc/mosquitto/passwd ognngo"
  3. Create a file mosquitto.conf by executing "vi /etc/mosquitto/mosquitto.conf" and enter the following text (configuration parameters) in it.
  4. allow_anonymous true
  5. allow_zero_length_clientid true
  6. password_file /etc/mosquitto/passwd
  7. max_qos 2
  8. max_queued_messages 1000
  9. queue_qos0_messages true
  10. sys_interval 10
  11. upgrade_outgoing_qos true
  12. user mosquitto
  13. listener 1883
  14. socket_domain ipv4
  15. bind_interface ens32
  16. max_connections -1
  17. protocol mqtt
  18. Execute "mosquitto -c /etc/mosquitto/mosquitto.conf". This should help you execute the mosquitto broker with the error "unable to open passwd file. The error indicates that the user "mosquitto" is not having sufficient privileges to access the file.
  19. Execute "chown mosquitto /etc/mosquitto/mosquitto.conf" and "chgrp mosquitto /etc/mosquitto/mosquitto.conf" to address the issue.
  20. Execute "mosquitto -c /etc/mosquitto/mosquitto.conf" successfully and make the machine available for all your IIoT devices to post data over the intranet/intranet for further analysis.

Note: You don't need to have all the parameters configured as mentioned in this article. I have pasted what I have on my machine.

Final Check With MQTT Explorer

MQTT Explorer - 01.png
MQTT Explorer - 02.png
MQTTOnCentOSStream10-V3-2025-02-26-20-46-52.png
MQTTOnCentOSStream10-V3-2025-02-26-20-46-52.png
MQTTOnCentOSStream10-V3-2025-02-26-20-52-27.png
MQTTOnCentOSStream10-V3-2025-02-26-20-54-01.png
MQTT Explorer - 03.png
  1. Download MQTT Explorer from here and install it.
  2. Provide details as follows
  3. Protocol: mqtt
  4. host: 192.168.29.150 (in my case)
  5. port: 1883
  6. username: ognngo (in my case)
  7. password: abcd1234 (Suggested to have a strong password).
  8. Now hit on "Save" and then "Connect". You may face an error "connect ETIMEDOUT 192.168.29.150:1883". To address the issue, please proceed as follows and modify firewall settings.
  9. Navigate to CentOS Stream 10 console and press "CTRL + C" to stop the mosquitto broker.
  10. Execute the following:
  11. firewall-cmd --permanent --zone=public --add-port=1883/tcp
  12. firewall-cmd --permanent --zone=public --add-service=mqtt
  13. firewall-cmd --reload
  14. Execute "mosquitto -c /etc/mosquitto/mosquitto.conf" from CentOS Stream 10 console.
  15. Now open MQTT Explorer and hit "Connect" to successfully connect to the "mosquitto broker".

With this, we complete testing our "mosquitto broker"

Connecting & Testing Smart Energy Monitoring IIoT Device

Tasmota-001.png
Tasmota-002.png
Tasmota-003.png
Tasmota-004.png
Tasmota-005.png
Tasmota-006.png
Tasmota-007.png
Tasmota-008.png
Tasmota-009.png
Tasmota-010.png

To connect and test the smart energy monitoring device, I have accessed the web page of my microcontroller with tasmota installed on it.

Readers are requested to go through the screenshots to understand the process step-by-step

  1. Access the IP address from Internet Explorer (192.168.29.195 is the IP address assigned to the microcontroller in my case). Select "Configuration"
  2. Select "MQTT"
  3. Fill details: Host: 192.168.29.150; Port: 1883; User: ognngo; and Password: abcd1234. Hit on "Save" and move to "Configuration"
  4. Select "Main Menu"
  5. Select "Tools"
  6. Select "Console" to see the data getting posted to our mosquitto broker.
  7. Navigate to "MQTT Explorer" to see the data getting captured and represented graphically.

This completes our article. I hope you will like it. I will be uploading a complete video on my YouTube channel.

Post Your Questions on WhatsApp/Email

For any questions please feel free to WhatsApp me at +91 9398472594 (or) email me at yugendravenkata@gmail.com

Refer to this YouTube Video for further help.