Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. gerard
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    gerard

    @gerard

    0
    Reputation
    4
    Posts
    424
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    gerard Follow

    Best posts made by gerard

    This user hasn't posted anything yet.

    Latest posts made by gerard

    • 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

      posted in Troubleshooting
      gerard
      gerard
    • RE: Call to begin function hangs arduino

      @SiLeX So it may be due to an incorrect connection? Pins of module are untagged and I connected them according to the positions of schemes that I found online. All modules have same pinout?

      posted in Troubleshooting
      gerard
      gerard
    • RE: Call to begin function hangs arduino

      @BartE Its simply a test. My final project is to connect a motion sensor and a NRF24L01+ module to an arduino nano board. And in the other side another arduino with a NRF24L01+ module connected to a Raspberry.
      But at this moment I just want to test communication between two nodes

      posted in Troubleshooting
      gerard
      gerard
    • Call to begin function hangs arduino

      I have a NRF24L01+ module connected to an arduino uno board. I use a 100uF 25V capacitor. When execute sketch arduino hangs and returns this text in serial output:

      send: 2-2-0-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=ok:0

      I tried to call MySensor constructor and begin function with and without parameters.

      Where is the problem?

      Thanks

      The code I used is

      #include <MySensor.h>
      #include <MySigningNone.h>
      #include <MyTransportNRF24.h>
      #include <MyHwATMega328.h>
      #include <SPI.h>
       
      #define ID 0
      #define OPEN 1
      #define CLOSE 0
      
      MyTransportNRF24 transport(9, 10);
      MySigningNone signer;
      MyHwATMega328 hw;
      MySensor gw(transport,hw);
      //MySensor gw;
      MyMessage msg(ID, V_TRIPPED);
      
      void response(const MyMessage &m){
      
      }
       
      void setup() 
      { 
        Serial.begin(115200);
        //Serial.print("Setup ");
        gw.begin(response,2,false,AUTO);
        //gw.begin();
        Serial.println("begin");
        gw.present(ID, S_DOOR,"Sensor de prova",false); 
      }
       
      void loop()
      {
           Serial.print("Identificador ");
           Serial.println(gw.getNodeId());
           gw.send(msg.set(OPEN));
           gw.sendSketchInfo("Sketch de prova","0.0", true);
           delay(1000); // Wait 10 seconds
      }```
      posted in Troubleshooting
      gerard
      gerard