• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Cannot connect to MQTT with ESP32

Q&A Forum › Category: ESP32 › Cannot connect to MQTT with ESP32
0 Vote Up Vote Down
Don Black asked 12 months ago

I have been going through the Smart Home Raspberry Pi book and have gone through all modules successfully up to module 5.  Here, I am using a NodeMCU ESP32S and I copied the example code provided in the book for the ESP32.  I modified the locations with my SSID, Password, Broker User Name and Password.  When I try to run this code, I successfully connect to WiFi, but I cannot connect to the MQTT.  Here is my result on the monitor:
mode:DIO,���div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13232
load:0x40080400,len:3028
entry 0x400805e4

Connecting to Wi-Fi…
[WiFi-event] event: 0
[WiFi-event] event: 2
[WiFi-event] event: 4
[WiFi-event] event: 7
WiFi connected
IP address:
192.168.86.37
Connecting to MQTT…
Publishing on topic counter at QoS 1, packetId: 0
Publishing on topic counter at QoS 1, packetId: 0
Disconnected from MQTT.
Connecting to MQTT…
Publishing on topic counter at QoS 1, packetId: 0
Publishing on topic counter at QoS 1, packetId: 0
Disconnected from MQTT.
Connecting to MQTT…
Publishing on topic counter at QoS 1, packetId: 0
Publishing on topic counter at QoS 1, packetId: 0
Disconnected from MQTT.
Connecting to MQTT…
Publishing on topic counter at QoS 1, packetId: 0
Publishing on topic counter at QoS 1, packetId: 0
Disconnected from MQTT.
As I said, up to this point I have had no issues — I installed Node-Red and was able to control the GPIO on the RPi5. Next, I installed Mosquitto Broker, sent the “Hello World” message to testTopic, and then enabled remote access/authentication.  All of this worked fine with the username and password.  Then, using MQTT with Node-Red also controlled an LED on the RPi GPIO.  
As can be seen from the output, I never get a message indicating that MQTT is connected.  I never get to this function:

void onMqttConnect(bool sessionPresent) {
Serial.println(“Connected to MQTT.”);
Serial.print(“Session present: “);
Serial.println(sessionPresent);

 
I have double checked the mosquitto.conf file for correctness and verified that it is at /etc/mosquitto/.  
 
Differences from your book:  a) I am using Platformio  b) I am using a RPi5.
 
Any suggestion for me to try would be greatly appreciated.
 
Thanks

2 Answers
0 Vote Up Vote Down
Don Black answered 12 months ago

I just installed the Arduino IDE, and everything works fine using it, so I think this issue is more appropriate for the Platformio community.  
Thanks.

0 Vote Up Vote Down
Sara Santos Staff answered 12 months ago

Hi.
Yes. Maybe something wrong with the PaltformIO configurations…? Or the way you’re loading the library?
 
I haven’t tested this using PlatformIO.
 
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.