PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.5KB

  1. // rf95_server.pde
  2. // -*- mode: C++ -*-
  3. // Example sketch showing how to create a simple messageing server
  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_client
  8. // Tested with Anarduino MiniWirelessLoRa, Rocket Scream Mini Ultra Pro with
  9. // the RFM95W, Adafruit Feather M0 with RFM95
  10. #include <SPI.h>
  11. #include <RH_RF95.h>
  12. // Singleton instance of the radio driver
  13. RH_RF95 rf95;
  14. //RH_RF95 rf95(5, 2); // Rocket Scream Mini Ultra Pro with the RFM95W
  15. //RH_RF95 rf95(8, 3); // Adafruit Feather M0 with RFM95
  16. // Need this on Arduino Zero with SerialUSB port (eg RocketScream Mini Ultra Pro)
  17. //#define Serial SerialUSB
  18. int led = 9;
  19. void setup()
  20. {
  21. // Rocket Scream Mini Ultra Pro with the RFM95W only:
  22. // Ensure serial flash is not interfering with radio communication on SPI bus
  23. // pinMode(4, OUTPUT);
  24. // digitalWrite(4, HIGH);
  25. pinMode(led, OUTPUT);
  26. Serial.begin(9600);
  27. while (!Serial) ; // Wait for serial port to be available
  28. if (!rf95.init())
  29. Serial.println("init failed");
  30. // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
  31. // The default transmitter power is 13dBm, using PA_BOOST.
  32. // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
  33. // you can set transmitter powers from 5 to 23 dBm:
  34. // driver.setTxPower(23, false);
  35. // If you are using Modtronix inAir4 or inAir9,or any other module which uses the
  36. // transmitter RFO pins and not the PA_BOOST pins
  37. // then you can configure the power transmitter power for -1 to 14 dBm and with useRFO true.
  38. // Failure to do that will result in extremely low transmit powers.
  39. // driver.setTxPower(14, true);
  40. }
  41. void loop()
  42. {
  43. if (rf95.available())
  44. {
  45. // Should be a message for us now
  46. uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
  47. uint8_t len = sizeof(buf);
  48. if (rf95.recv(buf, &len))
  49. {
  50. digitalWrite(led, HIGH);
  51. // RH_RF95::printBuffer("request: ", buf, len);
  52. Serial.print("got request: ");
  53. Serial.println((char*)buf);
  54. // Serial.print("RSSI: ");
  55. // Serial.println(rf95.lastRssi(), DEC);
  56. // Send a reply
  57. uint8_t data[] = "And hello back to you";
  58. rf95.send(data, sizeof(data));
  59. rf95.waitPacketSent();
  60. Serial.println("Sent a reply");
  61. digitalWrite(led, LOW);
  62. }
  63. else
  64. {
  65. Serial.println("recv failed");
  66. }
  67. }
  68. }