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.
-
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
-
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 }
-
@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
-
Suggested Topics
-
Arduino Celebrates 10 years (Malmö/Sweden)
Announcements • 29 Mar 2014, 17:08 • hek 29 Mar 2014, 17:08 -
Home Assistant/MySensors quirks
Development • 17 Mar 2025, 02:35 • OldSurferDude 17 Mar 2025, 02:35 -
Sending offset to node
Development • 31 Jan 2025, 00:59 • bsl88k 4 Feb 2025, 12:14 -
MQTT-Help me understand about the MQTT Gateway.
Development • 2 Mar 2025, 01:44 • dpcons 12 Mar 2025, 23:39 -
Saving last known good state, but not in EEPROM
Development • 30 Jan 2024, 18:46 • OldSurferDude 15 Jan 2025, 08:51 -
LAN8720A - will mysensors work with this module
Development • 13 Nov 2024, 17:06 • Marcin 15 Nov 2024, 10:59