Advertisement
hwthinker

LoraReceiverCallback-433Mhz

Jan 30th, 2019
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //modified lora library by Sandeep Mistry for TTGO ESP32 Lora
  2. // lora receiverCallBack
  3.  
  4. #include <SPI.h>
  5. #include <LoRa.h>
  6.  
  7. #ifdef ARDUINO_SAMD_MKRWAN1300
  8. #error "This example is not compatible with the Arduino MKR WAN 1300 board!"
  9. #endif
  10.  
  11. // GPIO5  -- SX1278's SCK
  12. // GPIO19 -- SX1278's MISO
  13. // GPIO27 -- SX1278's MOSI
  14. // GPIO18 -- SX1278's CS
  15. // GPIO14 -- SX1278's RESET
  16. // GPIO26 -- SX1278's IRQ(Interrupt Request)
  17.  
  18. #define SS      18
  19. #define RST     14
  20. #define DI0     26
  21. #define BAND    433E6
  22.  
  23. void setup() {
  24.   Serial.begin(115200);
  25.   while (!Serial);
  26.   SPI.begin(5,19,27,18);
  27.   LoRa.setPins(SS,RST,DI0);
  28.  
  29.   Serial.println("LoRa Receiver Callback");
  30.  
  31.   if (!LoRa.begin(BAND)) {
  32.     Serial.println("Starting LoRa failed!");
  33.     while (1);
  34.   }
  35.  
  36.   // register the receive callback
  37.   LoRa.onReceive(onReceive);
  38.  
  39.   // put the radio into receive mode
  40.   LoRa.receive();
  41. }
  42.  
  43. void loop() {
  44.   // do nothing
  45. }
  46.  
  47. void onReceive(int packetSize) {
  48.   // received a packet
  49.   Serial.print("Received packet '");
  50.  
  51.   // read packet
  52.   for (int i = 0; i < packetSize; i++) {
  53.     Serial.print((char)LoRa.read());
  54.   }
  55.  
  56.   // print RSSI of packet
  57.   Serial.print("' with RSSI ");
  58.   Serial.println(LoRa.packetRssi());
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement