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! :confused: )
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login