Homey v6.0.0

How to upgrade to Homey v6.0.0

Homey v6.0.0 adds several updates to the Bluetooth Low Energy (BLE) SDK. Besides adding support for BLE notifications, also several bug fixes have been applied. With the changes in this update it will be much easier to create BLE apps for Homey.

No breaking changes are present in this update - BLE apps that worked on Homey v5.0.0 will keep working on Homey v6.0.0

BLE Notifications

The code snippet below shows an example of how to use Bluetooth Notifications in your app:

// Subscribe to notifications
await characteristic.subscribeToNotifications((data) => {
this.log("I received a notification: ", data);
});
// Wait for 5 seconds
await wait(5000);
// Unsubscribe from the notifications
await characteristic.unsubscribeFromNotifications();

Disconnect event

Homey v6.0.0 reintroduces the 'disconnect' event. This method can be especially useful when used together with BLE notifications. The disconnect event is not always emitted when a device is disconnected, for example by turning it off, it is emitted whenever Homey knows that it is disconnected. This behaviour occurs from the fact that BLE devices may turn off their radio's while maintaining an active connection.

// Register a callback for when the peripheral disconnects
peripheral.on("disconnect", () => {
this.log("Disconnected from peripheral: ", peripheral.uuid);
});

The disconnect event is not guaranteed to trigger on each disconnect. But if it does trigger then it is guaranteed that the peripheral is disconnected.

Addressed BLE caching issues

The previous versions of the Bluetooth Low Energy SDK contained some caching issues which have been resolved. Discovery results will be kept in cache for at least 30 seconds.

A peripheral will not automatically disconnect anymore after 60 seconds. It will stay connected until the app it is used by closes, or when the corresponding device is removed by the user, or until peripheral.disconnect() is explicitly called.

The connection status of a peripheral is assumed to stay the same until the SDK receives an indication that suggests otherwise - therefore the peripheral.state may be incorrectly indicating a connected state when a device silently disconnects.

(Deprecation) 128bit UUID convention

A common practice in BLE is to use shortened UUID's for common services and characteristics. Generally, a UUID used in BLE has 128 bits. However, if the UUID is formatted like the base UUID it can be shortened to a 16bit uuid by using the 4th to the 8th hexadecimal only. For example:

// 128bit UUID
'0000ABCD-0000-1000-8000-00805F9B34FB'
// 16bit UUID (Deprecated)
'ABCD'

Starting from Homey v6.0.0 it has been decided that Homey will use long UUID's for all BLE device by default. The reason for this is to prevent confusion - and also to ensure that the SDK can give consistent results when used for different devices on different Homey models.

Short UUIDs are still supported and your current apps will keep working.