• 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 Authentication enabled: Micropython Code

Q&A Forum › Category: ESP8266 › MQTT Authentication enabled: Micropython Code
0 Vote Up Vote Down
Jose Ayala Villareal asked 2 years ago

Hello,
following your lessons in the ebook “MicroPython Programming with ESP32 and ESP8266”, in the chapter MQTT – Establishing a Two-way Communication you present code for a MQTT broker without authentication (no username, no password). Could you please provide a code snippet for the case with authentication? I tried it by myself but my python skills are not good enough. I didn’t find the place where to insert the information.
Thanks in advance!

Question Tags: MQTT Broker Authentication
5 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Hi.
When initializing an MQTT client, instead of:

  client = MQTTClient(client_id, mqtt_server)

You use:

  client = MQTTClient(client_id, mqtt_server, user=YOUR_USERNAME, password=YOUR_PASSWORD)

replace with your username and password. For example:

  client = MQTTClient(client_id, mqtt_server, user="sara", password="12345")

Let me know if this works.
Regards,
Sara

0 Vote Up Vote Down
Jose Ayala Villareal answered 2 years ago

Hello Sara,
thank you very much for your prompt answer.
Btw: I tried the scripts (without authentication) for ESP #1 importing from umqtt.simple (the built in module included in micropython) instead of using umqttsimple.py and it worked!. Just for your information.
Regards.

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Ok.
Thanks for letting me know.
 
Tell me if you need help with anything else.
Regards,
Sara

0 Vote Up Vote Down
Jose Ayala Villareal answered 2 years ago

Hello Sara,

the statement with credentials (user, password) for the MQTT broker works, thanks again.

Regards.

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Great.
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

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

  • [eBook Updated] Learn LVGL: Build GUIs for ESP32 Projects – Version 1.5 July 7, 2025
  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 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.