# wx.createBLEConnection(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

Connect to a Bluetooth low-power device.

If the Mini Program in the previous search has been a Bluetooth device, and successfully established a connection, can be directly passed before the search access deviceId Try to connect the device directly without the need to search again.

# parameter

# Object object

attribute type Default values Required Introductions
deviceId string yes Bluetooth Device id
timeout number no Timeout, units Ms, no fill means no timeout
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

  • Make sure to call as many pairs as possible wx.createBLEConnection and wx.closeBLEConnection Interface. Android, if repeated wx.createBLEConnection Creating connections that can cause the system to hold multiple instances of connections on the same device, causing a call to the closeBLEConnection When the device does not really disconnect from the connection.
  • Bluetooth connection may be disconnected at any time. Monitor advised. wx.onBLEConnectionStateChange Callback event to perform on-demand reconnect when the Bluetooth device is disconnected
  • To invoke an interface for a data read or write operation on an unconnected device or a disconnected device, the 10006 Error, reconnection is recommended.

# sample code

Preview with Developer Tool

  success (res) {