当前位置:网站首页>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
边栏推荐
猜你喜欢
Promtail + Loki + Grafana 日志监控系统搭建
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
RobotFramework 之 文件上传和下载
MYSQL 主从同步避坑版教程
Wechat applet positioning and ranging through low-power Bluetooth device (2)
Chrome插件 之 Selenium IDE、XPath 安装
Nodejs安装及环境配置
POI operation word template replaces data and exports word
Programming travel function
按实际取,每三级分类汇总一次,看图知需求
随机推荐
基于ibeacons签到系统
PySide2
Three point positioning based on ibeacons (wechat applet)
容差分析相关的计算公式
微信小程序的订阅号开发(消息推送)
leetcode--977. Squares of a Sorted Array
leetcode--357. Count the number of different figures
RobotFramework 之 公共变量
理解虚基类、虚函数与纯虚函数的概念(转)
Pycharm连接远程服务器并实现远程调试
leetcode--380. O (1) time insertion, deletion and acquisition of random elements
微信小程序基于udp协议与esp8266进行通信
There is a mining virus in the server
STM32 learning record 0007 - new project (based on register version)
SQL数据库
scikit-learn構建模型的萬能模板
scikit-learn构建模型的万能模板
DeepinV20安装Mariadb
对List集合进行分页
Can global variables be defined in header files