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.

58 lines
1.4KB

  1. // rf22_client.pde
  2. // -*- mode: C++ -*-
  3. // Example sketch showing how to create a simple messageing client
  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_server
  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. Serial.println("Sending to rf22_server");
  25. // Send a message to rf22_server
  26. uint8_t data[] = "Hello World!";
  27. rf22.send(data, sizeof(data));
  28. rf22.waitPacketSent();
  29. // Now wait for a reply
  30. uint8_t buf[RH_RF22_MAX_MESSAGE_LEN];
  31. uint8_t len = sizeof(buf);
  32. if (rf22.waitAvailableTimeout(500))
  33. {
  34. // Should be a reply message for us now
  35. if (rf22.recv(buf, &len))
  36. {
  37. Serial.print("got reply: ");
  38. Serial.println((char*)buf);
  39. }
  40. else
  41. {
  42. Serial.println("recv failed");
  43. }
  44. }
  45. else
  46. {
  47. Serial.println("No reply, is rf22_server running?");
  48. }
  49. delay(400);
  50. }