I'm currently working with Node.js on a Raspberry Pi and have connected a series 1 XBee radio via the USB port. To intergrate with Node.js, I am using the xbee-api module.
While I don't have any trouble issuing commands to the XBee from my laptop (pin changes, etc.) I am unable to issue any commands via API mode in xbee-api.
Here is my test code (mostly copied from the xbee-api homepage):
var util = require('util');
var SerialPort = require('serialport').SerialPort;
var xbee_api = require('xbee-api');
var C = xbee_api.constants;
var xbeeAPI = new xbee_api.XBeeAPI({
api_mode: 1
});
var serialport = new SerialPort("/dev/ttyUSB0", {
baudrate: 57600,
parser: xbeeAPI.rawParser()
});
serialport.on("open", function() {
console.log("open");
var frame_obj = { // AT Request to be sent to
type: C.FRAME_TYPE.AT_COMMAND,
command: "D0",
commandParameter: [0x05],
};
serialport.write(xbeeAPI.buildFrame(frame_obj));
});
// All frames parsed by the XBee will be emitted here
xbeeAPI.on("frame_object", function(frame) {
console.log(">>", frame);
});
I get the response "open", but there isn't any indication that the command is being sent. The above command is a local command to change pin D0 to high, but the pin value has not changed in reality.
I've reset the XBee radio to defaults and have then put it in API mode from my laptop (+++, ATAP 1, ATWR).
It's very puzzling, as no one else seems to have this problem with the xbee-api Node.js module.