bluetooth-programmer
Advanced tools
{ | ||
"name": "bluetooth-programmer", | ||
"version": "0.5.0", | ||
"version": "1.0.0", | ||
"description": "Api to make programming bluetooth modules via USB or Serial simple and easy.", | ||
@@ -5,0 +5,0 @@ "main": "bluetooth-programmer.js", |
154
README.md
@@ -14,5 +14,155 @@ Bluetooth To Serial Hookup And Programming | ||
Connecting the bluetooth board manually | ||
Connecting and programming the bluetooth board via node | ||
==== | ||
`sudo npm install bluetooth-programmer` | ||
You will most likely need to run your app with root privileges in order to program the Bluetooth module. | ||
`sudo node yourProgram` | ||
For the most part to program one module at a time, you can use the example app and modify the settings you would like. You can also tweak it just a bit to program many modules. | ||
### Finding bluetooth modules connected via USB or serial | ||
|param|required| | ||
|-----|--------| | ||
|callback when all USB/Serial ports scanned|true| | ||
|baud rate (if not specified all valid bauds will be checked)|false| | ||
You can search all detected USB or Serial ports on all baud rates using the below command. This comes in handy when you have a module which you don't know the baud rate of. | ||
BTP.find( | ||
foundDevices | ||
); | ||
function foundDevices(devices){ | ||
console.log(devices); | ||
} | ||
For a faster scan if you know the baud rate of the device you can specify it so the app does not need to itterate over all of the common baud rates. | ||
BTP.find( | ||
foundDevices, | ||
9600 | ||
); | ||
function foundDevices(devices){ | ||
console.log(devices); | ||
} | ||
### Connecting to the bluetooth module | ||
you can manually connect to a Bluetooth module by passing in the port info | ||
{ | ||
comName : '/tty/USB0' //COM1 etc | ||
baud : 9600 | ||
} | ||
this information and more is provided for you when you use the `BT.find` method. | ||
function foundDevices(devices){ | ||
console.log(devices); | ||
} | ||
Connecting using the `BT.find` results : | ||
function foundDevices(devices){ | ||
var list=Object.keys(devices); | ||
BTDevices=devices; | ||
console.log('Found BT Devices :\n####>',devices); | ||
if(!list[0]) | ||
return; | ||
BTP.connect(devices[list[0]],connectedToBT); | ||
} | ||
Connecting Manually : | ||
var BTP=require('bluetooth-programmer'); | ||
BTP.connect( | ||
{ | ||
comName : '/tty/USB0' //COM1 etc | ||
baud : 9600 | ||
}, | ||
connectedToBT | ||
); | ||
you can also assign the port to a variable. | ||
var myBTModule=BTP.connect(devices[list[0]],connectedToBT); | ||
Things to do once connected. | ||
|event|when it happens|trigger| | ||
|-----|---------------|-------| | ||
|open|when the serial socket to the bluetooth module is opened|this.open() myBTModule.open() (rarely used as this should be automatic)| | ||
|close|when the serial socket to the bluetooth module has been closed|this.close() myBTModule.close()| | ||
|error|when something goes wrong with the serial socket|false| | ||
function connectedToBT(){ | ||
this.on( | ||
"data", | ||
function(data){ | ||
console.log(data); | ||
} | ||
); | ||
this.on( | ||
"close", | ||
function(){ | ||
console.log('closed'); | ||
} | ||
); | ||
this.on( | ||
"error", | ||
function(err){ | ||
console.log('error',err); | ||
} | ||
); | ||
} | ||
### Simple commands you can use to program to the Bluetooth module | ||
|Command|Details|Settable|Response| | ||
|-------|------|--------|--------| | ||
|BTTest|Tests Raw Connection you may also want to use this to check for a return from your last command|false|null or the last message from a command| | ||
|BTName|Sets Bluetooth Device name. 20 Chars max.|true|setname| | ||
|BTBaud|1 or 1200, 2 or 2400, 3 or 4800, 4 or 9600, 5 or 19200, 6 or 38400, 7 or 57600, 8 or 115200|true|{BaudRate} i.e. 9600| | ||
|BTVersion|Returns the firmware version|false|linvor1.8 or something similar| | ||
|BTPin|Sets a new pairing code, 4 digits|true|setPIN| | ||
|BTParity|Set board parity. You probably don't need to do this. None (no parity), Odd (odd parity) or Even (even parity)|true| {None|Odd|Even}| | ||
this.BTName('DNZ38400'); | ||
this.BTPin('1314'); | ||
this.BTParity('None'); | ||
this.BTBaud(38400); | ||
this.BTTest(); | ||
OR | ||
myBTModule.BTName('DNZ38400'); | ||
myBTModule.BTPin('1314'); | ||
myBTModule.BTParity('None'); | ||
myBTModule.BTBaud(38400); | ||
myBTModule.BTTest(); | ||
***It is always a good idea to end with a BTTest() call to see the last response returned.*** | ||
Connecting and programming the bluetooth board manually | ||
==== | ||
1. Open a serial terminal such as `CuteCom` or `CoolTerm` depending on your operating system. | ||
@@ -31,3 +181,3 @@ 2. Choose the USB port your bluetooth to serial is connected to. Likely `/dev/USB0` on linux, unix, and Mac ***OR*** `Com0` on windows, though this could be different depending on what you have connected to your computer. | ||
#Some common commands | ||
|Command|Action|Settable|Response| | ||
|Command|Details|Settable|Response| | ||
|-------|------|--------|--------| | ||
@@ -34,0 +184,0 @@ |AT|Tests Raw Connection|false|OK| |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
98517
4.44%2
-33.33%190
375%