package
Compact and opinionated LoRa communications library
npm install loranoGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
High-level Node.js module for reading and writing LoRa packets, with support for over-the-air activation (OTAA) of devices.
It uses streams supplied by node-lora-comms and Anthony Kirby’s excellent packet decoder.
Your application is given a single Duplex stream operating in object mode for reading and writing packets. Replying to a packet typically involves just supplying a payload, though your application can override the default transmission settings if required.
Tested on a Raspberry Pi 3 Model B with an IMST iC880A-SPI.
API documentation is available here.
This program works in conjunction with a corresponding Arduino sketch (tested on a SODAQ Explorer).
It reads 12-byte packets from the LoRa radio, leaves the first 6 bytes unchanged and randomizes the last 6 bytes. It then sends the packet back to the radio. The Explorer does the same but randomizes the first 6 byes it receives, leaving the last 6 bytes unchanged.
Each side then checks whether it gets back the bytes it randomized in the previous packet it sent.
example.js.
const path = require('path');
const crypto = require('crypto');
const { Link } = require('lorano');
const lora_comms = require('lora-comms');
const { Model } = require('objection');
// Start radio
process.on('SIGINT', lora_comms.stop);
lora_comms.start_logging();
lora_comms.log_info.pipe(process.stdout);
lora_comms.log_error.pipe(process.stderr);
lora_comms.start();
// Connect to database
const
First you need to modify at least DevEUI with the unique identifier of
your device. You can then run the example like this:
grunt examplenpm install loranoIn the top-level directory you’ll find a file called
lorano.empty.sqlite3. This contains an empty copy of the database
lorano uses to store information about your devices (addresses, keys,
activation state etc).
You should use a copy of this file in your application and pass its location when setting up Knex.js. By default the database is SQLite but Knex.js supports many other databases. If you want to use a different database, use the lorano migrations to populate it and edit knexfile.js accordingly.
You need to add your devices to the database otherwise lorano will ignore packets it receives from them.
For each of your devices, you must add a row to the OTAADevices table
containing the following columns:
NwkAddr: Unique network address of the device. This can be random
as long as it’s unique. It must be a binary value 4 bytes long but
only the 25 least significant bits are used and the 7 most
significant must be 0.
DevEUI: Unique global device ID in the IEEE EUI64 address space.
This must be a binary value 8 bytes long and can usually be quered
from the hardware by calling a device API.
AppKey: The AES-128 key that you’ve assigned to the device for
your application. This is a shared secret between your application
and the device and is used to derive session keys specific for the
device to encrypt and verify packets communication with it. It must
be a binary value 16 bytes long.
An example of seeding the database for an OTAA device using Knex.js can be found in test/seeds/test_otaa.js.
For each of your devices, you must add a row to the ABPDevices table
containing the following columns:
DevAddr: The identifier of your network (7 most significant bits)
and the unique address of the device within it (25 least significant
bits). This must be a binary value 4 bytes long.
NwkSKey: Network session key for the device. This is a shared
secret between your application and the device and is used to
calculate and verify the message integrity code of data messages. It
must be a binary value 16 bytes long.
AppSKey: Application session key for the device. This is a shared
secret between your application and the device and it used to
encrypt and decrypt data messages. It must be a binary value 16
bytes long.
An example of seeding the database for an ABP device using Knex.js can be found in test/seeds/test_abp.js.
If you’re using an IMST iC880A-SPI, it needs to be reset after it’s powered up.
My iC880A-SPI is connected to a Pi via a backplane which brings the reset line out on GPIO 25. I run the following shell script to perform the reset:
iC880A-SPI_reset.sh.
#!/bin/sh
echo "25" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio25/direction
echo "1" > /sys/class/gpio/gpio25/value
sleep 5
echo "0" > /sys/class/gpio/gpio25/value
sleep 1
echo "0" > /sys/class/gpio/gpio25/value
chmod o+rw /dev/spidev0.0By default, the tests simulate LoRa packets and can be run with:
grunt testIf you have a LoRa device that can run test/lorano_test.ino then you can pass its DEVEUI as an argument like this:
grunt test --deveui=XXXXXXXXXXXXXXXXI’ve tested this with a SODAQ Explorer.
grunt lintgrunt coverageOr with a LoRa device running test/lorano_test.ino:
grunt coverage --deveui=XXXXXXXXXXXXXXXXc8 results are available here.
Estimated unpacked size across 12 packages.
4.8 MB
Includes dependencies.
3 direct · 2 outdated