• 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

MQTT Mosquitto – RaspberryPi4 – ESP32 / ERROR : MQTTClient is not definied / Module5 – 5.3 – Programming MicroPython Course

Q&A Forum › Category: ESP32 › MQTT Mosquitto – RaspberryPi4 – ESP32 / ERROR : MQTTClient is not definied / Module5 – 5.3 – Programming MicroPython Course
0 Vote Up Vote Down
ANTONELLI Luc asked 9 months ago

Hello,
I come back to you after many hours to search a solution… (i’m biguiner in MQTT and microphyton)…
I’m following your “MicroPython_Programming_with_ESP32_and_ESP8266_V2” Courses -> MODULE 5 – MQTT Protocol -> 5.3 – MQTT – Establishing a Two-way Communication…
When i arrive to Page 271, after the configuration of ESP#1 (with umqttsimple.py + boot.py + main.py) The following message appear when i launch the main.py :

>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
File “<stdin>”, line 25, in <module>
File “<stdin>”, line 10, in connect_and_subscribe
NameError: name ‘MQTTClient’ isn’t defined

I don’t understand why MQTTClient is not defined….?!
And finaly, when i push the “enable” buton of ESP#1, the following message appear :

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:4728
load:0x40078000,len:14888
load:0x40080400,len:3368
entry 0x400805cc
Connection successful
(‘192.168.1.97’, ‘255.255.255.0’, ‘192.168.1.254’, ‘192.168.1.254’)
Failed to connect to MQTT broker. Reconnecting…

Please could you help me to resolve it ?

6 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 9 months ago

Hi.
Did you insert your MQTT credentials?
Try copying the code in boot.py to the beginning of the main.py.
Let me know if that fixes the issue.
Regards,
Sara

0 Vote Up Vote Down
ANTONELLI Luc answered 9 months ago

Hello Sara,
Thank you for your initial response.
After copying the boot.py code at the beginning of the main.py code, and after executing the main.py code, the error: MQTTClient isn’t defined no longer appears. Which is better!
However, the connection with the MQTT broker still doesn’t work… here’s the message in the shell after executing the main.py code (or after pressing the enable button on the card):
’
Connection successful
(‘192.168.1.97’, ‘255.255.255.0’, ‘192.168.1.254’, ‘192.168.1.254’)
Failed to connect to MQTT broker. Reconnecting...
’

0 Vote Up Vote Down
ANTONELLI Luc answered 9 months ago

Well; i have purged mosquitto and reload it in the RPi, (i just changed the password by  letters instead of digit, by the way…) and now connexion to the MQTT broker is OK ! So system is running !

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

That’s great.
I’m glad everything is working as expected now.
I’ll mark this issue as resolved. If you need further help, you just need to open a new question in our forum.
Regards,
Sara

0 Vote Up Vote Down
Meelis Kalder answered 6 months ago

Hi!
I have the same problem. I use Raspberry Pi 5, ESP32 and Thonny. I’ve put mosquitto on and off many times, changed passwords and conf file, nothing helps, the message below is still: Connection successful … Failed to connect to MQTT broker. Reconnecting…

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

This was already solved: https://rntlab.com/question/micropython-programming-with-esp32-and-esp8266-module-5-mqtt-protocol/#answer-134228
 

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.