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.

81 lines
2.5KB

  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. #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. void setup()
  19. {
  20. // Rocket Scream Mini Ultra Pro with the RFM95W only:
  21. // Ensure serial flash is not interfering with radio communication on SPI bus
  22. // pinMode(4, OUTPUT);
  23. // digitalWrite(4, HIGH);
  24. Serial.begin(9600);
  25. while (!Serial) ; // Wait for serial port to be available
  26. if (!rf95.init())
  27. Serial.println("init failed");
  28. // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
  29. // The default transmitter power is 13dBm, using PA_BOOST.
  30. // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
  31. // you can set transmitter powers from 5 to 23 dBm:
  32. // driver.setTxPower(23, false);
  33. // If you are using Modtronix inAir4 or inAir9,or any other module which uses the
  34. // transmitter RFO pins and not the PA_BOOST pins
  35. // then you can configure the power transmitter power for -1 to 14 dBm and with useRFO true.
  36. // Failure to do that will result in extremely low transmit powers.
  37. // driver.setTxPower(14, true);
  38. }
  39. void loop()
  40. {
  41. Serial.println("Sending to rf95_server");
  42. // Send a message to rf95_server
  43. uint8_t data[] = "Hello World!";
  44. rf95.send(data, sizeof(data));
  45. rf95.waitPacketSent();
  46. // Now wait for a reply
  47. uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
  48. uint8_t len = sizeof(buf);
  49. if (rf95.waitAvailableTimeout(3000))
  50. {
  51. // Should be a reply message for us now
  52. if (rf95.recv(buf, &len))
  53. {
  54. Serial.print("got reply: ");
  55. Serial.println((char*)buf);
  56. // Serial.print("RSSI: ");
  57. // Serial.println(rf95.lastRssi(), DEC);
  58. }
  59. else
  60. {
  61. Serial.println("recv failed");
  62. }
  63. }
  64. else
  65. {
  66. Serial.println("No reply, is rf95_server running?");
  67. }
  68. delay(400);
  69. }