-->
Page 1 of 3

ESP07 MQTT ISR crash

PostPosted: Fri Jun 30, 2017 3:09 am
by paysan
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

Re: ESP07 MQTT ISR crash

PostPosted: Fri Jun 30, 2017 3:17 am
by torntrousers
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.

Re: ESP07 MQTT ISR crash

PostPosted: Fri Jun 30, 2017 4:17 am
by paysan
Thanks for the quick answer but why does a Serial.print work inside the ISR?

Re: ESP07 MQTT ISR crash

PostPosted: Fri Jun 30, 2017 4:23 am
by paysan
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.