arduino-LoRa icon indicating copy to clipboard operation
arduino-LoRa copied to clipboard

Is there a way tu purpesfully ignore packets?

Open mistrjirka opened this issue 3 years ago • 1 comments

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)?

mistrjirka avatar Jul 23 '22 15:07 mistrjirka

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

IoTThinks avatar Aug 06 '22 09:08 IoTThinks