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

does not implement -[peripheral:didModifyServices:] #756

Open
sdetweil opened this issue Jun 16, 2023 · 3 comments
Open

does not implement -[peripheral:didModifyServices:] #756

sdetweil opened this issue Jun 16, 2023 · 3 comments

Comments

@sdetweil
Copy link

sdetweil commented Jun 16, 2023

relative to #329. from 2016

I have a device that has over the air firmware upgrade support. on a different service from the main ble services.
I do NOT want that service findable except when OTA is started.

so, I write a characteristic on the existing services, and it adds the OTA service, and changes the primary UUID.

but when I try to send to the new service (on the same device) I get error

send data error ={"message":"Service not found","name":"c8:f0:9e:75:25:6a","error":"service","address":"684C6956-37BB-46B0-32E7-369897ABFDCE"}

the write also forces a disconnect.

so, I've added a close() after the write.. to signal the connection is not valid
then a new connect

and then a new discover... but it shows only the old services

To Native Cordova ->  BluetoothLePlugin close BluetoothLePlugin491036025 ["options": [{
    address = "684C6956-37BB-46B0-32E7-369897ABFDCE";
}]]
⚡️  [log] - start ota after write
⚡️  [log] - disconnected rc={"name":"c8:f0:9e:75:25:6a","address":"684C6956-37BB-46B0-32E7-369897ABFDCE","status":"closed"}
To Native Cordova ->  BluetoothLePlugin connect BluetoothLePlugin491036026 ["options": [{
    address = "684C6956-37BB-46B0-32E7-369897ABFDCE";
}]]
⚡️  [log] - startOTA after reconnect
To Native Cordova ->  BluetoothLePlugin discover BluetoothLePlugin491036027 ⚡️  [log] -  calling discover after OTA started
["options": [{
    address = "684C6956-37BB-46B0-32E7-369897ABFDCE";
}]]
⚡️  [log] - discover results OTA={"status":"discovered","services":[{"characteristics":[{"descriptors":[],"properties":{"write":true},"uuid":"9A61"},{"descriptors":[],"properties":{"write":true},"uuid":"9A62"},{"descriptors":[],"properties":{"write":true,"read":true},"uuid":"9AFF"},{"descriptors":[{"uuid":"2902"}],"properties":{"notify":true,"read":true},"uuid":"2A05"},{"descriptors":[],"properties":{"read":true},"uuid":"9A63"},{"descriptors":[],"properties":{"write":true},"uuid":"9A64"}],"uuid":"21010001-27B9-42F0-82AA-2E951747BBF9"},{"characteristics":[{"descriptors":[],"properties":{"write":true},"uuid":"9A61"},{"descriptors":[],"properties":{"write":true},"uuid":"9A62"},{"descriptors":[],"properties":{"write":true,"read":true},"uuid":"9AFF"},{"descriptors":[{"uuid":"2902"}],"properties":{"notify":true,"read":true},"uuid":"2A05"},{"descriptors":[],"properties":{"read":true},"uuid":"9A63"},{"descriptors":[],"properties":{"write":true},"uuid":"9A64"}],"uuid":"21010011-27B9-42F0-82AA-2E951747BBF9"}],"name":"c8:f0:9e:75:25:6a","address":"684C6956-37BB-46B0-32E7-369897ABFDCE"}

nrfconnect shows the new service
Screenshot_20230616_093116_nRF Connect
Screenshot_20230616_093102_nRF Connect

@sdetweil
Copy link
Author

sdetweil commented Jun 16, 2023

I think an example of the didModifyServices delegate would be

- (void)peripheral:(CBPeripheral *)peripheral  didModifyServices:_ {
      NSMutableArray *noSpecifiedServices = [NSMutableArray new];
      // discover all the services . I think this is the one we want.. as we are in a generic plugin.. 
      [peripheral discoverServices:noSpecifiedServices];
  }

the note on the didModifyServices is

When the peripheral discovers one or more services, it calls the [peripheral(_:didDiscoverServices:)]
(https://developer.apple.com/documentation/corebluetooth/cbperipheraldelegate/1518744-peripheral): method of its 
delegate object. After a peripheral discovers services, you can access them through the peripheral’s [services]
(https://developer.apple.com/documentation/corebluetooth/cbperipheral/1518978-services) property.

which says UNLESS this delegate is provided AND discovers the services, you CANNOT access them

@sdetweil
Copy link
Author

I added the didModifyServices delegate, no longer get the error, but don't get the new service detected...

@sdetweil
Copy link
Author

well, there is a small doc that says the device MUST have the two default services

As you can see, even before we have done anything, **there are already two mandatory services** set up for us:

[The Generic Access service](https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.generic_access.xml). Service UUID 0x1800. Three mandatory characteristics:

[Characteristic: Device name](https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.device_name.xml). UUID 0x2A00.
[Characteristic: Appearance](https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml). UUID 0x2A01.
[Characteristic: Peripheral Preferred Connection Parameters](https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.peripheral_preferred_connection_parameters.xml). UUID 0x2A04.
[The Generic Attribute service](https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.generic_attribute.xml). UUID 0x1801. One optional characteristic:

[Characteristic: Service Changed](https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gatt.service_changed.xml). UUID 0x2A05.
The Generic Access Service contains general information about the device. You can recognize a characteristic holding the device name “OurService”. The second characteristic holds the appearance value and in our case we haven't set the value to anything so it just shows 0x0000. The third characteristic holds various parameters used to establish a connection. You can recognise values from the #defines in the example called: MIN_CONN_INTERVAL, MAX_CONN_INTERVAL, SLAVE_LATENCY, and CONN_SUP_TIMEOUT. [Here](https://devzone.nordicsemi.com/question/60/what-is-connection-parameters/) is a short explanation regarding these parameters.

The second service is the Generic Attribute Service. Simply put, this service can be used to notify the central of changes made to the fundamental structure of services and characteristics on the peripheral. Short explanation [here](https://devzone.nordicsemi.com/question/15099/changing-gatt-characteristic-properties/).

I didn't add those 'mandatory' services

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