当前位置:网站首页>Wechat applet initializes Bluetooth, searches nearby Bluetooth devices and connects designated Bluetooth (I)
Wechat applet initializes Bluetooth, searches nearby Bluetooth devices and connects designated Bluetooth (I)
2022-04-23 14:05:00 【one billion twenty-nine million one hundred and seventy-nine th】
Preface :
Wechat applet searches for nearby Bluetooth devices , Bluetooth initialization must be performed first , initialization ok Search for nearby Bluetooth devices . The specified Bluetooth connection requires deviceId( Hardware through at Commands can be viewed deviceId)
preparation :
Software : Wechat applet
Hardware :
Bluetooth devices :hc-09
Single chip microcomputer :stm32
One : hardware component
see hc-09deviceId
Hardware :
Two : Software part
Software
wxml
<button class="to-clock" hover-class="hover-to-clock" bindtap="toClock"> Bluetooth initialization </button>
js
// Bluetooth initialization
wx.openBluetoothAdapter({
success: function (res) {
console.log(" Initialize Bluetooth adapter ");
/*getBluetoothAdapterState() Get the status of the native Bluetooth adapter , Determine if it is available ,available by false Because the user does not turn on the system Bluetooth */
wx.getBluetoothAdapterState({
success:function (res) {
// Print related information
console.log(JSON.stringify(res.errMsg) + "\n Bluetooth is available :" + res.available);
// res.available==true Adapter available res.available==false Adapter not available
if(res.available){
// Search for Bluetooth devices
wx.startBluetoothDevicesDiscovery({
services: [],
allowDuplicatesKey: false,
success: function (res) {
console.log(" Search for Bluetooth devices :"+res)
// Get Bluetooth device output information list
wx.getBluetoothDevices({
success: function (res) {
console.log(' Number of search devices :' + res.devices.length)
console.log(' Equipment information :\n' + JSON.stringify(res.devices)+"\n")
// Wechat applet connects to Bluetooth hc-09
wx.createBLEConnection({
deviceId:"2C:AB:33:33:94:08",
success: function (res) {
console.log(' Connection success output information :' + res)
wx.hideLoading()
wx.showModal({
title: ' reminder ',
content: ' Bluetooth connection successful '
})
},
fail: function () {
wx.hideLoading()
wx.showModal({
title: ' reminder ',
content: ' Bluetooth connection failed '
})
},
})
}
})
},
fail: function (err) {
wx.hideLoading()
console.log(err);
wx.showModal({
title: ' reminder ',
content: ' Bluetooth search failed '
})
}
});
}else{
wx.hideLoading()
wx.showModal({
title: ' reminder ',
content: ' Bluetooth device not available '
})
}
},
fail: function (res) {
// Print related information
console.log(JSON.stringify(res.errMsg) + "\n Bluetooth is available :" + res.available);
wx.hideLoading()
wx.showModal({
title: ' reminder ',
content: ' Bluetooth device not available '
})
}
})
},
fail: function (err) {
wx.hideLoading()
console.log(err);
wx.showToast({
title: ' Bluetooth initialization failed ',
icon: 'success',
duration: 2000
})
setTimeout(function () {
wx.hideToast()
}, 2000)
}
});
More knowledge of WeChat applet and Bluetooth communication knowledge, and the following official account.
版权声明
本文为[one billion twenty-nine million one hundred and seventy-nine th]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231401297802.html
边栏推荐
- Decimal 格式化小数位/DateTime 转换处理
- Yarn online dynamic resource tuning
- RobotFramework 之 项目框架
- Quartus prime hardware experimental development (de2-115 board) experiment II function adjustable comprehensive timer design
- Windos中安装labellmg教程
- 生成随机高质量符合高斯分布的随机数
- 微信小程序获取登录用户信息、openid和access_token
- 微信小程序基于udp协议与esp8266进行通信
- 微信小程序与低功耗蓝牙通信-往硬件端发送数据(三)
- DeepinV20安装Mariadb
猜你喜欢
DDT+Excel进行接口测试
RobotFramework 之 文件上传和下载
Pytorch 经典卷积神经网络 LeNet
nodejs通过require读取本地json文件出现Unexpected token / in JSON at position
关于pthread多线程一些好文章
As a junior college student, I studied hard in closed doors for 56 days, won Ali offer with tears, five rounds of interviews and six hours of soul torture
smart-doc + torna生成接口文档
linux安装mysql后修改密码
Mock测试
Pycharm连接远程服务器并实现远程调试
随机推荐
室内外地图切换(室内基于ibeacons三点定位)
接口文档yaml
Programming travel function
Windos中安装labellmg教程
Lin Lin, product manager of Lenovo: network failure of local network operator in Tianjin. The background server of Zui system can't work normally for the time being
There is a mining virus in the server
生成随机高质量符合高斯分布的随机数
分页SQL
多线程 @Async 线程池
Oracle alarm log alert Chinese trace and trace files
org.apache.parquet.schema.InvalidSchemaException: A group type can not be empty. Parquet does not su
CDH cluster integration Phoenix based on CM management
封装logging模块
微信小程序进行蓝牙初始化、搜索附近蓝牙设备及连接指定蓝牙(一)
Universal template for scikit learn model construction
Neuron and neural network
基于ibeacons签到系统
pthread_self()为何重复了
json反序列化匿名数组/对象
微信小程序与低功耗蓝牙通信-往硬件端发送数据(三)