npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sx127x-driver

v0.0.2

Published

Node.js driver for Semtech SX1276/77/78/79 LoRa circuits

Downloads

38

Readme

npm version npm

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
  • 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 = require('sx127x-driver');

let options = {
  // ...
};

let 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 (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.open();
} catch(err) {
  console.log('Failure to open device: ' + err)
}

Close

Close the device:

try {
  await sx127x.close();
} catch (err) {
  console.log('Close failure: ' + err);
  process.exit();
}

Sending data

try {
  await sx127x.write(new Buffer('hello ' + count++));
  console.log("successfully sent")
} catch (err) {
  console.log('Fail to send: ' + err);
} 

Blocking receive

try {
  let packetLength = await sx127x.receiveSingle();
  if (packetLength > 0) {
    let incoming = "";

    while (await sx127x.available()) {
      incoming += String.fromCharCode(await sx127x.read());
    }
  }
} catch (err) {
  console.log('Fail to receive: ' + err);
}

Interrupt receive

try {
   await sx127x.open();
   await sx127x.setContinuousReceiveMode();
} catch(err) {
   console.log('Fail to put into continuous receive mode: ' + err)
}

sx127x.on('data', function(data, rssi, snr) {
   console.log('data: ' +  data.toString() + ", rssi: " + rssi);
});

Sleep mode

Put the radio in sleep mode.

try {
  await sx127x.sleep();
} catch (err) {
  console.log('Fail to put into sleep mode: ' + err);
}

Stand by mode

Put the radio in stand by mode.

try {
  await sx127x.standBy();
} catch (err) {
  console.log('Fail to put into stand by: ' + err);
}

Radio parameters

TX Power

Change the TX power of the radio.

try {
  await sx127x.setTxPower(txPower);
} catch (err) {
  console.log(err);
}
  • txPower - TX power in dB, defaults to 17

Supported values are between 2 and 17.

Frequency

Change the frequency of the radio.

try {
  await sx127x.setFrequency(frequency);
} catch (err) {
  console.log(err);
}
  • frequency - frequency in Hz (433E6, 866E6, 915E6)

Spreading Factor

Change the spreading factor of the radio.

try {
  await sx127x.setSpreadingFactor(spreadingFactor);
} catch (err) {
  console.log(err);
}
  • spreadingFactor - spreading factor, defaults to 7

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.setSignalBandwidth(signalBandwidth);
} catch (err) {
  console.log(err);
}
  • signalBandwidth - signal bandwidth in Hz, defaults to 125E3.

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.setCodingRate(codingRate);
} catch (err) {
  console.log(err);
}
  • codingRate - coding rate, defaults to 4/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.setPreambleLength(preambleLength);
} catch (err) {
  console.log(err);
}
  • preambleLength - preamble length in symbols, defaults to 8

Supported values are between 6 and 65535.

Sync Word

Change the sync word of the radio.

try {
  await sx127x.setSyncWord(syncWord);
} catch (err) {
  console.log(err);
}
  • syncWord - byte value to use as the sync word, defaults to 0x34

CRC

Enable or disable CRC usage, by default a CRC is not used.

try {
  await sx127x.setCrc(crc);
} catch (err) {
  console.log(err);
}
  • 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.readRandom(crc);
} catch (err) {
  console.log(err);
}

Examples

See examples folder.

License

This library is licensed under the MIT Licence.