Building a Bluetooth LE temperature sensor client with Bleu
BLE (Bluetooth LE) for U🎁 Bleu is the best in the Bluetooth library.
At a glance
- What is it?
- Bleu exposes a nearby Swift actor through a Bluetooth Low Energy connection. Its temperature sensor examples show how to advertise an actor, find a peer and read a value from it.
- Who is it for?
- Bleu fits a pair of Apple applications that can agree on a distributed actor interface. Start with the sensor sample and test the intended hardware pair before designing the application around a discovery deadline or a particular message size.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 180 days ago.
- What is it written in?
- Mainly Swift, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Editorial analysis
The thermometer has two separate jobs
A thermometer needs to tell the phone it exists before the phone can ask for a reading. Bleu represents the reading as a method on a distributed actor, but it still has separate roles for advertising and finding a device. In the example server, the program creates a TemperatureSensor with a BLE actor system, starts the sensor simulation and asks the system to advertise it. The example then keeps running so the peer can find it. Closing that program removes the participant the client was trying to reach.
On the client, a scan for the temperature sensor type returns a collection of candidates. The example checks whether the collection has a first member, connects using its ID and calls the temperature method on the connected sensor. It explicitly disconnects after reading. Those are useful distinctions in an application interface: “looking for a thermometer,” “found a thermometer” and “received a temperature” each describe a different observation. A screen that shows the last stored value should preserve that distinction when a new scan comes up empty.
Check the package manifest before choosing a toolchain
Bleu is distributed as a Swift Package Manager library. The installation example supplies this dependency entry for a consuming package:
.package(url: "https://github.com/1amageek/Bleu.git", from: "2.2.0")At the 2.2.0 tag the package declares Swift tools version 6.3. The README also displays a Swift 6.0 badge. Use the manifest when checking whether a build machine can read this release. Its deployment targets are iOS 18, macOS 15, watchOS 11 and tvOS 18. A compatible compiler and a sufficiently recent deployment target are separate requirements. Updating one does not change the oldest device on which an existing application needs to run.
The production target depends on ActorRuntime and Swift Logging. The manifest pins swift-actor-runtime to 0.5.0. A separate test target uses CoreBluetoothEmulator, declared against its main branch. For a repeatable test failure, record which revision the resolver selected as well as which Bleu tag the application used. The emulator has a role in the tests even though the product's main target uses different dependencies.
Which part of the actor is shared?
The two sides can share a concrete distributed actor type or agree on a protocol. Bleu's temperature example for the protocol route declares the operation with an asynchronous, throwing signature. The peripheral supplies the implementation. A client that already has the actor's ID can resolve it using the generated interface and the actor system. The example puts the Resolvable annotation on the custom protocol with the device methods. PeripheralActor itself serves as the marker.
That makes a difference when two devices can perform the same operation with different hardware behind it. A client can ask each implementation for a reading without including the temperature conversion or sensor access code from each device. Both sides still have to agree on the callable interface. The transport cannot make a newly required method appear in an older peripheral. Keeping an older device in a compatibility test is more informative than checking only that the newest client compiles.
A successful scan and a successful call are different results
The basic sample gives discovery a ten-second timeout and handles the case where no sensors appear. Its subsequent connection identifies the selected peer by its actor ID. When several devices advertise the same kind of service, choosing the first result is a reasonable demonstration but may identify the wrong physical sensor for a person holding the phone. A product needs a way to associate the displayed reading with the device the user intended to select.
The method call can also fail after discovery. A peripheral may move out of range between those steps. Keep a connection failure distinguishable from a valid numeric reading of zero. At the protocol level a throwing method already gives the client a place to carry the failure. It is the presentation layer that decides whether to show an unavailable state, retain an older reading with its timestamp or ask the user to choose another peer.
What the integration test proves about resolution
Bleu's resolution test advertises a temperature sensor using controlled peers, discovers it and resolves the returned identifier using a custom temperature protocol. It asserts that the resolved ID matches the discovered ID. The test checks a reading of 25.5, changes the unit through another remote method and expects a Fahrenheit reading of 77.9. Together those assertions exercise identity, the call result and state observed across two calls. Checking only that one peer appeared would cover considerably less of the interface.
For physical testing the repository includes a separate SwiftUI project. Its documented pairing uses an iPhone or iPad as the peripheral and a Mac as the central. The sequence includes a handshake, a small echo and a larger echo. If a test reaches discovery but fails on the larger payload, report which exchange completed and which device held each role. A mock test can isolate a protocol regression; it cannot measure radio conditions in the room where the application will run.
Choosing between Bleu and a characteristic-level client
Bleu works particularly well when the team controls both endpoints and wants a device operation to have a Swift signature. An existing accessory may instead publish a particular service and set of characteristics without implementing this actor protocol. Start by determining what the accessory actually exposes. A Core Bluetooth client that reads the documented characteristic directly can be a better match for that interface. Finding a device with a particular advertised service does not establish that it understands Bleu method calls.
Conversely, when both applications use Bleu, the shared interface simplifies the client at the point where behavior varies between devices. Keep the peripheral's implementation private, define the smallest operation that the client needs, and exercise that operation across a connection. The sensor examples give a concrete acceptance condition: the client identifies the intended device, reads its result and releases the connection.
Editorial conclusion
Bleu fits a pair of Apple applications that can agree on a distributed actor interface. Start with the sensor sample and test the intended hardware pair before designing the application around a discovery deadline or a particular message size.
Frequently asked questions
What Swift tools version does Bleu 2.2.0 require?
Its Package.swift declares tools version 6.3. The package lists iOS 18, macOS 15, watchOS 11 and tvOS 18 as deployment targets.
Which device advertises in the physical Bleu example?
The end-to-end example uses an iPhone or iPad as the peripheral. The Mac scans as the central and selects a peer for the test.
Can a client use a protocol instead of the concrete sensor type?
Yes. The resolution test uses a custom Resolvable protocol and a discovered actor ID to obtain a remote reference, call a reading method and change its unit.
Official sources
Was this useful?