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