Xbee router API receiving packets.

Hi everyone,

when someone is using the xbee.readPacket() method the arduino with the router APi is stucked at this method until it receives a packet or the flow of the programm continues? I am asking this because i want my arduino when it is not receiving a command from the coordinator to continue excecuting the programm.But it is not working.When i send a command from the coordinator through processing everything works.

Sorry for my english.

i found the solution , i found out that using the readPacket() method the xbee is waiting for a packet so i used the the other method xbee.read(int). but i have another question.
i used the serial screen of the router to see what i am receiving for the coordinator.

Here is the code of the rooter

const int dimout=11;
const int ldr=A0;
const int relay=4;
float sensorValue=0,pwmValue1=0,pwmValue2=0;
float Volt,Lux,Difference;
float VDifference,d=2;
uint8_t SData[4];
XBee xbee=XBee();
XBeeResponse response=XBeeResponse();
ZBRxResponse zbRx=ZBRxResponse();
XBeeAddress64 rmtAddress=XBeeAddress64(0x0013a200,0x040b33b0c);
ZBTxRequest zbTx=ZBTxRequest(rmtAddress,SData,sizeof(SData));
int state=1;
long previousTime=0;
unsigned long start=0;
long timeStep=180000;// 15 lepta
long interval=20006060;//2 wres
union{
float f;
byte b[4];
}command,LuxValue;

void setup(){
Serial.begin(9600);
xbee.setSerial(Serial);
pinMode(dimout,OUTPUT);
pinMode(relay,OUTPUT);
pinMode(ldr,INPUT);

}

void loop(){

if(xbee.readPacket(5000))
{

if(xbee.getResponse().getApiId()==ZB_RX_RESPONSE){
xbee.getResponse().getZBRxResponse(zbRx);
Serial.println(“I received an RX packet”);
if (zbRx.getOption() == ZB_PACKET_ACKNOWLEDGED){
Serial.println(“Packet acknowledged”);
}
else{
Serial.println(“Packet not acknowledged”);
}
Serial.println(“The received Data length is”);
Serial.println(zbRx.getDataLength(),DEC);
for(int i=0;i<zbRx.getDataLength();i++){
Serial.print(“payload[”);
Serial.print(i,DEC);
Serial.print(“is]”);
Serial.print(zbRx.getData(),HEX);

  • Serial.println("");*
  • }*
  • if(zbRx.getDataLength()>1){*
  • for(int i=0;i<zbRx.getDataLength();i++){*
    _ command.b*=zbRx.getData(i);_
    _
    } _
    _
    Serial.println(“The user’s prefered value is”);_
    _
    Serial.println(command.f);_
    _
    sensorValue=analogRead(ldr);_
    _
    Serial.println(“sensor value=”);_
    _
    Serial.println(sensorValue);_
    _ Volt= (5sensorValue)/1023;
    Lux= (13.449exp(1.0055Volt))/pow(d,2); //edw tha mpei o tupos ths sunarthshs_

    * Difference=command.f-Lux;*
    * if(Difference<=0){*
    * digitalWrite(relay,HIGH);*
    * }*
    * else{*
    * digitalWrite(relay,LOW);*
    * float VDifference=(log(Difference)-log(13.449))/1.0055; // antestrammenos o tupos ths sunarthshs ga na dinei volt*
    _ pwmValue1=(VDifference255)/5;_
    _
    pwmValue2=constrain(pwmValue1,0,255);_
    _
    analogWrite(dimout,pwmValue2);_
    _
    }_
    _
    Serial.print(“The amount of light at your workspace is:”);_
    _
    Serial.print(Lux);_
    _
    LuxValue.f=Lux;_
    _
    SData[0]=LuxValue.b[0];_
    _
    SData[1]=LuxValue.b[1];_
    _
    SData[2]=LuxValue.b[2];_
    _
    SData[3]=LuxValue.b[3];_
    _
    xbee.send(zbTx);*_

* }*
* else{*
* state=zbRx.getData(0);*

* if(state==1){*
* digitalWrite(relay,LOW);*
* Serial.println(“The lights are ON”);*

* }*
* else{*
* digitalWrite(relay,HIGH);*
* Serial.println(“The lights are of”);*
* }*
* }*
}

else if(xbee.getResponse().isError())
{
* Serial.print(“Error API Id”);*
* Serial.println(xbee.getResponse().getErrorCode());*
}
* start=millis();*
* }*
* else{*

* if(state==1)*
{
* if(millis()-start>timeStep){*
* Serial.println(“Automatic Control”);*
* sensorValue=analogRead(ldr);*
* Serial.println(“sensor value=”);*
* Serial.println(sensorValue);*
_ Volt=(5sensorValue)/1023;
Lux=13.449
exp(1.0055Volt)/pow(d,2);//pali o tupos ths sunarthshs_
_
Difference=command.f-Lux;_
_
if(Difference>0){_
_
digitalWrite(relay,LOW);_
_
VDifference= (log(Difference)-log(13.449))/1.0055;// antestrammenos o tupos ths sunarthshs ga na dinei volt*_
_ pwmValue1=(VDifference255)/5;_
_
pwmValue2=constrain(pwmValue1,0,255);_
_
analogWrite(dimout,pwmValue2);_
_
}_
_
else{_
_
digitalWrite(relay,HIGH);_
_
}_
_
Serial.print(“The amount of light at your workspace is:”);_
_
Serial.print(Lux);_
_
LuxValue.f=Lux;_
_
SData[0]=LuxValue.b[0];_
_
SData[1]=LuxValue.b[1];_
_
SData[2]=LuxValue.b[2];_
_
SData[3]=LuxValue.b[3];_
_
xbee.send(zbTx);_
_
}_
and here is a screenshot from the serial screen attached
My question is why are these strange characters appeared when the programm reaches the xbee.send(zbTx) ?
thanks in advance
_

*_