I am writing an Android App that connects and communicates with a peripheral over BLE. I've been around the bases a few times on BLE development, with iOS and firmware and now android, and the doc always seems to advise you to:
- connect
- discover services
- (on some stacks, not android) a second round of discovery for characteristics within services
- save references to the characteristics
- read and write to characteristics (or subscribe to notifications) as you wish
In the back of my mind, I've always wondered if one can skip the discovery step? Say if its a situation where you are dead certain what you are talking to, and you know the UUIDs and properties of all services and attributes provided by the peripheral. Can my app just presumptively create my own BluetoothGattCharacteristic objects with UUIDs and properties, and read /write to them, and the stack will just send the corresponding commands, without having gone through that initial interogation?
Then, on this project that thought was forced to the front of my mind, because we are having some mysterious glitch/corruption in the discovery response -- on some phones it would publish services, but no peripherals. It is intermittent and we are sure it is due to some weirdness in the peripheral firmware or configuration, but unfortunately we can't wait for them to fix their problem. So I decided to test out the above theory, with some success:
I built in a secondary path that, in this event, would create BluetoothGattCharacteristic objects with the correct UUIDs and properties and attach them to the received service object. And lo and behold... it worked! Sort of. I could read and write to about 25 of the 28 characteristics... not sure yet what's wrong with the other three. But this seems to me to be a promising result w.r.t. my theory above!
So my question is, is my theory true? Can I skip discovery? If so, is there any sample code or guidance on how to do this, how to correctly set up your presumptive service and characteristic objects outside of the context of a discovery response? (Since I'm obviously close, batting 25/28=0.893, but no cigar.)
Would appreciate any pointers to discussion on this topic, and esp to any sample code, projects, or snippets.