var SX127x = require('sx127x');
var options = {
// ...
};
var sx127x = new SX127x(options);
Supported options:
Name | Default | Description |
---|---|---|
spiBus |
0 |
SPI bus to use |
spiDevice |
0 |
SPI chip select/enable to use |
resetPin |
24 |
GPIO pin number of reset pin |
dio0Pin |
25 |
GPIO pin number of DIO0 pin |
frequency |
915e6 |
Frequency of radio in Hz, see setFrequency for supported values |
spreadingFactor |
7 |
Spreading factor of radio, see setSpreadingFactor for supported values |
signalBandwidth |
125E3 |
Signal bandwidth of radio in Hz, see setSignalBandwidth for supported values |
codingRate |
4 / 5 |
Coding rate of radio, see setCodingRate for supported values |
preambleLength |
8 |
Preamble length of radio, see setPreambleLength for supported values |
syncWord |
0x12 |
Sync word of radio, see setSyncWord for supported values |
txPower |
17 |
TX power of radio, see setTxPower for supported values |
crc |
false |
Enable or disable CRC usage |
Open and configure the device:
sx127x.open(callback(err));
Close the device:
sx127x.close(callback(err));
var data = new Buffer(/* ... */);
// ...
sx127x.write(data [, implicitHeader, callabck(err)]);
data
- Node.js Buffer containing data to send.implicitHeader
- (optional) iftrue
, sends data in implicit header mode, otherwise explicit header mode is used. Defaults tofalse
.
sx127x.on('data', function(data, rssi, snr) {
// ...
});
sx127x.receive([length, callback(err)]);
length
- (optional) if> 0
, receives data of sizelength
in implicit header mode, otherwise explicit header mode is used. Defaults to0
.
data
event:
data
- Node.js Buffer containing received data.rssi
- RSSI of received data.snr
- SNR of received data.
Put the radio in sleep mode.
sx127x.sleep(callback(err));
Put the radio in idle mode.
sx127x.idle(callback(err));
Change the TX power of the radio.
sx127x.setTxPower(txPower, callback(err));
txPower
- TX power in dB, defaults to17
Supported values are between 2
and 17
.
Change the frequency of the radio.
sx127x.setFrequency(frequency, callback(error));
frequency
- frequency in Hz (433E6
,866E6
,915E6
)
Change the spreading factor of the radio.
sx127x.setSpreadingFactor(spreadingFactor, callback(err));
spreadingFactor
- spreading factor, defaults to7
Supported values are between 6
and 12
. If a spreading factor of 6
is set, implicit header mode must be used to transmit and receive packets.
Change the signal bandwidth of the radio.
sx127x.setSignalBandwidth(signalBandwidth, callback(err));
signalBandwidth
- signal bandwidth in Hz, defaults to125E3
.
Supported values are 7.8E3
, 10.4E3
, 15.6E3
, 20.8E3
, 31.25E3
, 41.7E3
, 62.5E3
, 125E3
, and 250E3
.
Change the coding rate of the radio.
sx127x.setCodingRate4(codingRate, callback(err));
codingRate
- coding rate, defaults to4/5
Supported values are 4/5
, 4/6
, 4/7
and 4/8
.
Change the preamble length of the radio.
sx127x.setPreambleLength(preambleLength, callback(err));
preambleLength
- preamble length in symbols, defaults to8
Supported values are between 6
and 65535
.
Change the sync word of the radio.
sx127x.setSyncWord(syncWord, callback(err));
syncWord
- byte value to use as the sync word, defaults to0x34
Enable or disable CRC usage, by default a CRC is not used.
sx127x.crc(crc, callback(err));
crc
-true
to enable CRC,false
to disable
Generate a random byte, based on the Wideband RSSI measurement.
sx127x.readRandom(callback(err, data));