66* https://learn.sparkfun.com/tutorials/using-the-bluesmirf/all
77*/
88
9- var txt = ui . addText ( "" , 10 , 450 , ui . screenWidth , - 1 ) ;
9+ var txt = ui . addText ( 10 , 450 , ui . screenWidth , - 1 ) ;
1010
11- ui . addButton ( "Scan bluetooth" , 10 , 0 , function ( ) {
12- network . scanBluetoothNetworks ( function ( n , m , s ) {
11+ ui . addButton ( "Scan bluetooth" , 10 , 0 ) . onClick ( function ( ) {
12+ network . bluetooth . scanNetworks ( function ( n , m , s ) {
1313 console . log ( "hola" , n , m , s ) ;
1414 txt . append ( n + " " + m + " " + s + "\n" ) ;
1515 } ) ;
16- } )
17-
18- ui . addButton ( "Connect to bluetooth" , 10 , 150 , function ( ) {
19- network . connectBluetoothSerialByUi ( function ( m , data ) {
16+ } ) ;
17+
18+ var btClient ;
19+ ui . addButton ( "Connect to bluetooth" , 10 , 150 ) . onClick ( function ( ) {
20+ //if you want to use the Bluetooth Address, use
21+ //network.bluetooth.connectSerial(macAddess, function(status) {});
22+ btClient = network . bluetooth . connectSerial ( function ( status ) {
23+ console . log ( "connected " + status ) ;
24+ } ) ;
25+
26+ btClient . onNewData ( function ( data ) {
2027 txt . text ( data + "\n" ) ;
2128 } ) ;
22- } )
29+ } ) ;
2330
24- ui . addButton ( "Disconnect" , 380 , 150 , function ( ) {
25- network . disconnectBluetooth ( ) ;
26- } )
31+ ui . addButton ( "Disconnect" , 380 , 150 ) . onClick ( function ( ) {
32+ btClient . disconnect ( ) ;
33+ } ) ;
2734
2835var input = ui . addInput ( "message" , 10 , 300 , 200 , 100 ) ;
29- var send = ui . addButton ( "Send" , 210 , 300 , 150 , 100 , function ( ) {
30- network . sendBluetoothSerial ( input . getText ( ) + "\n" ) ;
31- } )
32-
33-
34-
35-
36- // ---------- other methods
37- // network.connectBluetoothSerialByMac("98:D3:31:30:1A:4E", function(m, data) {
38- // console.log(data);
39- // });
40-
41- // network.connectBluetoothSerialByName("bqZUM_BT328", function(m, data) {
42- // console.log(m, data);
43- // });
44- // network.enableBluetooth(true);
45- // network.enableBluetooth(false);
46- // network.isBluetoothConnected();
47- // network.getBluetoothBondedDevices();
36+ var send = ui . addButton ( "Send" , 210 , 300 , 150 , 100 ) . onClick ( function ( ) {
37+ btClient . send ( input . getText ( ) + "\n" ) ;
38+ } ) ;
0 commit comments