当前位置:网站首页>Wechat applet positioning and ranging through low-power Bluetooth device (2)
Wechat applet positioning and ranging through low-power Bluetooth device (2)
2022-04-23 14:05:00 【one billion twenty-nine million one hundred and seventy-nine th】
Principle of positioning and ranging
Wechat applet searches for nearby Bluetooth devices , Get the signal by specifying the Bluetooth name rssi, Then it is transformed into distance through signal strength , And then realize positioning and ranging .( See code for specific implementation )
The formula of signal loudness to distance
Code implementation
var pointBRSSi = res.devices[i].RSSI;
var iRssi = Math.abs(pointBRSSi);
var power = (iRssi-55)/(10*2.0);
var pointBDistance = Math.pow(10, power);
Wechat applet positioning and ranging
js
// Search for nearby Bluetooth devices At the same time find hc-09rssi Convert to distance
toClock1: function () {
var that = this;
//console.log(that.data.timer)
// Bluetooth initialization
wx.openBluetoothAdapter({
success: function (res) {
console.log(" Initialize Bluetooth adapter ");
/*getBluetoothAdapterState() Get the status of the native Bluetooth adapter , Determine if it is available ,available by false Because the user does not turn on the system Bluetooth */
wx.getBluetoothAdapterState({
success:function (res) {
// Print related information
console.log(JSON.stringify(res.errMsg) + "\n Bluetooth is available :" + res.available);
// Adapter available
if(res.available){
//clearTimeout(timer);
// Search for Bluetooth devices
wx.startBluetoothDevicesDiscovery({
services: [],
allowDuplicatesKey: false,
success: function (res) {
// Get Bluetooth device output information list
wx.getBluetoothDevices({
success: function (res) {
console.log(' Number of search devices :' + res.devices.length)
console.log(' Equipment information :\n' + JSON.stringify(res.devices)+"\n")
for (var i = 0; i < res.devices.length; i++) {
//console.log(" The first "+(i+1) + " individual RSSI:" + res.devices[i].RSSI+"\n")
if(res.devices[i].name==="HC-09"){
var rssi=res.devices[i].RSSI
// var pointBRSSi = res.devices[i].RSSI;
var iRssi = Math.abs(rssi);
var power = (iRssi-55)/(10*2.0);
var pointBDistance = Math.pow(10, power);
console.log("hc-o9 What is the distance from the mobile phone :"+pointBDistance)
that.setData({
dis:pointBDistance
})
// Greater than 5 rice shock
if(pointBDistance>5){
wx.vibrateLong();
}
}
}
}
})
},
fail: function (err) {
console.log(err);
wx.showModal({
title: ' reminder ',
content: ' Bluetooth search failed '
})
}
});
}else{
wx.showModal({
title: ' reminder ',
content: ' Bluetooth device not available '
})
}
},
fail: function (res) {
// Print related information
console.log(JSON.stringify(res.errMsg) + "\n Bluetooth is available :" + res.available);
wx.showModal({
title: ' reminder ',
content: ' Bluetooth device not available '
})
}
})
},
fail: function (err) {
console.log(err);
wx.showToast({
title: ' Bluetooth initialization failed ',
icon: 'fail',
duration: 2000
})
// The search timeout Stop scanning the device
setTimeout(function () {
var that = this;
wx.stopBluetoothDevicesDiscovery({
success: function (res) {
console.log(" stop searching " + JSON.stringify(res.errMsg));
}
})
}, 4000);
}
});
// },10000)
},
About Bluetooth initialization of wechat applet 、 To search for nearby Bluetooth devices and specify Bluetooth connections, you can refer to the following articles :
https://blog.csdn.net/baidu_38978508/article/details/123439507?spm=1001.2014.3001.5502
More about wechat applet knowledge and javaweb Develop knowledge and pay attention to the following official account for more source code. :
版权声明
本文为[one billion twenty-nine million one hundred and seventy-nine th]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231401297761.html
边栏推荐
- Check in system based on ibeacons
- 微信小程序的订阅号开发(消息推送)
- Basic knowledge learning record
- 网站_收藏
- 多重继承虚基类习题
- Force deduction brush question 101 Symmetric binary tree
- 接口文档yaml
- Three point positioning based on ibeacons (wechat applet)
- Quartus prime hardware experimental development (de2-115 board) experiment 1 CPU instruction calculator design
- 基于ibeacons签到系统
猜你喜欢
Nifi 快速安装及文件同步操作
分库分表 & ShardingSphere
SQL数据库
Use of WiFi module based on wechat applet
POI operation word template replaces data and exports word
Taobao released the baby prompt "your consumer protection deposit is insufficient, and the expiration protection has been started"
使用Postman进行Mock测试
Pytorch 经典卷积神经网络 LeNet
Mock测试
基于CM管理的CDH6.3.2集群集成Atlas2.1.0
随机推荐
Autumn recruitment in 2021, salary ranking No
Nacos+AspnetCore+Ocelot实战编码
Interesting talk about network protocol
微信小程序setInterval定时函数使用详细教程
Record a strange bug: component copy after cache component jump
浅谈基于openssl的多级证书,Multi-level CA的签发和管理,以及双向认证
PyMySQL
室内外地图切换(室内基于ibeacons三点定位)
SPC简介
金蝶云星空API调用实践
Universal template for scikit learn model construction
New关键字的学习和总结
JS 力扣刷题 103. 二叉树的锯齿形层序遍历
linux MySQL数据定时dump
Special test 05 · double integral [Li Yanfang's whole class]
生产环境——
Decimal 格式化小数位/DateTime 转换处理
RobotFramework 之 文件上传和下载
SQL数据库
Quartus prime hardware experimental development (de2-115 board) experiment 1 CPU instruction calculator design