Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
bluetooth-programmer
Advanced tools
Api to make programming bluetooth modules via USB or Serial simple and easy.
Diagrams and documents on hooking up bluetooth and serial boards to create a bluetooth to serial connection.
This is how to hook up the Bluetooth board to the serial board.
Note that the TX and RX cables cross. TX->RX & RX->TX
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.
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);
}
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);
}
);
}
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 |
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.
CuteCom
or CoolTerm
depending on your operating system./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.line ending
to none or no line end this is normally defaulted to CRLF or something similar.AT
this should return OK
, if it does not you are not properly connected to your board. Check the hardware connections, and the serial terminal settings. is your line ending set to no line ending
? Are you connected to the right port? Perhaps your board starts with a different baud rate?AT+VERSION
this should return the firmware version on your bluetooth board. Perhaps something similar to linvorV1.8
if you want to know specific commands for your version you can always google the returned version number to learn more. If nothing returns try sending AT VERSION?
and AT VERSION
#Some common commands
Command | Details | Settable | Response |
---|---|---|---|
AT | Tests Raw Connection | false | OK |
AT+NAME{name} | Sets Bluetooth Device name. 20 Chars max. | true | OKsetname |
AT+BAUD{baudID} | 1=1200, 2=2400, 3=4800, 4=9600, 5=19200, 6=38400, 7=57600, 8=115200 | true | OK{BaudRate} i.e. OK9600 |
AT+VERSION | Returns the firmware version | false | linvor1.8 or something similar |
AT+PIN{pin} | Sets a new pairing code, 4 digits | true | OKsetPIN |
AT+P{N | O | E} | Set board parity. You probably don't need to do this. N (no parity), O (odd parity) or E (even parity) |
FAQs
Api to make programming bluetooth modules via USB or Serial simple and easy.
We found that bluetooth-programmer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.