How to stop receiving messages temporarily?



  • Is there a neat way to stop receiving messages temporarily in mysensors node? I have a node which must perform a routine of sequence of actions of roughly 5 seconds upon receiving a command. If another command comes when the routine is performed it produces unwanted side effects.

    So I am looking for a method or workaround, which would allow when command is received to stop listening to radio, after the routine is completed - restart listening again.

    Any advice?

    regards, rimantas



  • @rzylius
    maybe too simple, but can't you put your specific code within a 'while' loop?
    Something like:

    unsigned long Wait_time;
    unsigned long Start_time;
    ...
    ...
    //
    Start_time = millis();
    Wait_time = millis() - Start_time;
    
    while (Wait_time < 5000){
    //insert your code for the routine of actions of roughly 5000 ms here
    Wait_time = millis() - Start_time;
    }
    

    BR,
    Boozz


  • Admin

    @rzylius

    Can't you do this with a state variable? something like:

    boolean state = false;
    void receive(const MyMessage &message) {
      if (!state) {
        if (message.cmd = xxx) {
          state = true;
          startOperation();
        }
      }
    }
    
    void startOperation() {
       delay(5000);
       state = false;
    }
    


  • @tbowmo works like a charm, thank you.


Log in to reply
 

Suggested Topics

  • 4
  • 2
  • 1
  • 5
  • 933
  • 2

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts