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 ?
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
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...
’
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 !
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
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…