don/BluetoothSerial

I can't show data in html

AlexandreInsua opened this issue · 0 comments

Hi people.
I am currently using the plugin to build an angular style ionic app.
This application must receive arduino data using the HC-05 bluetooth module.
I managed to connect the device but when I receive the data I can only see them on the console or alerts but I were not able to display them in html using variable interpolation.
I noticed that by pressing the Back button on the device, the data is displayed on the html template..
I suspect the data stream is left open and for this reason no data is displayed, even if a value is set for the variable.
I also noticed that the documentation describes a method unsubscribe() that my IDE does not recognize.
Does any body have any ideas?
I leave a snippet in my code below.
Thank you very much.

connect(device: any) {
    let i = 1;
    this.presentToast("Connecting with " + device.name + "... ")
    this.serial.connect(device.address).subscribe(
      ok => {
        this.presentToast(device.name + "Connected.")
        this.presentToast("Recibiendo datos...");
        this.dataSubscription = this.serial.subscribe('\n').subscribe(
          data => {
            console.log(`${i}.- Receiving data  ${data}`);
            this.receivedData = data;

            // this.serial.unsubscribe() my IDE does not recognize this function

            // this options also do not working 

            // this.dataSubscription.unsubscribe(); 

            // this.serial.readUntil("\n")
            //   .then(data2 => {
            //     this.receivedData = data2;
            //   })

            // this.serial.clear();

            i++;
          },
          error => {
            console.log('subscribe data', error);
            this.presentToast("Subscribe data error.")
          }
        )
      },
      error => {
        console.warn('error', error);
        this.presentToast("Connection error.")
      }
    );
  }