The use of the ESP8266 in the world of IoT

User avatar
By paysan
#67751 Hello, I want to do a MQTT client.publish(topic,msg); on my ESP07 in Arduino language inside an ISR.

When the publish is executing I got an Exception 9 and a stack-dump.

void ISR() // Interrupt-Service-Routine
{
client.publish("button", "1"); // Publish topic "button" with message "1"
}

When I test the publish line outside the ISR it works without any problem.
Also when I replace the client.plublish with something else like a Serial.print("hello."); there is no stack-dump.

Who knows a solution for this problem.

Regards, Wim
User avatar
By torntrousers
#67752 It crashes because you shouldn't do IO inside an ISR. Instead have the ISR just set a flag to indicate the event has happened and check that flag in the main loop to see if it should do the publish.
User avatar
By paysan
#67755
paysan wrote:Thanks for the quick answer but why does a Serial.print work inside the ISR?


And if I use the "flag" methode in the ISR there is no need to use the interrupt system.
If I need to check the flag in the mainloop I can check the button also in the mainloop straight away.