lora.ino 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. This is a simple example show the Heltec.LoRa sended data in OLED.
  3. The onboard OLED display is SSD1306 driver and I2C interface. In order to make the
  4. OLED correctly operation, you should output a high-low-high(1-0-1) signal by soft-
  5. ware to OLED's reset pin, the low-level signal at least 5ms.
  6. OLED pins to ESP32 GPIOs via this connecthin:
  7. OLED_SDA -- GPIO4
  8. OLED_SCL -- GPIO15
  9. OLED_RST -- GPIO16
  10. by Aaron.Lee from HelTec AutoMation, ChengDu, China
  11. 成都惠利特自动化科技有限公司
  12. https://heltec.org
  13. this project also realess in GitHub:
  14. https://github.com/Heltec-Aaron-Lee/WiFi_Kit_series
  15. */
  16. #include "heltec.h"
  17. #define BAND 915E6 //you can set band here directly,e.g. 868E6,915E6
  18. String packSize = "--";
  19. String packet ;
  20. void cbk(int packetSize) {
  21. packet ="";
  22. packSize = String(packetSize,DEC);
  23. for (int i = 0; i < packetSize; i++) { packet += (char) LoRa.read(); }
  24. Serial.println(packet);
  25. }
  26. void setup()
  27. {
  28. Heltec.begin(false /*DisplayEnable Enable*/, true /*Heltec.Heltec.Heltec.LoRa Disable*/, true /*Serial Enable*/, true /*PABOOST Enable*/, BAND /*long BAND*/);
  29. Serial.begin(115200);
  30. Serial.setRxBufferSize(1024);
  31. LoRa.setSignalBandwidth(250E3);
  32. }
  33. void loop()
  34. {
  35. if(Serial.available() > 0) {
  36. String data = "";
  37. data = Serial.readStringUntil('\n');
  38. // send packet
  39. LoRa.beginPacket();
  40. LoRa.print(data);
  41. LoRa.endPacket();
  42. // set radio back to receive mode
  43. LoRa.receive();
  44. }
  45. int packetSize = LoRa.parsePacket();
  46. if (packetSize) { cbk(packetSize); }
  47. }