Skip to content

Modules.BLE.Peripheral

A remote peripheral device.

The CBPeripheral class represents remote peripheral devices that your app discovers with a central manager (an instance of CentralManager). In iOS, Peripherals use universally unique identifiers (UUIDs), to identify themselves. For Android, Peripherals use address to be uniqely identified. Peripherals may contain one or more services or provide useful information about their connected signal strength.

Extends: Titanium.Proxy · Since: 1.0.0 · Platforms: android, iphone, ipad

Properties #

address#

Type: String

Once a peripheral has been connected at least once by the system, it is assigned a address (UUID). This address can be stored and later provided to the retrievePeripherals method.

ancsAuthorized#

Type: Boolean

A Boolean value that indicates if the remote device has authorization to receive data over ANCS protocol.

canSendWriteWithoutResponse#

Type: Boolean

A Boolean value that indicates whether the remote device can send a write without a response.

isConnected#

Type: Boolean

Whether or not the peripheral is currently connected.

name#

Type: String

The name of the peripheral.

services#

Type: Array<Modules.BLE.Service>

A list of a peripheral’s discovered services.

state#

Type: Number

The current connection state of the peripheral. Possible values defined by PERIPHERAL_STATE_* constants.

Methods #

discoverCharacteristics #

Discovers the specified characteristic(s) of a service. The result of this operation is returned via the didDiscoverCharacteristics event. In android, all the characteristics have already been discovered, as part of the discoverServices operation. So, this method is kept in android to keep parity with the iOS platform.

Parameters:
NameTypeSummaryOptional
servicesModules.BLE.ServiceThe service whose characteristics you want to discover.No
characteristicUUIDsArray<String>An array of UUID objects that you are interested in. Each UUID identifies the characteristic you want to discover.Yes

Returns: void

discoverDescriptorsForCharacteristic #

Discovers the descriptor(s) of a characteristic.The result of this operation is returned via the didDiscoverDescriptorsForCharacteristics event. In android, all the descriptors have already been discovered, as part of the discoverServices operation. So, this method is kept in android to keep parity with the iOS platform.

Parameters:
NameTypeSummaryOptional
characteristicModules.BLE.CharacteristicThe characteristic whose descriptors you want to discover.No

Returns: void

discoverIncludedServices #

Discovers the specified included service(s) of a service.The result of this operation is returned via the didDiscoverIncludedServices event. In android, all the included services have already been discovered, as part of the discoverServices operation. So, this method is kept in android to keep parity with the iOS platform.

Parameters:
NameTypeSummaryOptional
servicesModules.BLE.ServiceThe service whose characteristics you want to discover.No
includedServiceUUIDsArray<String>An array of UUID objects that you are interested in. Each UUID identifies the included service you want to discover.Yes

Returns: void

discoverServices #

Discovers available service(s) on the peripheral. The result of this operation is returned via the didDiscoverServices event.

Parameters:
NameTypeSummaryOptional
serviceUUIDsArray<String>An array of UUID objects that you are interested in. Each UUID identifies the services you want to discover. In android, the behavior is discoverServices discovers all the available services irrespective of this parameter.Yes

Returns: void

maximumWriteValueLength #

The maximum amount of data, in bytes, you can send to a characteristic in a single write type.

Parameters:
NameTypeSummaryOptional
characteristicWriteTypeNumberValues representing the possible write types to a characteristic’s value.No

Returns: void

openL2CAPChannel #

Attempts to open an L2CAP channel to the peripheral using the supplied Protocol/Service Multiplexer (PSM).

Parameters:
NameTypeSummaryOptional
psmIdentifierNumberThe PSM of the channel to open.No
encryptionRequiredBooleanThe bool can be true if the service requires the link to be encrypted before a stream can be established. false if the service can be used over an unsecured link. This parameter is applicable in android only and the default value is false.Yes

Returns: void

readRSSI #

Retrieves the current RSSI value for the peripheral while connected to the central manager.

Returns: void

readValueForCharacteristic #

Reads the value of a characteristic.The result of this operation is returned via the didUpdateValueForCharacteristic event.

Parameters:
NameTypeSummaryOptional
characteristicModules.BLE.CharacteristicThe characteristic whose value you want to read.No

Returns: void

readValueForDescriptor #

Reads the value of a descriptor. The result of this operation is returned via the didUpdateValueForDescriptor event.

Parameters:
NameTypeSummaryOptional
descriptorModules.BLE.DescriptorThe characteristic descriptor whose value you want to read.No

Returns: void

requestConnectionPriority #

Request the specific connection priority. This method will send connection parameter update request to the remote device.

Parameters:
NameTypeSummaryOptional
connectionPriorityNumberConnection priority to set. Must be one of CONNECTION_PRIORITY_HIGH, CONNECTION_PRIORITY_BALANCED and CONNECTION_PRIORITY_LOW_POWER.No

Returns: void

subscribeToCharacteristic #

Enables notifications/indications for a characteristic. If the characteristic allows both, notifications will be used.

In Android, subscribing to a characteristic is a two step process in which, first the setCharacteristicNotification() is called which enables the notification locally(on Android device), followed by writing on the descriptor, which is optional.
If the second paramater(descriptorUUID) not provided, then writing on the descriptor would not be done. Reference (https://developer.android.com/guide/topics/connectivity/bluetooth-le#notification)

Parameters:
NameTypeSummaryOptional
characteristicModules.BLE.CharacteristicThe characteristic whose value you want to read.No
descriptorUUID="00002902-0000-1000-8000-00805f9b34fb"StringThe UUID of the configuration descriptor of the characteristic. The module will attempt to write descriptorValue to this descriptor. If you do not want the module to do this, set this parameter to an empty string. This parameter is only for Android.Yes
descriptorValue=ENABLE_NOTIFICATION_VALUETitanium.BufferThe value to be written to the configuration descriptor. This parameter is only for Android.Yes

Returns: void

unsubscribeFromCharacteristic #

Disables notifications/indications for a characteristic.

Parameters:
NameTypeSummaryOptional
characteristicModules.BLE.CharacteristicThe characteristic whose value you want to read.No
descriptorUUID="00002902-0000-1000-8000-00805f9b34fb"StringThe UUID of the configuration descriptor of the characteristic. The module will attempt to write descriptorValue to this descriptor. If you do not want the module to do this, set this parameter to an empty string. This parameter is only for Android.Yes
descriptorValue=DISABLE_NOTIFICATION_VALUETitanium.BufferThe value to be written to the configuration descriptor. This parameter is only for Android.Yes

Returns: void

writeValueForCharacteristic #

Writes a value to a characteristic.

Parameters:
NameTypeSummaryOptional
characteristicModules.BLE.CharacteristicThe characteristic whose value you want to write.No
dataTitanium.BufferThe new value of the characteristic.No
characteristicWriteTypeNumberThe type of write to be executed. See CHARACTERISTIC_TYPE_WRITE_WITH_RESPONSE and CHARACTERISTIC_TYPE_WRITE_WITHOUT_RESPONSE.No

Returns: void

writeValueForDescriptor #

Writes the value of a descriptor. The result of this operation is returned via the didWriteValueForDescriptor event.

Writes the value of a characteristic descriptor.
This method copies the data passed into the data parameter, and you can dispose of it after the method returns.
Note (iOS): You can’t use this method to write the value of a client configuration descriptor (represented by the BLE.CBUUID_CLIENT_CHARACTERISTIC_CONFIGURATION_STRING constant),
which describes the configuration of notification or indications for a characteristic’s value.
If you want to manage notifications or indications for a characteristic’s value, you must use the subscribeToCharacteristic({characteristic:}) and unsubscribeFromCharacteristic({characteristic:}) method instead.
Another Note (iOS): Once published, you can’t update the value dynamically. Reference (https://developer.apple.com/documentation/corebluetooth/cbmutabledescriptor/1518999-init)

Parameters:
NameTypeSummaryOptional
descriptorModules.BLE.DescriptorThe descriptor whose value you want to write.No
dataTitanium.BufferThe new value of the characteristic.No

Returns: void

Events #

didDiscoverCharacteristics #

This event returns the result of a call to the discoverCharacteristics method. If the characteristic(s) were read successfully, they can be retrieved via the service property's characteristics property.

Core Bluetooth invokes this method when your app calls the discoverCharacteristics method. If the peripheral successfully discovers the characteristics of the specified service, you can access them through the service’s characteristics property.

Event Properties:
NameTypeSummary
sourcePeripheralModules.BLE.PeripheralThe peripheral providing this information.
serviceModules.BLE.ServiceThe service to which the characteristics belong.
errorCodeStringThe error code; only present if an error occurred.
errorDomainStringThe error domain; only present if an error occurred.
errorDescriptionStringThe error description; only peresent if an error occurred.

didDiscoverDescriptorsForCharacteristics #

This event returns the result of a call to the discoverDescriptorsForCharacteristic method.

Core Bluetooth invokes this method when your app calls the discoverDescriptors method. If the peripheral successfully discovers the descriptors of the specified characteristic, you can access them through the characteristic’s descriptors property.

Event Properties:
NameTypeSummary
sourcePeripheralModules.BLE.PeripheralThe peripheral providing this information.
characteristicModules.BLE.CharacteristicThe service to which the characteristics belong.
errorCodeStringThe error code; only present if an error occurred.
errorDomainStringThe error domain; only present if an error occurred.
errorDescriptionStringThe error description; only peresent if an error occurred.

didDiscoverIncludedServices #

This event returns the result of a call to the discoverIncludedServices method.

Core Bluetooth invokes this method when your app calls the discoverIncludedServices method. If the peripheral successfully discovers services, you can access them through the service’s includedServices property.

Event Properties:
NameTypeSummary
sourcePeripheralModules.BLE.PeripheralThe peripheral providing this information.
errorCodeStringThe error code; only present if an error occurred.
errorDomainStringThe error domain; only present if an error occurred.
errorDescriptionStringThe error description; only peresent if an error occurred.

didDiscoverServices #

Discovers the specified services of the peripheral.

Core Bluetooth invokes this method when your app calls the discoverServices method. If the peripheral successfully discovers services, you can access them through the peripheral’s services property.

Event Properties:
NameTypeSummary
sourcePeripheralModules.BLE.PeripheralThe peripheral providing this information.
errorCodeStringThe error code; only present if an error occurred.
errorDomainStringThe error domain; only present if an error occurred.
errorDescriptionStringThe error description; only peresent if an error occurred.

didModifyServices #

This event is fired when the services of the peripheral change.

Core Bluetooth invokes this method whenever one or more services of a peripheral change. The invalidatedServices parameter includes any changed services that you previously discovered; you can no longer use these services. You can use the discoverServices method to discover any new services that the peripheral added to its database. Use this same method to find out whether any of the invalidated services that you were using (and want to continue using) now have a different location in the peripheral’s database.

Event Properties:
NameTypeSummary
sourcePeripheralModules.BLE.PeripheralThe peripheral providing this information.
servicesArray<Modules.BLE.Service>The services that have been invalidated.

didOpenChannel #

This method delivers the result of a previous call to openL2CAPChannel.

Delivers the result of an attempt to open an L2CAP channel.

Event Properties:
NameTypeSummary
sourcePeripheralModules.BLE.PeripheralThe peripheral sending the event.
channelModules.BLE.L2CAPChannelA live L2CAP connection to a remote device.
errorCodeStringThe error code; only present if an error occurred.
errorDomainStringThe error domain; only present if an error occurred.
errorDescriptionStringThe error description; only peresent if an error occurred.

didReadRSSI #

This event returns the result of a call to the readRSSI method.

Core Bluetooth invokes this method when your app calls the readRSSI() method, while the peripheral is connected to the central manager. If successful, the error parameter is nil and the parameter RSSI reports the peripheral’s signal strength, in decibels. If unsuccessful, the error parameter returns the cause of the failure.

Event Properties:
NameTypeSummary
sourcePeripheralModules.BLE.PeripheralThe peripheral providing this information.
rssiNumbervalue last read
errorCodeStringThe error code; only present if an error occurred.
errorDomainStringThe error domain; only present if an error occurred.
errorDescriptionStringThe error description; only peresent if an error occurred.

didUpdateName #

This event is fired when the name of the peripheral changes.

Core Bluetooth invokes this method whenever the peripheral’s Generic Access Profile (GAP) device name changes. Since a peripheral device can change its GAP device name, you can implement this method if your app needs to display the current name of the peripheral device.

Event Properties:
NameTypeSummary
sourcePeripheralModules.BLE.PeripheralThe peripheral providing this information.

didUpdateNotificationStateForCharacteristics #

This event returns the result of a call to the subscribeToCharacteristic or unsubscribeFromCharacteristic method.

Core Bluetooth invokes this method when your app calls the subscribeToCharacteristic or unsubscribeFromCharacteristic method.

Event Properties:
NameTypeSummary
sourcePeripheralModules.BLE.PeripheralThe peripheral providing this information.
characteristicModules.BLE.CharacteristicThe characteristic to subscribe.
isSubscribedBooleanA Boolean value that specifies whether the didUpdateNotificationStateForCharacteristics event is for subscribe or unsubscribe operation. true, if subscribe and false otherwise.
errorCodeStringThe error code; only present if an error occurred.
errorDomainStringThe error domain; only present if an error occurred.
errorDescriptionStringThe error description; only peresent if an error occurred.

didUpdateValueForCharacteristic #

This event is fired after a call to the readValueForCharacteristic method, or upon receipt of a notification/indication.

Core Bluetooth invokes this method when your app calls the readValueForCharacteristic method. A peripheral also invokes this method to notify your app of a change to the value of the characteristic for which the app previously enabled notifications by calling subscribeToCharacteristic or unsubscribeFromCharacteristic method.

Event Properties:
NameTypeSummary
sourcePeripheralModules.BLE.PeripheralThe peripheral providing this information.
characteristicModules.BLE.CharacteristicThe characteristic containing the value.
errorCodeStringThe error code; only present if an error occurred.
errorDomainStringThe error domain; only present if an error occurred.
errorDescriptionStringThe error description; only peresent if an error occurred.

didUpdateValueForDescriptor #

This event returns the result of a call to the readValueForDescriptor method.

Core Bluetooth invokes this method when your app calls the readValueForDescriptor method.

Event Properties:
NameTypeSummary
sourcePeripheralModules.BLE.PeripheralThe peripheral providing this information.
descriptorModules.BLE.DescriptorThe characteristic descriptor containing the value.
errorCodeStringThe error code; only present if an error occurred.
errorDomainStringThe error domain; only present if an error occurred.
errorDescriptionStringThe error description; only peresent if an error occurred.

didWriteValueForCharacteristic #

This event returns the result of a call to the writeValueForCharacteristic method.

Core Bluetooth invokes this method only when your app calls the writeValueForCharacteristic method with the BLE.CHARACTERISTIC_WRYTE_TYPE_WITH_RESPOSNE constant specified as the write type.

Event Properties:
NameTypeSummary
sourcePeripheralModules.BLE.PeripheralThe peripheral providing this information.
characteristicModules.BLE.CharacteristicThe characteristic containing the value.
errorCodeStringThe error code; only present if an error occurred.
errorDomainStringThe error domain; only present if an error occurred.
errorDescriptionStringThe error description; only peresent if an error occurred.

didWriteValueForDescriptor #

This event returns the result of a call to the writeValueForDescriptor method.

Core Bluetooth invokes this method when your app calls the writeValueForDescriptor method.

Event Properties:
NameTypeSummary
sourcePeripheralModules.BLE.PeripheralThe peripheral sending the event.
descriptorModules.BLE.DescriptorThe object representing the descriptor that was changed.
errorCodeStringThe error code; only present if an error occurred.
errorDomainStringThe error domain; only present if an error occurred.
errorDescriptionStringThe error description; only peresent if an error occurred.

peripheralIsReadyToSendWriteWithoutResponse #

Tells the delegate that a peripheral is again ready to send characteristic updates.

The peripheral calls this delegate method after a failed call to writeValueForCharacteristic, once peripheral is ready to send characteristic value updates.

Event Properties:
NameTypeSummary
sourcePeripheralModules.BLE.PeripheralThe peripheral sending the event.

Titanium SDK Documentation