Bluetooth for Xojo

Over the years several Xojo developers asked for a Bluetooth plugin. As we got two projects this year with need for Bluetooth, the classic one and the LE one, we decided it may be worth starting a Xojo plugin for Bluetooth.

For Bluetooth Low Energy, we got CoreBluetooth classes for MacOS. You can enumerate devices, connect to them and read/write data and get notifications for updates. That works well with a heart monitor here to get the current BPM value to Xojo.
See CBPeripheralMBS class.

Next we got WindowsBlueToothLE classes for Windows. Again, you can see which devices are there, connect and get/set values and get notified for updates. For heart rate monitor, this class works well, too.
See WindowsBlueToothLEMBS class.

For the classic Bluetooth on MacOS, we got the IOBluetooth classes. This is only a subset from the Apple framework, but you can use IOBluetoothDeviceMBS class to control a device. The IOBluetoothRFCOMMChannelMBS class allows you to do a serial port via bluetooth, which is enough for our devices here.

To select a device, you can use the IOBluetoothUI classes. The IOBluetoothDeviceSelectorControllerMBS class provides a dialog or sheet to select a device while IOBluetoothServiceBrowserControllerMBS allows to pick a service on a device.

On Windows, you can use WindowsBlueTooth classes to find devices and configure them. The WindowsBlueToothSelectDeviceDialogMBS class provides a dialog for the user to pick a device.

Once you got the device ID and the port, you can use the WindowsBlueToothSocketMBS class to connect and transfer data. This class work like a normal socket in Xojo, but targets bluetooth. You can get an event for incoming data and even accept connections.

If you come to our Xojo conference, we can present you details on the new plugin and show some examples, maybe even a live demo.

Available in 18.3pr4 and later.

MBS Xojo Bluetooth Plugin is part of MBS Xojo Complete Plugin Set, which is currently available as part of OmegaBundle.

Hello,
Thank you Christian Schmitz for your great work.
Is it possible to obtain heart rate datas from a FitBit watch (Blaze, Ionic) ? If so, how ?

You could simply check whether your heart monitor has same device type and just works.

I don’t know if Fitbit now uses standard BTLE protocols in recent devices, but I started using a Fitbit One five years ago and tried doing some integration projects using their developer API (for talking to Fitbit web server, not the device). At the time, Fitbit developer forum posts made it clear the actual devices (at the time) while BTLE as the communication layer did not use industry standard services but instead a proprietary data exchange.

Sounds like MBS’s new APIs would let you browse exposed services (he mentioned IOBluetoothServiceBrowserControllerMBS above) and see what gets listed. Or use a BTLE explorer program from App Store or Google Play to get an idea first. For example Light Blue LE.

But my information is dated and from older devices, and they may have moved to industry standard services by now.

Of course you can let the CoreBluetooth classes list devices in range.

With my older Fitbit device, the device shows up using something like LightBlue and I’ll use or a similar BT explorer to help locate my Fitbit by watching signal strength. (I have a pocket based model, not watch type, so easier to misplace.) However it doesn’t advertise much more than the Manufacturer Name String and a couple of UUIDs that I think are proprietary data exchange formats. Even the battery level shows up as 0%.

Last I worked with the developer APIs to make myself a custom iOS app, others in the Fitbit developer forums said there had been some work to reverse engineer the BTLE layer Fitbit used at the time in an attempt to get real time data instead of just the data available at last server sync via the supported API calls. But I have not kept on those forums, or if Fitbit has transitioned newer devices to standard services. Or published how to interpret their proprietary data exchange.

My point was that while it is likely possible to find and connect to the device, actually obtaining the current heart rate from a Fitbit was not (or is not?) the same as using the BTLE standard services. That may have changed.

Hi…a Bluetooth device which has an RFCOMM driver should is assigned a device name by the operating system. For instance, ‘COM4’ in Windows or ‘/dev/rfcom0’ in Linux. In Windows the device will appear in Device Manager under COM and LPT ports. In Linux there should be an entry in /dev/ although you may need to create the device file yourself.
Once you know the device name you can connect it to an RB SerialPort control and use it like any other serial port.