Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2021
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 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 packSize = "--";
  6.  
  7. void setup() {
  8.   Heltec.begin(true /*DisplayEnable Enable*/, true /*Heltec.LoRa Disable*/, true /*Serial Enable*/, true /*PABOOST Enable*/, BAND /*long BAND*/);
  9. }
  10.  
  11. void loop() {
  12.   //receive
  13.   int packetSize = LoRa.parsePacket();
  14.     if (packetSize) {
  15.       while (LoRa.available()) {
  16.         if (packetSize) { cbk(packetSize);  }      
  17. }
  18.   Serial.print("Recevied ");
  19.   Serial.print(packet);
  20.   Serial.print(" with RSSI ");
  21.   Serial.println(LoRa.packetRssi());
  22.   sendack();
  23. }}
  24.  
  25. void sendack(){
  26.   Serial.print("Sending packet ");
  27.   Serial.println(packet);
  28.   LoRa.beginPacket();
  29.   LoRa.setTxPower(14,RF_PACONFIG_PASELECT_PABOOST);
  30.   LoRa.print(packet);
  31.   LoRa.endPacket();
  32. }
  33.  
  34. void cbk(int packetSize) {
  35.   packet ="";
  36.   packSize = String(packetSize,DEC);
  37.   for (int i = 0; i < packetSize; i++) { packet += (char) LoRa.read(); }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement