sandeepmistry / arduino-LoRa

An Arduino library for sending and receiving data using LoRa radios.
MIT License
1.61k stars 621 forks source link

Is there a way tu purpesfully ignore packets? #586

Open mistrjirka opened 1 year ago

mistrjirka commented 1 year ago

Hi, is there a way to ignore packets comming in that isn't intended for the receiving device? To pick a example:

void onReceive(int packetSize) {
  if (packetSize == 0) return;          // if there's no packet, return

  // read packet header bytes:
  int recipient = LoRa.read();          // recipient address
  byte sender = LoRa.read();            // sender address
  byte incomingMsgId = LoRa.read();     // incoming msg ID
  byte incomingLength = LoRa.read();    // incoming msg length

  String incoming = "";

  while (LoRa.available()) {
    incoming += (char)LoRa.read();
  }

  if (incomingLength != incoming.length()) {   // check length for error
    Serial.println("error: message length does not match length");
    return;                             // skip rest of function
  }

  // if the recipient isn't this device or broadcast,
  if (recipient != localAddress && recipient != 0xFF) {
    Serial.println("This message is not for me.");
    return;                             // skip rest of function
  }

Is there a way to skip the

  while (LoRa.available()) {
    incoming += (char)LoRa.read();
  }

and not waste the computational time if the recipient isn't the receiving device (recipient != local address)?

IoTThinks commented 1 year ago

To put a byte in front of the message to store node id. Only process if the id is matched.