当前位置:网站首页>Wechat applet communicates with low-power Bluetooth - receives data sent by hardware (IV)
Wechat applet communicates with low-power Bluetooth - receives data sent by hardware (IV)
2022-04-23 14:05:00 【one billion twenty-nine million one hundred and seventy-nine th】
Accept data as long as wx.notifyBLECharacteristicValueChange Listener on ,
wx.onBLECharacteristicValueChange Is a function that accepts data .
After receiving the data, you need to analyze the data
function ab2hex(buffer) {
var hexArr = Array.prototype.map.call(
new Uint8Array(buffer),
function(bit) {
return ('00' + bit.toString(16)).slice(-2)
}
)
return hexArr.join('');
}
This process also needs to obtain the corresponding parameters of the interface :
How to get it, please see Wechat applet communicates with low-power Bluetooth - Send data to the hardware side
deviceId: "2C:AB:33:33:94:08",
serviceId: "0808FF00-0808-0A09-0807-060504030201",
characteristicId:"0808FF01-0808-0A09-0807-060504030201",
Wechat applet to obtain data :
Put it in onload function
onLoad:function(){
console.log(" monitor hc-09 Incoming data ")
// Turn on the listener obtain hc-09 Data sent
wx.notifyBLECharacteristicValueChange({
state: true,
deviceId: "2C:AB:33:33:94:08",
serviceId: "0808FF00-0808-0A09-0807-060504030201",
characteristicId:"0808FF01-0808-0A09-0807-060504030201",
success: function (res) {
console.log('notifyBLECharacteristicValueChange success', res.errMsg)
}
})
//hc-09 Analysis of incoming data Convert to string
function ab2hex(buffer) {
var hexArr = Array.prototype.map.call(
new Uint8Array(buffer),
function(bit) {
return ('00' + bit.toString(16)).slice(-2)
}
)
return hexArr.join('');
}
// monitor hc-09 Incoming data
wx.onBLECharacteristicValueChange(function (res) {
console.log('hc-09 The data is :', ab2hex(res.value))
var date=ab2hex(res.value)
// according to hc-09 The data from the phone vibrates on== open off== Turn off
if(date==="on"){
console.log(" Open vibration ")
wx.vibrateLong();
}else{
console.log(" Turn off vibration ")
}
})
},
Wechat applet for Bluetooth initialization 、 Search for nearby Bluetooth devices and connect to designated Bluetooth devices ( One )
Wechat applet performs positioning and ranging through low-power Bluetooth devices ( Two )
Wechat applet communicates with low-power Bluetooth - Send data to the hardware side ( 3、 ... and )
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/202204231401297689.html
边栏推荐
- Wechat applet obtains login user information, openid and access_ token
- Cdh6 based on CM management 3.2 cluster integration atlas 2 one
- Program compilation and debugging learning record
- Chrome插件 之 Selenium IDE、XPath 安装
- Prediction of tomorrow's trading limit of Low Frequency Quantization
- 关于密匙传递的安全性和数字签名
- 使用Postman进行Mock测试
- 多重继承虚基类习题
- leetcode--380. O (1) time insertion, deletion and acquisition of random elements
- 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
猜你喜欢
随机推荐
The latest development of fed digital currency
linux安装mysql后修改密码
Program compilation and debugging learning record
生产环境——
Go语言 RPC通讯
微信小程序与低功耗蓝牙通信-往硬件端发送数据(三)
mysql新表,自增id长达20位,原因竟是......
关于密匙传递的安全性和数字签名
Qt Designer怎样加入资源文件
Quartus prime hardware experimental development (de2-115 board) experiment 1 CPU instruction calculator design
查询2013年到2021年的数据,只查询到2020的数据,遇到了这个问题所进行的解决办法
微信小程序基于udp协议与esp8266进行通信
Yarn online dynamic resource tuning
基于ibeacons签到系统
百度图片识别自定义实现(替代AipOcr)
Kettle -- control parsing
Programming travel function
不同时间类型的执行计划计算
Prediction of tomorrow's trading limit of Low Frequency Quantization
基於CM管理的CDH集群集成Phoenix