File tree Expand file tree Collapse file tree 2 files changed +27
-7
lines changed
Expand file tree Collapse file tree 2 files changed +27
-7
lines changed Original file line number Diff line number Diff line change @@ -71,13 +71,28 @@ find serial port channel
7171``` js
7272device .findSerialPortChannel (address, function (channel ){
7373 console .log (' Found RFCOMM channel for serial port on %s: ' , name, channel);
74-
74+
7575 // make bluetooth connect to remote device
7676 bluetooth .connect (address, channel, function (err , connection ){
7777 if (err) return console .error (err);
7878 connection .write (new Buffer (' Hello!' , ' utf-8' ));
7979 });
80-
80+
81+ });
82+ ```
83+
84+ create connection to device, read and write
85+
86+ ``` js
87+ // make bluetooth connect to remote device
88+ bluetooth .connect (address, channel, function (err , connection ){
89+ if (err) return console .error (err);
90+
91+ connection .on (' data' , (buffer ) => {
92+ console .log (' received message:' , buffer .toString ());
93+ });
94+
95+ connection .write (new Buffer (' Hello!' , ' utf-8' ));
8196});
8297```
8398
Original file line number Diff line number Diff line change @@ -8,19 +8,24 @@ var list = [];
88device
99. on ( 'finished' , console . log . bind ( console , 'finished' ) )
1010. on ( 'found' , function found ( address , name ) {
11-
11+
1212 console . log ( 'Found: ' + address + ' with name ' + name ) ;
13-
13+
1414 // find serial port channel
1515 device . findSerialPortChannel ( address , function ( channel ) {
1616 console . log ( 'Found RFCOMM channel for serial port on %s: ' , name , channel ) ;
17-
17+
1818 // make bluetooth connect to remote device
1919 bluetooth . connect ( address , channel , function ( err , connection ) {
2020 if ( err ) return console . error ( err ) ;
21+
22+ connection . on ( 'data' , ( buffer ) => {
23+ console . log ( 'received message:' , buffer . toString ( ) ) ;
24+ } ) ;
25+
2126 connection . write ( new Buffer ( 'Hello!' , 'utf-8' ) ) ;
2227 } ) ;
23-
28+
2429 } ) ;
25-
30+
2631} ) . inquire ( ) ;
You can’t perform that action at this time.
0 commit comments