Skip to content

Instantly share code, notes, and snippets.

@mindoftea
Created June 21, 2014 22:09
Show Gist options
  • Save mindoftea/ac6ca90687e0f1c10d0f to your computer and use it in GitHub Desktop.
Save mindoftea/ac6ca90687e0f1c10d0f to your computer and use it in GitHub Desktop.
Node-bluetooth-serial-port writing lag test case. Writing consistently takes 250ms to complete on OSX.
"use strict";
var bluetooth=require('bluetooth-serial-port');
bluetooth=new bluetooth.BluetoothSerialPort();
var write=function()
{
var timeStamp;
console.log("sending...");
timeStamp=Date.now();
bluetooth.write(
new Buffer("some data","utf-8"),
function(err,bytesWritten)
{
console.log("sent.");
console.log("lag time: "+(Date.now()-timeStamp));
write();
}
);
};
var fail=function()
{
console.log('cannot connect');
}
bluetooth.on(
'found',
function(address,name)
{
bluetooth.findSerialPortChannel(
address,
function(channel)
{
bluetooth.connect(
address,
channel,
write,
fail
);
}
);
}
);
bluetooth.inquire();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment