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.

55 lines
1.4KB

  1. // rf24_server.pde
  2. // -*- mode: C++ -*-
  3. // Example sketch showing how to create a simple messageing server
  4. // with the RH_RF24 class. RH_RF24 class does not provide for addressing or
  5. // reliability, so you should only use RH_RF24 if you do not need the higher
  6. // level messaging abilities.
  7. // It is designed to work with the other example rf24_client
  8. // Tested on Anarduino Mini http://www.anarduino.com/mini/ with RFM24W and RFM26W
  9. #include <SPI.h>
  10. #include <RH_RF24.h>
  11. // Singleton instance of the radio driver
  12. RH_RF24 rf24;
  13. void setup()
  14. {
  15. Serial.begin(9600);
  16. if (!rf24.init())
  17. Serial.println("init failed");
  18. // Defaults after init are 434.0MHz, modulation GFSK_Rb5Fd10, power 0x10
  19. // if (!rf24.setFrequency(433.0))
  20. // Serial.println("setFrequency failed");
  21. }
  22. void loop()
  23. {
  24. if (rf24.available())
  25. {
  26. // Should be a message for us now
  27. uint8_t buf[RH_RF24_MAX_MESSAGE_LEN];
  28. uint8_t len = sizeof(buf);
  29. if (rf24.recv(buf, &len))
  30. {
  31. // RF24::printBuffer("request: ", buf, len);
  32. Serial.print("got request: ");
  33. Serial.println((char*)buf);
  34. // Serial.print("RSSI: ");
  35. // Serial.println((uint8_t)rf24.lastRssi(), DEC);
  36. // Send a reply
  37. uint8_t data[] = "And hello back to you";
  38. rf24.send(data, sizeof(data));
  39. rf24.waitPacketSent();
  40. Serial.println("Sent a reply");
  41. }
  42. else
  43. {
  44. Serial.println("recv failed");
  45. }
  46. }
  47. }