Problem connecting to MQTT broker

RouseA
Posts: 3
Joined: Tue Oct 08, 2024 2:01 pm

Problem connecting to MQTT broker

Postby RouseA » Tue Oct 08, 2024 2:08 pm

I’m new to MQTT so forgive my ignorance. I have designed a simple interface board around an ESP32-C3-WROOM module, which I have loaded with ESP-AT firmware. The ESP-AT documentation explains all the allowable commands, but in general terms. I cannot manage to access a broker.

I have installed HiveMQ on a laptop and the log shows that it has loaded correctly and started. I can then access it through the HiveMQ dashboard. However, I can’t communicate with it from the ESP32. This is the sequence of commands I’m using:

Code: Select all

    WIFI CONNECTED
    WIFI GOT IP
    AT+CWMODE=1

    OK
    AT+CWLAPOPT=1,31

    OK
    AT+CWJAP=“Virgin2.4”,“Wjsh318263”
    WIFI DISCONNECT
    WIFI CONNECTED
    WIFI GOT IP

    OK
    AT+CIPSNTPCFG=1,0,“0.uk.pool.ntp.org”,“1.uk.pool.ntp.org”,“2.uk.pool.ntp.org”

    OK
    +TIME_UPDATED
    AT+MQTTUSERCFG=0,5,“esp32”,“espressif”,“1234567890”,0,0,“mqtt”

    OK
    AT+CIPSTA?
    +CIPSTA:ip:“192.168.0.136”
    +CIPSTA:gateway:“192.168.0.1”
    +CIPSTA:netmask:“255.255.255.0”

    OK
The next step should be to connect, so I need an IP address or a web address. I’m trying initially to access the local HiveMQ broker. However, I tried looking at the router and it doesn’t show HiveMQ as a connected device, so I can’t see an IP address there. I have tried various combinations without success:

Code: Select all

    OK
    AT+MQTTCONN=0,“0.0.0.0”,1883,1
    +MQTTDISCONNECTED:0

    ERROR
    AT+MQTTCONN=0,“192.168.3.102”,8883,1
    +MQTTDISCONNECTED:0

    ERROR
    AT+MQTTCONN=0,“192.168.188.20”,1883,0
    +MQTTDISCONNECTED:0

    ERROR
When I succeed in accessing the local broker my next step would be to access a cloud broker. I want to use encryption but can’t find a means to do that other than hard-programming an encryption code into each ESP32 module. Does anyone have any guidance?

esp-at
Posts: 200
Joined: Mon May 09, 2022 3:00 am

Re: Problem connecting to MQTT broker

Postby esp-at » Wed Oct 09, 2024 11:54 am

maybe you can read following examples first:
- https://docs.espressif.com/projects/esp ... mples.html
- https://docs.espressif.com/projects/esp ... cloud.html

You can use the MQTT broker under https://test.mosquitto.org/ webpage as a test.

RouseA
Posts: 3
Joined: Tue Oct 08, 2024 2:01 pm

Re: Problem connecting to MQTT broker

Postby RouseA » Wed Oct 09, 2024 1:45 pm

Thanks, but these were the examples I was using:

- https://docs.espressif.com/projects/esp ... mples.html
This gives examples using TCP, TLS and WSS. WHich is appropriate for a local MQTT broker? It gives sample code over TCP using
AT+MQTTCONN=0,"192.168.3.102",8883,1
I don't know where the IP address 192.168.3.102 comes from, and it doesn't work in my case. I've tried numerous alternatives without success.

- https://docs.espressif.com/projects/esp ... cloud.html
This expects the certificates and keys to be downloaded from AWS and hard-coded into the ESP32 so a device is fixed to a defined broker. I would like to have standard ESP-AT code so devices could be supplied off the shelf and configured by customers. I think this should be possible since other systems don't require anything to be downloaded. For example, WhatsApp uses encryption, but doesn't require th user to download anything first.

esp-at
Posts: 200
Joined: Mon May 09, 2022 3:00 am

Re: Problem connecting to MQTT broker

Postby esp-at » Sat Oct 12, 2024 3:45 am

You should start a MQTT broker firstly, the ip address and port is that your MQTT broker listen to.

you can use AT+SYSMFG command to update certificate and key.

Who is online

Users browsing this forum: No registered users and 33 guests