about ACK ...
-
Hi, all
I am trying to build a simple project of two nodes.One node with a push button(TOGGLE) and one switch, both with feedback LEDs.The other node with two relays and local control buttons.
Its mandatory to have a reliable feedback to first node LEDs so, trying to figure out how ACK work in mysensors and how to resend the message if not ACK, I used
this...//function to handle the ACK . #define ATTEMPTS 5 void SendData(byte sensor, byte destination, bool value, bool ack) { msg.setSensor(sensor); msg.setDestination(destination); for(byte i=0; i<=ATTEMPTS; i++){ if(send(msg.set((bool)value),ack)){ Serial.println("ACK"); break; }else{ Serial.println("NACK"); } } }
... which works great but only until the message reaches the gateway, not the target node! although I can see the ACK back from the target node it remains unparsed!
Can anyone give me an example of how to do it?
-
... this approach seems that work !
#define ACKDELAY 40 //seems 40 millis is a good value bool nodeACK = false; void SendData(byte sensor, byte destination, bool value, bool ack) { msg.setSensor(sensor); msg.setDestination(destination); for(byte i=0; i<=ATTEMPTS; i++){ if(send(msg.set(value),ack)){ Serial.println("Gateway ACK"); // wait(ACKDELAY); if(nodeACK == true){ Serial.println("Node ACK"); nodeACK = false; break;}else{ Serial.println("Node NACK"); } }else{ Serial.println("Gateway NACK"); } wait(ACKDELAY); } }
... in combination with this
void receive(const MyMessage &message) { if (message.isAck()){ nodeACK=true; digitalWrite(LED_PINS[message.sensor], message.getBool()? LED_ON:LED_OFF); Serial.println(F("ACK recieved LED Status Changed")); }
... but probably is not the most elegand way!
... because if during the send/ack back message duty cycle, an ack from an other sensor received, a conflict may occure! i do not feel safe!
(i also have a feeling that i did that post in the wrong topic!)
Suggested Topics
-
Welcome
Announcements • 23 Mar 2014, 08:24 • hek 2 Apr 2014, 14:39 -
BMP280 SPI Adafruit
My Project • 24 Aug 2016, 01:56 • Matt 23 Jan 2025, 16:25 -
Door chime
My Project • 21 days ago • Paul Scarbro 17 days ago -
Water Meter or "How to get Home Assistant to send saved data to an Arduino"
My Project • 18 Oct 2024, 02:19 • OldSurferDude 18 Oct 2024, 02:19 -
A low cost energy meter
My Project • 25 Jan 2024, 01:03 • OldSurferDude 12 Aug 2024, 06:03 -
Long time test done with soil sensor!
My Project • 7 Jan 2025, 09:13 • Nicklas Starkel 13 Jan 2025, 09:10