jpbarraca / pynrf24

Python port of the RF24 library for NRF24L01+ radios.
GNU General Public License v2.0
152 stars 84 forks source link

openReadingPipe() is limited to two nodes #33

Open MarkusHaberzettl opened 7 years ago

MarkusHaberzettl commented 7 years ago

Hi,

I tried to register two listening-nodes with openReadingPipe(). This raised an "Invalid Address Lenght"-error, even though registering multiple listening-nodes should be possible.

The error is raised in line 625 of the nrf24.py:

def openReadingPipe(self, pipe, address):
        if pipe >= 6:
            raise RuntimeError("Invalid pipe number")
        if (pipe >= 2 and len(address) > 1) or len(address) > 5:
            raise RuntimeError("Invalid adress length") # -> Error occurs here

The if-condition here prevents any openReadingPipe(2, ..) till openReadinPipe(5, ...). But why? In maniacbugs original NRF24-library there is no such restriction

void RF24::openReadingPipe(uint8_t child, uint64_t address)
{
  if (child == 0){
    memcpy(pipe0_reading_address,&address,addr_width);
  }
  if (child <= 6)
  {
    if ( child < 2 )
      write_register(pgm_read_byte(&child_pipe[child]), reinterpret_cast<const uint8_t*>(&address), addr_width);
//--------------- Here is the Relevant Line:
    else
      write_register(pgm_read_byte(&child_pipe[child]), reinterpret_cast<const uint8_t*>(&address), 1);

    write_register(pgm_read_byte(&child_payload_size[child]),payload_size);

    write_register(EN_RXADDR,read_register(EN_RXADDR) | _BV(pgm_read_byte(&child_pipe_enable[child])));
  }
}

Is there a reason for your restriction?