Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NRF24 Network: network.available() returns true in every loop iteration when sending frequent messages from the master node #242

Closed
mirhamza708 opened this issue Jan 4, 2025 · 39 comments
Labels

Comments

@mirhamza708
Copy link

mirhamza708 commented Jan 4, 2025

I'm experiencing an issue where the network.available() function in the receiveCommand method returns true in each loop iteration, even when the master node is not sending any data. This issue occurs only when a large number of messages are sent quickly from the master node (with intervals reduced to around 100ms-200ms). When a delay of approximately 500ms is introduced between messages, the issue does not occur, and the function behaves as expected.

Steps to Reproduce:

  1. Set up the NRF24Handler on a node to receive data.
  2. Use the master node to send frequent messages with intervals of around 100ms-200ms and then after 5-10 seconds stop sending new data.
  3. Observe the behavior in the receiveCommand method where network.available() returns true in every iteration of the loop, even when no new data is received. The while loop is exited but in the next iteration it returns true again.
  4. Reducing the interval between messages (e.g., to 100ms) triggers this issue.
  5. Introducing a delay of 500ms between messages resolves the issue.

Expected Behavior: network.available() should return true only when new data is available for reading, not in every iteration of the loop.

Actual Behavior: When a lot of messages are sent rapidly from the master node, network.available() returns true in every iteration of the loop, even when no new data has been received.

nrf24Handler class methods

void NRF24Handler::begin(uint16_t nodeAddress, uint8_t network_channel) {
    setChannel(network_channel);
    setNodeAddress(nodeAddress);
    
    if (radio.begin()) {
        network.begin(network_channel, nodeAddress); // 90 is the RF24 channel
        radio.setPALevel(RF24_PA_HIGH);  // Adjust power level as needed
        radio.setDataRate(RF24_1MBPS);  // 1Mbps for better range
        Serial.println("NRF24 Network: Initialized successfully.");
    } else {
        Serial.println("NRF24 Network: Failed to initialize radio hardware. Check connections.");
    }
}

void NRF24Handler::sendData(const uint8_t* buffer, size_t bufferSize) {
    network.update();
    RF24NetworkHeader header(masterAddress, 'D'); // 'D' is the message type
    Serial.print("Size of buffer: ");
    Serial.println(bufferSize);
    
    // Write the buffer to the network
    bool success = network.write(header, buffer, bufferSize);

    if (success) {
        Serial.println("NRF24 Network: Data sent to master node.");
    } else {
        Serial.println("NRF24 Network: Failed to send data.");
    }
}

bool NRF24Handler::receiveCommand(ThermostatData& data) {
    network.update();
    
    while (network.available()) {
        RF24NetworkHeader header;
        uint16_t payloadSize = network.peek(header);     // Use peek() to get the size of the payload
        uint8_t buffer[payloadSize]; 
        // Read the data into the temporary buffer
        network.read(header, buffer, payloadSize);

        // Check if the message type matches the command type 'C'
        switch (header.type) {
            case 'C': // 'C' is the command message type
                Serial.println("NRF24 Network: Command received from master node.");

                return true;
            case 'S':
                Serial.println("Settings received!");

                break;
        }
    }
    return false;
}

my main.cpp

NRF24Handler nrfHandler(NRF_CE_PIN, NRF_CSN_PIN);

/**
 * @brief Checks for incoming commands from the master node.
 *
 * If a new command is received, it updates the thermostat state and sends the updated data to the LCD.
 */
void checkForNrfCommands() {
    if (nrfHandler.receiveCommand(thermostat)) {
        Serial.println("NRF24: Thermostat updated with new command.");
        lcd.dwinPageChange(static_cast<uint16_t>(thermostat.state));
        lcd.updateModeIcon(thermostat.mode);
        if (thermostat.mode != ThermostatMode::Auto) {
            lcd.setFanSpeedIcon(static_cast<uint16_t>(thermostat.fanSpeed));
        }
        lcd.updateSetTemperature(thermostat.setTemperature);
    }
}

void setup() {
    Serial.begin(9600);
    Serial.setTimeout(1000);

    delay(2000);

    // Initialize nRF24 Network
    nrfHandler.begin(01, 90);

}

void loop() {
    if (millis() - lastDataSendTime >= 5000) {
        lastDataSendTime = millis();
        sendDataToMasterNode();
    }

    checkForNrfCommands();
}
@TMRh20
Copy link
Member

TMRh20 commented Jan 4, 2025

I am unable to recreate any issue using your code.

@mirhamza708
Copy link
Author

Let me create a simple example to share here.

@mirhamza708
Copy link
Author

I am unable to recreate any issue using your code.

I think I found the problem. Nothing wrong in the library but if the network update is not called often enough then this happens. Can you tell me how often, the frequency, should this update method be called?

@TMRh20
Copy link
Member

TMRh20 commented Jan 4, 2025

network.update needs to be called as often as possible in a high traffic environment, typically at a rate equal to or faster than the transmitting device(s) are sending.

Typically, you want to call network.update() very regularly, and it will load the data into a buffer.
The available() function can be called at a slower rate, allowing you to process data at a slower rate if necessary.

Keep in mind, the radios will buffer up to 3 payloads, while RF24Network will buffer up to 144 bytes of data by default. The radio will also keep receiving data while the microcontroller is doing other things, as long as its in RX mode.

@TMRh20 TMRh20 added the question label Jan 4, 2025
@mirhamza708
Copy link
Author

But even if this is called at a slower rate the network.available should not return true if there is no payload for this node. If due to any reason example some heavy calculation or some other process delays the network update the network.available should not break.

@TMRh20
Copy link
Member

TMRh20 commented Jan 4, 2025

Nope, I would suggest a potential issue with your code if that is happening.

Often, if you have buffer overwrites or other memory related issues, it tends to invoke strange behavior that cannot be easily explained.

If you can post some simplified code that demonstrates this behavior, I can take a closer look.

@mirhamza708
Copy link
Author

yeah sure I will share.

@mirhamza708
Copy link
Author

mirhamza708 commented Jan 4, 2025

So here is the node side code

#include <Arduino.h>
#include <RF24.h>
#include <RF24Network.h>

const uint8_t STATUS_LED = PC13; ///< Pin for nRF24 CSN

HardwareSerial Serial1(USART1);

const uint8_t NRF_CE_PIN = PB0; ///< Pin for nRF24 CE
const uint8_t NRF_CSN_PIN = PB1; ///< Pin for nRF24 CSN

unsigned long lastDataSendTime = 0; ///< Last time data was sent to the master node
RF24 radio(NRF_CE_PIN, NRF_CSN_PIN);
RF24Network network(radio);

void sendData(const uint8_t* buffer, size_t bufferSize) {
    RF24NetworkHeader header(00, 'D'); // 'D' is the message type
    Serial.print("Size of buffer: ");
    Serial.println(bufferSize);
    
    // Write the buffer to the network
    bool success = network.write(header, buffer, bufferSize);

    if (success) {
        Serial.println("NRF24 Network: Data sent to master node.");
    } else {
        Serial.println("NRF24 Network: Failed to send data.");
    }
}

bool receiveCommand(void) {
    network.update();
    
    while (network.available()) {
        RF24NetworkHeader header;
        uint16_t payloadSize = network.peek(header);     // Use peek() to get the size of the payload
        uint8_t buffer[payloadSize]; // Adjusted to the size of the expected command payload (6 bytes)
        // Read the data into the temporary buffer
        network.read(header, buffer, payloadSize);

        // Check if the message type matches the command type 'C'
        switch (header.type) {
            case 'C': // 'C' is the command message type
                Serial.println("NRF24 Network: Command received from master node.");
                return true;
            case 'S':
                Serial.println("NRF24 Network: Settings received from master node.");
                break;
        }
    }
    return false;
}

void setup() {
    Serial.begin(57600);
    Serial.setTimeout(1000);
    pinMode(STATUS_LED, OUTPUT);
    delay(2000);

    if (radio.begin()) {
        network.begin(90, 01); // 90 is the RF24 channel
        radio.setPALevel(RF24_PA_HIGH);  // Adjust power level as needed
        radio.setDataRate(RF24_1MBPS);  // 1Mbps for better range
        Serial.println("NRF24 Network: Initialized successfully.");
    } else {
        Serial.println("NRF24 Network: Failed to initialize radio hardware. Check connections.");
    }
}

void loop() {

    if (millis() - lastDataSendTime >= 5000) {
        lastDataSendTime = millis();
        uint8_t buffer[18];  // Increase the buffer size to 17 to accommodate roomTemperature
        buffer[0] = 1;
        uint64_t some_data = 0x1234567812345678;
        memcpy(&buffer[1], &some_data, sizeof(some_data));

        buffer[9] = 12;
        buffer[10] = 34;
        buffer[11] = 2;
        buffer[12] = 2;
        buffer[13] = 2;
        buffer[14] = 2;
        buffer[15] = 22;
        buffer[16] = 22;
        buffer[17] = 2;

        sendData(buffer, sizeof(buffer));
    }

    receiveCommand();
    // delay(500); // after adding this delay the network.available keeps returning true even if the master note is completely powered off
}

The following is the orange pi side master node python code
main.py

import time
from logger_config import logger
from nrf24_handler import NRF24Handler  # Import NRF24Handler
import json

def main():

    # Uncomment and configure NRF24Handler when required
    nrf_handler = NRF24Handler(
        this_node=0,
        channel=90,
        ce_pin=8,
        csn_pin=10
    )

    transmit_interval = 0.1
    last_publish_time = time.time()
    try:
        while True:
            current_time = time.time()
            if current_time - last_publish_time >= transmit_interval:
                last_publish_time = current_time
                success = nrf_handler.transmit()
            
            # Uncomment when NRF24Handler is enabled
            nrf_data = nrf_handler.receive()
            time.sleep(0.01)
    except KeyboardInterrupt:
        logger.info("User cancelled program, stopping processes...")
        nrf_handler.cleanup()
        logger.info("Shutting down...")

if __name__ == "__main__":
    # Run the main application logic
    main()

nrf24_handler.py

import threading
import struct
import json
import logging
from pyrf24 import RF24, RF24Network, RF24NetworkHeader, RF24_DRIVER
from logger_config import logger

class NRF24Handler:
    def __init__(self, this_node, channel=90, ce_pin=8, csn_pin=10):
        self.radio = RF24(ce_pin, csn_pin)
        self.network = RF24Network(self.radio)
        self.this_node = this_node
        self.channel = channel
        self.lock = threading.Lock()  # Add a threading lock

        # Initialize the radio and network
        if not self.radio.begin():
            raise OSError("nRF24L01 hardware isn't responding")

        self.radio.channel = self.channel
        self.network.begin(self.this_node)
        self.radio.print_pretty_details()

    def receive(self):
        """
        Check for incoming messages and process them based on node type.
        """
        with self.lock:  # Ensure thread-safe access
            self.network.update()
            while self.network.available():
                header, payload = self.network.read(32)  # Adjust maxlen as needed
                node_network_address = header.from_node

                # Parse the first byte to identify the node type
                node_type = payload[0]  # The first byte indicates the node type

                if header.type == ord('D'):  # 'D' is the message type
                    if node_type == 1:  # Thermostat node
                        if len(payload) == 18:
                            data1, data2, data3, data4, data5, data6, data7, data8, data9 = struct.unpack(
                                "<QHBBBBBBB", payload[1:]  # Skip the first byte (node_type)
                            )

                        else:
                            logger.error(f"Error: Payload size is {len(payload)} bytes. Expected 17 bytes. ")

                        return {
                            "node_type": data1,
                        }

                    elif node_type == 2:  # 3-in-1 Sensor node
                        data1, data2, data3, data4 = struct.unpack(
                            "<QHHH", payload[1:]  # Skip the first byte (node_type)
                        )

                        return {
                            "node_type": data1,
                        }

                    else:
                        # Unknown node type
                        return {
                            "node_type": "unknown",
                            "raw_payload": payload,
                        }

            return None  # No data received

    def transmit(self):
        with self.lock:  # Ensure thread-safe access
            try:
                data1 = 1
                data2 = 2
                data3 = 2
                data4 = 22
                # Prepare the payload
                payload = struct.pack("<BBBB", data1, data2, data3, data4)

                # Create the header for the target node
                header = RF24NetworkHeader(1, ord('C'))  # 'C' message type

                # Send the payload
                ok = self.network.write(header, payload)

                if ok:
                    logger.info(f"Message sent to node {1}.")
                else:
                    logger.error(f"Failed to send message to node {1}.")

                return ok

            except Exception as e:
                logger.error(f"Error in transmit function: {e}")
                return False

    def cleanup(self):
        """
        Power down the radio safely.
        """
        self.radio.power = False
logger_config.py
import logging
from logging.handlers import RotatingFileHandler
from collections import deque

# In-memory log handler
class InMemoryLogHandler(logging.Handler):
    def __init__(self, max_logs=200):
        super().__init__()
        self.log_buffer = deque(maxlen=max_logs)

    def emit(self, record):
        # Format the log entry
        log_entry = self.format(record).rstrip("\n")  # Apply the formatter here
        self.log_buffer.append(log_entry)

    def get_logs(self):
        return list(self.log_buffer)

# In-memory log stream
in_memory_handler = InMemoryLogHandler(max_logs=200)

# Log file configuration
log_file = "gateway.log"
max_log_size = 10 * 1024 * 1024  # 10 MB
backup_count = 3

# Configure logging
logger = logging.getLogger("gateway_logger")
logger.setLevel(logging.INFO)

# Handlers
console_handler = logging.StreamHandler()  # Terminal
console_handler.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(message)s"))

file_handler = RotatingFileHandler(log_file, maxBytes=max_log_size, backupCount=backup_count)
file_handler.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(message)s"))

# Apply the same formatter to InMemoryLogHandler
log_formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
in_memory_handler.setFormatter(log_formatter)

# Add handlers to logger
logger.addHandler(console_handler)
logger.addHandler(file_handler)
logger.addHandler(in_memory_handler)

Maybe you can run either on raspberry pi or orange pi zero 3 lts (if you have) but I think in master there shouldn't be any issue
sorry I couldn't strip it down any more that's the minimum code. The node side code is run on stm32f103cbt6 and the nrf24 is from ebyte.

@TMRh20
Copy link
Member

TMRh20 commented Jan 4, 2025

I still can't recreate using your Arduino example and can't run your python example for now.

  1. What Arduino board are you running?
  2. Are you able to test/recreate the issue with two Arduino boards? I modified the code below to send to your example. How about if you use two Arduinos and the following code or a modified version:

Send a 's' over serial to stop sending and 'g' to resume.

#include <SPI.h>
#include <RF24.h>
#include <RF24Network.h>

RF24 radio(7, 8);  // nRF24L01(+) radio attached using Getting Started board

RF24Network network(radio);  // Network uses that radio

const uint16_t this_node = 00;   // Address of our node in Octal format
const uint16_t other_node = 01;  // Address of the other node in Octal format

const unsigned long interval = 0;  // How often (in ms) to send 'hello world' to the other unit

unsigned long last_sent;     // When did we last send?
unsigned long packets_sent;  // How many have we sent already


struct payload_t {  // Structure of our payload
  unsigned long ms;
  unsigned long counter;
};

void setup(void) {
  Serial.begin(115200);
  while (!Serial) {
    // some boards need this because of native USB capability
  }
  Serial.println(F("RF24Network/examples/helloworld_tx/"));

  if (!radio.begin()) {
    Serial.println(F("Radio hardware not responding!"));
    while (1) {
      // hold in infinite loop
    }
  }
  radio.setChannel(90);
  network.begin(/*node address*/ this_node);
}

bool sending = 1;

void loop() {

  if(Serial.available()){
    char c = Serial.read();
    if(c == 'g'){
      sending = 1;
    }else
    if(c == 's'){
      sending = 0;
    }
  }


  network.update();  // Check the network regularly

  unsigned long now = millis();

  // If it's time to send a message, send it!
  if (now - last_sent >= interval) {
    last_sent = now;
    if(sending){
    Serial.print(F("Sending... "));
    payload_t payload = { millis(), packets_sent++ };
    RF24NetworkHeader header(/*to node*/ other_node);
    bool ok = network.write(header, &payload, sizeof(payload));
    Serial.println(ok ? F("ok.") : F("failed."));
    }
  }

  while (network.available()) {  // Is there anything ready for us?

    RF24NetworkHeader header;  // If so, grab it and print it out
    
    network.read(header, 0, 0);
    Serial.println(F("Received packet: counter="));

  }

}

and in the receiver example I modified mainly the below:

        switch (header.type) {
            case 'C': // 'C' is the command message type
                Serial.println("NRF24 Network: Command received from master node.");
                return true;
            case 'S':
                Serial.println("NRF24 Network: Settings received from master node.");
                break;
            default: Serial.println("xD"); break;
        }

@TMRh20
Copy link
Member

TMRh20 commented Jan 4, 2025

Maybe we should call in the expert: @2bndy5 any thoughts?

@2bndy5
Copy link
Member

2bndy5 commented Jan 4, 2025

      switch (header.type) {
            case 'C': // 'C' is the command message type
                Serial.println("NRF24 Network: Command received from master node.");

                return true;
            case 'S':
                Serial.println("Settings received!");

                break;
        }

When you hit this while available() remains true, does it print anything?


It's been a while since I went over the internal pointer that manages the network "queue" for non-linux platforms. The user code posted here seems right at a glance.

@mirhamza708
Copy link
Author

Yeah it goes to the case 'C'

@mirhamza708
Copy link
Author

I still can't recreate using your Arduino example and can't run your python example for now.

  1. What Arduino board are you running?
  2. Are you able to test/recreate the issue with two Arduino boards? I modified the code below to send to your example. How about if you use two Arduinos and the following code or a modified version:

Send a 's' over serial to stop sending and 'g' to resume.

#include <SPI.h>
#include <RF24.h>
#include <RF24Network.h>

RF24 radio(7, 8);  // nRF24L01(+) radio attached using Getting Started board

RF24Network network(radio);  // Network uses that radio

const uint16_t this_node = 00;   // Address of our node in Octal format
const uint16_t other_node = 01;  // Address of the other node in Octal format

const unsigned long interval = 0;  // How often (in ms) to send 'hello world' to the other unit

unsigned long last_sent;     // When did we last send?
unsigned long packets_sent;  // How many have we sent already


struct payload_t {  // Structure of our payload
  unsigned long ms;
  unsigned long counter;
};

void setup(void) {
  Serial.begin(115200);
  while (!Serial) {
    // some boards need this because of native USB capability
  }
  Serial.println(F("RF24Network/examples/helloworld_tx/"));

  if (!radio.begin()) {
    Serial.println(F("Radio hardware not responding!"));
    while (1) {
      // hold in infinite loop
    }
  }
  radio.setChannel(90);
  network.begin(/*node address*/ this_node);
}

bool sending = 1;

void loop() {

  if(Serial.available()){
    char c = Serial.read();
    if(c == 'g'){
      sending = 1;
    }else
    if(c == 's'){
      sending = 0;
    }
  }


  network.update();  // Check the network regularly

  unsigned long now = millis();

  // If it's time to send a message, send it!
  if (now - last_sent >= interval) {
    last_sent = now;
    if(sending){
    Serial.print(F("Sending... "));
    payload_t payload = { millis(), packets_sent++ };
    RF24NetworkHeader header(/*to node*/ other_node);
    bool ok = network.write(header, &payload, sizeof(payload));
    Serial.println(ok ? F("ok.") : F("failed."));
    }
  }

  while (network.available()) {  // Is there anything ready for us?

    RF24NetworkHeader header;  // If so, grab it and print it out
    
    network.read(header, 0, 0);
    Serial.println(F("Received packet: counter="));

  }

}

and in the receiver example I modified mainly the below:

        switch (header.type) {
            case 'C': // 'C' is the command message type
                Serial.println("NRF24 Network: Command received from master node.");
                return true;
            case 'S':
                Serial.println("NRF24 Network: Settings received from master node.");
                break;
            default: Serial.println("xD"); break;
        }

I will do this

@mirhamza708
Copy link
Author

I still can't recreate using your Arduino example and can't run your python example for now.

  1. What Arduino board are you running?
  2. Are you able to test/recreate the issue with two Arduino boards? I modified the code below to send to your example. How about if you use two Arduinos and the following code or a modified version:

Send a 's' over serial to stop sending and 'g' to resume.

#include <SPI.h>
#include <RF24.h>
#include <RF24Network.h>

RF24 radio(7, 8);  // nRF24L01(+) radio attached using Getting Started board

RF24Network network(radio);  // Network uses that radio

const uint16_t this_node = 00;   // Address of our node in Octal format
const uint16_t other_node = 01;  // Address of the other node in Octal format

const unsigned long interval = 0;  // How often (in ms) to send 'hello world' to the other unit

unsigned long last_sent;     // When did we last send?
unsigned long packets_sent;  // How many have we sent already


struct payload_t {  // Structure of our payload
  unsigned long ms;
  unsigned long counter;
};

void setup(void) {
  Serial.begin(115200);
  while (!Serial) {
    // some boards need this because of native USB capability
  }
  Serial.println(F("RF24Network/examples/helloworld_tx/"));

  if (!radio.begin()) {
    Serial.println(F("Radio hardware not responding!"));
    while (1) {
      // hold in infinite loop
    }
  }
  radio.setChannel(90);
  network.begin(/*node address*/ this_node);
}

bool sending = 1;

void loop() {

  if(Serial.available()){
    char c = Serial.read();
    if(c == 'g'){
      sending = 1;
    }else
    if(c == 's'){
      sending = 0;
    }
  }


  network.update();  // Check the network regularly

  unsigned long now = millis();

  // If it's time to send a message, send it!
  if (now - last_sent >= interval) {
    last_sent = now;
    if(sending){
    Serial.print(F("Sending... "));
    payload_t payload = { millis(), packets_sent++ };
    RF24NetworkHeader header(/*to node*/ other_node);
    bool ok = network.write(header, &payload, sizeof(payload));
    Serial.println(ok ? F("ok.") : F("failed."));
    }
  }

  while (network.available()) {  // Is there anything ready for us?

    RF24NetworkHeader header;  // If so, grab it and print it out
    
    network.read(header, 0, 0);
    Serial.println(F("Received packet: counter="));

  }

}

and in the receiver example I modified mainly the below:

        switch (header.type) {
            case 'C': // 'C' is the command message type
                Serial.println("NRF24 Network: Command received from master node.");
                return true;
            case 'S':
                Serial.println("NRF24 Network: Settings received from master node.");
                break;
            default: Serial.println("xD"); break;
        }

I will do this

Works fine with an Arduino uno as master

@mirhamza708
Copy link
Author

mirhamza708 commented Jan 4, 2025

image

when the node is in delay then it just fails to transmit. but after stoppin master the node works fine

image

but there is one issue: the node can't send to master when master is bombarding with messages.

image

@TMRh20
Copy link
Member

TMRh20 commented Jan 4, 2025

Can you confirm that powering off the Orange Pi AND disconnecting the radio from the Orange Pi results in the same behavior with your original code?

@mirhamza708
Copy link
Author

Can you confirm that powering off the Orange Pi AND disconnecting the radio from the Orange Pi results in the same behavior with your original code?

working on it

@2bndy5
Copy link
Member

2bndy5 commented Jan 4, 2025

I suspected a hardware problem from the start, but it is strange to see it in the network layer. Usually hardware errors annoyingly surface when using the core layer (RF24 lib). Have we checked behavior in that layer first? The payloads aren't big enough to need fragmentation, so recreating this with only RF24 layer shouldn't be too hard.

If it is not a hardware error, then some kind of memory leak might be preventing available() from returning accurately. The internal pointer doesn't seem to be misused in a way that would cause this problem.

@mirhamza708 You could try reusing a globally/statically allocated buffer instead of declaring the buffer every time you need one. Or use a data structure like we do in some RF24 examples (see RF24/examples/multiceiverDemo.ino)...

@TMRh20
Copy link
Member

TMRh20 commented Jan 7, 2025

@mirhamza708 Any luck or progress on this issue?

@mirhamza708
Copy link
Author

Shit man I was busy couldn't get my hands on it. Let me update you in a while.

@mirhamza708
Copy link
Author

Can you confirm that powering off the Orange Pi AND disconnecting the radio from the Orange Pi results in the same behavior with your original code?

So I completely removed the nrf24 from master and the node is still receiving messages this is the code of the node

#include <Arduino.h>
#include <RF24.h>
#include <RF24Network.h>

const uint8_t STATUS_LED = PC13; ///< Pin for nRF24 CSN

HardwareSerial Serial1(USART1);

const uint8_t NRF_CE_PIN = PB0; ///< Pin for nRF24 CE
const uint8_t NRF_CSN_PIN = PB1; ///< Pin for nRF24 CSN

unsigned long lastDataSendTime = 0; ///< Last time data was sent to the master node
RF24 radio(NRF_CE_PIN, NRF_CSN_PIN);
RF24Network network(radio);

void sendData(const uint8_t* buffer, size_t bufferSize) {
    RF24NetworkHeader header(00, 'D'); // 'D' is the message type
    Serial.print("Size of buffer: ");
    Serial.println(bufferSize);
    
    // Write the buffer to the network
    bool success = network.write(header, buffer, bufferSize);

    if (success) {
        Serial.println("NRF24 Network: Data sent to master node.");
    } else {
        Serial.println("NRF24 Network: Failed to send data.");
    }
}

bool receiveCommand(void) {
    network.update();
    
    while (network.available()) {
        RF24NetworkHeader header;
        uint16_t payloadSize = network.peek(header);     // Use peek() to get the size of the payload
        uint8_t buffer[payloadSize]; // Adjusted to the size of the expected command payload (6 bytes)
        // Read the data into the temporary buffer
        network.read(header, buffer, payloadSize);

        // Check if the message type matches the command type 'C'
        switch (header.type) {
            case 'C': // 'C' is the command message type
                Serial.println("NRF24 Network: Command received from master node.");
                return true;
            case 'S':
                Serial.println("NRF24 Network: Settings received from master node.");
                break;
            default: Serial.println("xD"); break;
        }
    }
    return false;
}

void setup() {
    Serial.begin(57600);
    Serial.setTimeout(1000);
    pinMode(STATUS_LED, OUTPUT);
    delay(2000);

    if (radio.begin()) {
        network.begin(90, 01); // 90 is the RF24 channel
        radio.setPALevel(RF24_PA_LOW);  // Adjust power level as needed
        radio.setDataRate(RF24_1MBPS);  // 1Mbps for better range
        Serial.println("NRF24 Network: Initialized successfully.");
    } else {
        Serial.println("NRF24 Network: Failed to initialize radio hardware. Check connections.");
    }
}

void loop() {

    if (millis() - lastDataSendTime >= 5000) {
        lastDataSendTime = millis();
        uint8_t buffer[18];  // Increase the buffer size to 17 to accommodate roomTemperature
        buffer[0] = 1;
        uint64_t some_data = 0x1234567812345678;
        memcpy(&buffer[1], &some_data, sizeof(some_data));

        buffer[9] = 12;
        buffer[10] = 34;
        buffer[11] = 2;
        buffer[12] = 2;
        buffer[13] = 2;
        buffer[14] = 2;
        buffer[15] = 22;
        buffer[16] = 22;
        buffer[17] = 2;

        sendData(buffer, sizeof(buffer));
    }

    receiveCommand();
    delay(500); // after adding this delay the network.available keeps returning true
}

@TMRh20
Copy link
Member

TMRh20 commented Jan 7, 2025

I was able to recreate this behavior between Arduino Due and Arduino Nano with the following as TX:

/**

#include <SPI.h>
#include <RF24.h>
#include <RF24Network.h>

RF24 radio(7, 8);  // nRF24L01(+) radio attached using Getting Started board

RF24Network network(radio);  // Network uses that radio

const uint16_t this_node = 00;   // Address of our node in Octal format
const uint16_t other_node = 01;  // Address of the other node in Octal format

const unsigned long interval = 50;  // How often (in ms) to send 'hello world' to the other unit

unsigned long last_sent;     // When did we last send?
unsigned long packets_sent;  // How many have we sent already

//data1 = 1
//                data2 = 2
//                data3 = 2
//                data4 = 22
//                # Prepare the payload
//                payload = struct.pack("<BBBB", data1, data2, data3, data4)

struct payload_t {  // Structure of our payload
  uint8_t data1 = 1;
  uint8_t data2 = 2;
  uint8_t data3 = 2;
  uint8_t data4 = 22;
};

void setup(void) {
  Serial.begin(115200);
  while (!Serial) {
    // some boards need this because of native USB capability
  }
  Serial.println(F("RF24Network/examples/helloworld_tx/"));

  if (!radio.begin()) {
    Serial.println(F("Radio hardware not responding!"));
    while (1) {
      // hold in infinite loop
    }
  }
  radio.setChannel(90);
  network.begin(/*node address*/ this_node);
}


bool send = 1; 

void loop() {
   
   if(Serial.available()){
     char c = Serial.read();
     if(c == 'g'){
      send = 1;
     }else
     if(c == 's'){
      send = 0;
     }
   }
   



  network.update();  // Check the network regularly

  unsigned long now = millis();

  // If it's time to send a message, send it!
  if (now - last_sent >= interval && send) {
    last_sent = now;

    Serial.print(F("Sending... "));
    //payload_t payload = { millis(), packets_sent++ };
    payload_t payload;
    RF24NetworkHeader header(/*to node*/ other_node, 'C');
    bool ok = network.write(header, &payload, sizeof(payload));
    Serial.println(ok ? F("ok.") : F("failed."));
  }
}

Houston, we've had a problem...

This is going to take some debugging to fix.

@TMRh20 TMRh20 added bug and removed question labels Jan 7, 2025
@TMRh20
Copy link
Member

TMRh20 commented Jan 7, 2025

https://github.com/nRF24/RF24Network/blob/master/RF24Network.cpp#L518

I think this should be if (message_size + (next_frame - frame_queue) <= MAX_PAYLOAD_SIZE) {

Are you able to test this change out @mirhamza708 ?

@mirhamza708
Copy link
Author

mirhamza708 commented Jan 7, 2025

https://github.com/nRF24/RF24Network/blob/master/RF24Network.cpp#L518

I think this should be if (message_size + (next_frame - frame_queue) <= MAX_PAYLOAD_SIZE) {

Are you able to test this change out @mirhamza708 ?

Yeah just checked it, resolves the issue, but need to test more.

@mirhamza708
Copy link
Author

2025-01-07 12:37:13,087 - INFO - Message sent to node 1.
2025-01-07 12:37:13,190 - INFO - Message sent to node 1.
2025-01-07 12:37:13,296 - INFO - Message sent to node 1.
2025-01-07 12:37:13,431 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:13,536 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:13,608 - INFO - Message sent to node 1.
2025-01-07 12:37:13,715 - INFO - Message sent to node 1.
2025-01-07 12:37:13,818 - INFO - Message sent to node 1.
2025-01-07 12:37:13,952 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:14,057 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:14,130 - INFO - Message sent to node 1.
2025-01-07 12:37:14,234 - INFO - Message sent to node 1.
2025-01-07 12:37:14,337 - INFO - Message sent to node 1.
2025-01-07 12:37:14,472 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:14,576 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:14,649 - INFO - Message sent to node 1.
2025-01-07 12:37:14,759 - INFO - Message sent to node 1.
2025-01-07 12:37:14,854 - INFO - Message sent to node 1.
2025-01-07 12:37:14,991 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:15,097 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:15,173 - INFO - Message sent to node 1.
2025-01-07 12:37:15,278 - INFO - Message sent to node 1.
2025-01-07 12:37:15,382 - INFO - Message sent to node 1.
2025-01-07 12:37:15,517 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:15,611 - INFO - Message sent to node 1.
2025-01-07 12:37:15,696 - INFO - Message sent to node 1.
2025-01-07 12:37:15,799 - INFO - Message sent to node 1.
2025-01-07 12:37:15,933 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:16,038 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:16,111 - INFO - Message sent to node 1.
2025-01-07 12:37:16,215 - INFO - Message sent to node 1.
2025-01-07 12:37:16,318 - INFO - Message sent to node 1.
2025-01-07 12:37:16,453 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:16,557 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:16,630 - INFO - Message sent to node 1.
2025-01-07 12:37:16,734 - INFO - Message sent to node 1.
2025-01-07 12:37:16,843 - INFO - Message sent to node 1.
2025-01-07 12:37:16,977 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:17,082 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:17,160 - INFO - Message sent to node 1.
2025-01-07 12:37:17,269 - INFO - Message sent to node 1.
2025-01-07 12:37:17,375 - INFO - Message sent to node 1.
2025-01-07 12:37:17,512 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:17,606 - INFO - Message sent to node 1.
2025-01-07 12:37:17,692 - INFO - Message sent to node 1.
2025-01-07 12:37:17,797 - INFO - Message sent to node 1.
2025-01-07 12:37:17,933 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:18,039 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:18,116 - INFO - Message sent to node 1.
2025-01-07 12:37:18,225 - INFO - Message sent to node 1.
2025-01-07 12:37:18,335 - INFO - Message sent to node 1.
2025-01-07 12:37:18,471 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:18,578 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:18,653 - INFO - Message sent to node 1.
2025-01-07 12:37:18,758 - INFO - Message sent to node 1.
2025-01-07 12:37:18,864 - INFO - Message sent to node 1.
2025-01-07 12:37:18,999 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:19,103 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:19,176 - INFO - Message sent to node 1.
2025-01-07 12:37:19,282 - INFO - Message sent to node 1.
2025-01-07 12:37:19,389 - INFO - Message sent to node 1.
2025-01-07 12:37:19,524 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:19,628 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:19,703 - INFO - Message sent to node 1.
2025-01-07 12:37:19,809 - INFO - Message sent to node 1.
2025-01-07 12:37:19,914 - INFO - Message sent to node 1.
2025-01-07 12:37:20,048 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:20,139 - INFO - Message sent to node 1.
2025-01-07 12:37:20,225 - INFO - Message sent to node 1.
2025-01-07 12:37:20,328 - INFO - Message sent to node 1.
2025-01-07 12:37:20,463 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:20,567 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:20,643 - INFO - Message sent to node 1.
2025-01-07 12:37:20,749 - INFO - Message sent to node 1.
2025-01-07 12:37:20,861 - INFO - Message sent to node 1.
2025-01-07 12:37:20,988 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:21,094 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:21,168 - INFO - Message sent to node 1.
2025-01-07 12:37:21,272 - INFO - Message sent to node 1.
2025-01-07 12:37:21,375 - INFO - Message sent to node 1.
2025-01-07 12:37:21,512 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:21,618 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:21,692 - INFO - Message sent to node 1.
2025-01-07 12:37:21,800 - INFO - Message sent to node 1.
2025-01-07 12:37:21,905 - INFO - Message sent to node 1.
2025-01-07 12:37:22,039 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:22,139 - INFO - Message sent to node 1.
2025-01-07 12:37:22,222 - INFO - Message sent to node 1.
2025-01-07 12:37:22,326 - INFO - Message sent to node 1.
2025-01-07 12:37:22,461 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:22,566 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:22,642 - INFO - Message sent to node 1.
2025-01-07 12:37:22,748 - INFO - Message sent to node 1.
2025-01-07 12:37:22,851 - INFO - Message sent to node 1.
2025-01-07 12:37:22,986 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:23,091 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:23,163 - INFO - Message sent to node 1.
2025-01-07 12:37:23,268 - INFO - Message sent to node 1.
2025-01-07 12:37:23,370 - INFO - Message sent to node 1.
2025-01-07 12:37:23,505 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:23,610 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:23,687 - INFO - Message sent to node 1.
2025-01-07 12:37:23,793 - INFO - Message sent to node 1.
2025-01-07 12:37:23,900 - INFO - Message sent to node 1.
2025-01-07 12:37:24,037 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,142 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,248 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,353 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,457 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,562 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,666 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,771 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,876 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,980 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,085 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,190 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,294 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,399 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,503 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,608 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,713 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,817 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,922 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,027 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,131 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,236 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,341 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,446 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,551 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,656 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,760 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,865 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,969 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,074 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,179 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,283 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,388 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,492 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,597 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,702 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,806 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,911 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,015 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,120 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,225 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,329 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,434 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,539 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,645 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,750 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,855 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,959 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,064 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,168 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,273 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,378 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,482 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,587 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,692 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,796 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,901 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,005 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,110 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,215 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,319 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,424 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,528 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,633 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,738 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,844 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,949 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,053 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,158 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,263 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,367 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,472 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,577 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,681 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,786 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,890 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,995 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,100 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,204 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,309 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,413 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,518 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,623 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,727 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,832 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,937 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,043 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,148 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,252 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,357 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,462 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,566 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,671 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,776 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,880 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,985 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:34,089 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:34,194 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:34,299 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:34,403 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:34,508 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:34,612 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:34,717 - ERROR - Failed to send message to node 1.

Somehow after sending these messages the master node keeps failing. Restarting the app resolves the issue.

@mirhamza708
Copy link
Author

https://github.com/nRF24/RF24Network/blob/master/RF24Network.cpp#L518

I think this should be if (message_size + (next_frame - frame_queue) <= MAX_PAYLOAD_SIZE) {

Are you able to test this change out @mirhamza708 ?

Works fine with my setup.

@mirhamza708
Copy link
Author

2025-01-07 12:37:13,087 - INFO - Message sent to node 1.
2025-01-07 12:37:13,190 - INFO - Message sent to node 1.
2025-01-07 12:37:13,296 - INFO - Message sent to node 1.
2025-01-07 12:37:13,431 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:13,536 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:13,608 - INFO - Message sent to node 1.
2025-01-07 12:37:13,715 - INFO - Message sent to node 1.
2025-01-07 12:37:13,818 - INFO - Message sent to node 1.
2025-01-07 12:37:13,952 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:14,057 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:14,130 - INFO - Message sent to node 1.
2025-01-07 12:37:14,234 - INFO - Message sent to node 1.
2025-01-07 12:37:14,337 - INFO - Message sent to node 1.
2025-01-07 12:37:14,472 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:14,576 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:14,649 - INFO - Message sent to node 1.
2025-01-07 12:37:14,759 - INFO - Message sent to node 1.
2025-01-07 12:37:14,854 - INFO - Message sent to node 1.
2025-01-07 12:37:14,991 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:15,097 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:15,173 - INFO - Message sent to node 1.
2025-01-07 12:37:15,278 - INFO - Message sent to node 1.
2025-01-07 12:37:15,382 - INFO - Message sent to node 1.
2025-01-07 12:37:15,517 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:15,611 - INFO - Message sent to node 1.
2025-01-07 12:37:15,696 - INFO - Message sent to node 1.
2025-01-07 12:37:15,799 - INFO - Message sent to node 1.
2025-01-07 12:37:15,933 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:16,038 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:16,111 - INFO - Message sent to node 1.
2025-01-07 12:37:16,215 - INFO - Message sent to node 1.
2025-01-07 12:37:16,318 - INFO - Message sent to node 1.
2025-01-07 12:37:16,453 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:16,557 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:16,630 - INFO - Message sent to node 1.
2025-01-07 12:37:16,734 - INFO - Message sent to node 1.
2025-01-07 12:37:16,843 - INFO - Message sent to node 1.
2025-01-07 12:37:16,977 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:17,082 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:17,160 - INFO - Message sent to node 1.
2025-01-07 12:37:17,269 - INFO - Message sent to node 1.
2025-01-07 12:37:17,375 - INFO - Message sent to node 1.
2025-01-07 12:37:17,512 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:17,606 - INFO - Message sent to node 1.
2025-01-07 12:37:17,692 - INFO - Message sent to node 1.
2025-01-07 12:37:17,797 - INFO - Message sent to node 1.
2025-01-07 12:37:17,933 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:18,039 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:18,116 - INFO - Message sent to node 1.
2025-01-07 12:37:18,225 - INFO - Message sent to node 1.
2025-01-07 12:37:18,335 - INFO - Message sent to node 1.
2025-01-07 12:37:18,471 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:18,578 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:18,653 - INFO - Message sent to node 1.
2025-01-07 12:37:18,758 - INFO - Message sent to node 1.
2025-01-07 12:37:18,864 - INFO - Message sent to node 1.
2025-01-07 12:37:18,999 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:19,103 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:19,176 - INFO - Message sent to node 1.
2025-01-07 12:37:19,282 - INFO - Message sent to node 1.
2025-01-07 12:37:19,389 - INFO - Message sent to node 1.
2025-01-07 12:37:19,524 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:19,628 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:19,703 - INFO - Message sent to node 1.
2025-01-07 12:37:19,809 - INFO - Message sent to node 1.
2025-01-07 12:37:19,914 - INFO - Message sent to node 1.
2025-01-07 12:37:20,048 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:20,139 - INFO - Message sent to node 1.
2025-01-07 12:37:20,225 - INFO - Message sent to node 1.
2025-01-07 12:37:20,328 - INFO - Message sent to node 1.
2025-01-07 12:37:20,463 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:20,567 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:20,643 - INFO - Message sent to node 1.
2025-01-07 12:37:20,749 - INFO - Message sent to node 1.
2025-01-07 12:37:20,861 - INFO - Message sent to node 1.
2025-01-07 12:37:20,988 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:21,094 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:21,168 - INFO - Message sent to node 1.
2025-01-07 12:37:21,272 - INFO - Message sent to node 1.
2025-01-07 12:37:21,375 - INFO - Message sent to node 1.
2025-01-07 12:37:21,512 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:21,618 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:21,692 - INFO - Message sent to node 1.
2025-01-07 12:37:21,800 - INFO - Message sent to node 1.
2025-01-07 12:37:21,905 - INFO - Message sent to node 1.
2025-01-07 12:37:22,039 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:22,139 - INFO - Message sent to node 1.
2025-01-07 12:37:22,222 - INFO - Message sent to node 1.
2025-01-07 12:37:22,326 - INFO - Message sent to node 1.
2025-01-07 12:37:22,461 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:22,566 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:22,642 - INFO - Message sent to node 1.
2025-01-07 12:37:22,748 - INFO - Message sent to node 1.
2025-01-07 12:37:22,851 - INFO - Message sent to node 1.
2025-01-07 12:37:22,986 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:23,091 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:23,163 - INFO - Message sent to node 1.
2025-01-07 12:37:23,268 - INFO - Message sent to node 1.
2025-01-07 12:37:23,370 - INFO - Message sent to node 1.
2025-01-07 12:37:23,505 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:23,610 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:23,687 - INFO - Message sent to node 1.
2025-01-07 12:37:23,793 - INFO - Message sent to node 1.
2025-01-07 12:37:23,900 - INFO - Message sent to node 1.
2025-01-07 12:37:24,037 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,142 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,248 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,353 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,457 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,562 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,666 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,771 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,876 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,980 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,085 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,190 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,294 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,399 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,503 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,608 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,713 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,817 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,922 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,027 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,131 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,236 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,341 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,446 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,551 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,656 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,760 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,865 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,969 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,074 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,179 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,283 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,388 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,492 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,597 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,702 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,806 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,911 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,015 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,120 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,225 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,329 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,434 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,539 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,645 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,750 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,855 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,959 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,064 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,168 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,273 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,378 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,482 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,587 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,692 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,796 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,901 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,005 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,110 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,215 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,319 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,424 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,528 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,633 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,738 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,844 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,949 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,053 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,158 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,263 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,367 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,472 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,577 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,681 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,786 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,890 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,995 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,100 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,204 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,309 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,413 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,518 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,623 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,727 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,832 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,937 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,043 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,148 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,252 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,357 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,462 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,566 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,671 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,776 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,880 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,985 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:34,089 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:34,194 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:34,299 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:34,403 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:34,508 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:34,612 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:34,717 - ERROR - Failed to send message to node 1.

Somehow after sending these messages the master node keeps failing. Restarting the app resolves the issue.

This is not after the change this was there even before the change.

@TMRh20
Copy link
Member

TMRh20 commented Jan 7, 2025

Lol more issues?

Can you include something like if (radio.failureDetected > 0 || radio.getDataRate() != RF24_1MBPS) but in python, to see if you are encountering radio errors on the OrangePi side of things?

@mirhamza708
Copy link
Author

        if self.radio.failureDetected > 0 or self.radio.getDataRate() != RF24_1MBPS:
            return True
        return False

I don't know this always returns true is this correct python implementation?

TMRh20 added a commit that referenced this issue Jan 7, 2025
Per #242 fix buffer overrun
@2bndy5
Copy link
Member

2bndy5 commented Jan 7, 2025

Python looks right. You will find more details of in the pyrf24 API docs.

@2bndy5
Copy link
Member

2bndy5 commented Jan 7, 2025

2025-01-07 12:37:14,649 - INFO - Message sent to node 1.
2025-01-07 12:37:14,759 - INFO - Message sent to node 1.
2025-01-07 12:37:14,854 - INFO - Message sent to node 1.
2025-01-07 12:37:14,991 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:15,097 - ERROR - Failed to send message to node 1.

This looks to me like the receiver's RX FIFO is getting full and it takes the time of 2 failed transmissions to free up it's RX FIFO.

@TMRh20
Copy link
Member

TMRh20 commented Jan 7, 2025

That is odd. Maybe try just if self.radio.failureDetected > 0 ?

I would like to somehow isolate the problem to either the Orange Pi or the STM32. It works for me, so not quite sure how to address this problem yet.

@mirhamza708
Copy link
Author

This always returned 1 for failureDetected. The self.radio.getDataRate() reads 1MBPS.

    def radio_failure_check(self):
        """
        Check if there were any radio failures
        """
        # if self.radio.failureDetected > 0:
        #    return 1
        if self.radio.getDataRate() != RF24_1MBPS:
            return 2
        return 0

@mirhamza708
Copy link
Author

2025-01-07 12:37:13,087 - INFO - Message sent to node 1.
2025-01-07 12:37:13,190 - INFO - Message sent to node 1.
2025-01-07 12:37:13,296 - INFO - Message sent to node 1.
2025-01-07 12:37:13,431 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:13,536 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:13,608 - INFO - Message sent to node 1.
2025-01-07 12:37:13,715 - INFO - Message sent to node 1.
2025-01-07 12:37:13,818 - INFO - Message sent to node 1.
2025-01-07 12:37:13,952 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:14,057 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:14,130 - INFO - Message sent to node 1.
2025-01-07 12:37:14,234 - INFO - Message sent to node 1.
2025-01-07 12:37:14,337 - INFO - Message sent to node 1.
2025-01-07 12:37:14,472 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:14,576 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:14,649 - INFO - Message sent to node 1.
2025-01-07 12:37:14,759 - INFO - Message sent to node 1.
2025-01-07 12:37:14,854 - INFO - Message sent to node 1.
2025-01-07 12:37:14,991 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:15,097 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:15,173 - INFO - Message sent to node 1.
2025-01-07 12:37:15,278 - INFO - Message sent to node 1.
2025-01-07 12:37:15,382 - INFO - Message sent to node 1.
2025-01-07 12:37:15,517 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:15,611 - INFO - Message sent to node 1.
2025-01-07 12:37:15,696 - INFO - Message sent to node 1.
2025-01-07 12:37:15,799 - INFO - Message sent to node 1.
2025-01-07 12:37:15,933 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:16,038 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:16,111 - INFO - Message sent to node 1.
2025-01-07 12:37:16,215 - INFO - Message sent to node 1.
2025-01-07 12:37:16,318 - INFO - Message sent to node 1.
2025-01-07 12:37:16,453 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:16,557 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:16,630 - INFO - Message sent to node 1.
2025-01-07 12:37:16,734 - INFO - Message sent to node 1.
2025-01-07 12:37:16,843 - INFO - Message sent to node 1.
2025-01-07 12:37:16,977 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:17,082 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:17,160 - INFO - Message sent to node 1.
2025-01-07 12:37:17,269 - INFO - Message sent to node 1.
2025-01-07 12:37:17,375 - INFO - Message sent to node 1.
2025-01-07 12:37:17,512 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:17,606 - INFO - Message sent to node 1.
2025-01-07 12:37:17,692 - INFO - Message sent to node 1.
2025-01-07 12:37:17,797 - INFO - Message sent to node 1.
2025-01-07 12:37:17,933 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:18,039 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:18,116 - INFO - Message sent to node 1.
2025-01-07 12:37:18,225 - INFO - Message sent to node 1.
2025-01-07 12:37:18,335 - INFO - Message sent to node 1.
2025-01-07 12:37:18,471 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:18,578 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:18,653 - INFO - Message sent to node 1.
2025-01-07 12:37:18,758 - INFO - Message sent to node 1.
2025-01-07 12:37:18,864 - INFO - Message sent to node 1.
2025-01-07 12:37:18,999 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:19,103 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:19,176 - INFO - Message sent to node 1.
2025-01-07 12:37:19,282 - INFO - Message sent to node 1.
2025-01-07 12:37:19,389 - INFO - Message sent to node 1.
2025-01-07 12:37:19,524 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:19,628 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:19,703 - INFO - Message sent to node 1.
2025-01-07 12:37:19,809 - INFO - Message sent to node 1.
2025-01-07 12:37:19,914 - INFO - Message sent to node 1.
2025-01-07 12:37:20,048 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:20,139 - INFO - Message sent to node 1.
2025-01-07 12:37:20,225 - INFO - Message sent to node 1.
2025-01-07 12:37:20,328 - INFO - Message sent to node 1.
2025-01-07 12:37:20,463 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:20,567 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:20,643 - INFO - Message sent to node 1.
2025-01-07 12:37:20,749 - INFO - Message sent to node 1.
2025-01-07 12:37:20,861 - INFO - Message sent to node 1.
2025-01-07 12:37:20,988 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:21,094 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:21,168 - INFO - Message sent to node 1.
2025-01-07 12:37:21,272 - INFO - Message sent to node 1.
2025-01-07 12:37:21,375 - INFO - Message sent to node 1.
2025-01-07 12:37:21,512 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:21,618 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:21,692 - INFO - Message sent to node 1.
2025-01-07 12:37:21,800 - INFO - Message sent to node 1.
2025-01-07 12:37:21,905 - INFO - Message sent to node 1.
2025-01-07 12:37:22,039 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:22,139 - INFO - Message sent to node 1.
2025-01-07 12:37:22,222 - INFO - Message sent to node 1.
2025-01-07 12:37:22,326 - INFO - Message sent to node 1.
2025-01-07 12:37:22,461 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:22,566 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:22,642 - INFO - Message sent to node 1.
2025-01-07 12:37:22,748 - INFO - Message sent to node 1.
2025-01-07 12:37:22,851 - INFO - Message sent to node 1.
2025-01-07 12:37:22,986 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:23,091 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:23,163 - INFO - Message sent to node 1.
2025-01-07 12:37:23,268 - INFO - Message sent to node 1.
2025-01-07 12:37:23,370 - INFO - Message sent to node 1.
2025-01-07 12:37:23,505 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:23,610 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:23,687 - INFO - Message sent to node 1.
2025-01-07 12:37:23,793 - INFO - Message sent to node 1.
2025-01-07 12:37:23,900 - INFO - Message sent to node 1.
2025-01-07 12:37:24,037 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,142 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,248 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,353 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,457 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,562 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,666 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,771 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,876 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:24,980 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,085 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,190 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,294 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,399 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,503 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,608 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,713 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,817 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:25,922 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,027 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,131 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,236 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,341 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,446 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,551 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,656 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,760 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,865 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:26,969 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,074 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,179 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,283 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,388 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,492 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,597 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,702 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,806 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:27,911 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,015 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,120 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,225 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,329 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,434 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,539 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,645 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,750 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,855 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:28,959 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,064 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,168 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,273 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,378 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,482 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,587 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,692 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,796 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:29,901 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,005 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,110 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,215 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,319 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,424 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,528 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,633 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,738 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,844 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:30,949 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,053 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,158 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,263 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,367 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,472 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,577 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,681 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,786 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,890 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:31,995 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,100 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,204 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,309 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,413 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,518 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,623 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,727 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,832 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:32,937 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,043 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,148 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,252 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,357 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,462 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,566 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,671 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,776 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,880 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:33,985 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:34,089 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:34,194 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:34,299 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:34,403 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:34,508 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:34,612 - ERROR - Failed to send message to node 1.
2025-01-07 12:37:34,717 - ERROR - Failed to send message to node 1.

Somehow after sending these messages the master node keeps failing. Restarting the app resolves the issue.

This is not after the change this was there even before the change.

there was a mistake in this from my side, it works now. The only issue is that the self.radio.failureDetected always return greater than zero.

@TMRh20
Copy link
Member

TMRh20 commented Jan 8, 2025

How about using something like the following, again though in python:

if(radio.failureDetected) {
  radio.begin();
  radio.setChannel(90);
  network.begin();
  radio.failureDetected = 0;
  Serial.println("Failure Detected");
}

Wondering if you really are getting failures, or if there is something wrong in the code. Will this print "Failure Detected" in rapid succession, or will it be intermittent or go away entirely?

@mirhamza708
Copy link
Author

mirhamza708 commented Jan 8, 2025

Setting the radio.failureDetected = 0 at init solves the issue but is it updated internally or not, meaning that does this really detect radio errors?

class NRF24Handler:
    def __init__(self, this_node, channel=90, ce_pin=8, csn_pin=10):
        self.radio = RF24(ce_pin, csn_pin, 8000000)
        self.network = RF24Network(self.radio)
        self.this_node = this_node
        self.channel = channel
        self.lock = threading.Lock()  # Add a threading lock

        # Initialize the radio and network
        if not self.radio.begin():
            raise OSError("nRF24L01 hardware isn't responding")
        self.radio.channel = self.channel
        self.network.begin(self.this_node)
        self.radio.print_pretty_details()
        logger.info(f"radio.failureDetected={self.radio.failureDetected}")
        self.radio.failureDetected = 0
================ SPI Configuration ================
CSN Pin                 = /dev/spidev1.0
CE Pin                  = Custom GPIO8
SPI Frequency           = 8 Mhz
================ NRF Configuration ================
Channel                 = 90 (~ 2490 MHz)
Model                   = nRF24L01+
RF Data Rate            = 1 MBPS
RF Power Amplifier      = PA_MAX
RF Low Noise Amplifier  = Enabled
CRC Length              = 16 bits
Address Length          = 5 bytes
Static Payload Length   = 32 bytes
Auto Retry Delay        = 1500 microseconds
Auto Retry Attempts     = 5 maximum
Packets lost on
    current channel     = 0
Retry attempts made for
    last transmission   = 0
Multicast               = Disabled
Custom ACK Payload      = Disabled
Dynamic Payloads        = Enabled
Auto Acknowledgment     = 0b111110
Primary Mode            = RX
TX address              = 0xcccccc3ce3
pipe 0 ( open ) bound   = 0xccccccccc3
pipe 1 ( open ) bound   = 0xcccccccc3c
pipe 2 ( open ) bound   = 0x33
pipe 3 ( open ) bound   = 0xce
pipe 4 ( open ) bound   = 0x3e
pipe 5 ( open ) bound   = 0xe3
2025-01-08 10:43:55,299 - INFO - radio.failureDetected=True

@TMRh20
Copy link
Member

TMRh20 commented Jan 8, 2025

Hmm, I think now this is just because the failureDetected var is not initialized in the library at runtime. Something we should correct.

It uses a simple timer to detect timeouts in SPI communication. So if the radio is unresponsive via SPI, the failureDetected will return true. Sometimes SPI does give data, but it is garbage data, so I typically check in internal variable like the dataRate as well, in attempts to correct all SPI/radio errors.

@mirhamza708
Copy link
Author

I would like to correct/contribute to it but I don't understand how the python code is written I see cpp files in the pyrf24 repo all around so I guess I will have to wait for your update. Thanks guys 👍

@TMRh20
Copy link
Member

TMRh20 commented Jan 8, 2025

Basically, to fix temporarily you can initialize failureDetected to 0 like you are doing. It should still work afterwards. I will go ahead an open an issue on your behalf to fix it.

Thanks alot for identifying these issues! It helps to have really good info and communication when trying to figure out what exactly is going on.

@TMRh20 TMRh20 closed this as completed Jan 8, 2025
TMRh20 added a commit that referenced this issue Jan 10, 2025
Issue identified by @mirhamza708

* Fix buffering of user payloads: Per #242 fix buffer overrun
* Mods to #243 per @2bndy5
2bndy5 pushed a commit that referenced this issue Jan 10, 2025
Issue identified by @mirhamza708

* Fix buffering of user payloads: Per #242 fix buffer overrun
* Mods to #243 per @2bndy5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants