3

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user1618840
  • 453
  • 1
  • 5
  • 14
  • While this is a programming question you would find a lot more help if you asked this at the robotics stack exchange: http://robotics.stackexchange.com/ – krowe Jan 30 '14 at 09:07
  • Not getting a lot of views on the robotics stack exchange – user1618840 Jan 30 '14 at 09:55
  • I've noticed that you used a singular form of XBee 2 times. You do have 2 XBee radios correct? You need one to send and the other to receive. – krowe Jan 30 '14 at 09:57
  • @krowe eventually yes, but at the moment I'm just trying to send a local AT command to the connected xBee, and not succeeding in even that. – user1618840 Jan 30 '14 at 10:01
  • Are you using X-CTU? If not I STRONGLY suggest that you grab it in order to get yourself setup. I followed this tutorial to figure it out: http://www.ladyada.net/make/xbee/configure.html – krowe Jan 30 '14 at 10:13
  • @krowe is there a reason to use that over another terminal program? I have been using coolterm to set it up, and had no trouble configuring the module – user1618840 Jan 30 '14 at 10:39
  • X-CTU is not primarily a terminal program it is a configuration utility for your XBee. – krowe Jan 30 '14 at 10:47
  • While we always appreciate people sending us new users @krowe please make sure you look at what questions are [on topic](http://robotics.stackexchange.com/help/on-topic) before recommending Stack Exchange sites to people. – Mark Booth Jan 30 '14 at 19:53
  • @user1618840 - Please don't [post the same question to multiple sites](http://robotics.stackexchange.com/q/2408/37). If a question needs to be on another site, flag it for the attention of a moderator and it will be moved to the other sites if appropriate. Also, please be impatient, not every question can get answered immediately, especially on smaller sites. – Mark Booth Jan 30 '14 at 19:55

1 Answers1

1

It turns out it was the baudrate! It needs to be 9600 (unless I change the baudrate of the XBee).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user1618840
  • 453
  • 1
  • 5
  • 14
  • Not really, for you it does because you haven't used X-CTU to configure your XBee. 9600 baud is just the default factory baudrate (it is also the slowest supported). – krowe Jan 30 '14 at 10:46