bt
8 min
el objeto bt le permite comprobar si bluetooth está instalado; establecer, supervisar o recuperar los anuncios ble actuales; escanear dispositivos bluetooth; y activar la conexión y desconexión de otro dispositivo idl de bt 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; }; creación de objetos para crear un objeto bt primero cargue el módulo brightsign/bt usando el método require() luego cree una instancia de la clase bt var btclass = require("@brightsign/bt"); var bt = new btclass(); btcentraladvertisingreportevent adapter path \<font color="#704ae0">string\</font> \<font color="#01a0af">required\</font> el adaptador al que pertenece el dispositivo de anuncios device address \<font color="#704ae0">string\</font> \<font color="#01a0af">required\</font> el identificador de un dispositivo remoto de anuncios rssi \<font color="#704ae0">int\</font> \<font color="#01a0af">required\</font> la intensidad de señal del dispositivo cuando se informa un anuncio datos \<font color="#704ae0">array\<byte\>\</font> \<font color="#01a0af">required\</font> datos del anuncio btcentraldevicefoundevent indica si se encuentra un dispositivo bluetooth durante el escaneo adapter path \<font color="#704ae0">string\</font> \<font color="#01a0af">required\</font> el adaptador al que pertenece el dispositivo de anuncios dirección \<font color="#704ae0">string\</font> \<font color="#01a0af">required\</font> la dirección bluetooth única del dispositivo alias \<font color="#704ae0">string\</font> \<font color="#01a0af">required\</font> un nombre alternativo para el dispositivo remoto nombre \<font color="#704ae0">string\</font> \<font color="#01a0af">optional\</font> el nombre del dispositivo bluetooth rssi \<font color="#704ae0">int\</font> \<font color="#01a0af">optional\</font> la intensidad de señal del dispositivo tx power \<font color="#704ae0">int\</font> \<font color="#01a0af">optional\</font> el nivel de potencia transmitida del dispositivo uuids \<font color="#704ae0">array\<string\>\</font> \<font color="#01a0af">optional\</font> cadenas uuid advertising flags \<font color="#704ae0">array\<byte\>\</font> \<font color="#01a0af">optional\</font> las marcas utilizadas para advertising datos del fabricante \<font color="#704ae0">array\<array\<int, array\<byte\>\>\>\</font> \<font color="#01a0af">optional\</font> los datos de advertising específicos del fabricante indexados por id del fabricante service data \<font color="#704ae0">map\<string, array\<byte\>\>\</font> \<font color="#01a0af">optional\</font> los datos de advertising del servicio indexados por uuid btcentraldevicelostevent esto se utiliza para informar cuando se pierde un dispositivo bluetooth adapter path \<font color="#704ae0">string\</font> \<font color="#01a0af">required\</font> el adaptador al que pertenece el dispositivo de advertising dirección \<font color="#704ae0">string\</font> \<font color="#01a0af">required\</font> la dirección bluetooth única del dispositivo btcentral utilice esta interfaz para realizar acciones en conexiones de streaming bluetooth getadapters() promise\<array\<adapter>> getadapters() devuelve una matriz de cadenas de identidad del adaptador el número de elementos en la matriz es el número de adaptadores bluetooth instalados scan() promise\<void> scan(optional scanparameters) informa sobre nuevos dispositivos bluetooth a medida que se descubren también es posible supervisar informes de advertising sin procesar scanparameters \<font color="#01a0af">optional\</font> stopscan() promise\<void> stopscan() detiene el escaneo y el informe de nuevos dispositivos bluetooth addeventlistener addeventlistener(btcentraleventtype type, btcentraleventcallback callback) este evento se genera cuando cambia el estado de bluetooth utilice este método para escuchar este evento consulte gestión de eventos en javascript docid\ pqiipi27tfco3zuvjmnyx para obtener más información removeeventlistener removeeventlistener(btcentraleventtype type, btcentraleventcallback callback) utilice este método para eliminar un detector de eventos consulte gestión de eventos en javascript docid\ pqiipi27tfco3zuvjmnyx para obtener más información adapter en versiones de bos inferiores a 9 1 21 e inferiores a 9 0 198, esto devuelve una matriz de cadenas de identidad del adaptador el número de elementos en la matriz es el número de adaptadores bluetooth instalados en versiones de bos superiores a 9 1 21 y 9 0 198, esto devuelve una matriz de objetos de adaptador nombre \<font color="#704ae0">string\</font> alimentado \<font color="#704ae0">bool\</font> indica si el adaptador está encendido o no scanparameters esta interfaz contiene información sobre un dispositivo de streaming bluetooth escaneado advertisingreports \<font color="#704ae0">bool\</font> indica si el escaneo de advertisements está activo o no