当前位置:网站首页>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
边栏推荐
猜你喜欢
帆软实现一个单选按钮,可以统一设置其他单选按钮的选择状态
Promtail + Loki + Grafana 日志监控系统搭建
按实际取,每三级分类汇总一次,看图知需求
1256: bouquet for algenon
Use of WiFi module based on wechat applet
Quartus prime hardware experimental development (de2-115 board) experiment II function adjustable comprehensive timer design
CentOS mysql多实例部署
Detailed tutorial on the use of setinterval timing function of wechat applet
Node接入支付宝开放平台的沙箱实现支付功能
scikit-learn构建模型的万能模板
随机推荐
Redis docker 安装
1256:献给阿尔吉侬的花束
smart-doc + torna生成接口文档
对List集合进行分页
微信小程序setInterval定时函数使用详细教程
Nacos+AspnetCore+Ocelot实战编码
帆软中需要设置合计值为0时,一整行都不显示的解决办法
Autumn recruitment in 2021, salary ranking No
Wechat applet communicates with esp8266 based on UDP protocol
L2-024 tribe (25 points)
初识go语言
FBS(fman build system)打包
mysql新表,自增id长达20位,原因竟是......
Quartus prime hardware experimental development (de2-115 board) experiment 1 CPU instruction calculator design
Subscription number development of wechat applet (message push)
Pytorch 经典卷积神经网络 LeNet
多线程 @Async 线程池
帆软调用动态传参的方法,在标题中设置参数
腾讯根据ip解析地址
生成随机高质量符合高斯分布的随机数