help to sketch. motion sensor with ack



  • hi friends.
    i want know how i can use ack for motion sensor. i want when motion is trigger and send message to controller , so controller send a ack to motion sensor. and if message dont receive to controller so motion node send again message .
    can you help me how use ack in sketch from controller for trust of send message from motion node.


  • Mod

    If I remember well the send function returns a boolean according to the success of the send. You can check for the result and do a cycle


  • Hardware Contributor

    There are two types of ack in Mysensors:

    • hardware ack from the radio. Is enabled in Mysensors. So if msg fails, the send function will return false.
    • software ack. This is another option. You need to enable and process it.

    In both cases, when your node will send a msg, you need to code a loop, in which

    • send msg and test ack
    • increment a retry counter variable if it fails
    • test how many retries and exit your retry loop if your max reached
    • do what you want then, regarding this
    • better to add a timeout option on this loop

    There are mutliple ways of doing this "loop", imho i prefer to use non blocking ways, so the mcu can do others thing during this time. But it's simpler, and will work well, like explained above.

    if you take a look at the Motion examples, there is this line for sending

    send(msg.set(tripped?"1":"0"));  // Send tripped value to gw
    

    The send function allow a second parameter for ack. This is a boolean, set it to true if you want to enable ack. Like this:

    send(msg.set(tripped?"1":"0"), true);  // Send tripped value to gw and ask for ack
    

    To receive the ack answer from the gw, you'll need to add the "receive" function callback in your sketch. Something like that (extracted from relay sketch) :

    void receive(const MyMessage &message) {
      if (message.isAck() && message.type == V_TRIPPED) {  // Test if ack received and for which type of msg, you could also test for which child id
         Serial.println("This is an ack from gateway for V_TRIPPED messages");
         // set your "flag" ack variable to true here. Test it in your retry loop and reset it to false
      }
    

  • Hero Member

    @Reza Both send and request will return a boolean result that you can use to check if a message has been completed, I use both in this sketch



  • @gohan @scalz @Boots33 thanks my friends for help🌹


Log in to reply
 

Suggested Topics

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts