当前位置:网站首页>微信小程序与低功耗蓝牙通信-往硬件端发送数据(三)
微信小程序与低功耗蓝牙通信-往硬件端发送数据(三)
2022-04-23 14:02:00 【1029179954】
准备工作:
软件:微信小程序
硬件:
蓝牙设备:hc-09
单片机:stm32
微信小程序往硬件端发送数据,对应的函数是wx.writeBLECharacteristicValue,他的参数是:(对应的下面的参数获取有2种获取方式(1):通过硬件的at指令获取,(2)也可以通过微信小程序特征值获取)
deviceId:"2C:AB:33:33:94:08",
serviceId:"0808FF00-0808-0A09-0807-060504030201",
characteristicId:"0808FF01-0808-0A09-0807-060504030201",
value: buffer(往过传数据的类型是buffer,必须是buffer,不然传数据失败)
具体如下面的代码
let buffer = new ArrayBuffer(1)
let dataView = new DataView(buffer)
dataView.setUint8(0,0x23)
参数获取方式:
deviceId:“2C:AB:33:33:94:08”,
serviceId:“0808FF00-0808-0A09-0807-060504030201”,
characteristicId:“0808FF01-0808-0A09-0807-060504030201”,
(1)wx.getBLEDeviceCharacteristics获取serviceId、characteristicId
deviceId 根据 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取
wx.getBLEDeviceCharacteristics({
// 这里的 deviceId 根据 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取
// deviceId: that.data.connectedDeviceId,
deviceId: "deviceId",
// 这里的 serviceId 根据 getBLEDeviceServices 接口中获取
serviceId: "serviceId ",
success: function(res) {
for (var i = 0; i < res.characteristics.length; i++) {
if (res.characteristics[i].properties.notify) {
console.log("第" + i)
console.log(that.data.services[0].uuid);
console.log( res.characteristics[0].uuid);
that.setData({
notifyServicweId: that.data.services[0].uuid,
notifyCharacteristicsId: res.characteristics[0].uuid,
})
}
}
console.log('device getBLEDeviceCharacteristics:', res.characteristics);
that.setData({
msg: JSON.stringify(res.characteristics),
})
},
fail: function(res) {
console.log("fail" + res);
},
complete: function() {
}
})
(2)通过at指令获取
所有参数拿到及数据类型准备完毕进行数据发送
js
var that = this
let buffer = new ArrayBuffer(1)
let dataView = new DataView(buffer)
dataView.setUint8(0,0x23)
// var typedArray = new Uint8Array(hex.match(/[\da-f]{2}/gi).map(function (h) {
// return parseInt(h, 16)
// }))
// console.log("二进制数据:"+typedArray)
// var buffer1 = typedArray.buffer
wx.writeBLECharacteristicValue({
deviceId:"2C:AB:33:33:94:08",
serviceId:"0808FF00-0808-0A09-0807-060504030201",
characteristicId:"0808FF01-0808-0A09-0807-060504030201",
// 这里的value是ArrayBuffer类型
value: buffer,
success: function (res) {
console.log('写入成功', res.errMsg)
},
fail(res){
console.log('写入失败', res.errMsg)
}
})
微信小程序进行蓝牙初始化、搜索附近蓝牙设备及连接指定蓝牙(一)
https://blog.csdn.net/baidu_38978508/article/details/123439507?spm=1001.2014.3001.5502
微信小程序通过低功耗蓝牙设备进行定位及测距(二)
https://blog.csdn.net/baidu_38978508/article/details/123441079
更多关于微信小程序与蓝牙的知识关注下面公众号:
小白XBIT
版权声明
本文为[1029179954]所创,转载请带上原文链接,感谢
https://blog.csdn.net/baidu_38978508/article/details/123444402
边栏推荐
- FBS(fman build system)打包
- groutine
- [code analysis (1)] communication efficient learning of deep networks from decentralized data
- 2022年江西最新建筑八大员(质量员)模拟考试题库及答案解析
- 联想产品经理林林:天津当地网络运营商网络故障 ZUI系统后台服务器暂时无法正常工作
- CentOS mysql多实例部署
- 浅谈基于openssl的多级证书,Multi-level CA的签发和管理,以及双向认证
- PySide2
- What is the difference between blue-green publishing, rolling publishing and gray publishing?
- Express middleware ③ (custom Middleware)
猜你喜欢
Qt Designer怎样加入资源文件
Choreographer full resolution
Oracle告警日志alert.log和跟踪trace文件中文乱码显示
Taobao released the baby prompt "your consumer protection deposit is insufficient, and the expiration protection has been started"
SQL数据库
scikit-learn构建模型的万能模板
Elmo (bilstm-crf + Elmo) (conll-2003 named entity recognition NER)
Port occupied 1
联想产品经理林林:天津当地网络运营商网络故障 ZUI系统后台服务器暂时无法正常工作
商家案例 | 运动健康APP用户促活怎么做?做好这几点足矣
随机推荐
Choreographer full resolution
项目中遇到的问题(五)操作Excel接口Poi的理解
1256: bouquet for algenon
mysql通过binlog文件恢复数据
浅谈基于openssl的多级证书,Multi-level CA的签发和管理,以及双向认证
33 million IOPs, 39 microsecond delay, carbon footprint certification, who is serious?
对List集合进行分页
[VMware] address of VMware Tools
大专的我,闭关苦学 56 天,含泪拿下阿里 offer,五轮面试,六个小时灵魂拷问
visio安装报错 1:1935 2:{XXXXXXXX...
Express ② (routage)
freeCodeCamp----time_ Calculator exercise
容差分析相关的计算公式
About note 1
Nacos+AspnetCore+Ocelot实战编码
Port occupied 1
leetcode--977. Squares of a Sorted Array
[code analysis (1)] communication efficient learning of deep networks from decentralized data
读了一篇博客,重新理解闭包整理一下
Scientists say Australian plan to cull up to 10,000 wild horses doesn’t go far enough