Behaviour after WakeUp due to Interrupt

I have a question about DeepSleep and Interrupts.

Assume this simple scenario:

  • Arduino Nano + ESP-01
  • PIR Sensor on Interrupt
  • LastPIR_State Variable
  • MQTT Client

My problem, I want to e.g. send an MQTT message on PIR detection, then go back to sleep. Without the sleep I could simply write a loop which checks for state change of PIR, if detected, send MQTT and so on..

Now simply moving the "checkStateAndSend" to interrupt function is not feasable (mqtt and possible WLAN setup takes to long). Now I am asking myself what effect does interrupt have on logic, like if I have:

SETUP:

  • Register the interrupt handler

LOOP:

  • CheckStateAndSendMQQT
  • GoToDeepSleep

INTERRUPT:

  • Basically do nothing, just wake up

Would the interrupt trigger one execution of CheckStateAndSendMQQT or would it just wake up, do nothing, go back to sleep? If so, any elegant way of "starting" a longer lasting routine from Interrupt while sleeping?

Thanks, (I tried searching, btw, but its a bit of to generic search terms) :slight_smile:
Chris

hi @cruppert welcome to the forum.

I don't know about starting, sleeping and stopping anyhting like MATT or whatever, but usually a process that goes to sleep is woken up at exactly the point where it went to sleep.

So in your pseudocode loop, the loop will start at the top again after waking up has been the last thing the loop did.

In any case, it may be worth your while to look at the best source for sleep

HTH

a7

An idea, maybe something like:

SETUP:

  • Register the interrupt handler

LOOP:

  • IF doSleep THEN GoToDeepSleep
  • CheckStateAndSendMQQT
  • doSleep = true

INTERRUPT:

  • doSleep = false

Weird way, but might get me there. Not sure if better ways :slight_smile:

What interrupts are you registering to be handled? I make no sense of your idea, perhaps you could expand on it a bit while still presenting it in pseudocode.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.