src/app/www/js/functions.js
/**
     * Enables the bluetooth API implementation.
     * Checks if the ESP32 is already paired; if so, tries to connect to it.
     * @returns {Promise.<any>}
     */
Enables the bluetooth API implementation.
Checks if the ESP32 is already paired; if so, tries to connect to it.
@returns {Promise.}
Enables the bluetooth API implementation . Checks if the ESP32 is already paired ; if so tries to connect to it . @returns { Promise . }
async enable() {
        return new Promise((resolve, reject) => {
            bluetoothSerial.list((pairedDevices) => {
                const device = pairedDevices.find((el) => el.name === "MyESP32");
                if(device) {
                    bluetoothSerial.connect
                    .bind(bluetoothSerial)
                    .promisify(device.address)
                    .then(() => {
                        this._enable()
                            .then(() => { 
                                this.isEnabled = true;
                                this.canSend = true;
                                resolve();
                            })
                            .catch(() => { 
                                bluetoothSerial.unsubscribe();
                                bluetoothSerial.disconnect();
                                reject();
                            });
                    })
                    .catch((err) => {
                        this.error(err);
                        reject();
                    });
                }
                else {
                    this.error("ESP32 not paired!");
                    reject();
                }
            },
            (err) => this.error(err)
            );
        });
    }
async enable ( ) { return new Promise ( ( resolve , reject ) => { bluetoothSerial . list ( ( pairedDevices ) => { const device = pairedDevices . find ( ( el ) => el . name === "MyESP32" ) ; if ( device ) { bluetoothSerial . connect . bind ( bluetoothSerial ) . promisify ( device . address ) . then ( ( ) => { this . _enable ( ) . then ( ( ) => { this . isEnabled = true ; this . canSend = true ; resolve ( ) ; } ) . catch ( ( ) => { bluetoothSerial . unsubscribe ( ) ; bluetoothSerial . disconnect ( ) ; reject ( ) ; } ) ; } ) . catch ( ( err ) => { this . error ( err ) ; reject ( ) ; } ) ; } else { this . error ( "ESP32 not paired!" ) ; reject ( ) ; } } , ( err ) => this . error ( err ) ) ; } ) ; }
Enables the bluetooth API implementation.
Enables the bluetooth API implementation .