jankolkmeier / svd-xbee

Node talks to xbee radios through serialport

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error sending or broadcasting

freakent opened this issue · comments

I'm trying to send some data to a remote XBee using the following lines of code:

addr64 = [0x00, 0x13, 0xa2, 0x00, 0x40, 0xaa, 0x18, 0xdf];
xbee.send(packet.payload, addr64, [0xff, 0xfe], function(err, status) {
console.log(err, status);
});

But I'm getting the following runtime error:
Users/martin/Development/node/homa/components/xbee/node_modules/svd-xbee/lib/xbee-api.js:243
payload.push(this.destination64[i]);
^
TypeError: Cannot read property '0' of undefined
at TransmitRFData.getPayload (/Users/martin/Development/node/homa/components/xbee/node_modules/svd-xbee/lib/xbee-api.js:243:36)
at Packet.getBytes (/Users/martin/Development/node/homa/components/xbee/node_modules/svd-xbee/lib/xbee-api.js:83:24)
at XBee.send (/Users/martin/Development/node/homa/components/xbee/node_modules/svd-xbee/index.js:327:19)
at null. (/Users/martin/Development/node/homa/components/xbee/xbee-bridge:54:8)
at EventEmitter.emit (events.js:95:17)
at MqttClient. (/Users/martin/Development/node/homa/components/xbee/node_modules/homa/homa.js:128:10)
at MqttClient.EventEmitter.emit (events.js:106:17)
at MqttClient._handlePublish (/Users/martin/Development/node/homa/components/xbee/node_modules/homa/node_modules/mqtt/lib/client.js:459:12)
at Connection. (/Users/martin/Development/node/homa/components/xbee/node_modules/homa/node_modules/mqtt/lib/client.js:130:10)
at Connection.EventEmitter.emit (events.js:95:17)

It appears your code is expecting the 64 bit address in some form other than a hex array as it is calling .dec on the address. In the broadcast function you pass the same send method the broadcast address as a hex array and that also gives the same error.

Is this a bug or are you expecting the destination64 parameter to be passed through as some other type? If so I think the broadcast method may be wrong. I have for the moment removed the .dec and have it working but I'm not sure what the knock on effect might be.

Thanks.

Could you post a complete example that reproduces? You should not have to worry about the 64/16 addresses after creating a node like this:

// Add Node by hand...
var myNode = xbee.addNode([0x00,0x13,0xa2,0x00,0x40,0x61,0x2f,0xe4]);

Now you can send to the node:

myNode.send("payload");

Have you checked the examples in https://github.com/jouz/svd-xbee/blob/master/examples/ ?

I can produce a more complete code example later if still required, but it might be enough just to clarify how the api should be used. Apart from the need to include the 16 bit address, what's the difference between using these two methods?

  1. Send function on XBee
    xbee.send(payload, address64, address16)

  2. Send function on Node
    myNode = xbee.addNode(address)
    myNode.send(payload)

(this is obviously pseudo code)

Thanks for asking back! This made me realize that there is a bug in the
broadcast function in index.js!

address64 and address16 are not simply byte arrays, but objects that
internally store two representations of the address. If you want to create
those objects by hand, something like this should work:

var _r16 = [0xff,0xfe];
var _r64 = [0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff];
var remote16 = { dec: _r16, hex: XBee.Tools.bArr2HexStr(_r16) };
var remote64 = { dec: _r64, hex: XBee.Tools.bArr2HexStr(_r64) };
this.send(data, remote64, remote16, cb); // or xbee.send(..)

I understand this is confusing, but this design is inherited from the
project I forked svd-xbee from - and I didn't see any use in changing it.

I don't have access to any XBee equipment for the next two weeks, so I
can't properly fix and test this. If you want to do that feel free to make
a pull request, so I can get the fix upstream.

On Fri, Jul 12, 2013 at 1:25 PM, Martin Jarvis notifications@github.comwrote:

Apart from the need to include the 16 bit address, what's the difference
between using these two methods?

  1. Send function on XBee

xbee.send(payload, address64, address16)

  1. Send function on Node
    myNode = xbee.addNode(address)
    myNode.send(payload)

(this is obviously pseudo code)


Reply to this email directly or view it on GitHubhttps://github.com//issues/9#issuecomment-20871247
.

Ah now that makes perfect sense. If I get it working I will send you a pull request - I might also try to document some of the API calls! Is there a utility method somewhere to create a useful 64bit address (byte array?) from a plain string (e.g. "0013a20040aa18df") ? I have written one and I could add it to your tools library if that would be useful.

There is no such utility yet, I think it might be a nice addition!

On Fri, Jul 12, 2013 at 2:19 PM, Martin Jarvis notifications@github.comwrote:

Ah now that makes perfect sense. If I get it working I will send you a
pull request - I might also try to document some of the API calls! Is there
a utility method somewhere to create a useful 64bit address (byte array?)
from a plain string (e.g. "0013a20040aa18df") ? I have written one and I
could add it to your tools library if that would be useful.


Reply to this email directly or view it on GitHubhttps://github.com//issues/9#issuecomment-20873192
.