Make NRF24L01 as Router

Hello, I tried using my NRF as a router. so it would recieve data from master node and share it to the end nodes. Then the end nodes send feedback in scheduled time (50 ms delay between each) to the router. The router would recieve it under 250 ms time, upper that the data will send back to the master node.

But, i tried this code in router

void loop()  
{ 
     current_time = millis();
 
  if ( Radio.available(&pipeNum))
  {

I insert current time code makes my NRF doesn’t recieve any data. Any suggest?

this is my full code

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>

//Create up to 6 pipe addresses P0 - P5;  the "LL" is for LongLong type
const uint64_t 
Node[] = {0xB3B4B5B6F1LL, 0xB3B4B5B6CDLL, 0xB3B4B5B6A3LL, 0xB3B4B5B60FLL, 0xB3B4B5B605LL  };

uint64_t MASTER    = 0x7878787878LL;
uint64_t BC      = 0x1910000000LL;

uint8_t  CE   = 9;
uint8_t  CSN  = 10;
long n,i,j    = 1;
int k         = 0;

long current_time, send_time;

float baca_volt, volt;
byte pipeNum = 5;
boolean Flag  = false;

//Format data between Node 1 and HOST
struct payload
{
  char node[3];//This part is command from master node to another
  char id[4];//The list of node identity I try to order
  float value_1;//baterry value of node 1
  float value_2;//baterry value of node 2
  float value_3;//baterry value of node 3
  float value_4;//baterry value of node 4
  long dat[4];//list of data has come per node
};
payload Data;

//Format data Node 1 and  other Node
struct payload_1
{
  char node[3];//Command from master node to another
};
payload_1 Data_1;

//Format data Node 2 with Node 1
struct payload_2
{ char node[3];//Command from master node to another
  char id;//Identity of node, the value always '2'
  float value;//baterry value of node 2
  long dat;//To know how many data send
};
payload_2 Data_2;

//Format data Node 3 with Node 1
struct payload_3
{ char node[3];//Command from master node to another
  char id;//Identity of node, the value always '3'
  float value;//baterry value of node 3
  long dat;//To know how many data send
};
payload_3 Data_3;

//Format data Node 4 with Node 1
struct payload_4
{ char node[3];//Command from master node to another
  char id;//Identity of node, the value always '4'
  float value;//baterry value of node 4
  long dat;//To know how many data send
};
payload_4 Data_4;

RF24 Radio(CE, CSN);

void setup()   
{
  Serial.begin(9600); 
  Radio.begin();
  Radio.setChannel(108);
  Radio.setAutoAck(true);
  Radio.enableDynamicPayloads();
  Radio.enableAckPayload();

  //Set transmission power(one only)
  Radio.setPALevel(RF24_PA_MIN);
  //Radio.setPALevel(RF24_PA_LOW);
  //Radio.setPALevel(RF24_PA_HIGH);
  //Radio.setPALevel(RF24_PA_MAX);
  
  Data.id [3] ='1';//the identity of node 1(more like address in simple way)
  Serial.println(Data.id [4]);
  Data.node[0]='S';
  
  long time1x= millis();
  Radio.openWritingPipe(MASTER);
  Radio.write(&Data, sizeof(Data) );
  delay(5);
  Radio.openWritingPipe(BC);
  Radio.write(&Data_1, sizeof(Data_1) );
  long time2x= millis();
  long timeOpWrite = time2x-time1x;
  Serial.println(timeOpWrite);
  

  // Open up to six pipes for PRX to receive data
  long time1= millis();
  Radio.openReadingPipe(0,MASTER);//This is addres for Master Node
  Radio.openReadingPipe(1,Node[0]);//This is addres for Node2 
  Radio.openReadingPipe(2,Node[1]);//This is addres for Node3
  Radio.openReadingPipe(3,Node[2]);//This is addres for Node4
  Radio.startListening(); // Start listening for messages
  long time2= millis();
  long timeOpList = time2-time1;
  Serial.println(timeOpList);  
}

void loop()  
{ 
      current_time = millis();
      
  if ( Radio.available(&pipeNum))
  {  
    if (pipeNum ==0)//Data from host
    {
      Radio.read(&Data, sizeof(Data) );
      Radio.stopListening();
      
      Data_1.node[0] = Data.node[0];//Data.node is a command to do from master node to another node
      Data_1.node[1] = Data.node[1];
      Data_1.node[2] = Data.node[2];
      
      Radio.openWritingPipe(BC);// write broadcast to another node telling command from master node
      Radio.write(&Data_1, sizeof(Data_1));
      
      Serial.print("Data from Master to All Node");
    }
    
    if (pipeNum == 1)//Data from node 2
    {
      Radio.read(&Data_2, sizeof(Data_2));
      Radio.stopListening();
      
      Data.id[k] = '2'; k++;
      Data.value_2 = Data_2.value;
      Data.dat[1] = Data_2.dat;
      Serial.print("Data from Node 2");
    }
    
    if (pipeNum == 2)//Data from node 3
    {
      Radio.read(&Data_3, sizeof(Data_3));
      Radio.stopListening();
      n=n+1;
      Data.id[k] = '3'; k++;
      Data.value_3 = Data_3.value;
      Data.dat[2] = n;
      Serial.print("Data from Node 3");
    }
    
    if (pipeNum == 3)//Data from node 4
    {
      Radio.read(&Data_4, sizeof(Data_4));
      Radio.stopListening();
      i=i+1;
      Data.id[k] = '4'; k++;
      Data.value_4 = Data_4.value;
      Data.dat[3] = i;
      Serial.print("Data from Node 4");
    }

    if (k==2)//it means data send from all node is complete
    {
      k=0;
      //Flag=true;
    }

    //Program untuk memeriksa nilai baterai
    if (Data_1.node[0] == 'B')
   {

    //ukur voltase
    baca_volt=analogRead(A1);
    volt=(5*5*baca_volt/1023)-0.2;
    Data.value_1=volt;

    i=i+1;//NIlai Data bertambah 1
    
    Serial.print("Data ke: ");
    Serial.print(i);
    Serial.print(' ');
    Serial.print(volt);
    Serial.print("V  ");
   }
      
    Radio.openReadingPipe(0,MASTER);//This is addres for Master Node
    Radio.openReadingPipe(1,Node[0]);//This is addres for Node2 
    Radio.openReadingPipe(2,Node[1]);//This is addres for Node3
    Radio.openReadingPipe(3,Node[2]);//This is addres for Node4
    Radio.startListening(); // Start listening for messages
    Serial.println("Open Read for All Pipes");       
}


  if (current_time-send_time>250)
  {
    Data.dat[0]=j;
    Radio.openWritingPipe(MASTER);
    Radio.write(&Data, sizeof(Data));
    
    send_time = millis();
    
    delay(5);
    Serial.println("Data to Master");
    j=j+1;

    Radio.openReadingPipe(0,MASTER);//This is addres for Master Node
    Radio.openReadingPipe(1,Node[0]);//This is addres for Node2 
    Radio.openReadingPipe(2,Node[1]);//This is addres for Node3
    Radio.openReadingPipe(3,Node[2]);//This is addres for Node4
    Radio.startListening(); // Start listening for messages
    Serial.println("Open Read for All Pipes");
  }
}

totagsayogya: Hello, I tried using my NRF as a router. so it would recieve data from master node and share it to the end nodes.

It is not the nRF24 that will be the router - it is the Arduino attached to it.

Based on your Original Post I don't understand the problem you are having. You need to give a lot more detail.

What is the master? Why is it not sending the data directly to the end nodes?

...R Simple nRF24L01+ Tutorial

The problem is my router node is not able recieve any radio I sent from MASTER or any end node. But it able to send data to MASTER or any end node.

I tried to remove the timming code, and it work normally. But it can't change when router node send back to master node.

Why there is router node, because I tried to make that in my school project and use it in case the distance between master node and end node is too far even using RF24_PA_MAX.

The master node is node that connected to my PC for send and display the data. So it two way communication between master, router, and end nodes.

I've read your tutorial, and I got the concept about it. But some little thing still don't know haha...

totagsayogya: The problem is my router node is not able recieve any radio I sent from MASTER or any end node. But it able to send data to MASTER or any end node.

You did not answer my question "What is the master".

Post the code for the master Arduino and the router Arduino and tell us exactly what happens when you run the pair of programs. Post some examples of the output from both Arduinos.

I've read your tutorial, and I got the concept about it. But some little thing still don't know haha...

Rather than laugh it off, If you tell me what you are having trouble understanding I will try to help.

...R

This is master node

totagsayogya:
The master node is node that connected to my PC for send and display the data. So it two way communication between master, router, and end nodes.

this bellow is full code of master node and this is the full code of end node, the router node in upper comment

the node 1 is the router, and node 2,3,4 is the end node. the program of node 3 and 4 is simillar with node 2.

I only have the picture of node master display, and knows another node work or not with seeing the tx led on arduino. this is the result, it only send the node_id (it send once when node is on).(picture)

Capture.PNG

RR_Master.ino (5.23 KB)

RR_Node1.ino (5.8 KB)

RR_Node2.ino (3.09 KB)

The part that still I don't understand is in ACK payload that I asked before this post.

Yesterday I assume this problem is the ACK part, but actually isn't.

The problem is like I said before the timming code before if (Radio.available) makes my router node not able to recieve any data that I send from master node or from end node.

I think the if (Radio.available) must be alone in void(loop), but it just my opinion

Do you any suggest how to make timming code to slove problem in my router node?

Please make your images visible in your Reply #4 - see this Simple Image Guide

I don't understand is in ACK payload that I asked before this post.

Post a link to the Thread in which you asked about AckPayload. Perhaps it would be more sensible to pause your enquiry in this Thread until you do understand AckPayload.

As far as this Thread is concerned please describe in a few sentences the sequence of communication that you would like to happen, Then I can more easily see if your code is doing what is necessary to achieve that.

Also, please describe the overall project that you are trying to implement. Knowing the context makes it much easier to give useful advice.

I have to say if this was my project I would start by doing everything with a single pipe for simplicity. There are not many situations where multiple pipes are needed - especially when you take account of the fact that the nRF24 only has a single wireless receiver and can only receive one message at a time.

...R

this is shown in master node, the only recieved is the node_id of node 1(the router). When I input anything the router doesn’t respond.
RR error router.PNG

this is my planning
Capture.PNG
The master node can command the end node by entering B_ to check the battery and P_ to start sending data(node_id and dat(many data send)).

The first it will be recieve in the router(node 1) to sperate the data to each end node using pipe BC. Then the end node will respond with randomly order(I use delay for make it like waiting time). Then the router recieve all end node data and compose it back before sending to the master node.

The time I want to router listen to all end node is 250ms, after it data would send to master node and display in serial monitor.

This is the result of command P_ when i try to communicate without router and end node send data not randomly

Hasil berhasil Round Robin pt 1.PNG

The router and sending data randomly is the request from my teacher

this is my question about ACK payload
Question about ACK with payload in NRF24L01
Some tutorial explain that those array use to set number of retries, and in your tutorial it’s like use just like code/sign of ACK

I have replied to your other Thread but you have not yet responded.

Please don't post pictures of text - they are always hard to read. Just copy and paste the text.

After looking at your diagram I would make the device at Node1 the master and have it call each of the others in turn. Just for clarity I have redrawn the diagram with my own nomenclature

Slaves.jpg

Then the master can pass on the messages from the controller to each of the slaves.

To be honest I would not bother splitting up the message. I would leave it to each slave to extract the part that is relevant to it.

I think I would also get each slave to send all the data every time so I would not need to tell it what data I required. That would simplify things because the slave could have the data ready before it gets the request and allow the simplicity of the AckPayload feature to be used.

...R

Slaves.jpg

I've tried to not split the data, but it being replaced one variable with one another variable from each end node in the router because data format between node communication must be same.

Yes, I'm sorry not reply because I concern with this timming code in router

You still have not told us what the whole project is.

You don't have to have the same data going in both directions. The master could pass on to the slaves whatever it gets from the controller and could get a specific piece of data from each slave and combine them into a single message to send on to the controller.

But without knowing what the project is all about this feels like a pointless discussion.

...R

This is my project

totagsayogya:
this is my planning
Capture.PNG
The master node can command the end node by entering B_ to check the battery and P_ to start sending data(node_id and dat(many data send)).

The first it will be recieve in the router(node 1) to sperate the data to each end node using pipe BC. Then the end node will respond with randomly order(I use delay for make it like waiting time). Then the router recieve all end node data and compose it back before sending to the master node.

The time I want to router listen to all end node is 250ms, after it data would send to master node and display in serial monitor.

The end node send back to the router not in order of node_id, but in randomly

This is what I want in the result of P_ (This is the result without router and end node send data in order of node_id)
Hasil berhasil Round Robin pt 1.PNG

The number after “Data” is how many data recieved master node, the number after “Node” is the order of node_id are recieved, the three last number is how many data send from node 2 3 and 4.

The number 2341 bellow “Data” just ignore it, it same as node_id

This is my problem

totagsayogya: But, i tried this code in router

void loop()  
{ 
     current_time = millis();

  if ( Radio.available(&pipeNum))   {




I insert current time code makes my NRF doesn't recieve any data. Any suggest?

totagsayogya:
This is my project

Why are you repeating yourself?

I thought we were making some progress?

…R

I tried to answer this

Robin2: You still have not told us what the whole project is.

I know, but the main problem is that timming in the router make it cannot to recieve any data, not in my format data or any else. Is it so hard to know?

I just assume that if (Radio.available(&pipeNum)) have to only the one in void(loop) {.....}

That timming code is to open listenig for all node in 250ms, after that data will send to the master node and open listening again for all node. The router collect all/some data from end node in that time then send it to master node in one time send.

Did you know more about that or any suggest to write another code for timming in my router node?

void loop() 
{
      current_time = millis();
     
  if ( Radio.available(&pipeNum))
  { 
    if (pipeNum ==0)//Data from host
    {
      Radio.read(&Data, sizeof(Data) );
      Radio.stopListening();
     
      Data_1.node[0] = Data.node[0];//Data.node is a command to do from master node to another node
      Data_1.node[1] = Data.node[1];
      Data_1.node[2] = Data.node[2];
     
      Radio.openWritingPipe(BC);// write broadcast to another node telling command from master node
      Radio.write(&Data_1, sizeof(Data_1));
     
      Serial.print("Data from Master to All Node");
    }
   
    if (pipeNum == 1)//Data from node 2
    {
      Radio.read(&Data_2, sizeof(Data_2));
      Radio.stopListening();
     
      Data.id[k] = '2'; k++;
      Data.value_2 = Data_2.value;
      Data.dat[1] = Data_2.dat;
      Serial.print("Data from Node 2");
    }
   
    if (pipeNum == 2)//Data from node 3
    {
      Radio.read(&Data_3, sizeof(Data_3));
      Radio.stopListening();
      n=n+1;
      Data.id[k] = '3'; k++;
      Data.value_3 = Data_3.value;
      Data.dat[2] = n;
      Serial.print("Data from Node 3");
    }
   
    if (pipeNum == 3)//Data from node 4
    {
      Radio.read(&Data_4, sizeof(Data_4));
      Radio.stopListening();
      i=i+1;
      Data.id[k] = '4'; k++;
      Data.value_4 = Data_4.value;
      Data.dat[3] = i;
      Serial.print("Data from Node 4");
    }

    if (k==2)//it means data send from all node is complete
    {
      k=0;
      //Flag=true;
    }

    //Program untuk memeriksa nilai baterai
    if (Data_1.node[0] == 'B')
   {

    //ukur voltase
    baca_volt=analogRead(A1);
    volt=(5*5*baca_volt/1023)-0.2;
    Data.value_1=volt;

    i=i+1;//NIlai Data bertambah 1
   
    Serial.print("Data ke: ");
    Serial.print(i);
    Serial.print(' ');
    Serial.print(volt);
    Serial.print("V  ");
   }
     
    Radio.openReadingPipe(0,MASTER);//This is addres for Master Node
    Radio.openReadingPipe(1,Node[0]);//This is addres for Node2
    Radio.openReadingPipe(2,Node[1]);//This is addres for Node3
    Radio.openReadingPipe(3,Node[2]);//This is addres for Node4
    Radio.startListening(); // Start listening for messages
    Serial.println("Open Read for All Pipes");       
}


  if (current_time-send_time>250)
  {
    Data.dat[0]=j;
    Radio.openWritingPipe(MASTER);
    Radio.write(&Data, sizeof(Data));
   
    send_time = millis();
   
    delay(5);
    Serial.println("Data to Master");
    j=j+1;

    Radio.openReadingPipe(0,MASTER);//This is addres for Master Node
    Radio.openReadingPipe(1,Node[0]);//This is addres for Node2
    Radio.openReadingPipe(2,Node[1]);//This is addres for Node3
    Radio.openReadingPipe(3,Node[2]);//This is addres for Node4
    Radio.startListening(); // Start listening for messages
    Serial.println("Open Read for All Pipes");
  }
}

I'm sorry if my answer isn't like what you want, for all respect I've done all what I can do. I know you try to help my improvement in this code, but I just want to finnish this project as soon as I can. Because the deadline is near...

Sorry for bad english LOL

totagsayogya: I tried to answer this

You still have not told us what the whole project is.

I know,

If you are not prepared to provide that information then I am not prepared to waste any more of my time on this.

My guess is that you are trying to get free advice for a commercial project.

...R

Okay I’m sorry for wasting your time I tried understand what you want me to explain? Is my big line algorithm of my system or the algortihm of every node?

I’ve told you this is school project and next week I must finish my report. If you don’t believe there is my unfinished report.

BAB II TINJAUAN PUSTAKA.pdf (401 KB)

BAB I PENDAHULUAN.pdf (18.7 KB)

HALAMAN DEPAN.pdf (60.4 KB)

totagsayogya: Okay I'm sorry for wasting your time I tried understand what you want me to explain?

I don't understand what is complicated about my question - what are you making?

For example are you making a system to control the delivery of dog food to three pet dogs?

Or are you making a system to collect windspeed data from 3 anemometers?

Separately, I suspect your teacher is expecting you to do your homework without getting people on the internet to do it for you.

...R

Nothing, I'm not to do implementation. I just try to build a wireless sensor network with that case, with the router, with end nodes reply randomly, and I tested how many data send and checking battery voltage decrease.

I just asked to help slove the problem, not to make another people to do it all. Am I do it wrong to asking another people to help slove this problem? I think my teacher not problem with this, because it's not a test. And all I know it from the internet too

CMIIW