You are here: Lua Scripting Resources eGuide > Lua Scripting API Reference Guide > Bluetooth® Smart Library > addStateListener

20.1.1 addStateListener

ble.addStateListener(callback [, object])

Registers a Bluetooth® LE state-change listener callback. The registration of multiple listener callbacks at the same time is supported. Registered listener callbacks can be removed by calling removeStateListener

Parameter

Type

Description

callback

in function

Callback to receive unsolicited events
about Bluetooth® LE state changes

object

in any (optional)

If an object is provided it will be passed as the first parameter to the specified callback function.
The object can be of any type except nil.

Callback Function

callback([object,] state)

The callback function provided in addStateListener will be called for unsolicited Bluetooth® LE state changes. This includes switching on/off Bluetooth ® technology or the OS resetting the Bluetooth® stack.

Parameter

Type

Description

object

in any (optional)

If an object was provided as a parameter to the function addStateListener,
it will be passed as the first parameter to this callback function

state

in ble table constant

Please see the following section for details.

Bluetooth® LE State Constants

The constants described in the following table are part of the ble table, e.g. ble.OFF.

Name

Description

ON

Bluetooth® technology is switched on

OFF

Bluetooth® technology is switched off. This implies that any ongoing scan has been stopped and connected peripherals lose their connection.

RESETTING

The Bluetooth ® stack is resetting.
This is an intermittent state and an update will follow.
In this state the Lua script should release all Bluetooth® LE object references as these objects have become invalid and cannot be used anymore.
The use of invalidated objects will cause a Lua error.

UNSUPPORTED

Bluetooth® technology is not supported on this platform

Introduced in platform.apiLevel = '2.5'