tencent cloud

Feedback

Bluetooth - Low Energy Peripheral Device

Last updated: 2024-03-04 23:09:58

    onBLEPeripheralConnectionStateChanged

    This API is used via wx.onBLEPeripheralConnectionStateChanged(function listener).
    Feature Description: Monitors the current peripheral device for connection or disconnection events.
    Parameter and Description: Object res parameter, function listener, the listener function for connection or disconnection events of the current peripheral device.
    Attribute
    Type
    Description
    deviceId
    String
    Device ID with changing connection status
    serverId
    String
    Server's UUID
    connected
    Boolean
    Current Connection Status

    offBLEPeripheralConnectionStateChanged

    This API is used via wx.offBLEPeripheralConnectionStateChanged(function listener).
    Feature Description: Removes the listener function for connection or disconnection events of the current peripheral device.
    Parameter and Description: function listener, the listener function passed in by onBLEPeripheralConnectionStateChanged. If this parameter is not passed in, all listener functions will be removed.
    Sample Code
    const listener = function (res) { console.log(res) }
    
    wx.onBLEPeripheralConnectionStateChanged(listener)
    wx.offBLEPeripheralConnectionStateChanged(listener) // The same function object as the listener must be passed in.

    createBLEPeripheralServer

    This API is used via wx.createBLEPeripheralServer(Object object).
    Feature Description: Establishes a local server as a Bluetooth Low Energy peripheral device and allows for the creation of multiple servers.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    server
    BLEPeripheralServer
    Server of a peripheral device

    BLEPeripheralServer

    Note:
    Server of a peripheral device.

    .addService

    This method is used via BLEPeripheralServer.addService(Object object).
    Feature Description: Adds service.
    Parameter and Description: Object.
    Attribute
    Type
    Required
    Description
    service
    Object
    Yes
    Object describing the service
    success
    function
    No
    Callback Function of Successful Interface Call
    fail
    function
    No
    Callback Function of Failing Interface Call
    complete
    function
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Structure attribute of service
    Structure attributes
    Type
    Required
    Description
    uuid
    string
    Yes
    Bluetooth service UUID
    characteristics
    Array.<Object>
    Yes
    List of Characteristics
    Structure attributes of characteristics
    Structure attributes
    Type
    Required
    Description
    uuid
    string
    Yes
    UUID of characteristic
    properties
    Object
    No
    Operations Supported by the Characteristic
    permission
    Object
    No
    Permission of characteristic
    value
    Array.<Object>
    No
    Binary data corresponding to the characteristic
    descriptors
    Array.<Object>
    No
    File descriptor data
    Structure attributes of properties
    Structure attributes
    Type
    Default value
    Required
    Description
    write
    boolean
    false
    No
    Write
    writeNoResponse
    boolean
    false
    No
    Write Without Response
    read
    boolean
    false
    No
    Read
    notify
    boolean
    false
    No
    Subscribe
    indicate
    boolean
    false
    No
    Return packet
    Structure attributes of permission
    Structure attributes
    Type
    Default value
    Required
    Description
    readable
    boolean
    false
    No
    Readable
    writeable
    boolean
    false
    No
    Writable
    readEncryptionRequired
    boolean
    false
    No
    Encrypted Read Request
    writeEncryptionRequired
    boolean
    false
    No
    Encrypted Write Request
    Structure attributes of descriptors
    Structure attributes
    Type
    Required
    Description
    uuid
    string
    Yes
    UUID of Descriptors
    permission
    Object
    No
    Permissions of descriptors
    value
    ArrayBuffer
    No
    File descriptor data
    Structure attributes of permission
    Structure attributes
    Type
    Default value
    Required
    Description
    write
    boolean
    false
    No
    Write
    read
    boolean
    false
    No
    Read

    .removeService

    This method is used via BLEPeripheralServer.removeService(Object object).
    Feature Description: Removes service.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    serviceId
    String
    -
    Yes
    UUID of service
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)

    .startAdvertising

    This method is used via BLEPeripheralServer.startAdvertising(Object Object).
    Feature Description: Initiates broadcasting of locally created peripheral devices.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    advertiseRequest
    object
    -
    Yes
    //Custom parameters of broadcasting
    powerLevel
    string
    medium
    No
    Broadcasting power, whose valid values are:
    Low: Low power
    Medium: Moderate power
    High: High power
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Structure attributes of advertiseRequest
    Structure attributes
    Type
    Default value
    Required
    Description
    connectable
    boolean
    ture
    No
    Current device's connectivity status
    deviceName
    string
    -
    No
    The deviceName field in the broadcasting, which is empty by default.
    serviceUuids
    Array.<string>
    -
    No
    List of service UUIDs to be broadcast. Follow the notes when using 16/32 bit UUIDs.
    manufactureData
    Array.<Object>
    -
    No
    Broadcasting manufacturer information. Customization is supported on Android only and not possible on iOS due to system limitations.
    beacon
    object
    -
    No
    Parameters broadcast in the form of a beacon device.
    Structure attributes of manufactureData
    Structure attributes
    Type
    Required
    Description
    manufacturerId
    String
    Yes
    Manufacturer ID, a hexadecimal beginning with 0x.
    manufacturerSpecificData
    ArrayBuffer
    No
    Manufacturer information
    Structure attributes of "beacon"
    Structure attributes
    Type
    Required
    Description
    uuid
    number
    Yes
    UUID broadcast by a beacon device.
    major
    number
    Yes
    Primary ID of beacon device
    minor
    number
    Yes
    Secondary ID of beacon device
    measurePower
    number
    Yes
    Reference value for determining the RSSI size when the distance to the device is 1 meter.

    .stopAdvertising

    This method is used via BLEPeripheralServer.stopAdvertising().
    Feature Description: Ceases broadcasting.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)

    .writeCharacteristicValue

    This method is used via BLEPeripheralServer.writeCharacteristicValue(Object Object).
    Feature Description: Writes binary data values into the specified characteristic and notify the connected host. As the replica node's characteristic value has changed, this interface will handle whether to take the return packet or the subscription route.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    serviceId
    string
    -
    Yes
    UUID corresponding to the Bluetooth characteristic service
    characteristicId
    string
    -
    Yes
    Bluetooth characteristic UUID
    value
    ArrayBuffer
    -
    Yes
    Binary data corresponding to the characteristic
    needNotify
    boolean
    -
    Yes
    Whether it is necessary to notify the host that the value has been updated.
    callbackId
    number
    -
    No
    Optional, used when handling return packets.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)

    .onCharacteristicWriteRequest

    This method is used via BLEPeripheralServer.onCharacteristicWriteRequest(function listener).
    Feature Description: Monitors events where the connected device requests to write the characteristic value of the current peripheral device. Upon receiving this message, it is imperative to immediately call writeCharacteristicValue to write back the data. Otherwise, the host will not receive a response.
    Parameter and Description: Object res.
    Attribute
    Type
    Description
    serviceId
    String
    UUID corresponding to the Bluetooth characteristic service
    characteristicId
    String
    Bluetooth characteristic UUID
    callbackId
    Number
    Unique identifier, used when invoking writeCharacteristicValue.
    value
    ArrayBuffer
    Binary data value requested for characteristic write.

    .offCharacteristicWriteRequest

    This method is used via BLEPeripheralServer.offCharacteristicWriteRequest(function listener).
    Feature Description: Removes the listener function for events associated with characteristic value changes of the currently connected peripheral device, a method used as follows.
    Parameter and Description: function listener, the listener function passed in by onCharacteristicWriteRequest. If this parameter is not passed in, all listener functions will be removed.

    .onCharacteristicReadRequest

    This method is used via BLEPeripheralServer.onCharacteristicReadRequest(function listener).
    Feature Description: Monitors events where the connected device requests to read the characteristic value of the current peripheral device. Upon receiving this message, it is imperative to immediately call writeCharacteristicValue to write back the data. Otherwise, the host will not receive a response.
    Parameter and Description: Object res.
    Attribute
    Type
    Description
    serviceId
    String
    UUID corresponding to the Bluetooth characteristic service
    characteristicId
    String
    Bluetooth characteristic UUID
    callbackId
    Number
    Unique identifier, used when invoking writeCharacteristicValue.

    .offCharacteristicReadRequest

    This method is used via BLEPeripheralServer.offCharacteristicReadRequest(function listener).
    Feature Description: Removes the listener function for events where the connected device requests to read the characteristic value of the current peripheral device.
    Parameter and Description: function listener, the listener function passed in by onCharacteristicReadRequest. If this parameter is not passed in, all listener functions will be removed.
    Sample Code
    const listener = function (res) { console.log(res) }
    
    BLEPeripheralServer.onCharacteristicReadRequest(listener)
    BLEPeripheralServer.offCharacteristicReadRequest(listener) // The same function object as the listener must be passed in.

    .onCharacteristicSubscribed

    This method is used via BLEPeripheralServer.onCharacteristicSubscribed(function listener).
    Feature Description: Monitors characteristic subscription events, supported exclusively on iOS.
    Parameter and Description: Object res parameter, function listener, the listener function for characteristic subscription events.
    Attribute
    Type
    Description
    serviceId
    String
    UUID corresponding to the Bluetooth characteristic service
    characteristicId
    String
    Bluetooth characteristic UUID

    .offCharacteristicSubscribed

    This method is used via BLEPeripheralServer.offCharacteristicSubscribed(function listener).
    Feature Description: Removes the listener function for characteristic subscription events.
    Parameter and Description: function listener, the listener function passed in by onCharacteristicSubscribed. If this parameter is not passed in, all listener functions will be removed.
    Sample Code
    const listener = function (res) { console.log(res) }
    
    BLEPeripheralServer.onCharacteristicSubscribed(listener)
    BLEPeripheralServer.offCharacteristicSubscribed(listener) // The same function object as the listener must be passed in.

    .onCharacteristicUnsubscribed

    This method is used via BLEPeripheralServer.onCharacteristicUnsubscribed(function listener).
    Feature Description: Monitors characteristic unsubscription events, supported exclusively on iOS.
    Parameter and Description: Object res parameter, function listener, the listener function for characteristic unsubscription events.
    Attribute
    Type
    Description
    serviceId
    String
    UUID corresponding to the Bluetooth characteristic service
    characteristicId
    String
    Bluetooth characteristic UUID

    .offCharacteristicUnsubscribed

    This method is used via BLEPeripheralServer.offCharacteristicUnsubscribed(function listener).
    Feature Description: Removes the listener function for characteristic unsubscription events.
    Parameter and Description: function listener, the listener function passed in by onCharacteristicUnsubscribed. If this parameter is not passed in, all listener functions will be removed.
    Sample Code
    const listener = function (res) { console.log(res) }
    
    BLEPeripheralServer.onCharacteristicUnsubscribed(listener)
    BLEPeripheralServer.offCharacteristicUnsubscribed(listener) // The same function object as the listener must be passed in.
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support