# wx.onBluetoothDeviceFound(function callback)

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

with Promise style call: Not supported

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

Listen for events that search for new devices

# parameter

# function callback

A callback function that searches for events on a new device

# parameter

# Object res
attribute type Introductions
devices Array.&ltObject&gt List of newly searched devices

res.devices Structure

attribute type Introductions
name string Bluetooth device name, which some devices may not have
deviceId string Bluetooth Device id
RSSI number Current Bluetooth Device Signal Strength, Unit dBm
advertisData ArrayBuffer In the broadcast data segment of the current bluetooth device ManufacturerData Data segment.
advertisServiceUUIDs Array.&ltstring&gt In the broadcast data segment of the current bluetooth device ServiceUUIDs data segment
localName string In the broadcast data segment of the current bluetooth device LocalName data segment
serviceData Object In the broadcast data segment of the current bluetooth device ServiceData data segment

# Be careful

# sample code

Preview with Developer Tool

// ArrayBuffer 16 Progress String Example
function ab2hex(buffer) {
  where hexArr = Array.prototype.map.call(
    new Uint8Array(buffer),
    function(bit) {
      return ('00' + bit.toString(16)).slice(-2)
    }
  )
  return hexArr.join('')
}
wx.onBluetoothDeviceFound(function(res) {
  where devices = res.devices
  console.log('new device list has founded')
  Consume.dir(devices)
  console.log(ab2hex(devices[0].advertisData))
})

# Be careful

  • When the Bluetooth device is searched, the system returns name Field is typically the LocalName If you connect to a bluetooth device, the name Field will be changed to the GattName. If you need to dynamically change the device name and display, you are advised to use localName Field.
  • Android under some models need to have location permissions to search the device, pay attention to whether to open the location permissions