sx127x-driver
Node.js driver for Semtech SX1276/77/78/79 based LoRa radios.
Based on node-sx127x, built on top of @fivdi's onoff and spi-device modules.
Prerequisites
- Linux
- SPI hardware with driver installed and enabled
- for raspberry pi, uncomment
dtparam=spi=on
in/boot/config.txt
- for raspberry pi, uncomment
- Node.js
Hardware Wiring
Semtech SX1276/77/78/79 | Generic Linux | Raspberry Pi |
---|---|---|
VCC | 3.3V | 3.3V |
GND | GND | GND |
SCK | SCK | SCK (pin 11) |
MISO | MISO | MISO (pin 10) |
MOSI | MOSI | MOSI (pin 9) |
NSS | Chip enable/select | CS0 (pin 8) or CS1 (pin 7) |
NRESET | GPIO pin | GPIO pin |
DIO0 | GPIO pin | GPIO pin |
Installation
npm install sx127x-driver
API
Initialize
let SX127x = ; let options = // ...; let 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 (make sure your chip supports the frequency you chose) |
spreadingFactor |
7 |
Spreading factor of radio, see setSpreadingFactor for supported values (spreading factors are orthogonal, so make sure they match when trying to communicate from one chip to another) |
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 |
tempCompensationFactor |
false |
compensation factor for temperature measurements in degrees celsius (+- some degrees) |
debug |
false |
enable / disable debug output |
invertIqReg |
false |
inverts IQ register on call to open() |
Open
Open and configure the device:
try await sx127x; catcherr console
Close
Close the device:
try await sx127x; catch err console; process;
Sending data
try await sx127x; console catch err console;
Blocking receive
try let packetLength = await sx127x; if packetLength > 0 let incoming = ""; while await sx127x incoming += String; catch err console;
Interrupt receive
try await sx127x; await sx127x; catcherr console sx127x;
Sleep mode
Put the radio in sleep mode.
try await sx127x; catch err console;
Stand by mode
Put the radio in stand by mode.
try await sx127x; catch err console;
Radio parameters
TX Power
Change the TX power of the radio.
try await sx127x; catch err console;
txPower
- TX power in dB, defaults to17
Supported values are between 2
and 17
.
Frequency
Change the frequency of the radio.
try await sx127x; catch err console;
frequency
- frequency in Hz (433E6
,866E6
,915E6
)
Spreading Factor
Change the spreading factor of the radio.
try await sx127x; catch err console;
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.
Signal Bandwidth
Change the signal bandwidth of the radio.
try await sx127x; catch err console;
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
, 250E3
and 500E3
.
Coding Rate
Change the coding rate of the radio.
try await sx127x; catch err console;
codingRate
- coding rate, defaults to4/5
Supported values are 4/5
, 4/6
, 4/7
and 4/8
.
Preamble Length
Change the preamble length of the radio.
try await sx127x; catch err console;
preambleLength
- preamble length in symbols, defaults to8
Supported values are between 6
and 65535
.
Sync Word
Change the sync word of the radio.
try await sx127x; catch err console;
syncWord
- byte value to use as the sync word, defaults to0x34
CRC
Enable or disable CRC usage, by default a CRC is not used.
try await sx127x; catch err console;
crc
-true
to enable CRC,false
to disable
Other functions
Random
Generate a random byte, based on the Wideband RSSI measurement.
try let random = await sx127x; catch err console;
Examples
See examples folder.
License
This library is licensed under the MIT Licence.