Skip to main content

bluetooth

Availability

Device

Description

The bluetooth class represents the Bluetooth sub-system integrated into the imp004m and, from impOS™ 42, the imp006. Attempting to access bluetooth instances and methods on any other imp will throw an error.

Unlike other imp API entities, bluetooth is a class rather than an automatically instantiated object, so you will work with instances returned by the open() method. The class is accessed as a property of the hardware object.

Compatible imps’ Bluetooth sub-systems support Bluetooth 4.1 (imp004m) or 5.0 (imp006). The standard’s Core Specifications can be downloaded from the Bluetooth SIG here.

Squirrel Suspension and Bluetooth

When a device’s Squirrel VM is suspended, no new callbacks (for Bluetooth or for any other reason) can be executed until the VM is resumed. When this happens, the whole Bluetooth stack is paused so that it does not cause new events requiring Squirrel execution. This can mean that any in-progress operations will be paused, and may cause large latency spikes in Bluetooth operations — even ones which don’t require Squirrel execution.

In addition, GATT read and write callbacks are called in a context where suspending is not possible. Therefore, if any operation that suspends the VM occurs within these callbacks, a Squirrel error will be raised.

With these two factors in mind, it is strongly recommended that the RETURN_ON_ERROR send timeout policy is selected as the first line in Squirrel that uses Bluetooth features.

Hardware Notes

For information on setting up the imp004m Breakout Board for Bluetooth LE operation, please see this developer guide.

For information on setting up the imp006 Breakout Board for Bluetooth LE operation, please see the reference design notes.

Modem Firmware

The Bluetooth LE firmware you will require when working with the imp004m — it is not a requirement for the imp006 — is available as a Squirrel library which you can include in your code using the statement:

#require "bt_firmware.lib.nut:1.0.0"

Member Entities

The bluetooth object has the following member methods: