I’m using the arduino API library and trying to perform AT commands. I’ve had plenty of luck before using remote AT commands, but for some reason this nearly identical process won’t work.
I’m not actually using software serial. I’m loading the program to the board, running it with the Xbee attached, and then checking it in XCTU afterward to see if the parameter has changed. There should be no conflicts with serial ports.
All I get with this code is a ‘~’ (7E, the start delimiter byte) character that shows up in the serial port. Then the script progresses no further and the command is not executed.
I thought it had something to do with my Arduino so I trued a Nano (I had one lying around) instead of an Uno.This time, It looks like I got the whole string out, but the radio still does not respond or change values.
#include
#include
// Define SoftSerial TX/RX pins
// Connect Arduino pin 8 to TX of usb-serial device
uint8_t ssRX = 8;
// Connect Arduino pin 9 to RX of usb-serial device
uint8_t ssTX = 9;
// Remember to connect all devices to a common Ground: XBee, Arduino and USB-Serial device
SoftwareSerial nss(ssRX, ssTX);
XBee xbee = XBee();
// serial high
uint8_t D3Cmd[] = { ‘D’, ‘3’ }; //D3
uint8_t low[] = { 0x04 };////for DI03 pin parameter
AtCommandRequest atRequest = AtCommandRequest(D3Cmd, low, 1);
AtCommandResponse atResponse = AtCommandResponse();
void setup() {
Serial.begin(9600);
xbee.begin(Serial);
// start soft serial
//nss.begin(9600);
// Startup delay to wait for XBee radio to initialize.
// you may need to increase this value if you are not getting a response
delay(10000);
}
void loop() {
atRequest.setCommand(D3Cmd);
atRequest.setCommandValue(low);
atRequest.setCommandValueLength(sizeof(low));
sendAtCommand();
while (1) {};
}
void sendAtCommand() {
nss.println(“Sending command to the XBee”);
// send the command
xbee.send(atRequest);
// 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() == AT_COMMAND_RESPONSE) {
xbee.getResponse().getAtCommandResponse(atResponse);
if (atResponse.isOk()) {
nss.print("Command [");
nss.print(atResponse.getCommand()[0]);
nss.print(atResponse.getCommand()[1]);
nss.println("] was successful!");
if (atResponse.getValueLength() > 0) {
nss.print("Command value length is ");
nss.println(atResponse.getValueLength(), DEC);
nss.print("Command value: ");
for (int i = 0; i < atResponse.getValueLength(); i++) {
nss.print(atResponse.getValue()[i], HEX);
nss.print(" ");
}
nss.println("");
}
}
else {
nss.print("Command return error code: ");
nss.println(atResponse.getStatus(), HEX);
}
}
else {
nss.print("Expected AT response but got ");
nss.print(xbee.getResponse().getApiId(), HEX);
}
}
else {
// at command failed
if (xbee.getResponse().isError()) {
nss.print("Error reading packet. Error code: ");
nss.println(xbee.getResponse().getErrorCode());
}
else {
nss.print("No response from radio");
}
}
}