I have write code as follow
#include <SoftwareSerial.h>
SoftwareSerial softSerial(10, 11);
void setup() {
Serial.begin(9600);
softSerial.begin(9600);
}
void loop() {
at_command(01,'S','L',"");
if(softSerial.available()){
Serial.print(softSerial.read());
}
}
void at_command(char id, char c1, char c2, char *cmdData) {
softSerial.write(0x7E); softSerial.write((byte)0x00); softSerial.write(0x05); softSerial.write(0x88); softSerial.write(id); softSerial.write(c1); softSerial.write(c2); long cmdDataSum = 0;
if(sizeof(cmdData) > 0) {
for(int i=0; i<= sizeof(cmdData)-1; i++) {
softSerial.write(i); cmdDataSum = cmdDataSum + i;
}
} else { ;
}
long sum = 0x88 + id + c1 + c2 + cmdDataSum;
softSerial.write(0xFF - (sum - 0xFF));
delay(10);
}
void at_response(){
if(Serial.available() > 21 ) {
if(Serial.read() == 0x7E) {
for (int i=0; i<19; i++) {
byte discard = Serial.read();
}
byte atResponse = Serial.read();
}
}
}
Now suppose if i will send some command to XBee that will return AT Command Response to read which i have to use a loop as i have done in at_response() function along with putting values i am reading as check as in
if(Serial.available() > 21 )
. What if XBee send some variable length response and i have to read that?
I hope question is clear! let me explain once more that i want to read some variable length response through Zigbee on serial as i have done with fixed length response by
if(Serial.available() > 21 )
Can anyone tell me how to do so?