Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. help to sketch. motion sensor with ack

help to sketch. motion sensor with ack

Scheduled Pinned Locked Moved Development
5 Posts 4 Posters 2.0k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Reza
    wrote on last edited by Reza
    #1

    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.

    Boots33B 1 Reply Last reply
    0
    • gohanG Offline
      gohanG Offline
      gohan
      Mod
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      2
      • scalzS Offline
        scalzS Offline
        scalz
        Hardware Contributor
        wrote on last edited by scalz
        #3

        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
          }
        
        1 Reply Last reply
        1
        • R Reza

          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.

          Boots33B Offline
          Boots33B Offline
          Boots33
          Hero Member
          wrote on last edited by
          #4

          @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

          1 Reply Last reply
          1
          • R Offline
            R Offline
            Reza
            wrote on last edited by
            #5

            @gohan @scalz @Boots33 thanks my friends for help:rose:

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            32

            Online

            11.7k

            Users

            11.2k

            Topics

            113.1k

            Posts


            Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • MySensors
            • OpenHardware.io
            • Categories
            • Recent
            • Tags
            • Popular