A Node module for sending and receiving through RFM69 radios on the Raspberry Pi.
Ported from etrombly's python version of the LowPowerLab code.
This version tested on a pair of Adafruit RFM69HCW Radios with this NodeJS code running on a Raspberry Pi 3 Model B.
The default wiring is:
RFM pin | Pi pin |
---|---|
3v3 | 17 |
DIO0 | 18 (GPIO24) |
MOSI | 19 (GPIO10) |
MISO | 21 (GPIO09) |
CLK | 23 (GPIO11) |
CS (NSS) | 24 (GPIO08 CS0) |
Ground | 25 |
RESET | 29 (GPIO05) |
See here for the Raspberry Pi 3 GPIO pins.
The second radio is connected to an Arduino UNO running the code in frm69_test.ino and connected according to the instrucitons from Adafruit.
npm install rfm69radio
Create the module.
const RFM69 = require('rfm69radio');
const rfm69 = new RFM69();
Initialize the radio. Provide an address for the node and optionally a 16 char encryption key. Then, register callback to handle recevied packets. Then, read the temperature of the radio ic. Then, calibrate the radio. Then, send some packets.
rfm69.initialize({
address: 1,
// encryptionKey: '0123456789abcdef',
verbose: false,
powerLevelPercent: 20,
})
.then(() => {
console.log('Initialized');
rfm69.registerPacketReceivedCallback(packetReceivedCallback1);
rfm69.registerPacketReceivedCallback(packetReceivedCallback2);
return true;
})
.then(() => rfm69.readTemperature())
.then((temp) => {
console.log(`Temp: ${temp}`);
rfm69.calibrateRadio();
return true;
})
.then(() => {
setInterval(() => {
const toAddress = 2;
console.log(`Sending packet to address ${toAddress}`);
rfm69.send({ toAddress: toAddress, payload: `Hello ${timeStamp()}`, attempts: 3, requireAck: true })
.then((packet) => {
console.log(`Sent on attempt ${packet.attempts} after ${packet.ackTimestamp - packet.timestamp}ms`);
return true;
})
.catch(err => console.log(err));
}, 3000);
setTimeout(() => {
rfm69.broadcast('Broadcast!!')
.then(() => {
console.log('Sent broadcast');
return true;
})
.catch(err => console.log(err));
}, 2000);
return true;
})
.catch(err => {
console.log(`Error initializing radio: ${err}`);
rfm69.shutdown();
});
function packetReceivedCallback1(packet) {
console.log(`Packet received (callback1) from peer ${packet.senderAddress} "${packet.payloadString}" RSSI:${packet.rssi}`);
}
function packetReceivedCallback2(packet) {
console.log(`Packet received (callback2) from peer ${packet.senderAddress} "${packet.payloadString}" RSSI:${packet.rssi}`);
}
- GPIO access and interrupt detection: onoff
- SPI Interface: spi-device