-
Notifications
You must be signed in to change notification settings - Fork 21
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
PeripheralManager.characteristicRead and GattCharacteristicReadEventArgs #45
Comments
This is by design. I think developers should not care about how to response the read and write request because the So I decide to send response by the plugin itself. if you want to change the characteristic's value, just call the The characteristcRead event is just to tell developers that the characteristic is read by centrals, you can ignore this event if you don't care about this event. In short, you just need to call writeCharacteristic method if you want to change the characteristic's value, central can receive that value by read or notify. =========== EDIT |
@yanshouwang I understand and appreciate the simplicity. However there is an extra cost and additional complexity adds up for changing those char values from different data sources. Take a battery service as an example. Instead of simply pulling the current battery level at the time battery char is read - we have to subscribe to battery level change and call And when you have a few of such services - maintaining subscriptions to their value updates and updating chars up from gets costly. So, allowing to provide a |
If I add the sendResponse method, instead of listen custom data source, you need to listen the But if you really want to call the ==== Edit |
That is not what I'm suggesting. Right now chars and descriptors are created like this, even if there are no values available:
You could add an optional value provider parameters, so it would allow to hook up any custom values
|
That may work too. Internally you already transforming/truncating value before passing it to central. Currently we have to listen like this
Perhaps you could add another method that would return the same read stream but allow to provide custom values:
|
@ekuleshov You can do this by override the Just add |
@yanshouwang but isn't MyGattCharacteristic being instantiated by a various platform-specific implementations? Also, having to depend in |
The Anyone can depend the platform_interface plugin or the platform plugin without concern, you can even provide you own PeripheralManager implementation in this way. The api is stable(no breaking changes) until the main version changed. |
There is another thing to be noticed, if you read the battery level just when the central read, it will spend extra time to read the value from the battery plugin as this is an async function, so it's better to store the battery value directly in the characteristic itself, so the PeripheralManager can get the battery level and send response immediately. Anyway, I can expose the |
I also don't really want to modify values. I would prefer to be able to specify a data provider. I'm avare of the overhead of pulling char values. Though some use cases are harder to implement another way. E.g. think of a service that returns a counter how many times it been read, or a service that returns a random number for every call. |
I don't want to make breaking changes for this, In the current version, the read/write value is just stored in the characteristic itself as intended, what you want will break current API. Also you can look at Apple's document about the descriptor value, there even doesn't have a descriptor read or write callback, the read and write descriptor response is handled by system, we don't even kown when the descriptor is read or write, we just maintain the descriptor's value when it's changed. |
U understand about the breaking changes, though making a required property optional and adding additional optional properties is not a breaking change. Also I see it mentioned there that you can call Here are a few examples using that delegate API: |
It's not so easy for me to do that... Obviously we can respond characteristcs read and write requests, but what I mean is that we can't resond descriptors read and write requests on iOS platform, I want to keep the characteristic's read/write API the same as the descriptor's. It's not just add something, It's a mechanism issue |
Understood. Hope you will consider adding support for this in the future. |
This issue is stale because it has been open for 30 days with no activity. |
This issue was closed because it has been inactive for 14 days since being marked as stale. |
New The new API contains I think the new API can resolve this issue. |
The 6.0.0-dev.0 has released. |
I'm struggling with converting my 5.x code to the new 6.x APIs. I have a service/char that receives commands and the app need to respond to another service/char with the dynamically created data for a received command. I can't figure out how to send a response to a different service when processing a Also the |
You can't respond if the service is not read or written by remote devices. You must respond to a request. The getState method just moved to state field. |
In 5.x API I simply used the
I know. Yet it is not in the migration notes. |
#You can use the I'll add that to the migration doc later |
Respond to read/write request how? The requesting device is getting UNKNOWN_GATT_ERROR 241 with 6.x peripheral. |
Use the respondReadReuqestWithValue or the respondWriteRequest method. There is a sample code in the migration doc. And you can run the example to see how it works |
The
PeripheralManager.characteristicRead
stream spawnsGattCharacteristicReadEventArgs
events when connected "central" device is sending a read request to a certain characteristic.But I can't figure out how to return an app-specific data in response to that read request.
There is
PeripheralManager.writeCharacteristic()
method which sends an updated characteristic value to one or more subscribed centrals, using a notification or indication. But that requires additional orchestration, e.g. have central subscribe for notifications and use some command from central (e.g. a write event) to initiate transmission.It looks like the
value
is set in theGattCharacteristic
at the timeGattService.characteristics
are created and then gatt service is registered usingPeripheralManager.instance.addService()
, but it is unclear how to changevalue
in those chars because theGattCharacteristic
has no setter forvalue
, but even then it is too late to updatevalue
in those chars at the timecharacteristicRead
event is triggered.Perhaps you could add a
value
setter to theGattCharacteristic
or better allow to specify a callback there that would allow to pull the up to date value from any custom source.The text was updated successfully, but these errors were encountered: