• 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

Module 7 EPS32 MQTT – Unit3 MQTT Project – MQTT Client ESP32 #1

Q&A Forum › Category: ESP32 › Module 7 EPS32 MQTT – Unit3 MQTT Project – MQTT Client ESP32 #1
0 Vote Up Vote Down
Remi GAROT asked 4 years ago

Hello everybody,
inside the Unit3 MQTT Project – MQTT Client ESP32 #1:
There is one snipet I don’t understand in the code: more specifically I would say that something is missing: Rui says that the following snipet checks if a new message was published on the esp32/led topic:

if (strcmp(topic, "esp32/led") == 0) {

As for me:

  • this line only browses the different topics and executes the code inside the “if” brackets when the browsing of the topics reaches “esp32/led”.
  • In this code, we do not test if a change has occured in the topic. Can someone tell me more about this “if” statement and how do we test if a change has occured in the topic?

Thank you in advance 🙂
Rémi
 

Question Tags: Module 7 Client ESP32 MQTT
5 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi Remi.
 
Probably the explanation is not very clear.
 
And yes, you are right. The snippet doesn’t check if a new message was received. It just checks if the message was received on that specific topic.
 
When a new message is received on a specific topic (it doesn’t matter which topic), the onMqttMessage() function runs. And inside that function, we check if the topic is the topic that we are interested in— in this case, we are interested in the “esp32/led” topic.
 
The topic we are receiving messages from is saved on the topic variable, and the message received is saved on the messageTemp variable.
 
I hope this is clear.
Let me know if you need further help.
 
Regards,
Sara

0 Vote Up Vote Down
Remi GAROT answered 4 years ago

Hi Sara,
And thank you for this quick and precise answer. Now this is clear for me. 
Still, could we focus on a part of your explanation: when you say “when a new message is received, the onMqttMessage() function runs”, can I understand:
“when a message is received on the Mosquitto broker (in the topic esp32/led), this Mosquitto broker sends a packet to the subscribers of the topic esp32/led (for example, the ESP32 client #1). This packet “tells” the subscribers to trigger their function onMqttMessage()?
Regards,
Rémi
 

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

Ho.
Yes, it’s exactly that. Your description is correct!
I wouldn’t have explained it better.
Regards,
Sara

0 Vote Up Vote Down
Remi GAROT answered 4 years ago

Hi!
Thank you for this confirmation. I really appreciate your reactivity, it is quiet rare! 
And by the way, thank you (and Rui ) for the courses, these are very helpful!
Regards,
Rémi

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

Thank you so much for your feedback.
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 Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition 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.