Module rf24js wants to be a simple wrapper of RF24C++ library by TMRH20. No logic added, just existing methods wrapped.
The only one dependency is the library it wants to wrapper: RF24. Use the following instructions to compile and install it from sources:
git clone https://github.com/nRF24/RF24.git
cd RF24
make
sudo make install
After RF24 is installed, simple run:
npm install --save rf24js
import {radio, PALevel,CRCLength,Datarate} from 'rf24js'
var rf24js = require('rf24js');
var radio = rf24js.radio;
var PALevel = rf24js.PALevel;
var CRCLength = rf24js.CRCLength;
var Datarate = rf24js.Datarate;
Parameter ce is the mini-pc pin number in with is connected radio chip enable pin.
Parameter cs is a number (byte) to select SPI device in with is connected the radio. In general this parameter is an integer that represent the id, without dot, of the spi devices you find using command ls /dev
. Example: for spidev0.0
CS is 0, for spidev0.1
CS is 1, for spidev1.0
CS is 10, ecc
radio.create(2, 10); // OrangePi-Zero
radio.create(22, 0); // RaspberryPi 1/2/3
radio.begin();
radio.printDetails(); // Optionally: is used to show radio configuration
Declare and open read and write pipes
var pipe1 = new Buffer("1Node\0");
var pipe2 = new Buffer("2Node\0");
radio.openWritingPipe(pipe1);
radio.openReadingPipe(1, pipe2);
Read data
var buffer = null;
if (radio.available())
buffer = radio.read(4);
Write data
var buffer = new Buffer(4).fill(0);
buffer.writeUInt32LE(50);
var success = radio.write(buffer, buffer.length);
In some OS like Raspibian yuo need to start node application as super user.