1

目前,我尝试通过读取串行线并通过 LoRa 发送输入,在一个 Heltec WIFI LoRa V2 和另一个之间发送数据包。

小数据包(如 30 字节)每次都有效,但随着数据包的增大,每次都不会收到数据包,甚至永远不会收到数据包。

所以我写了一个小发送循环,我的发送者在每次迭代中发送一​​个数据包,每次都会变大 10 个字节,令人惊讶的是,发送者收到了每个数据包(我试过直到 500 个字节)。

之后,我想发送一个 80 字节的串行输入消息,但没有成功。你知道这有什么问题吗?

void setup() {
  // ... LoRa.begin(); ....
  LoRa.onReceive(onReceive);
  // ... LoRa.receive(); ...
}

void onReceive(int packetSize) { // uses the interrupt pin on the dio0
  String packet = "";
  
  packSize = String(packetSize,DEC);
  for (int i = 0; i < packetSize; i++) { 
    packet += (char) LoRa.read();
  }
  
  Serial.println(packet);
  delay(5);
} ``` 


``` // writer
boolean sendPacket (String packet) {
  Serial.println("Send begin");

  LoRa.beginPacket(false); // true: optional implicit mode (--> Set everything on both sides?!)
  LoRa.setTxPower(14,RF_PACONFIG_PASELECT_PABOOST);
  LoRa.print(packet); // also LoRa.write(byte(, length));
  LoRa.endPacket(false); // true: async mode: doas not wair until transmission is completed
      
  delay(250);
  
  // put the radio into receive mode
  LoRa.receive(); // set redio back in receive mode
  
  delay(750);
  Serial.println("Send end");
  return true;  // will be changed
}

void loop(){
  while(Serial.available() > 0 ){
      delay(2);  //delay to allow byte to arrive in input buffer
      String text = Serial.readString();
      digitalWrite(LED, HIGH);   // turn the LED on (HIGH is the voltage level)
      boolean packetSent = false;

      while (!packetSent) {
        packetSent = sendPacket(text);
        if (packetSent) {
          Serial.print("Packet has been sent: ");
          Serial.println(text);
        } else {
          Serial.print("Retry sending packet: ");
          Serial.println(text);
        }
      }                       
      digitalWrite(LED, LOW);   // turn the LED off (HIGH is the voltage level)
  }   
} ```
4

0 回答 0