ludiazv / node-nrf24

nRF24 (nrf24l01/nrfl24l01+) radios in the nodejs way
MIT License
39 stars 15 forks source link

How to send big buffers (4000 bytes) #2

Closed tobiasmuecksch closed 6 years ago

tobiasmuecksch commented 6 years ago

Hi @ludiazv,

I'm having a problem. I need to transmit buffers with a size of 4000 bytes. This package can't transmit more than 32 bytes. Do you have any idea or hint how to transmit bigger buffers?

ludiazv commented 6 years ago

32 bytes is hardware limit for a single frame. There is no way to send more than that in a single frame. This is typically called MTU in network protocols. For this radios the MTU is 32.

For sending 4K you need to implement fragmentation of the data in 32bytes chunks/fragments. A simple way could be to add a 2-byte header in your payload with the packet number & data length.

On transmission, split the original buffer in 30 byte chunks, pack each pakcket with the header and write each packet to the radio. You shold implement controlled retry sending each chunk

On the receiver, defragment the sequence controlling the order and the size of each chunk.

tobiasmuecksch commented 6 years ago

@ludiazv Thank you very much for the detailed in-depth answer.

FYI: I'm trying to make an audio transmitter that transmits the microphone signal from a raspberry pi to another raspberry pi. Currently I'm trying to transmit the raw signal, but maybe that won't work.

The maximum speed of this module is 2 Mbps = 250 kB/s am I right? That means 25000 / 32 Byte = ~781 Frames per Second. The raw signal currently is ten times this big.

Conclusion; I have to compress the signal.

ludiazv commented 6 years ago

Audio streaming is possible with this radios. I think that a better approach is not compressing but down-sampling the audio signal and send over the radio allowing some packets to be loss. With compression this could more complex. In principle an audio signal from 13-40khz could be transmited depending on the speed.

Check this information: https://tmrh20.github.io/RF24Audio/

Regards,