You've already forked arduino-LoRa
mirror of
https://github.com/sandeepmistry/arduino-LoRa.git
synced 2025-06-12 19:41:53 +03:00
Add receive callback mode using DIO0
This commit is contained in:
39
examples/LoRaReceiverCallback/LoRaReceiverCallback.ino
Normal file
39
examples/LoRaReceiverCallback/LoRaReceiverCallback.ino
Normal file
@ -0,0 +1,39 @@
|
||||
#include <SPI.h>
|
||||
#include <LoRa.h>
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
while (!Serial);
|
||||
|
||||
Serial.println("LoRa Receiver Callback");
|
||||
|
||||
if (!LoRa.begin(915E6)) {
|
||||
Serial.println("Starting LoRa failed!");
|
||||
while (1);
|
||||
}
|
||||
|
||||
// register the receive callback
|
||||
LoRa.onReceive(onReceive);
|
||||
|
||||
// put the radio into receive mode
|
||||
LoRa.receive();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void onReceive(int packetSize) {
|
||||
// received a packet
|
||||
Serial.print("Received packet '");
|
||||
|
||||
// read packet
|
||||
for (int i = 0; i < packetSize; i++) {
|
||||
Serial.print((char)LoRa.read());
|
||||
}
|
||||
|
||||
// print RSSI of packet
|
||||
Serial.print("' with RSSI ");
|
||||
Serial.println(LoRa.packetRssi());
|
||||
}
|
||||
|
Reference in New Issue
Block a user