当前位置:网站首页>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
边栏推荐
- 9月8日,临去松山湖的前夜
- Universal template for scikit learn model construction
- 编程旅行之函数
- 快捷键(多行)
- 使用Postman进行Mock测试
- Use of WiFi module based on wechat applet
- Analysis and understanding of atomicintegerarray source code
- org.apache.parquet.schema.InvalidSchemaException: A group type can not be empty. Parquet does not su
- Record a strange bug: component copy after cache component jump
- visio安装报错 1:1935 2:{XXXXXXXX...
猜你喜欢

Cdh6 based on CM management 3.2 cluster integration atlas 2 one

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

JDBC入门
Check in system based on ibeacons

Jmeter设置环境变量支持在任意终端目录输入jmeter直接启动

帆软中使用if else 进行判断-使用标题条件进行判断

Nifi 快速安装及文件同步操作

微信小程序setInterval定时函数使用详细教程

基础知识学习记录

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 之 用例执行
变长参数__VA_ARGS__ 和 写日志的宏定义
按实际取,每三级分类汇总一次,看图知需求
PySide2
帆软中需要设置合计值为0时,一整行都不显示的解决办法
Programming travel function
Can global variables be defined in header files
Expression「Func「TSource, object」」 转Expression「Func「TSource, object」」[]
基于ibeacons签到系统
linux安装mysql后修改密码
Indoor and outdoor map switching (indoor three-point positioning based on ibeacons)
网站_收藏
MYSQL 主从同步避坑版教程
SQL: How to parse Microsoft Transact-SQL Statements in C# and to match the column aliases of a view
Intégration de Clusters CDH Phoenix basée sur la gestion cm
Choreographer full resolution
微信小程序与低功耗蓝牙通信-接受硬件端发送来的数据(四)
快捷键(多行)
Mock测试
Switch usage (wechat applet)