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.

53 lines
1.4KB

  1. // nrf905_server.pde
  2. // -*- mode: C++ -*-
  3. // Example sketch showing how to create a simple messageing server
  4. // with the RH_NRF905 class. RH_NRF905 class does not provide for addressing or
  5. // reliability, so you should only use RH_NRF905 if you do not need the higher
  6. // level messaging abilities.
  7. // It is designed to work with the other example nrf905_client
  8. // Tested on Teensy3.1 with nRF905 module
  9. // Tested on Arduino Due with nRF905 module (Caution: use the SPI headers for connecting)
  10. #include <SPI.h>
  11. #include <RH_NRF905.h>
  12. // Singleton instance of the radio driver
  13. RH_NRF905 nrf905;
  14. void setup()
  15. {
  16. Serial.begin(9600);
  17. while (!Serial)
  18. ; // wait for serial port to connect. Needed for Leonardo only
  19. if (!nrf905.init())
  20. Serial.println("init failed");
  21. // Defaults after init are 433.2 MHz (channel 108), -10dBm
  22. }
  23. void loop()
  24. {
  25. if (nrf905.available())
  26. {
  27. // Should be a message for us now
  28. uint8_t buf[RH_NRF905_MAX_MESSAGE_LEN];
  29. uint8_t len = sizeof(buf);
  30. if (nrf905.recv(buf, &len))
  31. {
  32. // nrf905.printBuffer("request: ", buf, len);
  33. Serial.print("got request: ");
  34. Serial.println((char*)buf);
  35. // Send a reply
  36. uint8_t data[] = "And hello back to you";
  37. nrf905.send(data, sizeof(data));
  38. nrf905.waitPacketSent();
  39. Serial.println("Sent a reply");
  40. }
  41. else
  42. {
  43. Serial.println("recv failed");
  44. }
  45. }
  46. }