Unable to send remote AT commands when using Xbee/Zigbee API library

I have verified that my network is established and I can use the Python API module to send out remote AT commands and everything works just fine.

When I use Andrewrapp's Xbee library's remoteAtCommand example I am not getting any response after addressing and sending remote AT commands to my routers from the coordinator, or inversely, from my coordinator to the routers.

However I can run the basic AtCommand example and request data from the physically connected radio (which works).

I also believe I was able to send serial bytes to my coordinator using the address DH=0x00000000 DL=0x00000000 as both blue lights illuminated the instant the command was issued.

But if I change the address to a specific device's address I get no response no matter what.

I am using three S2 ZigBee pro's running the latest firmware from Digi. Two are routers and the other is a coordinator.

All are set for API mode and have matching PAN ids. All other options are default.

I have my radio connected to Serial1 on an Arduino Mega2560 board.

And my IDE is v1.6.5

After noticing a lack of information on the web/google regarding these exact issues I have concluded that it is not a common problem with this library?? Thus I feel either I'm doing something wrong, or possibly the new IDE is conflicting with the Xbee library?

Are there any other Xbee libraries available?

What should I do next?? help! Thx :slight_smile:

What should I do next?

Posting some code comes to mind.

Using the latest version of the IDE does too.

Thank you PaulS.

I have updated to IDE 1.6.11

Today my order arrived for additional ZigBees and some proper breakout boards.

So I have now connected everything up and given each radio a PanID=AF.

The sketch I'm using is very similar to the example, but with different address and no softwareserial.

Also this sketch is running on an arduino which is connected to a router and tries to set another router's D0 pin to disabled and set the interval to 0/off.

XBee xbee = XBee();

// Turn off I/O sampling
uint8_t irCmd[] = {'I','R'};
// Set sample rate to 65 seconds (0xffff/1000)
uint8_t irValue[] = { 0x00, 0x00 };

// Set DIO0 (pin 20) to Off
uint8_t d0Cmd[] = { 'D', '0' };
uint8_t d0Value[] = { 0x00 };

// SH + SL of your remote radio
XBeeAddress64 remoteAddress = XBeeAddress64(0x0013a200, 0x4089e9a7);
// Create a remote AT request with the IR command
RemoteAtCommandRequest remoteAtRequest = RemoteAtCommandRequest();
  
// Create a Remote AT response object
RemoteAtCommandResponse remoteAtResponse = RemoteAtCommandResponse();

void setup() { 
  Serial1.begin(57600);
  xbee.begin(Serial1);
  // start serial debug
  Serial.begin(9600);

 delay(5000);
 remoteAtRequest.setRemoteAddress64(remoteAddress);
}

void loop() {
  // now reuse same object for DIO0 command
  remoteAtRequest.setCommand(d0Cmd);
  remoteAtRequest.setCommandValue(d0Value);
  remoteAtRequest.setCommandValueLength(sizeof(d0Value));
  sendRemoteAtCommand();//this function has not been changed from the examples
  
  delay(5000);
  // now reuse same object for DIO0 command
  remoteAtRequest.setCommand(irCmd);
  remoteAtRequest.setCommandValue(irValue);
  remoteAtRequest.setCommandValueLength(sizeof(irValue));
  sendRemoteAtCommand();//this function has not been changed from the examples
  
  // it's a good idea to clear the set value so that the object can be reused for a query
  remoteAtRequest.clearCommandValue();
  
  // we're done
  while (1) {};
}

void sendRemoteAtCommand() {
  Serial.println("Sending command to the XBee");

  // send the command
  xbee.send(remoteAtRequest);

  // wait up to 5 seconds for the status response
  if (xbee.readPacket(5000)) {
    // got a response!

    // should be an AT command response
    if (xbee.getResponse().getApiId() == REMOTE_AT_COMMAND_RESPONSE) {
      xbee.getResponse().getRemoteAtCommandResponse(remoteAtResponse);

      if (remoteAtResponse.isOk()) {
        Serial.print("Command [");
        Serial.print(remoteAtResponse.getCommand()[0]);
        Serial.print(remoteAtResponse.getCommand()[1]);
        Serial.println("] was successful!");

        if (remoteAtResponse.getValueLength() > 0) {
          Serial.print("Command value length is ");
          Serial.println(remoteAtResponse.getValueLength(), DEC);

          Serial.print("Command value: ");
          
          for (int i = 0; i < remoteAtResponse.getValueLength(); i++) {
            Serial.print(remoteAtResponse.getValue()[i], HEX);
            Serial.print(" ");
          }

          Serial.println("");
        }
      } else {
        Serial.print("Command returned error code: ");
        Serial.println(remoteAtResponse.getStatus(), HEX);
      }
    } else {
      Serial.print("Expected Remote AT response but got ");
      Serial.print(xbee.getResponse().getApiId(), HEX);
    }    
  } else if (xbee.getResponse().isError()) {
    Serial.print("Error reading packet.  Error code: ");  
    Serial.println(xbee.getResponse().getErrorCode());
  } else {
    Serial.print("No response from radio");  
  }
}

When using the simple AtCommand example I still do see a response from the radio wired to the arduino.

When using the RemoteAtCommand if I set the destination address as 0x00000000 0x00000000 I can see that routers communicate with the coordinator but still no router-to-router communication.
seems that if the address is anything other than all zeros then things don't work as expected. Or maybe I've got the wrong idea about ZigBee??

I just hope my project isn't doomed!

This is my current configuration:
xbeemesh.jpg

This is my Coordinator's XCTU configuration:

And finally, this is how things are connected:

I have just built an adapter which allows me to log the serial bytes going into my radios.

Here's what it has revealed:

Bytes from Arduino Xbee library:
Address: DH=0x0013a200, DL=0x4089e9a7
Command: D0=0x00
Frame: 7E 00 10 17 01 00 7D 33 A2 00 40 89 E9 A7 00 00 00 44 30 00 DD
Command: IR=0x00
Frame: 7E 00 10 17 01 00 7D 33 A2 00 40 89 E9 A7 00 00 00 49 52 00 B6
(No Response)

Address: DH=0x00000000, DL=0x00000000
Command: D0=0x00
Frame: 7E 00 10 17 01 00 00 00 00 00 00 00 00 00 00 00 44 30 00 73
Command: IR=0x00
Frame: 7E 00 10 17 01 00 00 00 00 00 00 00 00 00 00 00 49 52 00 4C
(Response OK)

Bytes from Python Module:
Address: DH=0x0013a200, DL=0x4089e9a7
Command: D0=0x00
Frame: 7E 00 10 17 00 00 13 A2 00 40 89 E9 A7 FF FE 02 44 30 00 67
Command: IR=0x00
Frame: 7E 00 11 17 00 00 13 A2 00 40 89 E9 A7 FF FE 02 49 52 00 00 40
(Response OK)

Address: DH=0x00000000, DL=0x00000000
Command: D0=0x00
Frame: 7E 00 10 17 00 00 00 00 00 00 00 00 00 FF FE 02 44 30 00 75
Command: IR=0x00
Frame: 7E 00 11 17 00 00 00 00 00 00 00 00 00 FF FE 02 49 52 00 00 4E
(Response OK)

By comparing the frames from Python to frames from Arduino for the same commands and address I can definitely see a discrepancy in the addressing:

Arduino: 7E 00 10 17 01 00 7D 33 A2 00 40 89 E9 A7 00 00 00 44 30 00 DD

Python: 7E 00 10 17 00 00 13 A2 00 40 89 E9 A7 FF FE 02 44 30 00 67

So I'm very convinced the Arduino Xbee library is outputting an erroneous address of some sort. But why?

[Edit]

Closer look at the address data:

[color=limegreen]00 1[/color][color=teal]3 A2 00 40 89 E9 A7[/color] - Good Address (logged from Python)
[color=red]7D 3[/color][color=teal]3 A2 00 40 89 E9 A7[/color] - Bad Address (logged from Arduino)

[color=limegreen]00000000_0001[/color][color=teal]0011_10100010_00000000_01000000_10001001_11101001_10100111[/color]
[color=red]01111101_0011[/color][color=teal]0011_10100010_00000000_01000000_10001001_11101001_10100111[/color]

Seems it all boils down to those first 12 bits?

[Edit]

I found that byte 13 (carriage return) behaves strangely whenever/wherever it is used in the destination address. I notice that where ever the byte 13 exists the output is always 7D 33 and the address gets totally botched.

For example:

If I set the destination address to:
XBeeAddress64 remoteAddress = XBeeAddress64(0x0014a200, 0x4089e9a7);
Then the output is:
7E 00 10 17 01 00 14 A2 00 40 89 E9 A7 00 00 00 44 30 00 64

But lets say I set the destination address to:
XBeeAddress64 remoteAddress = XBeeAddress64(0x0014a200, 0x1389e9a7);
Then the output is:
7E 00 10 17 01 00 14 A2 00 7D 33 89 E9 A7 00 00 00 44 30 00 91

And if I were ever unlucky enough to get a radio with many 13s in the address:
XBeeAddress64 remoteAddress = XBeeAddress64(0x0013a200, 0x13131313);
Then the output is:
7E 00 10 17 01 00 7D 33 A2 00 7D 33 7D 33 7D 33 7D 33 00 00 00 44 30 00 72

I have absolutely no idea where to even begin looking now but I believe I have found part of the problem.
Could this possibly have something to do with the Arduino Serial library or the fact that I'm using Serial1 and not Serial?

1 Like

Could this possibly have something to do with the Arduino Serial library or the fact that I'm using Serial1 and not Serial?

I think I'd be more inclined to look at what the XBee library actually sends to the outgoing serial buffer. It seems very strange that it would mangle the address only, when the address contained a 0x13, but stranger things have happened.

I can't imagine that which serial port is the destination makes any difference. I'd expect the core functionality to be the same.

I think you've done a marvelous job, so far, of tracking the problem. It's far more than I would have accomplished.

I have resolved the issue entirely. And it was extremely simple to do.

Reffering to Digi's Xbee/Xbee-Pro manual on page 74 it states:

The confusion came from the fact that Python is not escaping byte 0x13 but Arduino is. And the option for "API Enable" operation was not very obvious at first.

So the register "API Enable" (AP) must be set accordingly.

AP=2 (were 0x13 is being escaped - this works with Arduino library)
AP=1 (were 0x13 is passed without escaping - this works with Python module)

Now all is good!
:slight_smile: