abandonware / bleno

A Node.js module for implementing BLE (Bluetooth Low Energy) peripherals
https://mastodon.social/@rzr/106068437787315146#bleno
MIT License
149 stars 51 forks source link

Data loss on notifications #7

Closed endrelovas closed 4 years ago

endrelovas commented 4 years ago

I experience major data loss on Raspi when subscribing to characteristic. My goal is to push through about 48000 bytes but I loose data at random places. The code I use is the following:

class A { 
     ...
     this.waitForData();
     setTimeout(async () => {
           await this.signUpForCharacteristic()
                 resolve()
     }, 250)

    waitForData() {
        let swinger = this
        var counter = 0
        this.characteristic.on('data', (data, isNotification) => {
            counter = counter + data.length
            let arr = [Buffer.from(swinger.downloadedData), data];
            swinger.downloadedData = Buffer.concat(arr);
            process.stdout.write(`Data received: [${counter}] [${isNotification}] [${swinger.downloadedData.length}] ${common.toHexString(data)}\x1B[0G`);
        });
    }

    async signUpForCharacteristic() {
        common.logger.info('Subscribing to notification')
        return new Promise((resolve, failure) => {
            this.characteristic.notify(true,error => {
                if (error == null) {
                    common.logger.info('Subscribed to notification')
                    resolve()
                }
                else {
                    common.logger.info(`Could not subscribe to notification: ${error.toString()}`)
                    failure(error)
                }
            })
        })
    }
}

Few bytes are missing. Using bluepy all data arrives perfectly 10 out 10 so it is not a hardware related issue. Also the peripheral works flawless with my mobile applications. Only Noble plays this with me. Do you have any suggestions?

endrelovas commented 4 years ago

Sorry wrong repo...