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.

97 lines
2.7KB

  1. // rf69_client.pde
  2. // -*- mode: C++ -*-
  3. // Example sketch showing how to create a simple messageing client
  4. // with the RH_RF69 class. RH_RF69 class does not provide for addressing or
  5. // reliability, so you should only use RH_RF69 if you do not need the higher
  6. // level messaging abilities.
  7. // It is designed to work with the other example rf69_server.
  8. // Demonstrates the use of AES encryption, setting the frequency and modem
  9. // configuration
  10. // Tested on Moteino with RFM69 http://lowpowerlab.com/moteino/
  11. // Tested on miniWireless with RFM69 www.anarduino.com/miniwireless
  12. // Tested on Teensy 3.1 with RF69 on PJRC breakout board
  13. #include <SPI.h>
  14. #include <RH_RF69.h>
  15. //For Teensy 3.x and T4.x the following format is required to operate correctly
  16. //This is a limitation of the RadioHead radio drivers
  17. #define RFM69_RST 3
  18. #define RFM69_CS 10
  19. #define RFM69_INT digitalPinToInterrupt(2)
  20. // Singleton instance of the radio driver
  21. RH_RF69 rf69(RFM69_CS,RFM69_INT);
  22. //----- END TEENSY CONFIG
  23. //RH_RF69 rf69(15, 16); // For RF69 on PJRC breakout board with Teensy 3.1
  24. void setup()
  25. {
  26. Serial.begin(9600);
  27. //For Teensy 3.x and T4.x the following format is required to operate correctly
  28. //pinMode(LED, OUTPUT);
  29. pinMode(RFM69_RST, OUTPUT);
  30. digitalWrite(RFM69_RST, LOW);
  31. Serial.println("Teensy RFM69 Client!");
  32. Serial.println();
  33. // manual reset
  34. digitalWrite(RFM69_RST, HIGH);
  35. delay(10);
  36. digitalWrite(RFM69_RST, LOW);
  37. delay(10);
  38. //----- END TEENSY CONFIG
  39. if (!rf69.init())
  40. Serial.println("init failed");
  41. // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
  42. // No encryption
  43. if (!rf69.setFrequency(433.0))
  44. Serial.println("setFrequency failed");
  45. // If you are using a high power RF69, you *must* set a Tx power in the
  46. // range 14 to 20 like this:
  47. rf69.setTxPower(14);
  48. // The encryption key has to be the same as the one in the server
  49. uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  50. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  51. rf69.setEncryptionKey(key);
  52. }
  53. void loop()
  54. {
  55. Serial.println("Sending to rf69_server");
  56. // Send a message to rf69_server
  57. uint8_t data[] = "Hello World!";
  58. rf69.send(data, sizeof(data));
  59. rf69.waitPacketSent();
  60. // Now wait for a reply
  61. uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
  62. uint8_t len = sizeof(buf);
  63. if (rf69.waitAvailableTimeout(500))
  64. {
  65. // Should be a reply message for us now
  66. if (rf69.recv(buf, &len))
  67. {
  68. Serial.print("got reply: ");
  69. Serial.println((char*)buf);
  70. }
  71. else
  72. {
  73. Serial.println("recv failed");
  74. }
  75. }
  76. else
  77. {
  78. Serial.println("No reply, is rf69_server running?");
  79. }
  80. delay(400);
  81. }