Enable MQTT discovery (Industrial ESP32 IoT Controller)

In this tutorial, we will guide you through the process of enabling MQTT discovery for your EQSP32 industrial ESP32 IoT controller.

We will also show you how to add an MQTT broker (e.g. Mosquitto MQTT) in your Home Assistant setup. Once Home Assistant (HA) is running with an MQTT broker installed, your device should appear even with basic initialization.

Before we begin, make sure you have completed the quickstart guide to set up your Arduino IDE environment. When the EQSP32 library runs on your IoT controller, it will be discoverable by the EQConnect mobile configuration utility. Using the EQConnect app, you can set up the Wi-Fi network and password, enable MQTT device discovery, and set up the broker username and password.

Prerequisites

Before we begin, ensure you have the following:

How to install MQTT broker in Home Assistant (HA)

Follow these steps to install the Mosquitto MQTT broker in Home Assistant. This setup will allow your EQSP32 device to communicate with Home Assistant via MQTT.

Step 1: Open Home Assistant Settings

  • Open Home Assistant and navigate to the Settings menu.
  • Click on Add-ons.
Home Assistant instruction for adding Mosquitto broker (MQTT broker). Navigate to Settings, then Add-ons.

Step 2: Add the MQTT Broker

  • Click on the Add-on Store button at the bottom right corner.
  • In the Add-on Store, search for “MQTT” and select Mosquitto broker.
Home Assistant instruction for adding Mosquitto broker (MQTT broker). Search MQTT and then select Mosquitto broker.
  • Click on the Install button to install the Mosquitto MQTT broker.
Home Assistant instruction for adding Mosquitto broker (MQTT broker). Install Mosquitto broker.

Step 3: Configure and Start the MQTT Broker

  • After installation, the Mosquitto broker settings should be Start on boot enabled, Watchdog disabled and Auto update disabled.
  • Click on the Start button to start the Mosquitto broker.
Home Assistant instruction for adding Mosquitto broker (MQTT broker). Start Mosquitto broker.

Step 4: Connect Home Assistant to the MQTT Broker

  • Navigate again to the Settings menu and now go to Devices & Services.
Home Assistant instruction for adding Mosquitto broker (MQTT broker). Settings then devices to access or configure your MQTT integration.
  • In Discovered section you should see the MQTT service.
Home Assistant instruction for adding Mosquitto broker (MQTT broker). MQTT integration discovered and ready to be configured.
  • Click on Configure, then Submit and finally Finish.
Home Assistant instruction for adding Mosquitto broker (MQTT broker). Allow MQTT broker to connect with Home Assistant (HA).
  • You are done!
Home Assistant instruction for adding Mosquitto broker (MQTT broker). Connecting Home Assistant (HA) with MQTT broker is successful.

Now your MQTT broker is installed and running in Home Assistant. You can proceed with setting up your EQSP32 device to communicate with Home Assistant using MQTT.

Upload a simple program to EQSP32

To enable your EQSP32 device to communicate with Home Assistant, we need to upload a program that at least initializes the device and sets up the system ID.

Once the device is initialized with the EQSP32 library, it will become available to EQConnect mobile configuration utility. From our mobile app, we can enable MQTT device discovery and configure the broker’s credentials.

#include <EQSP32.h>

EQSP32 eqsp32;

void setup() {
    EQSP32Configs configs;
    configs.devSystemID = "MySystemID";  // Replace with your actual system ID

    eqsp32.begin(configs, true);  // Initialize with verbose mode for debugging
}

void loop() {
    delay(1000);  // Ensure a small delay for non-blocking operation
}

Enable MQTT device discovery via EQConnect

Now that we have initialized the EQSP32 device, the next step is to enable MQTT device discovery using the EQConnect app.

Step 1: Connect to EQSP32 via Bluetooth

  • Launch the EQConnect app on your device.
  • Ensure EQSP32’s Bluetooth LED is blinking. If not, shortly press the Boot button.
  • Ensure the device is within range.
  • EQConnect will then automatically connect to your EQSP32.
EQConnect mobile application utility. Bluetooth connection success page.

Step 2: Set Up Wi-Fi Connection

Before enabling MQTT discovery, we first need to allow EQSP32 access to the same network with our Home Assistant (HA).

  • Tap on the Wi-Fi icon at the top of the screen.
EQConnect mobile application utility. Before configuring MQTT device discovery for Home Assistant. we need to connect EQSP32 - ESP32 PLC to the same network with our Home Assistant (HA)
  • Select your Wi-Fi network from the list.
  • Enter the Wi-Fi password and tap on Connect.
EQConnect mobile application utility. Before configuring MQTT device discovery for Home Assistant. we need to connect EQSP32 - ESP32 PLC to the same network with our Home Assistant (HA). Select network, add password and connect.

Step 3: Enable MQTT Device Discovery

  • Go back to connection screen.
  • Setup the preferred device name. This is the name your EQSP32 device will have in Home Assistant.
  • Tap on the advanced settings icon (gear icon) next to the device name.
EQConnect mobile application utility. Configuring MQTT device discovery for Home Assistant. Configure EQSP32 - ESP32 PLC device name for Home Assistant (HA).
  • Check the MQTT Device Discovery box.
EQConnect mobile application utility. Configuring MQTT device discovery for Home Assistant. Enable IoT controller's MQTT device discovery option for EQSP32 - ESP32 PLC. Home Assistant (HA) will automatically discover EQSP32.
  • Enter the username and password for your Home Assistant MQTT broker.
    By default these are going to be the same as your Home Assistant username and password.
EQConnect mobile application utility. Configuring MQTT device discovery for Home Assistant. Setup MQTT broker's credentials for MQTT device discovery. EQSP32 - ESP32 PLC will connect automatically to Home Assistant (HA) after reset.
  • Tap on Update to save the settings.
    The settings are now saved but will only be applied after reboot.
  • If you are done configuring EQSP32, tap on Reset & Apply to restart the EQSP32 device and apply the new MQTT settings.

Monitor EQSP32 in Home Assistant (HA)

We have successfully enabled MQTT device discovery for the EQSP32 device using the EQConnect app. If Home Assistant is online and the MQTT broker is running, we will be able to see EQSP32 as an MQTT device.

Even though we have not created any interfacing entities for Home Assistant, EQSP32 will publish its system parameters automatically. We can now monitor the Input & Output supply voltages and WiFi signal strength.

Monitoring EQSP32’s system parameters

  • Go to Settings and click on Devices & Services.
Home Assistant instruction for adding Mosquitto broker (MQTT broker). Settings then devices to access or configure your MQTT integration.
  • Under the configured integrations, find and click on Device under MQTT.
EQSP32 - Din rail mount industrial IoT controller - ESP32 PLC discovered as an MQTT device.
Home assistant (HA) automatically discovers EQSP32 device and its system parameters.
  • You should see your EQSP32 device with 3 entities, Input Voltage, Output Voltage and Signal Strength.
Monitoring EQSP32 - Din rail mount industrial IoT controller - ESP32 PLC.
Monitor EQSP32 in Home assistant (HA). Using MQTT protocol EQSP32 automatically publishes input voltage, output voltage and wifi signal strength. Device name, model and firmware version are also available in the discovery.

Now our device is discoverable in Home Assistant and we have monitoring access to its system parameters.

In our next tutorial, we will demonstrate how to create interfaces to monitor ADIO pins, custom sensors and send control commands via Home Assistant (HA). This setup creates a powerful and flexible automation system for iot applications.

For more technical information regarding EQSP32, check out EQSP32 datasheet.

Add a Comment

Your email address will not be published. Required fields are marked *