airsync android 版本,微信小程序 蓝牙控制支持airsync协议吗

// pages/bluetooth/bluetooth.js

Page({

data:{},

onLoad:function(options){

// 页面初始化 options为页面跳转所带来的参数

},

//初始化蓝牙适配器

openBluetooth:function(){

wx.openBluetoothAdapter({

success: function(res){

console.log(res.errMsg)

// success

wx.showToast({

title:"初始化蓝牙适配器成功",

duration:2000

})

},

})

},

//关闭蓝牙模块

closeBluetooth:function(){

wx.openBluetoothAdapter()

wx.closeBluetoothAdapter({

success: function(res){

// success

console.log("success"+res)

}

})

},

//获取本机蓝牙适配器状态

getBluetoothAdapterState:function(){

wx.getBluetoothAdapterState({

success: function(res){

// success

console.log("res:"+res)

console.log("errMsg:"+res.errMsg)

}

})

},

//监听蓝牙适配器状态变化事件

onBluetoothAdapterStateChange:function(){

wx.onBluetoothAdapterStateChange(function(res) {

console.log(`adapterState changed, now is`, res)

})

},

// 开始搜寻附近的蓝牙外围设备

startBluetoothDevicesDiscovery:function(){

wx.startBluetoothDevicesDiscovery({

success: function (res) {

console.log(res)

}

})

},

// 停止搜寻附近的蓝牙外围设备

stopBluetoothDevicesDiscovery:function(){

wx.stopBluetoothDevicesDiscovery({

success: function (res) {

console.log(res)

}

})

},

//获取所有已发现的蓝牙设备

getBluetoothDevices:function(){

wx.getBluetoothDevices({

success: function(res){

// success

console.log(res)

},

})

},

//监听寻找到新设备的事件

onBluetoothDeviceFound:function(){

wx.onBluetoothDeviceFound(function(res) {

// callback

console.log(res)

})

},

//根据 uuid 获取处于已连接状态的设备

getConnectedBluetoothDevices:function(){

wx.getConnectedBluetoothDevices({

success: function (res) {

console.log(res)

}

})

},

//连接低功耗蓝牙设备

createBLEConnection:function(){

wx.createBLEConnection({

deviceId: 'AC:BC:32:C1:47:80',

success: function(res){

// success

console.log(res)

},

fail: function(res) {

// fail

},

complete: function(res) {

// complete

}

})

},

//断开与低功耗蓝牙设备的连接

closeBLEConnection:function(){

wx.closeBLEConnection({

deviceId: 'AC:BC:32:C1:47:80',

success: function (res) {

console.log(res)

}

})

},

//监听低功耗蓝牙连接的错误事件,包括设备丢失,连接异常断开等等

onBLEConnectionStateChanged:function(){

wx.onBLEConnectionStateChanged(function(res) {

console.log(`device ${res.deviceId} state has changed, connected: ${res.connected}`)

})

},

//获取蓝牙设备所有 service(服务)

getBLEDeviceServices:function(){

wx.getBLEDeviceServices({

deviceId: '48:3B:38:88:E3:83',

success: function(res){

// success

console.log('device services:', res.services.serviceId)

},

fail: function(res) {

// fail

},

complete: function(res) {

// complete

}

})

},

//获取蓝牙设备所有 characteristic(特征值)

getBLEDeviceCharacteristics:function(){

wx.getBLEDeviceCharacteristics({

deviceId: '48:3B:38:88:E3:83',

serviceId: 'serviceId',

success: function(res){

// success

},

fail: function(res) {

// fail

},

complete: function(res) {

// complete

}

})

}

})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值