PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

rf69_server.pde 2.4KB

před 3 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // rf69_server.pde
  2. // -*- mode: C++ -*-
  3. // Example sketch showing how to create a simple messageing server
  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_client
  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. //RH_RF69 rf69(4, 2); // For MoteinoMEGA https://lowpowerlab.com/shop/moteinomega
  19. void setup()
  20. {
  21. Serial.begin(9600);
  22. if (!rf69.init())
  23. Serial.println("init failed");
  24. // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
  25. // No encryption
  26. if (!rf69.setFrequency(433.0))
  27. Serial.println("setFrequency failed");
  28. // If you are using a high power RF69, you *must* set a Tx power in the
  29. // range 14 to 20 like this:
  30. // rf69.setTxPower(14);
  31. // The encryption key has to be the same as the one in the client
  32. uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  33. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  34. rf69.setEncryptionKey(key);
  35. #if 0
  36. // For compat with RFM69 Struct_send
  37. rf69.setModemConfig(RH_RF69::GFSK_Rb250Fd250);
  38. rf69.setPreambleLength(3);
  39. uint8_t syncwords[] = { 0x2d, 0x64 };
  40. rf69.setSyncWords(syncwords, sizeof(syncwords));
  41. rf69.setEncryptionKey((uint8_t*)"thisIsEncryptKey");
  42. #endif
  43. }
  44. void loop()
  45. {
  46. if (rf69.available())
  47. {
  48. // Should be a message for us now
  49. uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
  50. uint8_t len = sizeof(buf);
  51. if (rf69.recv(buf, &len))
  52. {
  53. // RH_RF69::printBuffer("request: ", buf, len);
  54. Serial.print("got request: ");
  55. Serial.println((char*)buf);
  56. // Serial.print("RSSI: ");
  57. // Serial.println(rf69.lastRssi(), DEC);
  58. // Send a reply
  59. uint8_t data[] = "And hello back to you";
  60. rf69.send(data, sizeof(data));
  61. rf69.waitPacketSent();
  62. Serial.println("Sent a reply");
  63. }
  64. else
  65. {
  66. Serial.println("recv failed");
  67. }
  68. }
  69. }