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.

54 line
1.4KB

  1. // rf22_server.pde
  2. // -*- mode: C++ -*-
  3. // Example sketch showing how to create a simple messageing server
  4. // with the RH_RF22 class. RH_RF22 class does not provide for addressing or
  5. // reliability, so you should only use RH_RF22 if you do not need the higher
  6. // level messaging abilities.
  7. // It is designed to work with the other example rf22_client
  8. // Tested on Duemilanove, Uno with Sparkfun RFM22 wireless shield
  9. // Tested on Flymaple with sparkfun RFM22 wireless shield
  10. // Tested on ChiKit Uno32 with sparkfun RFM22 wireless shield
  11. #include <SPI.h>
  12. #include <RH_RF22.h>
  13. // Singleton instance of the radio driver
  14. RH_RF22 rf22;
  15. void setup()
  16. {
  17. Serial.begin(9600);
  18. if (!rf22.init())
  19. Serial.println("init failed");
  20. // Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
  21. }
  22. void loop()
  23. {
  24. if (rf22.available())
  25. {
  26. // Should be a message for us now
  27. uint8_t buf[RH_RF22_MAX_MESSAGE_LEN];
  28. uint8_t len = sizeof(buf);
  29. if (rf22.recv(buf, &len))
  30. {
  31. // RF22::printBuffer("request: ", buf, len);
  32. Serial.print("got request: ");
  33. Serial.println((char*)buf);
  34. // Serial.print("RSSI: ");
  35. // Serial.println(rf22.lastRssi(), DEC);
  36. // Send a reply
  37. uint8_t data[] = "And hello back to you";
  38. rf22.send(data, sizeof(data));
  39. rf22.waitPacketSent();
  40. Serial.println("Sent a reply");
  41. }
  42. else
  43. {
  44. Serial.println("recv failed");
  45. }
  46. }
  47. }