# wx.notifyBLECharacteristicValueChange(Object object)

Start from base library version 1.1.0. Please remaining backward compatible.

with Promise style call: Supported

Mini Program plugin: Support, need to Mini Program base library version no less than 1.9.6

Enables a Bluetooth low-power device when its eigenvalue changes notify Features, subscription features. Note: Features of the device must support notify or indicate Before it can be successfully invoked.

Also, you must first enable wx.notifyBLECharacteristicValueChange To listen to the device. characteristicValueChange event

# parameter

# Object object

attribute type Default values Required Introductions Minimum version
deviceId string yes Bluetooth Device id
serviceId string yes Bluetooth Feature Corresponding Service UUID
characteristicId string yes Bluetooth characteristic UUID
state boolean yes Enable notify
type string indication no Sets the characteristic subscription type with a valid value of notification and indication 2.4.0
success function no Interface calls the successful callback function
fail function no Interface calls failed callback functions
complete function no Callback function at the end of an interface call (both successful and unsuccessful calls are executed)

# error

Error code Error message Introductions
0 ok normal
-1 already connect Connected
10000 not init Uninitialized Bluetooth adapter
10001 not available The current Bluetooth adapter is not available
10002 No device Specified device not found
10003 connection fail Connection failure
10004 No service Specified service not found
10005 No characteristic Did not find the specified signature.
10006 No connection Current connection disconnected
10007 property not support Current feature does not support this operation
10008 system error All other system reported anomalies
10009 system not support Android System specific, system version below 4.3 Not supported WAS
10012 operate time out Connection Timeout
10013 invalid_data Connect deviceId Is empty or incorrectly formatted

# Be careful

  • Requires the device to actively update features after a successful subscription operation Value will trigger wx.onBLECharacteristicValueChange Callback.
  • On Android platform, call immediately after this interface is successfully invoked wx.writeBLECharacteristicValue Interface, which occurs on some models 10008 System error

# sample code

Preview with Developer Tool

  state: true, // Enable notify function
  // Here. deviceId Need has passed createBLEConnection Establish a link with the corresponding device
  // Here. serviceId Need to getBLEDeviceServices Get in interface
  // Here. characteristicId Need to getBLEDeviceCharacteristics Get in interface
  success (res) {
    console.log('notifyBLECharacteristicValueChange success', res.errMsg)