PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

74 行
2.0KB

  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. // Singleton instance of the radio driver
  16. RH_RF69 rf69;
  17. //RH_RF69 rf69(15, 16); // For RF69 on PJRC breakout board with Teensy 3.1
  18. void setup()
  19. {
  20. Serial.begin(9600);
  21. if (!rf69.init())
  22. Serial.println("init failed");
  23. // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
  24. // No encryption
  25. if (!rf69.setFrequency(433.0))
  26. Serial.println("setFrequency failed");
  27. // If you are using a high power RF69, you *must* set a Tx power in the
  28. // range 14 to 20 like this:
  29. // rf69.setTxPower(14);
  30. // The encryption key has to be the same as the one in the server
  31. uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  32. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  33. rf69.setEncryptionKey(key);
  34. }
  35. void loop()
  36. {
  37. Serial.println("Sending to rf69_server");
  38. // Send a message to rf69_server
  39. uint8_t data[] = "Hello World!";
  40. rf69.send(data, sizeof(data));
  41. rf69.waitPacketSent();
  42. // Now wait for a reply
  43. uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
  44. uint8_t len = sizeof(buf);
  45. if (rf69.waitAvailableTimeout(500))
  46. {
  47. // Should be a reply message for us now
  48. if (rf69.recv(buf, &len))
  49. {
  50. Serial.print("got reply: ");
  51. Serial.println((char*)buf);
  52. }
  53. else
  54. {
  55. Serial.println("recv failed");
  56. }
  57. }
  58. else
  59. {
  60. Serial.println("No reply, is rf69_server running?");
  61. }
  62. delay(400);
  63. }