Skip to content

Instantly share code, notes, and snippets.

@AdamMagaluk
Created March 19, 2014 17:50
Show Gist options
  • Save AdamMagaluk/9647344 to your computer and use it in GitHub Desktop.
Save AdamMagaluk/9647344 to your computer and use it in GitHub Desktop.
xbee and node
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 port = new SerialPort('/dev/tty.usbserial-A601EM9S', {
baudrate: 9600,
parser: xbeeAPI.rawParser()
});
var i = 0;
function sendToRemote(){
var frame = {
type: 0x10,
destination64: "0013a200408b8189",
options: 0x00, // optional, 0x00 is default
data: "Data Packet " + i++
};
port.write(xbeeAPI.buildFrame(frame), function(err, res) {
if (err) throw(err);
});
}
port.on('open',function(){
console.log('opened...')
setInterval(sendToRemote,1000);
});
xbeeAPI.on("frame_object", function(frame) {
console.log(frame)
if(frame.data)
console.log("Data> ",new Buffer(frame.data,'hex').toString());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment