Open RoyceTheBiker opened 6 days ago
I may have found a workaround. The Wiki for Characteristic Writing has a helpful statement Latest value may not be stored inside returned object.
, so I could have this problem again in the future, but for now I have something working.
I found that writeWithoutResponse
is able to get the correct reply by using monitor
. I hope this does not become a problem for follow-up messages.
Can anyone tell me if I need to destroy this monitor to prevent it from catching other replies for to other messages?
writeChannel.writeWithoutResponse(requestB64).then( (response: Characteristic) => {
response.monitor( (err: BleError, characteristic: Characteristic) => {
if(err) {
console.error(err.message);
} else {
console.log('characteristic value %s', Base64.decode(characteristic.value));
}
});
}).catch( (err) => {
console.error(err.message);
});
Prerequisites
Question
I have a peripheral device hosting BLE service with two characteristics, one for reading from the device, and one for writing to the device. The React-Native screen shows a list of Bluetooth devices and the user clicks on one to connect. My device is listening for a message
GET config
.After connecting to the device the
GET config
message is sent to the device, it arrives and is perfectly readable on the device. At that point, the device would send back some config data but I have removed that because the only thing that shows in theresponse.value
isGET config
I have removed the device code that would send a response, it is no longer sending a response, but the control app still gets a response that seems to be coming from itself with the same message it sent out.
I have tried using writeCharacteristicWithResponseForService and it does the same thing, replies with the outgoing message.
What am I missing? How can I stop the response from being the outgoing message?
Question related code
Update 2024-11-26
I have now tested my peripheral device using the LightBlue app by Punch Through. With the device having the notification on write disabled, the app receives the sent message as the reply. I re-enabled the
onWrite
callback and now LightBlue receives the message that the device is set to reply with. I tried addingnotify
permission to the write characteristic and now LightBlue shows me a subscribe button that does not seem to do anything. I don't think that would help because I need the response to be in the promise returned from sending a message.