ESP8266 and MQTT Problems

Hello, I am using an ESP8266 Wi-Fi module connected to my STM32 Microcontroller. I use a Raspberry Pi 5, which is running Home Assistant and an MQTT broker (Mosquitto). I use Zigbee2MQTT to connect my Zigbee devices to the broker.

I am currently having issues connecting my ESP8266 to the broker using the AT+MQTTCONN command—the response I get back is “ERROR.” I am programming in STM32CubeIDE, and here are the steps I have taken so far:

  • Verified that my ESP8266 is connected to my home network.
  • Successfully pinged Home Assistant from the ESP8266.
  • Used MQTT Explorer on my desktop to connect to Home Assistant by entering its IPv4 address and port 1886, and it connects successfully.
  • Checked the Mosquitto broker logs and do not see any connection attempt from my ESP8266’s IPv4 address, but I do see my desktop’s successful connection to the broker.

Despite these checks, my ESP8266 still fails to connect to the broker. Any ideas on what might be causing this issue? Thank You!

USART1_SendString(“AT\r\n”);
RESPONSE(“OK”)

USART1_SendString(“AT+CWMODE=1\r\n”);
RESPONSE(“OK”)

USART1_SendString(“AT+CWJAP="WifiUsername","WifiPWD"\r\n”);
RESPONSE(“WIFI DISCONNECT, WIFI CONNECTED, WIFI GOT IP, OK”

USART1_SendString(“AT+PING="HomeAssistantIP"\r\n”);
RESPONSE(“+PING:4 OK”)

USART1_SendString(“AT+MQTTUSERCFG=0,1,"mqtt","brokername","brokerpassword",0,0,""\r\n”);
RESPONSE(“OK”)
USART1_SendString(“AT+MQTTCONN=0,"HomeAssistantIP","1883",1\r\n”;
RESPONSE(“Error”)

Here is also my YAML config file for my MQTT Broker(Mosquitto):
logins:

  • username: brokername
    password: brokerpassword
    require_certificate: false
    certfile: fullchain.pem
    keyfile: privkey.pem
    customize:
    active: false
    folder: mosquitto