PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

69 Zeilen
1.8KB

  1. // mrf89_client.pde
  2. // -*- mode: C++ -*-
  3. // Example sketch showing how to create a simple messageing client
  4. // with the RH_MRF89 class. RH_MRF89 class does not provide for addressing or
  5. // reliability, so you should only use RH_RF95 if you do not need the higher
  6. // level messaging abilities.
  7. // It is designed to work with the other example mrf89_server
  8. // Tested with Teensy and MRF89XAM9A
  9. #include <SPI.h>
  10. #include <RH_MRF89.h>
  11. // Singleton instance of the radio driver
  12. RH_MRF89 mrf89;
  13. void setup()
  14. {
  15. Serial.begin(9600);
  16. while (!Serial)
  17. ; // wait for serial port to connect. Needed for native USB
  18. if (!mrf89.init())
  19. Serial.println("init failed");
  20. // Default after init is 1dBm, 915.4MHz, FSK_Rb20Fd40
  21. // But you can change that if you want:
  22. // mrf89.setTxPower(RH_MRF89_TXOPVAL_M8DBM); // Min power -8dBm
  23. // mrf89.setTxPower(RH_MRF89_TXOPVAL_13DBM); // Max power 13dBm
  24. // if (!mrf89.setFrequency(920.0))
  25. // Serial.println("setFrequency failed");
  26. // if (!mrf89.setModemConfig(RH_MRF89::FSK_Rb200Fd200)) // Fastest
  27. // Serial.println("setModemConfig failed");
  28. }
  29. void loop()
  30. {
  31. Serial.println("Sending to mrf89_server");
  32. // Send a message to mrf89_server
  33. uint8_t data[] = "Hello World!";
  34. mrf89.send(data, sizeof(data));
  35. mrf89.waitPacketSent();
  36. // Now wait for a reply
  37. uint8_t buf[RH_MRF89_MAX_MESSAGE_LEN];
  38. uint8_t len = sizeof(buf);
  39. if (mrf89.waitAvailableTimeout(3000))
  40. {
  41. // Should be a reply message for us now
  42. if (mrf89.recv(buf, &len))
  43. {
  44. Serial.print("got reply: ");
  45. Serial.println((char*)buf);
  46. // Serial.print("RSSI: ");
  47. // Serial.println(mrf89.lastRssi(), DEC);
  48. }
  49. else
  50. {
  51. Serial.println("recv failed");
  52. }
  53. }
  54. else
  55. {
  56. Serial.println("No reply, is mrf89_server running?");
  57. }
  58. delay(400);
  59. }