Tag: Bluetooth

  • 12 Days of Bluetooth – #7 Bluetooth Low Energy

    In 2011, Bluetooth 4.0 was introduced and contained the biggest update to the standard yet. It introduced a whole new way of talking to Bluetooth devices which allowed them to use considerably less power. Bluetooth Low Energy works entirely separately from Bluetooth Classic but the two can coexist. For example most mobile phones will support both and expose classic services like Handsfree and low energy services like Device Information or Battery.

    A key element of Bluetooth Low Energy is to move away from the need for a continuous connection and allow devices to make distinct read and write actions and subscribe to change notifications. This has made it possible to implement tiny devices which work for months or years on a small battery. Some examples include location beacons and key fob trackers.

    New Services

    Bluetooth Low Energy introduces a new model and so a large range of defined services for common use cases. As with Bluetooth Classic, those which are approved by the Bluetooth SIG have a short id code and the specifications are available online. You can however define your own custom service (with your own unique id) if you are building a specific device. You may keep this implementation entirely to yourself, or like Apple and Lego, you could publish a specification for others to use. All Low Energy services are based on the Generic Attribute Profile (known as GATT).

    GATT Services can be visualised as a tree – each service can have one or more Characteristic and each Characteristic one or more Descriptors e.g.

    Bluetooth Service (0x180F)
        Battery Level Characteristic (0x2A19)
            Characteristic Presentation Format Descriptor (0x2904) (optional)
            Client Characteristic Configuration (0x2902) (used for notifications)

    A Characteristic is an individual logical property supported by the service. Some services may only contain a single characteristic, other many. Some services may define optional characteristics which are not present on all devices. From a GATT Service you can use an API to either request a specific characteristic by id or request enumeration of all characteristics. Each characteristic may support Read, Write and Notify functionality. The characteristic exposes a Properties value which contains a mask of all the supported operations. It only makes sense for a device to support notifications if the value is likely to change over time – device manufacturer wouldn’t, but the battery level or weight on a scales definitely would. The Write operation may support one or both of WriteWithResponse or WriteWithoutResponse. As the name suggests WriteWithoutResponse is a fire-and-forget operation and you won’t know if or when the operation completed successfully. The Properties value of the Characteristic will tell you which is supported.

    The Descriptor provides additional information about the characteristic. This can often be to describe the units the value is presented in and other display properties so that the requesting device knows how to make sense of the raw bytes. There is a special Client Characteristic Configuration Descriptor which is used to support change notifications – the calling device must write a value to this in order to receive notifications on a specific characteristic. There is no subscribe to all functionality – you request separately for each characteristic.

    Overwhelmed by Advertising

    Bluetooth Low Energy devices broadcast packets, called Advertisements, both as a mechanism to support discovery but also use these to broadcast data themselves. This can be related to a specific service or a manufacturer specific chunk of data. In this way it’s possible to get data from a low energy device without ever establishing a connection. This form the basis of beacons which are constantly broadcasting a unique identifier which can be used to establish a location (especially when multiple beacons are used together).

    Strangely there isn’t an official Bluetooth standard for beacons, but there are multiple implementations in use. Apple devised the iBeacon standard, Eddystone was Google’s implementation – they achieve similar ends but Eddystone supports additional data alongside the unique id. There are some lesser know implementations including URIBeacon which broadcasts a Url rather than an id. It’s possible for a single beacon device to broadcast multiple formats.

    While there is a lot of potential for broadcasting data like this in the advertising packet, it’s important to remember that it is completely public and so not appropriate for all types of devices.

    What a Mesh!

    Following on from Bluetooth Low Energy another standard was created to allow smart devices to communicate between themselves and form a mesh. This is used for smart lighting and other groups of devices and sensors. Devices can send messages out into the mesh which are relayed around to reach further and more reliably than with individual Bluetooth Low Energy communication between two devices.

    Bluetooth LE and .NET

    APIs are available natively on all the platforms .NET runs on, but of course these APIs vary dramatically. 32feet.NET has an implementation for Windows, Android and Apple OSes which follows the Web Bluetooth API model. It currently contains all the client-side functionality described above. Obviously it would be great to eventually extend this to Linux and Tizen as well as add server side functionality to host services and customise advertisements.

  • New 32feet.NET Documentation

    New 32feet.NET Documentation

    I managed to complete one of those jobs I’d been meaning to get around to for sometime and to celebrate getting the to-do list down to triple figures I thought I’d share the good news!

    Many years ago I built the documentation for 32feet.NET combined with the other libraries I had at the time:-

    Pontoon – UWP APIs for multiple platforms – a kind of Uno light of its day

    InTheHand.Forms – Collection of various add-ons for Xamarin Forms including the original MediaElement.

    Since these are both essentially obsolete, and the 32feet documentation is now very out of date, I needed to completely refresh it. Ideally I’d have setup the magical DocFX and had the whole process automated to generate documentation on each release but, of course, perfect is the enemy of done. Instead I went back to my trusty Sandcastle Help File Builder and created a project to bring in all the current 32feet libraries (there are currently 5 with at least 1 more on the way). The latest docs should be much clearer and focus entirely on the current APIs. I’ve left the “preliminary” tag on for now and will be working through to fill in any gaps highlighted in the docs. If you have any specific bugs/suggestions please raise an issue in the GitHub project and tag it with the “documentation” topic.

  • Home Assistant Adds In-box Bluetooth Support

    Yesterday’s release of Home Assistant 2022.8 adds built-in Bluetooth support. This allows multiple integrations to share common functionality and (important for non-Linux platforms) share a single Bluetooth adapter.

    In the release are five integrations built on top of this support, along with Apple HomeKit support for Bluetooth devices (even if you don’t have an Apple device).

    For more information on the integration and details of supported Bluetooth adapters see the integration page.

  • New Windows Phone App

    Okay, now I’ve drawn you in with a click-bait headline I need to clarify a little! For some time now Windows 10 has had a tightly integrated app called Phone Link (previously Your Phone) which allows you to interact with your phone from the desktop. However, it doesn’t cater for the 50-odd percent of users who have fruit based phones. I’ve been working on closing this gap by creating an app for Windows which is now available in the Microsoft Store called Thy Phone.

    The name came about because thy is an archaic version of your and the name also happens to rhyme with a popular phone type.

    It uses functionality available in Windows 10 2004 and above to setup a phone device to use Windows as a handsfree device. This allows you to conduct calls through your PC microphone and speakers (or headset) and see call progress and incoming call alerts on your desktop. It also allows you to activate the Bluetooth Audio support so that you can play music, podcasts etc from your phone through your PC.

    Finally when using an iPhone it supports toast notifications and mirrors those notifications directly in the Windows notification center. Notifications which uses actions can also be triggered directly from the desktop Toast.

    I’ll be adding more functionality over time including Messaging support. I completed a proof of concept but I’m working on a new version of InTheHand.Net.Obex to make it easier to do this. That will also open up other functionality such as file transfers. Because these features all use standard Bluetooth profiles the app is not limited to just iPhones, you can even pair and use your Windows Phone or Nokia 3310 – whatever floats your boat!

    English badge
  • Bluetooth HID on Windows Phones

    Microsoft have already announced that Bluetooth HID (keyboard) support is finally coming in Windows 10, but it was quietly added in Windows Phone 8.1 GDR2. The problem is this update won’t be circulated to most phones. It is however present on the new Lumia 640 series. WP_20150511_19_41_09_Pro

    It’s very easy to setup a Bluetooth Keyboard with your phone once you’ve paired the devices you just type when you’re in an app which accepts text input and it just works. That could be writing an opus in Word or a quick text message. As a developer there is nothing special we have to do to support this. There are a couple of things to be aware of:-

    1. If the keyboard has special function keys like volume, search, windows etc these do nothing (even if they map to a logical function on the phone).
    2. The Page Up and Page Down keys raise and lower the soft input panel on screen
    3. The keyboard won’t allow you to skip to a section in jump lists (like picking a mail recipient for example)
    4. Although it paired successfully my Symbol CS3070 Barcode Scanner doesn’t actually do anything (When in HID mode it should work as a Bluetooth Keyboard and put the barcode value directly into the keyboard buffer).

    There are some interesting subtle visual changes in GDR2. The circular right-arrow button at the bottom of the start screen which provides an alternative to swiping to get to the programs list has been replaced with a more “Big Windows” all apps link

    All Apps GDR2

    Clear signs of the “oneness” of Windows which will follow!