xbee: Receiving data in interrupts

hi,

I am trying to establish XBee communication using API mode. I wanted to get the data received by XBee using Interrupts. I am using the below code but i could not read data. can any one suggest some way of reading data received by XBee using Interrupts

#include <SoftwareSerial.h>
#include <XBee.h>
#include <avr/power.h>
#include <avr/sleep.h>
 
XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
ZBRxResponse rx = ZBRxResponse();
SoftwareSerial test(2,1);
String sample;
void setup() {
 Serial.begin(9600);
 xbee.begin(test);
 attachInterrupt(0, receiveData, CHANGE  );
}
 
void receiveData() {
 
 xbee.readPacket();
 if (xbee.getResponse().isAvailable()) {
  if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
    xbee.getResponse().getZBRxResponse(rx);
      for (int i = 0; i < rx.getDataLength(); i++) {
        sample += (char)rx.getData(i);
      }
   }
 }else if (xbee.getResponse().isError()) {
     sample += xbee.getResponse().getErrorCode();
 }
 
}
 
void loop() {
Serial.println(sample);
delay(1000);  
}

I wanted to get the data received by XBee using Interrupts.

What is going to generate the interrupt? Since communication doesn't happen when you want it to (it happens when it needs to), why would checking for data when an interrupt happens make any sense.

That's like expecting mail to be in the mailbox when the phone rings.

Are you trying to use pin 2 to receive data OR to trigger an interrupt? Both is the wrong answer.

SoftwareSerial already uses interrupts to receive and buffer data.

Shitcan the stupid delay() in loop(). On every iteration of loop(), see if there is data from the XBee. Let that class handle all the interrupts, buffering of data, etc. All you need to do is deal with the data in the packet, when the packet has arrived.