Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

respond() to a status writeRequested not work #748

Open
marcui13 opened this issue Feb 17, 2023 · 1 comment
Open

respond() to a status writeRequested not work #748

marcui13 opened this issue Feb 17, 2023 · 1 comment

Comments

@marcui13
Copy link

marcui13 commented Feb 17, 2023

Hi everyone!

I'm trying to respond to a 'writeRequested' state with the respond() method, but I see that it doesn't work as expected.

I need to reply to the device that made the writeRequest with a 'received' message.

This is the code that proves:

`if (status.status == "writeRequested") {

  if (
    status.service == "1234" &&
    status.characteristic == "D6D95414-516C-4DCF-B5CF-3BB1A560AF0F"
  ) {
    this.bluetoothle
      .respond({
        address: status.address,
        requestId: status.requestId,
        value: btoa('Recived message in tablet!') // encode base64
      })
      .then((data) => {
        console.log(data);
      })
      .catch((err) => {
        console.log(err);
      });
    this.recivedMessages.push(atob(status.value)); // decode base64
    this.cdr.detectChanges();
    console.log(atob(status.value));
  }

}`

When i debug the code, i see that the respond() method have success status, but the message is not visible in the other device.

writeRequested

NOTE: when i use the same method to respond 'readRequested' status works fine

Like this:

`if (status.status == "readRequested") {

  if (
    status.service == "1234" &&
    status.characteristic == "D6D95414-516C-4DCF-B5CF-3BB1A560AF0F"
  ) {
    this.bluetoothle
      .respond({
        address: status.address,
        requestId: status.requestId,
        value: btoa('Hello from tablet!')
      })
      .then((data) => {
        console.log(data);
      })
      .catch((err) => {
        console.log(err);
      });
  }

}`

This is the code of my writeRequest method:

`writeRequest(devAddress:string, messageS:string){

this.bluetoothle.write({
  address: devAddress,
  service: "1337",
  characteristic:"99AD1F53-0DC6-4D84-85CF-33CBE47C6EF8",
  value: btoa(messageS),
  type: ""
})
.then((resp)=>{
  console.log('RESPONSE from writeRequest', resp);
})
.catch((err)=>{
  console.log('ERROR IN writeRequest:', err);
})

}`

Is there an error in my implementation? Any idea how to solve it?

Of course, thank you for your time and kindness!

Best regards,
marcui :)

@marcui13
Copy link
Author

marcui13 commented Feb 22, 2023

Hi folks!

I continued debugging the code and put some console logs to have more information of the ejecution.

I can see that the respond() method in the 'writeRequested' state has a success status, but i don´t know how to display the message 'Recived message in...' on the device sending the message.

writeRequested screen

That screenshot is the screen of the tablet that recive the message from my phone.

My idea is that when you receive a message on either device, you can send a 'received' message to the device that sent that message

I would greatly appreciate your help!

Regards, marcui :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant