Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2021
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include "heltec.h"
  2. #define BAND    915E6  //you can set band here directly,e.g. 868E6,915E6
  3.  
  4. String packet ="";
  5. String command ="";
  6. String packSize = "--";
  7.  
  8. void setup() {
  9.   Heltec.begin(true /*DisplayEnable Enable*/, true /*Heltec.LoRa Disable*/, true /*Serial Enable*/, true /*PABOOST Enable*/, BAND /*long BAND*/);
  10. }
  11.  
  12. void loop() {
  13.   if (Serial.available() > 0) {
  14.     command = Serial.readString();
  15.     senddata();
  16. }}
  17.  
  18. void senddata(){
  19.   Serial.print("Sending packet ");
  20.   Serial.println(command);
  21.   LoRa.beginPacket();
  22.   LoRa.setTxPower(14,RF_PACONFIG_PASELECT_PABOOST);
  23.   LoRa.print(command);
  24.   LoRa.endPacket();
  25.   getack();
  26. }
  27.  
  28. void getack(){
  29.     int packetSize = LoRa.parsePacket();
  30.       if (packetSize) {
  31.         while (LoRa.available()) {
  32.           if (packetSize) { cbk(packetSize);  }      
  33.         }
  34.   Serial.print("Recevied ");
  35.   Serial.print(packet);
  36.   Serial.print(" with RSSI ");
  37.   Serial.println(LoRa.packetRssi());
  38. }}
  39.  
  40. void cbk(int packetSize) {
  41.   packet ="";
  42.   packSize = String(packetSize,DEC);
  43.   for (int i = 0; i < packetSize; i++) { packet += (char) LoRa.read(); }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement