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

rfm9x

v1.0.1

Published

Node.js module for SPI communication with RFM9x wireless modules on Raspberry Pi (e.g. Adafruit Radio Bonnet)

Downloads

7

Readme

Introduction

Node.js module to interface with RFM9x LoRa wireless modules. Intended for use with Adafruit Radio Bonnets.

The code has only been tested on Raspberry Pi but could technically also work on other boards supported by onoff and spi-device.

Acknowledgements

Example

See example/pingpong.js for a simple example of receiving and sending data.

API

The modules exports a single class RFM9x.

Class RFM9x

Class representing the LoRa module. The constructor requires no arguments.

const rfm9x = require('rfm9x');
const module = new rfm9x();

await module.init({ ... });

Properties

  • debug - Output SPI debug information

debug

Set this property to true to get all SPI communication printed out to the console.

Note: Because console.log() calls are synchronous in most circumstances, enabling this can impact timing! For example, it might cause switching from sending to receiving mode to be slow enough to miss responses from other nodes.


Methods

init(options)

  • options - Options object (see below). All properties are optional, default values will be used when omitted.

Initialize module and LoRa settings. Needs to be called before using any of the radio functions.

Returns a Promise that resolves with no value.

The following options are supported:

  • frequencyMhz - Base frequency in MHz, default: 915
  • preambleLength - LoRa preamble length in bytes, default: 8
  • bandwidthHz - LoRa bandwidth in Hz, default: 500000
  • codingRate - LoRa coding rate, valid values are 5 (4/5) to 8 (4/8), default: 5
  • spreadingFactor - LoRa spreading factor, valid values are 6 to 12, default: 7
  • enableCrcChecking - Whether to enable CRC checking on incoming packets, default: false
  • txPowerDb - Transmitter power in dB, valid values are 5 to 23 (currently only high power mode is supported), default: 23
  • enableAgc - Whether to enable Automatic Gain Control, default: false
  • resetPin - Number of the GPIO pin that the RFM9x RESET line is connected to, default: 25
  • dio0Pin - Number of the GPIO pin that the RFM9x DIO0 line is connected to, default: 22
  • dio1Pin - Not currently used. Number of the GPIO pin that the RFM9x DIO1 line is connected to, default: 23
  • dio2Pin - Not currently used. Number of the GPIO pin that the RFM9x DIO2 line is connected to, default: 24
  • spiSpeedHz - Speed of the SPI communication in Hz, default: 100000
  • txTimeoutMs - Maximum time in milliseconds to wait for a packet transmission to finish, default: 2000

startReceive()

Put the LoRa module in receive mode and enable the receive event.

Returns a Promise that resolves with no value.

stopReceive()

Put the LoRa module in standby mode and stop receiving packets.

Returns a Promise that resolves with no value.

send(payload)

  • payload - A Buffer of up to 255 bytes

Send a packet via LoRa.

Returns a Promise that resolves with no value after the transmission is finished.

Note: After transmitting a packet, the module switches into standby mode automatically. If you want to continue receiving packets after a transmission, you will need to call startReceive() after the transmission completed.

getVersion()

Get the chip version number from the module.

Returns a Promise that resolves with the version number (one-byte integer).


Events

receive(packet)

Event that is emitted when a LoRa packet is received.

packet is an object containing the following properties:

  • payload - A Buffer containing the packet contents
  • rssiDb - RSSI of the packet in dB
  • snrDb - SNR of the packet in dB

receiveError()

Event that is emitted when a LoRa packet is received but was discarded due to receive errors (e.g. CRC check failed).