Ionic unable to write data in device bluetooth serial connection


#1

I am unable to write data in device when i use bluetooth serial plugin i successfully connect and read data from device

when i write data i got response in “NaN”


#2

What’s the data you’re trying to write? It seems that the plugin expects a number and you’re not posting a number.


#3

thanks for reply
i send data "Helloworld"
my code is
this.bluetoothSerial.write(this.data).then((success)=>{
alert(+success+’ Success for write’)
}, (failure)=>{
alert(‘failed data writing’)
}
);


#4

And where exactly are you seeing a response of Not a Number? Are you really getting a failure or does success gives you that response?


#5

No controls goes to success

response is:
“NaN Success for write”


#6

Okay so you do get in the success handler. So there’s actually no real failure, but you just are getting NaN as response. I’ve never used the plugin, so I wouldn’t now how a normal response should look like. Seems to me that you followed the example in the docs exactly, so that shouldn’t be the issue.

What kind of response are you expecting exactly?


#7

remove ‘+’ before this ‘+success+’


#8

How are you reading data from paired device using bluetooth serial let me know the code .
It is urgent for me.
Thanks in advance


#9

Hai iam also trying to write data,but iam getting success callback and iam getting OK in success calback. Can any one help me


#10

Hi, i don’t know if it could helps you but this is how i write on my bluetooth device (some hexadecimal stuff) :

    var dataBuffer = new Buffer("FF01DED100010401010104","hex");
    
    this.bluetoothSerial.isConnected()
    .then(data => {
        this.bluetoothSerial.write(dataBuffer).then(data => {
            this.output += "\r\nWrite : " + JSON.stringify(data);
        },
        error =>{
            this.output += "\r\nWrite Error : " + JSON.stringify(error);    
        });
    })
    .catch(error => {
      this.output += "\r\nBT disconnected";
    });