bt: Bluetooth functions (NX)

Top  Previous  Next

This Bluetooth library is used to manage and communicate wireless with Bluetooth enabled devices. It supports both Bluetooth Classic and Bluetooth Low Energy. For LX devices a dedicated BLE API is available. See the section Bluetooth Low Energy (LX).
 

Among the supported features are support for serial port profile(SPP) and Bluetooth Low Energy devices(BLE).

The Bluetooth Server example provides an example of an SPP application.

 

 

Common Bluetooth management


btWaitEvent

Waits for events from the Bluetooth module.


btEventDone

Marks the event as done.


btPower

Controls power to the Bluetooth module.


btNameSet

Sets the name to show to other devices.


btAdapterAddressGet

Get the address of the adapter.


btMakeDiscoverable

Controls if the device is discoverable.


btIsDiscoverable

Checks if the device is discoverable.


btScanStart

Starts scanning for other devices.


btScanStop

Stops scanning for devices.


btIsScanning

Checks if the adapter is scanning for devices.


btDeviceGet

Retrieves the address of a found device.


btDeviceInfo

Retrieves information about a device.


btDevicePair

Begins pairing with a device.


btDeviceRemove

Remove devices to e.g. remove pairing.


btHandlePairRequest

Handles an incoming pairing request.


btSendPairResponse

Sends a response to a pairing request.

 

 

Profiles


btSerialPortProfileConnect

Connects to a serial port profile on a remote device.


btDeviceProfileDisconnect

Disconnects from a profile on a remote device.


btSerialPortProfileEnable

Enables serial port profiles on the device.


btHandleSerialPortIncomingConnection

Handles an incoming serial port connection.

 

Bluetooth Low Energy(BLE)

BLE devices typically broadcasts(advertises) some data which is made available in the manufacturer data.

They may also provide a number of characteristics which are grouped by functionality into services.

Each characteristic is used to manage a specific piece of data, e.g. a temperature or the battery level.

 

When dealing with a new device, it is necessary to use the btLEServiceGet and btLECharGet functions to determine the IDs of the wanted characteristics.

Once the IDs are known, they can be used directly in the future, removing the need for the search.

The Bluetooth Low Energy example provides an example on how to use the BLE functionality.

 

 


btleManufacturerDataGet

Retrieves the manufacturer data of a device.


btleServiceDataGet

Retrieves the service data of a device.


btleConnect

Connect to a BLE device.


btleDisconnect

Disconnect from a BLE device.


btleServiceGet

Retrieves a service from the device.


btleCharGet

Retrieves a characteristic from the device.


btleWriteVal

Writes a value to a characteristic.


btleReadVal

Reads the value of a characteristic.


btleNotifyStart

Starts listening for notifications on a characteristic.


btleNotifyStop

Stops listening for notifications on a characteristic.


btleHandleNotification

Reads the data belonging to a BLE notification.

 

 

 

 

Error codes

The Bluetooth API uses a number of common error codes across the functions.

The following table lists the common error codes. The meaning may change slightly from function to function.

 

1

-

_BT_OK


Success

0

-

_BT_ERR_NOT_SUPPORTED


The API is not supported.

-1

-

_BT_ERR_NOT_OPEN


The adapter is not powered(see btPower).

-2

-

_BT_ERR_ALREADY_OPEN


The adapter is already turned on.

-4

-

_BT_ERR_NOT_FOUND


Could not find device.

-5

-

_BT_ERR_NO_ADAP


Could not find adapter.

-6

-

_BT_ERR_INVAL_ADAP


Invalid adapter provided.

-7

-

_BT_ERR_NO_RES


Could not allocate resources.

-8

-

_BT_ERR_INVAL


Invalid argument.

-9

-

_BT_ERR_NODATA


No valid data found.

-10

-

_BT_ERR_ALREADY_PAIRED


Already paired.

-12

-

_BT_ERR_BUSY


Busy

-13

-

_BT_ERR_STATE


Invalid state.

-14

-

_BT_ERR_CON_FAILED


Connection failed.

-15

-

_BT_ERR_NOT_AVAIL


Not available

-16

-

_BT_ERR_NOT_PERM


Not permitted.

-17

-

_BT_ERR_TIMEOUT


Timeout

-18

-

_BT_ERR_AUTH


Authentication failed.

-19

-

_BT_ERR_NOT_CONNECTED


Not connected.

-99

-

_BT_ERR_GENERIC


Unknown error.