bt
11 min
the bt object allows you to check if bluetooth is fitted; set, monitor, or retrieve the current ble advertisements; scan for bluetooth devices; and trigger connection to, and disconnection from, another device bt idl enum btcentraleventtype { 'advertising report', 'device found', 'device lost' }; interface btcentraladvertisingreportevent { attribute string adapter path; attribute string device address; attribute int rssi; attribute array\<byte> data; }; interface btcentraldevicefoundevent { attribute string adapter path; attribute string address; attribute string alias; \[optional] attribute string name; \[optional] attribute int rssi; \[optional] attribute int tx power; \[optional] attribute array\<string> uuids; \[optional] attribute array\<byte> advertising flags; \[optional] attribute array\<array\<int, array\<byte>>> manufacturer data; \[optional] attribute map\<string, array\<byte>> service data; }; interface btcentraldevicelostevent { attribute string adapter path; attribute string address; }; typedef (btcentraladvertisingreportevent | btcentraldevicefoundevent | btcentraldevicelostevent) btcentralevent; callback btcentraleventcallback = void (btcentralevent event); interface btcentral { promise\<array\<adapter>> getadapters(); promise\<void> scan(optional scanparameters); promise\<void> stopscan(); void addeventlistener(btcentraleventtype type, btcentraleventcallback callback); void removeeventlistener(btcentraleventtype type, btcentraleventcallback callback); }; interface adapter { attribute string name; attribute bool powered; }; interface scanparameters { attribute bool advertisingreports; }; object creation to create a bt object, first load the brightsign/bt module using the require() method then create an instance of the bt class var btclass = require("@brightsign/bt"); var bt = new btclass(); btcentraladvertisingreportevent adapter path \<font color="#704ae0">string\</font> \<font color="#01a0af">required\</font> the adapter that the advertising device belongs to device address \<font color="#704ae0">string\</font> \<font color="#01a0af">required\</font> the identifier for a remote advertising device rssi \<font color="#704ae0">int\</font> \<font color="#01a0af">required\</font> the signal strength of the device when an advertisement is reported data \<font color="#704ae0">array\<byte\>\</font> \<font color="#01a0af">required\</font> advertisement data btcentraldevicefoundevent indicates if a bluetooth device is found during scanning adapter path \<font color="#704ae0">string\</font> \<font color="#01a0af">required\</font> the adapter that the advertising device belongs to address \<font color="#704ae0">string\</font> \<font color="#01a0af">required\</font> the unique bluetooth address of the device alias \<font color="#704ae0">string\</font> \<font color="#01a0af">required\</font> an alternate name for the remote device name \<font color="#704ae0">string\</font> \<font color="#01a0af">optional\</font> the name of the bluetooth device rssi \<font color="#704ae0">int\</font> \<font color="#01a0af">optional\</font> the signal strength of the device tx power \<font color="#704ae0">int\</font> \<font color="#01a0af">optional\</font> the transmitted power level of the device uuids \<font color="#704ae0">array\<string\>\</font> \<font color="#01a0af">optional\</font> uuid strings advertising flags \<font color="#704ae0">array\<byte\>\</font> \<font color="#01a0af">optional\</font> the flags used for advertising manufacturer data \<font color="#704ae0">array\<array\<int, array\<byte\>\>\>\</font> \<font color="#01a0af">optional\</font> the manufacturer specific advertisement data keyed by manufacturer id service data \<font color="#704ae0">map\<string, array\<byte\>\>\</font> \<font color="#01a0af">optional\</font> the service advertisement data keyed by uuid btcentraldevicelostevent this is used to report when a bluetooth device is lost adapter path \<font color="#704ae0">string\</font> \<font color="#01a0af">required\</font> the adapter that the advertising device belongs to address \<font color="#704ae0">string\</font> \<font color="#01a0af">required\</font> the unique bluetooth address of the device btcentral use this interface to perform actions on bluetooth streaming connections getadapters() promise\<array\<adapter>> getadapters() returns an array of adapter identity strings the number of elements in the array is the number of bluetooth adapters fitted scan() promise\<void> scan(optional scanparameters) reports new bluetooth devices as they are discovered it is also possible to monitor raw advertising reports scanparameters \<font color="#01a0af">optional\</font> stopscan() promise\<void> stopscan() stops scanning and reporting new bluetooth devices addeventlistener addeventlistener(btcentraleventtype type, btcentraleventcallback callback) this event is raised when the bluetooth status changes use this method to listen for this event see javascript event handling docid\ surgnnhz666sb1wh6pbd9 for more information removeeventlistener removeeventlistener(btcentraleventtype type, btcentraleventcallback callback) use this method to remove an event listener see javascript event handling docid\ surgnnhz666sb1wh6pbd9 for more information adapter in bos versions below 9 1 21 and below 9 0 198, this returns an array of adapter identity strings the number of elements in the array is the number of bluetooth adapters fitted in bos versions above 9 1 21 and 9 0 198, this returns an array of adapter objects name \<font color="#704ae0">string\</font> powered \<font color="#704ae0">bool\</font> whether or not the adapter is powered on scanparameters this interface contains information about a scanned bluetooth streaming device advertisingreports \<font color="#704ae0">bool\</font> whether or not scanning for advertisements is active