Writing an SDK With Core Bluetooth – 17 – Asking Questions

This entry is part 21 of 24 in the series Writing an SDK With Core Bluetooth

We are now ready to have the Central Mode ask a question to one of its Magic 8-Balls.

After we are done with this step, we will be able to run an instance of the app as a Central (on a Mac, iPhone/iPad/iPod, Watch or TV), and an instance of the app as a Peripheral (on a Mac or iPhone/iPad/iPod).

The Central will discover the Peripheral, and display its name in the list. The user will then be able to select the Peripheral, and “ask it a question.”

The Peripheral device will almost immediately display the question.

Read more

Writing an SDK With Core Bluetooth – 15 – The Center

This entry is part 19 of 24 in the series Writing an SDK With Core Bluetooth

THIS IS NOT STRAIGHTFORWARD –NOT EVEN A LITTLE

One thing that we’ll learn about Core Bluetooth (which can also apply to other types of asynchronous communication), is that nothing is really direct or straightforward.

That means that we can’t just ask a CBCentralManager instance for its CBPeripherals. We need to ask the manager to discover the Peripherals, and, possibly, build up its own list; which we can then query.

The same goes for Services. We can’t just ask a CBPeripheral object for its CBService instances. We have to ask it to discover its Services.

After that, each Service needs to discover its Characteristics. That said, just to add insult to injury, we don’t ask the Service to discover its Characteristics; we ask the Peripheral to do so, on behalf of the Service.

Once the Characteristics have been discovered, then we can finally aggregate the Peripheral device.

We did just enough on the Peripheral side to give the Central something to find.

The Central, however, has its work cut out for it…

Read more

Writing an SDK With Core Bluetooth – 13 – Managers

This entry is part 17 of 24 in the series Writing an SDK With Core Bluetooth

We are now ready to start actually implementing the Bluetooth code.

Apple’s Core Bluetooth SDK uses the concept of “Managers” to implement Bluetooth capabilities for Central and Peripheral devices.

If we will be running the device as a Bluetooth Central, then we will instantiate CBCentralManager. If we will be running as a Peripheral, then we instantiate CBPeripheralManager. An instance of one these will be associated with each of the SDK instances that we create, and we will be managing these “under the radar.” The user of the SDK will not have any idea these are being used.

Read more

Writing an SDK With Core Bluetooth – 11 – At Your Service

This entry is part 15 of 24 in the series Writing an SDK With Core Bluetooth

An important part of setting up a Bluetooth system, is registering unique GATT IDs for our Service and Characteristics.

“GATT” is an acronym for “Generic ATTribute profile.” It is defined here. There are a number of “predetermined” types of services, and we can add to them.

Read more

Writing an SDK With Core Bluetooth – 10 – Dark Age

This entry is part 14 of 24 in the series Writing an SDK With Core Bluetooth

We will now start to add the actual Core Bluetooth code to our SDK; replacing the mock code that we have in there.

This will result in a short “dark age.” We won’t be able to do much more than syntax-check until there’s enough code in place –on both ends of the connection– to enable an actual running example.

All the work that we’ve done until now has been to reduce the duration of the “dark age,” and make sure that it can be tested as soon as possible.

Testing is life. My philosophy is that I test at every possible opportunity, and periods of coding without being able to run and step through the code really bother me.

Read more

Part Two -Preparing for Bluetooth

This entry is part 13 of 24 in the series Writing an SDK With Core Bluetooth

At this point, we have four test harness/demo apps prepared and ready to go. They currently operate using a very simple “mock” functionality that I took the liberty of adding to the SDK.

We also have the “skeleton” of the SDK ready. The SDK can be instantiated into two sets of functionality: Central (Bluetooth Central behavior), and Peripheral (Acting as a Bluetooth Peripheral).

The Central will “ask questions” of the Peripherals, which will act as “Magic 8-Balls.” In the Mac, iOS and TVOS variants of the apps, the user will be able to enter a question manually. In the Watch variant, due to the difficulty of entering arbitrary text, we will choose a random question from a pool of 20 questions.

Each Peripheral will have a pool of 20 answers. These will reflect the original answers from the Mattel Magic 8-Ball.

Read more