-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpingpong.js
32 lines (25 loc) · 933 Bytes
/
pingpong.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const rfm9x = require('rfm9x');
async function main() {
const device = new rfm9x();
// Initialize the LoRa module. All options can be omitted and default values will be used.
await device.init({
frequencyMhz: 868,
bandwidthHz: 500000,
codingRate: 5,
spreadingFactor: 7,
});
// Listen to the receive event that is emitted whenever a valid LoRa packet is received.
device.on('receive', packet => {
// Print out the packet contents and metadata for clarity.
console.dir(packet);
// If we received a PING, respond with a PONG.
if (packet.payload.toString() == 'PING') {
await device.send(Buffer.from('PONG'));
// After a transmission is finished, receiving mode needs to be re-enabled.
await device.startReceive();
}
});
// Enable receiving mode.
await device.startReceive();
}
main();