Advertisement
Guest User

experimental_RX

a guest
Jun 17th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.63 KB | None | 0 0
  1. // rf95_client.pde
  2. // -*- mode: C++ -*-
  3. // Example sketch showing how to create a simple messageing client
  4. // with the RH_RF95 class. RH_RF95 class does not provide for addressing or
  5. // reliability, so you should only use RH_RF95 if you do not need the higher
  6. // level messaging abilities.
  7. // It is designed to work with the other example rf95_server
  8. // Tested with Anarduino MiniWirelessLoRa, Rocket Scream Mini Ultra Pro with
  9. // the RFM95W, Adafruit Feather M0 with RFM95
  10.  
  11. #include <SPI.h>
  12. #include <RH_RF95.h>
  13.  
  14. // Singleton instance of the radio driver
  15. //RH_RF95 rf95;
  16. //RH_RF95 rf95(5, 2); // Rocket Scream Mini Ultra Pro with the RFM95W
  17. RH_RF95 rf95(8, 3); // Adafruit Feather M0 with RFM95
  18.  
  19. // Need this on Arduino Zero with SerialUSB port (eg RocketScream Mini Ultra Pro)
  20. //#define Serial SerialUSB
  21.  
  22. void setup()
  23. {
  24.   // Rocket Scream Mini Ultra Pro with the RFM95W only:
  25.   // Ensure serial flash is not interfering with radio communication on SPI bus
  26. //  pinMode(4, OUTPUT);
  27. //  digitalWrite(4, HIGH);
  28.  
  29.   Serial.begin(115200);
  30.   while (!Serial) ; // Wait for serial port to be available
  31.   if (!rf95.init())
  32.     Serial.println("init failed");
  33.   // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
  34.   rf95.setModemConfig(RH_RF95::Bw500Cr45Sf128);
  35.   // The default transmitter power is 13dBm, using PA_BOOST.
  36.   // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
  37.   // you can set transmitter powers from 5 to 23 dBm:
  38.     rf95.setFrequency(915.0);
  39.   rf95.setTxPower(23, false);
  40.   // If you are using Modtronix inAir4 or inAir9,or any other module which uses the
  41.   // transmitter RFO pins and not the PA_BOOST pins
  42.   // then you can configure the power transmitter power for -1 to 14 dBm and with useRFO true.
  43.   // Failure to do that will result in extremely low transmit powers.
  44. //  driver.setTxPower(14, true);
  45. }
  46.  
  47. void loop()
  48. {
  49. //  Serial.println("Sending to rf95_server");
  50.   // Send a message to rf95_server
  51.  
  52.   //uint8_t data[] = "Hello World!";
  53.   //rf95.send(data, sizeof(data));
  54.  
  55.   //rf95.waitPacketSent();
  56.   // Now wait for a reply
  57.   uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
  58.   uint8_t len = sizeof(buf);
  59.  
  60.   //if(rf95.waitAvailableTimeout(400))
  61.   //{
  62.     // Should be a reply message for us now  
  63.     if (rf95.recv(buf, &len))
  64.    {
  65. //      Serial.print("got reply: ");
  66.       Serial.println((char*)buf);
  67. //      Serial.print("RSSI: ");
  68. //      Serial.println(rf95.lastRssi(), DEC);    
  69.     }
  70.     else
  71.     {
  72.       Serial.println("NODATA");
  73.     }
  74.   //}
  75.   //else
  76.   //{
  77.     //Serial.println("NODATA");
  78.   //}
  79.   delay(50);
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement