nrf24 gateway don't send ack



  • I have an arduino that has connected one NRF24L01 + module and a motion sensor and other arduino that has just connected a NRF24L01 module configured as the father of the first . The gateway receives packets of motion sensor but does not return the ack

    This is the source code or gateway

    #include <MySensor.h>
    #include <MySigningNone.h>
    #include <MyTransportNRF24.h>
    #include <MyHwATMega328.h>
    #include <SPI.h>
     
    #define NODE_ID 0
    
    
    #define MOTION_SENSOR_ID 0
    #define MOTION_SENSOR_NODE 1
    #define BEGIN_TRANSMISSION "BEGIN"
    #define END_TRANSMISSION "END"
    #define WHO_AM_I "WHO_AM_I"
    #define WHICH_SENSOR "WHICH_SENSOR"
    #define WHATH "WHATH"
    #define SEND_TELEGRAM "SEND_TELEGRAM"
    #define OK "OK"
    
    MyTransportNRF24 transport(7, 8,RF24_PA_HIGH);
    MySigningNone signer;
    MyHwATMega328 hw;
    MySensor gw(transport,hw);
    
    bool begin_transmission=false;
    int who_am_i=-1;
    int which_sensor=-1;
    int whath=-1;
    String send_telegram="";
    unsigned long timeout=10000;
    unsigned long begin_transmission_time=millis();
    MyMessage msg(MOTION_SENSOR_ID,V_VAR1);
    
    
    void response(const MyMessage &m){
        
      String message_text=m.getString();
      Serial.println(message_text);
      if(message_text==BEGIN_TRANSMISSION && !begin_transmission){
        begin_transmission=true;
        begin_transmission_time=millis();
      }
      if(begin_transmission){
        if(who_am_i<0 && message_text.startsWith(WHO_AM_I)){
          who_am_i=message_text.substring(String(WHO_AM_I).length()+1).toInt();
        } 
        else if(which_sensor<0 && message_text.startsWith(WHICH_SENSOR)){
          which_sensor=message_text.substring(String(WHICH_SENSOR).length()+1).toInt();
        }
        else if(whath<0 && message_text.startsWith(WHATH)){
          whath=message_text.substring(String(WHATH).length()+1).toInt();
        }
        else if(message_text.startsWith(SEND_TELEGRAM)){
          send_telegram+=message_text.substring(String(SEND_TELEGRAM).length()+1);
        }
        else if(message_text.startsWith(END_TRANSMISSION)){
          begin_transmission=false;
          if(send_telegram!=""){
            String telegram=String("Node ")+who_am_i+String(" Sensor ")+which_sensor+String(" Valor ")+whath+String(" ")+send_telegram+String("*");
            who_am_i=-1;
            which_sensor=-1;
            whath=-1;
            send_telegram="";
            Serial.println(telegram);
          }
         }
        }
      msg.setDestination(MOTION_SENSOR_NODE);
      gw.send(msg.set(OK),true);
    }
     
    void setup() 
    { 
      Serial.begin(115200);
      gw.begin(response,NODE_ID,false,NULL);
      
    }
     
    void loop()
    {
         gw.process();
         gw.wait(10000); // Wait 10 seconds
         if((begin_transmission_time+timeout)<millis()){
          begin_transmission=false;
          who_am_i=-1;
          which_sensor=-1;
          whath=-1;
          send_telegram="";
         }
    }
    

    And this is the source code of motion sensor sketch

    #include <MySensor.h>
    #include <MySigningNone.h>
    #include <MyTransportNRF24.h>
    #include <MyHwATMega328.h>
    #include <SPI.h>
     
    #define MOTION_SENSOR_ID 0
    #define MOTION_SENSOR_PIN 5
    #define NODE_ID 1
    #define PARENT_ID 0
    #define BEGIN_TRANSMISSION "BEGIN"
    #define END_TRANSMISSION "END"
    #define WHO_AM_I "WHO_AM_I"
    #define WHICH_SENSOR "WHICH_SENSOR"
    #define WHATH "WHATH"
    #define SEND_TELEGRAM "SEND_TELEGRAM"
    
    String who_am_i;
    String which_sensor;
    String whath;
    String send_telegram;
    bool ack_received=false;
    unsigned long send_time=millis();
    int retry_times=5;
    
    MyTransportNRF24 transport(7, 8,RF24_PA_HIGH);
    MySigningNone signer;
    MyHwATMega328 hw;
    MySensor gw(transport,hw);
    MyMessage msg(MOTION_SENSOR_ID, V_TRIPPED);
    
    void response(const MyMessage &m){
      ack_received=m.isAck();
      Serial.print("ack_received ");
      Serial.println(ack_received);
    }
    
    void send_message(const char* text){
      for(int i=0;i<retry_times && !ack_received;++i){
        gw.send(msg.set(text),true);
        delay(100);
      }
    }
     
    void setup() 
    { 
      Serial.begin(115200);
      gw.begin(response,NODE_ID,false,PARENT_ID);
      gw.sendSketchInfo("Motion sensor", "0.1");
      gw.present(MOTION_SENSOR_ID,S_MOTION,"Motion sensor",false); 
      Serial.print("Id ");
      Serial.println(gw.getNodeId());
      pinMode(MOTION_SENSOR_PIN, INPUT);
    }
     
    void loop()
    {
         gw.process();
         if(digitalRead(MOTION_SENSOR_PIN)){
          
          send_message(BEGIN_TRANSMISSION);
          //Who am I
          if(ack_received){
            ack_received=false;
            who_am_i=String(WHO_AM_I)+" "+gw.getNodeId();
            send_message(who_am_i.c_str());
          }
          //Which sensor
          if(ack_received){
            ack_received=false;
            which_sensor=String(WHICH_SENSOR)+" "+MOTION_SENSOR_ID;
            send_message(which_sensor.c_str());
          }
          //Whath
          if(ack_received){
            ack_received=false;
            whath=String(WHATH)+" "+1;
            send_message(whath.c_str());
          }
          //Telegram
          if(ack_received){
            int string_pos=0;
            String message_text=String(" Detectada presencia");
            while(string_pos<message_text.length()){
              ack_received=false;
              send_telegram=String(SEND_TELEGRAM)+" "+message_text.substring(string_pos,string_pos+25-String(SEND_TELEGRAM).length());
              send_message(send_telegram.c_str());
              string_pos=string_pos+25-String(SEND_TELEGRAM).length()-1;
            }
          }
          //End transmission
          if(ack_received){
            ack_received=false;
            send_message(END_TRANSMISSION);
          }
          ack_received=false;
         }
         
         gw.wait(1000); // Wait 10 seconds
    }
    

    Serial port output for gateway is

    0;0;3;0;9;gateway started, id=0, parent=0, distance=0
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=16,pt=0,l=5,sg=0:BEGIN
    0;0;3;0;9;send: 0-0-0-1 s=0,c=1,t=16,pt=0,l=5,sg=0,st=fail:BEGIN
    BEGIN
    0;0;3;0;9;send: 0-0-0-1 s=0,c=1,t=24,pt=0,l=2,sg=0,st=fail:OK
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=16,pt=0,l=5,sg=0:BEGIN
    0;0;3;0;9;send: 0-0-0-1 s=0,c=1,t=16,pt=0,l=5,sg=0,st=fail:BEGIN
    BEGIN
    0;0;3;0;9;send: 0-0-0-1 s=0,c=1,t=24,pt=0,l=2,sg=0,st=fail:OK
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=16,pt=0,l=5,sg=0:BEGIN
    0;0;3;0;9;send: 0-0-0-1 s=0,c=1,t=16,pt=0,l=5,sg=0,st=fail:BEGIN
    BEGIN
    0;0;3;0;9;send: 0-0-0-1 s=0,c=1,t=24,pt=0,l=2,sg=0,st=fail:OK
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=16,pt=0,l=5,sg=0:BEGIN
    0;0;3;0;9;send: 0-0-0-1 s=0,c=1,t=16,pt=0,l=5,sg=0,st=fail:BEGIN
    BEGIN
    

    And serial port output for motion sensor sketch is

    send: 1-1-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=ok:1.5.4
    send: 1-1-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
    sensor started, id=1, parent=0, distance=1
    send: 1-1-0-0 s=255,c=3,t=11,pt=0,l=13,sg=0,st=ok:Motion sensor
    send: 1-1-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=fail:0.1
    send: 1-1-0-0 s=0,c=0,t=1,pt=0,l=13,sg=0,st=ok:Motion sensor
    Id 1
    send: 1-1-0-0 s=0,c=1,t=16,pt=0,l=5,sg=0,st=ok:BEGIN
    send: 1-1-0-0 s=0,c=1,t=16,pt=0,l=5,sg=0,st=ok:BEGIN
    send: 1-1-0-0 s=0,c=1,t=16,pt=0,l=5,sg=0,st=ok:BEGIN
    send: 1-1-0-0 s=0,c=1,t=16,pt=0,l=5,sg=0,st=ok:BEGIN
    send: 1-1-0-0 s=0,c=1,t=16,pt=0,l=5,sg=0,st=ok:BEGIN
    send: 1-1-0-0 s=0,c=1,t=16,pt=0,l=5,sg=0,st=ok:BEGIN
    send: 1-1-0-0 s=0,c=1,t=16,pt=0,l=5,sg=0,st=ok:BEGIN
    send: 1-1-0-0 s=0,c=1,t=16,pt=0,l=5,sg=0,st=ok:BEGIN
    send: 1-1-0-0 s=0,c=1,t=16,pt=0,l=5,sg=0,st=ok:BEGIN
    send: 1-1-0-0 s=0,c=1,t=16,pt=0,l=5,sg=0,st=ok:BEGIN
    

    Where is the problem? It seems that the gateway can not find the motion sensor.
    Moreover, there is a method in the myMessage class to know id of node sending a message?

    Thanks


 

193
Online

8.8k
Users

9.6k
Topics

100.3k
Posts