I've the following scenario: One Xbee Series 1 (coordinator) connected to the computer through Xbee USB xplorer and using the XCTU software in API mode (AP=2), and another Xbee Series 1 (end device) connected to an Arduino UNO through a Shield (also configured in API mode). Both are in the same PAN ID and can send and receive text messages in AT mode. I can send an API frame from XCTU to the Xbee connected to Arduino and I get a response. Now I'm trying to program arduino's code to send a remote at commands to the coordinator but it's not working. Here you can see the code I'm using:
#include <XBee.h>
#include <SoftwareSerial.h>
SoftwareSerial ss(3,2); //RX, TX
XBee xbee = XBee();
uint8_t atCmd[] = {'M','Y'}; //command AT
uint8_t atVal[]={}; // command AT value
XBeeAddress64 remoteAddress = XBeeAddress64(0x0013a200, 0x40cc0b20);
RemoteAtCommandRequest remoteAtRequest = RemoteAtCommandRequest(remoteAddress, atCmd);
RemoteAtCommandResponse remoteAtResponse = RemoteAtCommandResponse();
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
xbee.begin(Serial);
ss.begin(9600);
delay(5000);
}
void loop() {
// put your main code here, to run repeatedly:
sendRemoteAtCommand();
remoteAtRequest.clearCommandValue();
}
void sendRemoteAtCommand() {
ss.println("Sending Command");
xbee.send(remoteAtRequest);
if(xbee.readPacket(5000)){
if(xbee.getResponse().getApiId() == REMOTE_AT_COMMAND_RESPONSE) {
xbee.getResponse().getRemoteAtCommandResponse(remoteAtResponse);
if(remoteAtResponse.isOk()){
ss.print("Command [");
ss.print(remoteAtResponse.getCommand()[0]);
ss.print(remoteAtResponse.getCommand()[1]);
ss.print("] was successful");
if(remoteAtResponse.getValueLength() > 0){
ss.print("Command value length is ");
ss.println(remoteAtResponse.getValueLength(), DEC);
ss.print("Command value: ");
for(int i = 0; i < remoteAtResponse.getValueLength(); i++){
ss.print(remoteAtResponse.getValue()[i], HEX);
ss.print(" ");
}
ss.print(" ");
}
} else {
ss.print("Command returned error code: ");
ss.println(remoteAtResponse.getStatus(), HEX);
}
} else {
ss.print("Expected Remote AT response but got ");
ss.println(xbee.getResponse().getApiId(), HEX);
}
} else if (xbee.getResponse().isError()){
ss.print("Error reading packet. Error code: ");
ss.println(xbee.getResponse().getErrorCode());
}else{
ss.print("No response from radio");
}
}
I'm just trying to send the command ATMY and get the response from the coordinator, but what I get is the "No response from radio".
Here is the example (and library) I'm using https://code.google.com/p/xbee-arduino/source/browse/examples/RemoteAtCommand/RemoteAtCommand.pde It's the same but with a diferent request.
Anyone have some idea about what can be wrong?
Thank you!!