natevw / node-nrf

Pure-JavaScript nRF24L01 driver library
117 stars 31 forks source link

Unable to open 3 rx pipes at once #17

Closed Mrono closed 10 years ago

Mrono commented 10 years ago

When I open the third I get

/home/pi/node_modules/nrf/index.js:441
            else throw Error("No more "+aw+"-byte listener addresses available
                       ^
Error: No more 5-byte listener addresses available!
    at Error (<anonymous>)
    at slotForAddr (/home/pi/node_modules/nrf/index.js:441:24)
    at EventEmitter.nrf.openPipe (/home/pi/node_modules/nrf/index.js:453:21)
    at EventEmitter.<anonymous> (/home/pi/hub.js:12:23)
    at EventEmitter.g (events.js:180:16)
    at EventEmitter.emit (events.js:92:17)
    at /home/pi/node_modules/nrf/index.js:415:17
    at notify (/home/pi/node_modules/nrf/node_modules/queue-async/queue.js:47:18                                                                                                     )
    at /home/pi/node_modules/nrf/node_modules/queue-async/queue.js:39:16
    at notify (/home/pi/node_modules/nrf/node_modules/queue-async/queue.js:46:21                                                                                                     )

I'm also seeing the issue referenced in #2

natevw commented 10 years ago

It looks like you are trying to reserve more than two 5-byte-wide addresses. Here's how I tried to explain it in the docs:

Basically for 'rx' pipes, pass a 3, 4 or 5 byte Buffer the first time you call it, and it will be assigned a hardware pipe number automatically. Subsequent calls should ideally be single-byte Buffers only, representing the least significant byte in the address of up to four more pipes. If you open another pipe with a 3/4/5-byte address instead (or additionally), be aware that you may miss packets in certain situations.

Put differently: you can only reserve 2 RX pipes with 5-byte addresses [only one is recommended, if you are also using TX]; the other RX pipes should be opened with a 1-byte buffer suffix only. The limitation is kind of weird, but comes from the hardware itself.

[The current workaround for #2 is to open pipes after a little setTimeout (e.g. 250ms or so); that's something I hope to fix relatively soon.]

Mrono commented 10 years ago

I've found a way to work around this in the last 20min

var stream = require('stream'),
    pipes = [0xF0F0F0A0A1, 0xA2, 0xA3, 0xA4, 0xA5],
    nrf = require('nrf').connect('/dev/spidev0.0', 25, 24);

nrf.channel(0x07).dataRate('1Mbps').crcBytes(2).begin(function () {
    pipes.forEach(function (pipe, id)
    {
        setTimeout(function() { nrf.openPipe('rx', pipe).on('data', function (d){ handle(d, id+1) });},id+'00');
    });
});

function handle (d, id)
{
    var data = JSON.parse(d.toString().split("").reverse().join("").replace(/(\0|\r|\n)?/g, ''));
    data.id = id;
    console.log(data);
}

Why is the 5byte address not an issue when using a C++ lib?

const uint64_t pipes[6] = { 0x7365727631LL, 0xF0F0F0A0A1LL, 0xF0F0F0A0A2LL, 0xF0F0F0A0A3LL, 0xF0F0F0A0A4, 0xF0F0F0A0A5 };
natevw commented 10 years ago

Perhaps the C++ library looks for the common prefix, that might be something we could do but I'm afraid it really wouldn't make the documentation for this limitation much simpler.