rf24Network library issue

I am working on buillding a network having a size of around 40-50 nodes for this i am using nrf24l01+ modules with the rf24Network library.
I am making the master(00) device send/transmit a multicast group message and all the child nodes will transmit their sensor data after receiving this msg from master after a random delay.
but when i add nodes of level 2(011,021,015,025, etc) or below, their data is not received by the master most of the times.
The child nodes are in range of their own master.
Is this because child nodes are sending data of about 85 bytes, but using rf24Network you can send 144 bytes at max right?
The child nodes are in range of their own master.
has this happened to anyone? can anyone please explain why this might be happening?
I have a theory that this might be happening because the nodes below level 1 needs to do multi-hopping for their data to be received by the master.
I have provided my code below

// master device
void send_data() {
  uint8_t level1 = 1;
  uint8_t level2 = 2;
  uint8_t level3 = 3;
  uint8_t level4 = 4;
  String data_req = formatData(unique_code, deviceID, "cmd", "get_data");
  network.update();
  RF24NetworkHeader header1;                                                                // (Address where the data is going)
  bool ok1 = network.multicast(header1, &data_req[0], data_req.length(), level1);           // Send the data
  delay(Delay);
  bool ok2 = network.multicast(header1, &data_req[0], data_req.length(), level2);           // Send the data
  delay(Delay);
  bool ok3 = network.multicast(header1, &data_req[0], data_req.length(), level3);           // Send the data
  delay(Delay);
  bool ok4 = network.multicast(header1, &data_req[0], data_req.length(), level4);           // Send the data
  delay(Delay);

  if (ok1) {
    Serial.println();
    Serial.print("   sent: ");
    Serial.println(data_req);
  } else {
    Serial.println("failed");
  }
// child node
void received_data() {
  network.update();
  if(network.available() ) {
    digitalWrite(ledPin, LOW);
    network.update();
    RF24NetworkHeader header;
    network.read(header, &received_msg, sizeof(received_msg) );
    delay(Delay);

        int r_delay = random(0,5000);
        delay(r_delay);
        Serial.println(r_delay);
          sendData();
    }
    lastTransmissionTime = millis();
  
  // Check for timeout to clear the buffer
  currentTime = millis();
  if(currentTime - lastTransmissionTime > transmissionTimeout) {
      digitalWrite(ledPin, HIGH);
  }
}

void sendData() {
  String sensor_data;
  int data_variables[23] = {
    random(0, 100), random(0, 100), random(0, 100), random(0, 100), random(0, 100),
    random(0, 100), random(0, 100), random(0, 100), random(0, 100), random(0, 100),
    random(0, 100), random(0, 100), random(0, 100), random(0, 100), random(0, 100),
    random(0, 100), random(0, 100), random(0, 100), random(0, 100), random(0, 100),
    random(0, 100), random(0, 100), random(0, 100)
  };
  // Update the sensor_data variable with the values of the data variables
  sensor_data = "[";
  for (int i = 0; i < 23; i++) {
    sensor_data +=  String(data_variables[i]);
    if(i<22) {
      sensor_data += ",";
    }
  }
  sensor_data += "]";

  String data_resp = formatData(unique_code, deviceID, sensor_data);

  network.update();
  RF24NetworkHeader header2(master_node);
  bool ok = network.write(header2, &data_resp[0], data_resp.length() );
  if(ok) {
    Serial.print("  Sent: ");
    Serial.println(data_resp);
    Serial.println();
  }
  else{
    Serial.println("Failed!!!");
    Serial.println();
    bool ok = network.write(header2, &data_resp[0], data_resp.length() );
  }
}

Its probably a timing issue plus a bit of a coding issue. The main thing to remember is instead of delay(); calls you should keep the network updating and checking for incoming packets.

Something like:

  bool ok1 = network.multicast(header1, &data_req[0], data_req.length(), level1);
  uint32_t timer = millis();
  while( millis() - timer < 1000 ){ //Check for incoming packets for 1 second - adjust this as required
    network.update();
    //handle incoming packets here
  }

to avoid collisions it may be simpler to give each node an ID and the master polls each node in turn

thanks
I will try this method too

but I want to send a multicast message because there will be many nodes in the network
so each level nodes can get the send_data request at once.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.