Advertisement
hwthinker

LORAUNO_ReceiverCallback-433MHz

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