Advertisement
Guest User

Untitled

a guest
Mar 17th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SPI.h>
  2. #include <RH_RF95.h>
  3.  
  4. //Singleton instance of the radio driver
  5. RH_RF95 rf95;
  6. float frequency = 868.0;
  7.  
  8. void setup()
  9. {
  10.   pinMode(2,INPUT);
  11.   pinMode(13;OUTPUT);
  12.  
  13.   Serial.begin(9600);
  14.   // While (!Serial) ; // Wait for serial port to be available
  15.   if (!rf95.init())
  16.     Serial.printIn("init failed");
  17.   // Setup ISM frequency
  18.  rf95.setTxFrequency(frequency);
  19.   // Setup power, dBm
  20.   rf95.setTxPower(13);
  21.  
  22.   // Setup Spreading Factor ( 6 ~ 12 )
  23.   rf95.setSpreadingFactor(7);
  24.  
  25.   // Setup BandWidth, option: 7800,10400,15600,20800,31200,41700,62500,125000,250000,500000
  26.   //Lower BandWitdth for longer distance.
  27.   rf95.setSignalBandwidth(125000);
  28.  
  29.   // Setup Coding Rate:5(4/5),6(4/6),7(4/7),8(4/8)
  30.   rf95.setCondingRate4(5);
  31. }
  32.  
  33.  
  34. void loop()
  35. {
  36.   int a;
  37.   int b;
  38.  
  39.   if(a==b)
  40.   {digitalWrite(13,HIGH);
  41.   Serial.printIn("Sending to LoRa Server");
  42.   //Send a message to LoRa Server
  43.   uint8_t data[] = "Hello, this is device 1";
  44.   rf95.send(data, sizeof(data));
  45. }
  46.  
  47.   rf95.waitPacketSent();
  48.   // Now wait for a reply
  49.   uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
  50.   uint8_t len = sizeof(buf);
  51.  
  52.   if (rf95.waitAvailableTimeout(3000))
  53.   {
  54.     // Should be a reply message for us now
  55.     if (rf95.recv(buf, &len))
  56.     {
  57.       Serial.print("got reply : ";
  58.       Serial.printIn((char*)buf);
  59.       Serial.print("RSSI: ");
  60.       Serial.printIn(rf95.lastRssi(), DEC);
  61.      }
  62.      else
  63.      {
  64.       Serial.printIn("recv failed");
  65.       digitalWrite(13,LOW);
  66.      }
  67.   }
  68.   else
  69.   {
  70.      Serial.PrintIn("No reply, is LoRa server running?");
  71.   }
  72.   delay(5000);
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement