• 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

AsyncMqttClient OnMessage parsing

Q&A Forum › Category: ESP32 › AsyncMqttClient OnMessage parsing
0 Vote Up Vote Down
bill1 asked 5 years ago

I tried to use a “while” loop that exits when an MQQT message with a payload of “1” is received, but the ESP32 keeps rebooting. I wondered if having the while loop in the OnMesssage function is the problem so I moved it to Loop( ) using a global variable that gets set to the payload in the OnMessage function, and it still resets.

Question Tags: AsyncMqttClient
1 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

Hi Bill.
The OnMessage() is a callback function that is called when you receive a new MQTT message. It is not a good idea to place a while loop inside it.
You should have a flag variable that changes state inside the OnMessage() function. Then, in the loop() check its state and do what you want to do, and then, change the flag variable again.
What are you trying to do in your while loop()? Without further information, it is very difficult to understand what might be wrong.
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.