Hi, I'm creating an IoT system using the Home Assistant. I would like to add periodically (e.g. every 10 seconds) to the HA server update of temperature, humidity, etc. I was able to configure the timer TCC0, which reports interrupts every 10 seconds. The problem is that on the interrupt function, when executing the MQTT publish function, arduino hangs and doesn't continue. However, if I use MQTT publish outside of an interrupt, everything works fine. Someone would be able to help with this problem or suggest a better solution to periodically sending updates to the server?
It's never a good idea to run a complex function inside an interrupt service function!
My typical procedure: The interrupt service function sets a flag (bool) and in loop() the flag is reacted to and something is executed. And the flag is reset there.
Interrupts are a very bad choice for a periodic action to occur every 10 seconds. Why not using millis() in the loop() for that?
Never call code inside an interrupt handler that relies on interrupts to work. Although the Nano 33 IoT uses a SAMD21 processor which support nesting interrupts, it's usually overly complex to overview what happens if an interrupt handler whats for other interrupts to occur.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.