BluetoothLEModule Class
Item Index
Methods
- cancelPeripheralConnection
- clearAppLaunchIntent
- connectPeripheral
- createBeacon
- createBeaconRegion
- createPeripheral
- disable
- enable
- getState
- isAppLaunchConfigured
- isEnabled
- isSupported
- requestRegionState
- retrieveMonitoredRegions
- retrievePeripherals
- setAppLaunchIntent
- setScanTimers
- startRangingBeacons
- startRegionMonitoring
- startScan
- stopRangingBeacons
- stopRegionMonitoring
- stopScan
Properties
Constants
- BEACON_PROXIMITY_FAR
- BEACON_PROXIMITY_IMMEDIATE
- BEACON_PROXIMITY_NEAR
- BEACON_PROXIMITY_UNKNOWN
- CHAR_PERM_NONE
- CHAR_PERM_READ_ENCRYPTED
- CHAR_PERM_READABLE
- CHAR_PERM_WRITE_ENCRYPTED
- CHAR_PERM_WRITEABLE
- CHAR_PROP_BROADCAST
- CHAR_PROP_EXTENDED_PROPERTIES
- CHAR_PROP_INDICATE
- CHAR_PROP_NOTIFY
- CHAR_PROP_READ
- CHAR_PROP_SIGNED_WRITES
- CHAR_PROP_WRITE
- CHAR_PROP_WRITE_WITHOUT_RESPONSE
- CHARACTERISTIC_TYPE_WRITE_WITH_RESPONSE
- CHARACTERISTIC_TYPE_WRITE_WITHOUT_RESPONSE
- DISABLE_NOTIFICATION_VALUE
- ENABLE_INDICATION_VALUE
- ENABLE_NOTIFICATION_VALUE
- REGION_STATE_INSIDE
- REGION_STATE_OUTSIDE
- REGION_STATE_UNKNOWN
- STATE_OFF
- STATE_ON
- STATE_TURNING_OFF
- STATE_TURNING_ON
Methods
cancelPeripheralConnection
-
peripheral
Cancels an active or pending connection to the specified peripheral. This command is non-blocking, and any commands that are still pending to the peripheral may or may not complete.
It extremely important to note that canceling a connection does not guarantee the immediate disconnection of the underlying physical link. This can be caused by a variety of different factors, including other application(s) that hold an outstanding connection to the peripheral. However, in this situation, you will still immediately receive a disconnectedPeripheral event.
Parameters:
-
peripheral
PeripheralA Peripheral object.
Returns:
clearAppLaunchIntent
()
Void
Use this function to instruct the module not to launch the app when the user enters a monitored region.
Returns:
connectPeripheral
-
params
Initiates a connection to the specified peripheral. Connection attempts never time out and, depending on the outcome, will result in a connectedPeripheral or failedToConnectPeripheral event.
Pending attempts are cancelled automatically upon deallocation of the peripheral, and explicitly via the cancelPeripheralConnection method.
Parameters:
-
params
ObjectAn object with the following properties:
-
peripheral:
PeripheralThe object representing the peripheral.
-
[autoConnect=false]
Boolean optionalWhether to directly connect to the remote device (false) or to automatically connect as soon as the remote device becomes available (true).
-
Returns:
createBeacon
-
params
Creates a beacon object from scan data.
You can use this function to create a beacon object from information
received via the
discoveredPeripheral event, if the discovered peripheral is in fact a beacon.
Returns null
if the peripheral is not a beacon.
Parameters:
-
params
ObjectAn object with the following properties:
-
rawAdvertisementData
TiBuffer -
RSSI
Number
-
Returns:
createBeaconRegion
-
params
Creates a BeaconRegion object that can be used to start advertising an iBeacon.
Parameters:
-
params
ObjectAn object with the following properties (see the properties of the BeaconRegion class for details):
-
identifier
StringA unique identifier to associate with the returned region object. You use this identifier to differentiate regions within your application.
-
UUID
StringThe UUID of the beacon.
-
[major]
Number optionalThe major number of the beacon. If not specified, the major and minor numbers of the beacon are ignored.
-
[minor]
Number optionalThe minor number of the beacon. If not specified, the minor number of the beacon is ignored.
-
[notifyEntryStateOnDisplay=false]
Boolean optionalWhen set to
true
, the beacon notifications will be sent only when the user turns on the display and the device is already inside the region.
-
Returns:
createPeripheral
-
params
Creates a Peripheral object from a MAC address.
Parameters:
-
params
Object-
address
StringThe MAC address as string.
-
Returns:
disable
()
Boolean
Disables the Bluetooth adapter.
Returns:
Returns true
if the Bluetooth adapter
was successfully disabled.
enable
()
Boolean
Enables the Bluetooth adapter.
Returns:
Returns true
if the Bluetooth adapter
was successfully enabled.
getState
()
Number
Returns the current state of the local Bluetooth adapter.
See also the STATE_OFF, STATE_ON, STATE_TURNING_OFF, and STATE_TURNING_ON constants.
Returns:
isAppLaunchConfigured
()
Boolean
Determines whether the module is currently configured to launch the app when BLE activity is detected.
Returns:
isEnabled
()
Boolean
Determines whether the Bluetooth adapter is enabled and ready for use.
Returns:
Returns true
if Bluetooth is currently
enabled.
isSupported
()
Boolean
Determines whether the device is capable of communicating with other devices via Bluetooth Low Energy radio.
Returns:
requestRegionState
-
params
Retrieves the state of a region asynchronously.
Parameters:
-
params
ObjectAn object with the following properties:
-
beaconRegion
BeaconRegionThe region of interest.
-
Returns:
retrieveMonitoredRegions
()
Void
Retrieves the currently monitored beacon regions.
Async function; returns the results in a retrievedMonitoredRegions event.
Returns:
retrievePeripherals
()
Void
This function doesn't do anything on Android; only present for compatibility with iOS.
Returns:
setAppLaunchIntent
-
params
Specifies the parameters for the intent the module is expected to use to launch the app. Use this function to instruct the module to launch the app when the user enters a monitored region.
The intent launching the app will have an extra called eventName
,
which is a string holding the name of the event that caused the module
to launch the app.
Parameters:
-
params
Object-
packageName
StringThe package name of the app to be launched by the module.
-
className
StringThe name of the class (typically the app's main activity) to be launched by the module.
-
Returns:
setScanTimers
-
params
Use this function to control the timing of beacon related scanning. By default, scanning is restarted every 1.1 seconds while region monitoring or beacon ranging is enabled, to be able to provide beacon related events in a timely manner. You can use this function to increase the scan interval if less frequent beacon related events are sufficient for your use case.
Note that these timers don't impact general scanning unless general scanning is used in parallel with beacon related functionality. See the Beacon Support section of the Readme for more information.
Calling this function will reset scanning to make sure the new timers take effect immediately.
Parameters:
-
params
Object-
scanPeriod
NumberScan period in milliseconds. This is how long each scanning session lasts.
-
scanPausePeriod
NumberScan pause period in milliseconds. This is the time gap between scan periods.
-
Returns:
startRangingBeacons
-
params
Starts the delivery of notifications for beacons in the specified region.
Parameters:
-
params
ObjectAn object with the following properties:
-
beaconRegion
BeaconRegionThe region of interest.
-
Returns:
startRegionMonitoring
-
params
Starts monitoring the specified region.
You must call this method once for each region you want to monitor. If an existing region with the same identifier is already being monitored by the application, the old region is replaced by the new one. If that old region was being ranged, then so will the new one. Note that "identifier" literally means the identifier property, not the UUID! The regions you add using this method are stored in the monitoredRegions property.
Parameters:
-
params
ObjectAn object with the following properties:
-
beaconRegion
BeaconRegionThe region of interest.
-
Returns:
startScan
-
params
Starts scanning for peripherals.
The result of this operation is returned via the discoveredPeripheral event.
Parameters:
-
params
ObjectAn object with the following properties:
-
[UUIDs]
Array of Strings optionalThe UUIDs of services.
-
Returns:
stopRangingBeacons
-
[params]
Stops the delivery of notifications for beacons in the specified region. If no beacon region is specified, then it stops ranging for all regions.
Parameters:
-
[params]
Object optionalAn object with the following properties:
-
beaconRegion
BeaconRegionThe region of interest.
-
Returns:
stopRegionMonitoring
-
[params]
Stops the delivery of notifications for beacons in the specified region. If no beacon region is specified, then it stops ranging for all regions. Note that the region is being identified by its identifier property, not the UUID!
Parameters:
-
[params]
Object optionalAn object with the following properties:
-
beaconRegion
BeaconRegionThe region of interest.
-
Returns:
stopScan
()
Void
Stops scanning for peripherals.
Returns:
Properties
filterDuplicateBeacons
Boolean
Determines whether the beacons included with the
rangedBeacons
event will be filtered for duplicates. Defaults to false
.
A beacon is considered a duplicate of another if their UUID, major, and
minor numbers are all the same.
monitoredRegions
Array of BeaconRegions
read-only
The beacon regions currently being monitored by the module.
rangedRegions
Array of BeaconRegions
read-only
The beacon regions currently being ranged by the module.
state
Number
read-only
The current state of the local Bluetooth adapter.
See also the STATE_OFF, STATE_ON, STATE_TURNING_OFF, and STATE_TURNING_ON constants.
Constants
CHAR_PROP_BROADCAST
Number
Permits broadcasts of the characteristic value using a characteristic configuration descriptor. Not allowed for local characteristics.
CHAR_PROP_EXTENDED_PROPERTIES
Number
If set, additional characteristic properties are defined in the characteristic extended properties descriptor. Not allowed for local characteristics
CHAR_PROP_WRITE_WITHOUT_RESPONSE
Number
Permits writes of the characteristic value, without a response.
CHARACTERISTIC_TYPE_WRITE_WITH_RESPONSE
Number
Use this constant for the type
parameter of the
writeValueForCharacteristic method. It specifies that the write to be performed requires
a response.
CHARACTERISTIC_TYPE_WRITE_WITHOUT_RESPONSE
Number
Use this constant for the type
parameter of the
writeValueForCharacteristic method. It specifies that the write to be performed does not
require a response.
DISABLE_NOTIFICATION_VALUE
TiBuffer
Value used to disable notifications or indications for a client configuration descriptor. You may pass this constant to the unsubscribeFromCharacteristic method.
ENABLE_INDICATION_VALUE
TiBuffer
Value used to enable indication for a client configuration descriptor. You may pass this constant to the subscribeToCharacteristic method.
ENABLE_NOTIFICATION_VALUE
TiBuffer
Value used to enable notification for a client configuration descriptor. You may pass this constant to the subscribeToCharacteristic method.
REGION_STATE_INSIDE
Number
One of the possible values of the state
property of the
regionStateUpdated event.
REGION_STATE_OUTSIDE
Number
One of the possible values of the state
property of the
regionStateUpdated event.
REGION_STATE_UNKNOWN
Number
One of the possible values of the state
property of the
regionStateUpdated event.
Events
connectedPeripheral
This event is fired when a connection initiated by the connectPeripheral method has succeeded.
Event Payload:
-
peripheral
PeripheralAn object representing the peripheral that connected to the local central manager.
disconnectedPeripheral
Fired when a peripheral disconnects from the local central manager.
Event Payload:
-
peripheral
PeripheralAn object representing the peripheral that disconnected.
-
errorCode
NumberThe error code; only present if an error occurred.
discoveredPeripheral
Fired when a peripheral is discovered.
Event Payload:
-
peripheral
PeripheralAn object representing the peripheral that was discovered by the local central manager.
-
RSSI
NumberAn integer representing the RSSI value of the connection.
-
rawAdvertisementData
TiBufferA TiBuffer object holding the content of the advertisement record offered by the remote device. Note that on iOS, this information is provided as a dictionary (an object with various properties).
enteredRegion
This event is fired when the user enters a monitored region.
Event Payload:
-
region
BeaconRegionThe region in question.
exitedRegion
This event is fired when the user exits a monitored region.
Event Payload:
-
region
BeaconRegionThe region in question.
failedToConnectPeripheral
This event is fired when a connection initiated by the connectPeripheral method fails.
Event Payload:
-
peripheral
PeripheralAn object representing the peripheral that failed to connect.
-
errorCode
NumberThe error code; only present if an error occurred.
-
errorDescription
StringThe error description; only present if an error occurred.
moduleReady
This event is fired when the module is ready. Wait for this event before calling any methods on the module.
rangedBeacons
Use this event to determine which beacons are in range.
See also the filterDuplicateBeacons property.
Event Payload:
-
beacons
Array of BeaconsAn array of Beacon objects representing the beacons currently in range. You can use the information in these objects to determine the range of each beacon and its identifying information.
-
region
BeaconRegionThe region object containing the parameters that were used to locate the beacons.
regionStateUpdated
This event is fired when the state of a monitored region is updated.
Event Payload:
-
region
BeaconRegionThe region object containing the parameters that were used to locate the beacons.
-
state
NumberOne of the REGION_STATE_* constants.
retrievedMonitoredRegions
Returns the result of the retrieveMonitoredRegions function.
Event Payload:
-
beaconRegions
Array of BeaconRegionsAn array of BeaconRegion objects, representing the currently monitored beacon regions.
stateChanged
Fired when the state of the local Bluetooth adapter changes.
Event Payload:
-
state
NumberAn integer describing the state of the Bluetooth adapter.