
















startBLEDiscovery:'初始化蓝牙设备',
advertisServiceUUIDs: [],
avatarUrl:'../index/bg-image.jpg',
bindViewTap: function() {
app.getUserInfo(function(userInfo){
if (wx.openBluetoothAdapter) {
wx.openBluetoothAdapter({
wx.getBluetoothAdapterState({
complete: function(res) {
wx.showToast({title:'请打开本机蓝牙设备,重新扫码', duration:10000 })
complete: function(res) {
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
startBLEDevices: function(){
wx.startBluetoothDevicesDiscovery({
showPosition:setInterval(that.devicesFunc,1000)
complete: function(res) {
var arrayRSSI = new Array();
var arraydeviceName = new Array();
var arraydeviceId = new Array();
var arrayadvertisData = new Array();
for(var i = 0; i<res.devices.length;i++){
if(res.devices[i].name.indexOf('craft')==0){
arrayRSSI.push(res.devices[i].RSSI);
arraydeviceName.push(res.devices[i].name);
arraydeviceId[i]= res.devices[i].deviceId;
arrayUUIDs[i]= res.devices[i].advertisServiceUUIDs[i];
arrayadvertisData[i]= res.devices[i].advertisData ;
var iRssi = Math.abs(arrayRSSI[i]);
var power = (iRssi-59)/(10*2.0);
var mm = Math.pow(10, power);
console.log(arraydeviceName[i]+"距离的位置是"+mm+"米");
取01,02,03分别为,(2,0),(2,2),(0,2)固定坐标点,做定位
if(res.devices[i].name.indexOf('craft01')==0){
var pointARSSi = res.devices[i].RSSI ;
var iRssi = Math.abs(pointARSSi);
var power = (iRssi-55)/(10*2.0);
var pointADistance = Math.pow(10, power);
console.log("a"+pointADistance);
if(res.devices[i].name.indexOf('craft02')==0){
var pointBRSSi = res.devices[i].RSSI;
var iRssi = Math.abs(pointBRSSi);
var power = (iRssi-55)/(10*2.0);
var pointBDistance = Math.pow(10, power);
console.log("b"+pointBDistance);
if(res.devices[i].name.indexOf('craft03')==0){
var pointCRSSi = res.devices[i].RSSI;
var iRssi = Math.abs(pointCRSSi);
var power = (iRssi-57)/(10*2.0);
var pointCDistance = Math.pow(10, power);
console.log("c"+pointCDistance);
if(arrayRSSI.length > 3){
for(var i = 0 ; i < arrayRSSI.length ; i ++){
for(var j = i+1 ; j< arrayRSSI.length ; j++){
if(arrayRSSI[i]<arrayRSSI[j]){
var select = arrayRSSI[i];
arrayRSSI[i] = arrayRSSI[j];
for(var i = 0 ; i < 3; i++){
var pointARSSi = res.devices[i].RSSI ;
var iRssi = Math.abs(pointARSSi);
var power = (iRssi-55)/(10*2.0);
var pointADistance = Math.pow(10, power);
console.log("a"+pointADistance);
var pointBRSSi = res.devices[i].RSSI;
var iRssi = Math.abs(pointBRSSi);
var power = (iRssi-55)/(10*2.0);
var pointBDistance = Math.pow(10, power);
console.log("b"+pointBDistance);
var pointCRSSi = res.devices[i].RSSI;
var iRssi = Math.abs(pointCRSSi);
var power = (iRssi-57)/(10*2.0);
var pointCDistance = Math.pow(10, power);
console.log("c"+pointCDistance);
if(!pointADistance==''&&!pointBDistance==''&&!pointCDistance==''){
var pointDX='';var pointDY = '';
var p = Math.pow(pointADistance,2)/10-Math.pow(pointBDistance,2)/10;
var m = Math.pow(pointADistance,2)/10-Math.pow(pointCDistance,2)/10;
console.log('目标所在位置X是'+pointDX);
console.log('目标所在位置Y是'+pointDY);
if(pointDX > 0 && pointDY > 0){
wx.showToast({title:'欢迎进入25楼craft', duration:4000 });
var context = wx.createCanvasContext();
context.setStrokeStyle("#00ff00");
context.arc(that.data.canvasPointX*30,that.data.canvasPointY*30,5,0,2*Math.PI);
actions: context.getActions()
wx.showModal({title:'X轴:'+pointDX+'Y轴:'+pointDY, duration:5000 });
url: 'http://craftww.cn/weixinIbeacon/index.php',
complete: function(res) {
wx.showToast({title:'正在搜索...', duration:1000 })
url: 'http://craftww.cn/weixinIbeacon/index.php',
complete: function(res) {
complete: function(res) {
createList: function(thisName){
array:[{deviceDistance:"1"},{deviceDistance:"1"},{deviceDistance:"1"},{deviceDistance:"1"},{deviceDistance:"1"}]
reStartSearchBLE: function(){
wx.stopBluetoothDevicesDiscovery({
complete: function(res) {
clearInterval(that.data.showPosition);
console.log(that.data.showPosition);
wx.closeBluetoothAdapter({
wx.openBluetoothAdapter({
wx.getBluetoothAdapterState({
complete: function(res) {
complete: function(res) {
complete: function(res) {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。