1
0
mirror of https://github.com/sandeepmistry/arduino-LoRa.git synced 2025-04-22 11:02:52 +03:00
arduino-LoRa/examples/LoRaReceiverCallback/LoRaReceiverCallback.ino
Sandeep Mistry 039b138d80
Add support for Arduino MKR WAN 1300 boards (#105)
* Add support for Arduino MKR WAN 1300 board
* Add new LoRa.setSPI(...) API to use radio with a different SPI interface
* Disable LoRa.onReceive(...) and LoRa.receive() on Arduino MKR WAN 1300
* Add errors on sketches not compatible with the Arduino MKR WAN 1300
2018-05-07 13:02:06 -04:00

44 lines
795 B
C++

#include <SPI.h>
#include <LoRa.h>
#ifdef ARDUINO_SAMD_MKRWAN1300
#error "This example is not compatible with the Arduino MKR WAN 1300 board!"
#endif
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());
}