当前位置:网站首页>Wechat applet communicates with low-power Bluetooth - sending data to hardware (III)
Wechat applet communicates with low-power Bluetooth - sending data to hardware (III)
2022-04-23 14:05:00 【one billion twenty-nine million one hundred and seventy-nine th】
preparation :
Software : Wechat applet
Hardware :
Bluetooth devices :hc-09
Single chip microcomputer :stm32
Wechat applet sends data to the hardware , The corresponding function is wx.writeBLECharacteristicValue, His parameters are :( The corresponding parameters below are 2 There are two ways to get it (1): Through hardware at Instructions for ,(2) It can also be obtained through the characteristic value of wechat applet )
deviceId:"2C:AB:33:33:94:08",
serviceId:"0808FF00-0808-0A09-0807-060504030201",
characteristicId:"0808FF01-0808-0A09-0807-060504030201",
value: buffer( The type of data to be transmitted is buffer, Must be buffer, Otherwise, data transmission fails )
Specific as the following code
let buffer = new ArrayBuffer(1)
let dataView = new DataView(buffer)
dataView.setUint8(0,0x23)
Parameter acquisition method :
deviceId:“2C:AB:33:33:94:08”,
serviceId:“0808FF00-0808-0A09-0807-060504030201”,
characteristicId:“0808FF01-0808-0A09-0807-060504030201”,
(1)wx.getBLEDeviceCharacteristics obtain serviceId、characteristicId
deviceId according to getBluetoothDevices or onBluetoothDeviceFound Interface
wx.getBLEDeviceCharacteristics({
// there deviceId according to getBluetoothDevices or onBluetoothDeviceFound Interface
// deviceId: that.data.connectedDeviceId,
deviceId: "deviceId",
// there serviceId according to getBLEDeviceServices Interface
serviceId: "serviceId ",
success: function(res) {
for (var i = 0; i < res.characteristics.length; i++) {
if (res.characteristics[i].properties.notify) {
console.log(" The first " + 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) adopt at Instructions for
All parameters and data types are ready for data transmission
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(" binary data :"+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",
// there value yes ArrayBuffer type
value: buffer,
success: function (res) {
console.log(' Write successfully ', res.errMsg)
},
fail(res){
console.log(' Write failure ', res.errMsg)
}
})
Wechat applet for Bluetooth initialization 、 Search for nearby Bluetooth devices and connect to designated Bluetooth devices ( One )
https://blog.csdn.net/baidu_38978508/article/details/123439507?spm=1001.2014.3001.5502
Wechat applet performs positioning and ranging through low-power Bluetooth devices ( Two )
https://blog.csdn.net/baidu_38978508/article/details/123441079
More about WeChat's small program and Bluetooth knowledge, the following official account. :
The small white XBIT
版权声明
本文为[one billion twenty-nine million one hundred and seventy-nine th]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231401297720.html
边栏推荐
- Universal template for scikit learn model construction
- scikit-learn构建模型的万能模板
- _模_板_
- pthread_self()为何重复了
- 微信小程序与低功耗蓝牙通信-接受硬件端发送来的数据(四)
- scikit-learn構建模型的萬能模板
- Mock测试
- Wechat applet obtains login user information, openid and access_ token
- 室内外地图切换(室内基于ibeacons三点定位)
- Quartus prime hardware experimental development (de2-115 board) experiment II function adjustable comprehensive timer design
猜你喜欢
室内外地图切换(室内基于ibeacons三点定位)
Qt Designer怎样加入资源文件
Nacos+AspnetCore+Ocelot实战编码
groutine
Record a strange bug: component copy after cache component jump
基于ibeacons签到系统
微信小程序进行蓝牙初始化、搜索附近蓝牙设备及连接指定蓝牙(一)
poi操作word模板替换数据并且导出word
Cdh6 based on CM management 3.2 cluster integration atlas 2 one
Check in system based on ibeacons
随机推荐
Chrome插件 之 Selenium IDE、XPath 安装
Wechat applet initializes Bluetooth, searches nearby Bluetooth devices and connects designated Bluetooth (I)
使用itextpdf实现截取pdf文档第几页到第几页,进行分片
报表FCRA考试题集及答案(错了11题)
帆软报表设置单元格填报以及根据值的大小进行排名方法
基於CM管理的CDH集群集成Phoenix
Jmeter安装教程以及我遇到的问题的解决办法
go 语言 数组,字符串,切片
理解虚基类、虚函数与纯虚函数的概念(转)
Detailed tutorial on the use of smoke sensor (mq-2) (based on raspberry pie 3B +)
Choreographer full resolution
基于ibeacons签到系统
Windos中安装labellmg教程
log4j 输出日志信息到文件中
编程旅行之函数
Idea控制台乱码解决
基于ibeacons三点定位(微信小程序)
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
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
关于密匙传递的安全性和数字签名