当前位置:网站首页>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
边栏推荐
- Jmeter安装教程以及我遇到的问题的解决办法
- DeepinV20安装Mariadb
- 烟雾传感器(mq-2)使用详细教程(基于树莓派3b+实现)
- leetcode--380. O (1) time insertion, deletion and acquisition of random elements
- 容差分析相关的计算公式
- Check in system based on ibeacons
- Nifi 快速安装及文件同步操作
- RobotFramework 之 文件上传和下载
- 金蝶云星空API调用实践
- Expression「Func「TSource, object」」 转Expression「Func「TSource, object」」[]
猜你喜欢

Chrome插件 之 Selenium IDE、XPath 安装

编程旅行之函数

Program compilation and debugging learning record

MYSQL 主从同步避坑版教程

帆软中需要设置合计值为0时,一整行都不显示的解决办法

Neuron and neural network

分库分表 & ShardingSphere
Use of WiFi module based on wechat applet

Pycharm连接远程服务器并实现远程调试

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
随机推荐
SQL: How to parse Microsoft Transact-SQL Statements in C# and to match the column aliases of a view
Subscription number development of wechat applet (message push)
报表FCRA考试题集及答案(错了11题)
Chapter I review of e-commerce spike products
服务器日志分析工具(识别,提取,合并,统计异常信息)
趣谈网络协议
生成随机高质量符合高斯分布的随机数
帆软中使用if else 进行判断-使用标题条件进行判断
使用itextpdf实现截取pdf文档第几页到第几页,进行分片
微信小程序获取登录用户信息、openid和access_token
基于ibeacons三点定位(微信小程序)
微信小程序调用客服接口
多重继承虚基类习题
L2-024 tribe (25 points)
Programming travel function
微信小程序setInterval定时函数使用详细教程
MYSQL 主从同步避坑版教程
修改ddt生成的测试用例名称
visio安装报错 1:1935 2:{XXXXXXXX...
DeepinV20安装Mariadb