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! 😕 )


Log in to reply
 

Suggested Topics

  • 8
  • 2
  • 90
  • 1
  • 3
  • 44

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts