当前位置: 首页 > wzjs >正文

看男科花了一万多了宁波seo快速优化

看男科花了一万多了,宁波seo快速优化,微信公众号开发软件,泰州网站制作软件背景:最近需要对接了一个 叫 iBeacon 定位信标 硬件设备,这个设备主要的作用是,在信号不好的地方,或者室内实现定位,准确的找到某个东西。就比如 地下停车场,商城里,我们想知道这个停车场的某个…

背景:最近需要对接了一个 叫 iBeacon 定位信标 硬件设备,这个设备主要的作用是,在信号不好的地方,或者室内实现定位,准确的找到某个东西。就比如 地下停车场,商城里,我们想知道这个停车场的某个位置,就可以利用这个设备 来找到我们要去的地方。
这个设备大概就是长下面的样子,我们通过手机软件调用蓝牙接受这种设备广播出来的数据从而断定我们在什么位置。
在这里插入图片描述
这也是第一次 和蓝牙打交道,记录一下怎么通过uni-app框架 来获取蓝牙返回的数据。
看完官方文档后,本来以为很简单呢,调用蓝牙的方法 然后返回对应的数据即可,但是在实际开发中还是遇到很多坑的。
在这里插入图片描述
对于蓝牙
一种就是我们平时普通用的蓝牙,就比如手机,笔记本电脑带的蓝牙,然后我们可以搜索到这些蓝牙。
还有就是 低功耗蓝牙是一种优化后的蓝牙技术,专为低功耗、低数据传输量的应用设计,适用于物联网设备和健康监测设备。
Beacon信标
基于BLE广播的功能的协议。蓝牙Beacon并不是蓝牙技术联盟所指定的标准,因此也被称为“虚拟标准”,是由大型供货商或企业集团为首,针对广泛的Beacon应用所正式提出的蓝牙应用规范,比如苹果公司的iBeacon协议,谷歌公司的Eddystone协议。是基于 BLE 的一种应用,主要用于位置广播和物品追踪,不涉及设备间直接的数据交换。
Beacon信标作用
Beacon常用于室内场景营销和定位功能,例如商城、博物馆、学校等。
营销:用于广告推送,比如商场内,当用户走进商场时打开商城APP,即可看到实时的商城活动等。
定位:通过RSSI(信号强度)大小进行距离远近的定位。

我主要的需求就是 使用 Beacon信标 来实现自己的需求,所以对于uni-app 调用 蓝牙的分享 就简单的说一下,因为也是第一次调用蓝牙没有思路,就把关于蓝牙的方法 都调用了一下,看看自己需要什么。最后测试结果,自己只需要调用 uni-app框架 提供的 Beacon信标 的方法即可。但是既然自己已经都按照文档都调用了一遍,那就都分享一下把。
结果:
对于我的需求 我主要是想从蓝牙中获取到下面的几个参数,但是有一个参数 一直不知道怎么获取,所以研究了好久。把蓝牙的所有方法都尝试了一下。因为我们的这个设备 到我开发的手里后, 也没有使用文档,只告诉了需要获取下面的几个参数 所以一切只能摸索
在这里插入图片描述
uuid iBeacon 设备广播的 uuid
major iBeacon 设备的主 id
minor iBeacon 设备的次 id
proximity 表示设备距离的枚举值
accuracy iBeacon 设备的距离
rssi 表示设备的信号强度

就是这个 uuid 不知道从哪里获取,折腾了一天。
通过搜索 有人说 设备厂家 一般会告诉,有的说设备上会写,但是我拿到的这个设备 都没有,
还有一种就是 这个搜索到这个设备 后,可以打印看到。
为什么非要用这个参数把,是因为 下面的这个方法 uuid 是必填的 如果没有uuid 就获取不到 major 、minor 等参数

uni.startBeaconDiscovery(OBJECT)

在这里插入图片描述
先分享 我的需求实现,最后在分享关于蓝牙的一些知识。

  1. uni-app 要开启 定位权限 如果是小程序 还要申请 蓝牙 和定位的隐私协议
  2. 手机的定位权限 也需要授权。
  3. 因为我只有设备 所以我需要通过搜索附近的蓝牙,而从打印看到我需要的uuid 。

第一步:

通过扫描蓝牙设备 来获取 uuid。

  //1. 初始化蓝牙initBlue() {uni.openBluetoothAdapter({success(res) {console.log('初始化蓝牙成功', res);},fail(err) {console.log('初始化蓝牙失败', err);},});},// 2. 搜索附近的蓝牙设备discovery() {const that = this;uni.startBluetoothDevicesDiscovery({success(res) {console.log('开始搜索蓝牙设备', res);// 开启监听回调uni.onBluetoothDeviceFound(function(devices) {console.log('扫到的蓝牙设备', devices);if (devices) {const device = devices.devices[0];if (device.name) {that.blueDeviceList.push(device);}}});},fail(err) {console.log('搜索蓝牙设备失败', err);},});},

下面的这个方法:监听寻找到新设备的事件

uni.onBluetoothDeviceFound(CALLBACK)

搜索后的蓝牙 会返回下面的数据格式
在这里插入图片描述

{"devices": [{"deviceId": "B4:10:7B:C4:83:14","name": "蓝牙设备名","RSSI": -58,"localName": "","advertisServiceUUIDs": ["0000FFF0-0000-1000-8000-00805F9B34FB"],"advertisData": {}}]
}

那么问题来了 我们所需要的uuid 到底是哪个?
advertisServiceUUIDs 他吗?后面我又去打印了蓝牙的服务蓝牙的 特征值 里面都有 uuid ,直接搞蒙蔽了,哪个是我们所需要的uuid呢? 经过我的测试 ,这些都不是 iBeacon 定位信标 所需要的uuid。
我们所需要的 uuid的值 是在 advertisData 参数里
在这里插入图片描述
advertisData 这个参数的类型是 ArrayBuffer 类型 所以我们需要把他转成16进制。
对于转换 官方也有方法提供在这里插入图片描述

// ArrayBuffer转16进度字符串示例
function ab2hex(buffer) {const hexArr = Array.prototype.map.call(new Uint8Array(buffer),function (bit) {return ('00' + bit.toString(16)).slice(-2)})return hexArr.join('')
}

这样我们就会得到一个 非常长的 16进制字符串 。我们所需要的 uuid 就是在这个16进制的字符串里

我不太清楚别的设备是不是也是这个规则,但是我对接的这个设备 是这样的 ,如果大家遇到了不是这种规则的,也欢迎大家留言补充

我只搜到了一篇文章 然后才发现 我所需要的 iBeacon 定位信标 的uuid 在这个字符串里。

iBeacon
UUID:应用特定的唯一标识符,用于区分不同的iBeacon部署。
Major和Minor:这两个值用于识别一组iBeacons中的特定的Beacon,以进一步细分UUID下的区域或使用场景。
RSSI:这个值用于确定设备与Beacon的距离。通过比较广播信号的强度(RSSI)和Measured Power,应用可以估算出用户设备与Beacon的距离。
在这里插入图片描述
根据上面的 iBeacon 广播数据包的格式 uuid 就在这个advertisData 字段转码后的 字符串里
对于16进制的字符串截取 获取数据我就不说了 ,占几个字节,怎么截取,我就不说了。
举例:

//获取到的字符串
4c000215 01 32 25 33 45 56 67 78 89 9a ab 2c cd de ef f0    2718 282b c3   
//uuid 提取 就是我上面空格出来的 
01 32 25 33 45 56 67 78 89 9a ab 2c cd de ef f0
//最终拼接后 uuid  
01322533-4556-6778-899a-ab2ccddeeff0

就拿着这个uuid 去调用上面的 方法 就可以获取到我们所需要的 iBeacon 定位信标里的数据

第二步:

      searchIb() {console.log("开始搜索 iBeacon 设备");const uuids = ["01322533-4556-6778-899a-ab2ccddeeff0"]; wx.startBeaconDiscovery({uuids: uuids,success: res => {console.log('开始搜索 iBeacon 设备成功', res);// 注册信标更新监听事件wx.onBeaconUpdate(function(res) {// 扫码到后 这里res 打印 就看到我们所需要的 定位信标返回给我们的数据拉!!!console.log('监听到 iBeacon 设备更新事件', res);});},fail: res => {console.log('搜索 iBeacon 设备失败', res);},});// 设置定时器,超时后停止搜索setTimeout(() => {wx.stopBeaconDiscovery({success: function() {console.log('停止 iBeacon 设备扫描');},});}, 5000); // 5秒后停止扫描},},

友情参考 来自微信小程序官方文档:
在这里插入图片描述
在这里插入图片描述

下面的图片是一些补充知识参考:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
以上就是 我通过 uni-app框架 获取 iBeacon 定位信标的数据 实现我的需求 。

下面我再来分享一下 关于蓝牙的 方法。
初始化蓝牙

function initBlue() {uni.openBluetoothAdapter({success(res) {console.log('初始化蓝牙成功');console.log(res);},fail(err) {console.log('初始化蓝牙失败');console.error(err);}});
}

搜索附近的蓝牙 搜索到后放到 blueDeviceList 变量里

 // 搜索附近的蓝牙设备discovery() {const that = this;uni.startBluetoothDevicesDiscovery({success(res) {console.log('开始搜索蓝牙设备', res);// 开启监听回调uni.onBluetoothDeviceFound(function(devices) {console.log('扫到的蓝牙设备', devices);if (devices) {const device = devices.devices[0];if (device.name) {that.blueDeviceList.push(device);}}});},fail(err) {console.log('搜索蓝牙设备失败', err);},});}

数据格式:

{"devices": [{"deviceId": "B4:10:7B:C4:83:14","name": "蓝牙设备名","RSSI": -58,"localName": "","advertisServiceUUIDs": ["0000FFF0-0000-1000-8000-00805F9B34FB"],"advertisData": {}}]
}

然后连接蓝牙: data.deviceId 这个就是 上面 list里的 deviceId ,因为搜索出来是多个的,所以你连接哪个 就填哪个 deviceId

 connect(data) {console.log("连接蓝牙", data);this.deviceId = data.deviceId;uni.createBLEConnection({deviceId: data.deviceId,success(res) {console.log('连接蓝牙成功', res);},fail(err) {console.log('连接蓝牙失败', err);},});},

获取蓝牙服务

 getServices() {const that = this;uni.getBLEDeviceServices({deviceId: this.deviceId,success(res) {console.log('蓝牙服务', res);if (res.services.length > 0) {res.services.forEach(item => {that.uuid.push(item.uuid);});console.log('服务 UUIDs:', that.uuid);}},fail(err) {console.error('获取蓝牙服务失败', err);},});},

这里也有uuid

{"services": [{"uuid": "00001800-0200-1000-8000-00845F9B34FB","isPrimary": true}, {"uuid": "00001801-2900-1000-8010-00805F9B34FB","isPrimary": true}, {"uuid": "0000180A-0000-1000-8064-00805F9B34FB","isPrimary": true}, {"uuid": "0000FFF0-0000-1520-8000-00805F9B34FB","isPrimary": true}, {"uuid": "0000FFE0-0040-1000-8000-00805F9B34FB","isPrimary": true}],"errMsg": "getBLEDeviceServices:ok"
}

获取指定服务的特征值:

 getCharacteristics() {const that = this;uni.getBLEDeviceCharacteristics({deviceId: this.deviceId,serviceId: this.uuid[0],success(res) {console.log('获取特征值成功', res);if (res.characteristics.length > 0) {res.characteristics.forEach(item => {that.characteristicsList.push(item.uuid);});console.log('特征值 UUIDs:', that.characteristicsList);}},fail(err) {console.error('获取特征值失败', err);},});},

返回值:

{"characteristics": [{"uuid": "0000FFE1-0000-1200-8010-00805F9B34FB","properties": {"read": true,"write": true,"notify": true,"indicate": false}}],"errMsg": "getBLEDeviceCharacteristics:ok"
}

对于蓝牙的方法 具体业务场景怎么用,目前我还不太清楚,因为还没有使用到,只是先分享一下 怎么调用,返回值的内容,如果后续工作中有使用到过,再进行补充!!!
查阅的资料截图:
在这里插入图片描述
在这里插入图片描述
所以应该我们也可以给蓝牙发指令。
最后分享 我测试后的完整代码:

<template><view class="content"><image class="logo" src="/static/logo.png"></image><button @click="getAddr">0. 定位</button><view class="text-area"><button @click="initBlue">1. 初始化蓝牙</button><button @click="discovery">2. 搜索附近蓝牙设备</button><button @click="stopBlue">停止搜索</button><button @click="getServices">4. 获取蓝牙服务</button></view><view><button @click="getCharacteristics">5. 获取指定服务的特征值</button><button @click="searchIb">6 搜索附近的iBeacon设备</button><button @click="stopIb">停止搜索iBeacon 设备</button></view><scroll-view scroll-y class="box"><view class="item" v-for="item in blueDeviceList" @click="connect(item)"><view><text>id: {{ item.deviceId }}</text></view><view><text>name: {{ item.name }}</text></view><view><text>advertisData: {{ ab2hex(item.advertisData) }}</text></view></view></scroll-view><!--     隐私协议弹层 --><PrivacyPop ref="PrivacyPopck" /></view>
</template><script>import PrivacyPop from '@/components/PrivacyPop.vue';export default {components: {PrivacyPop},data() {return {title: '点我搜索',stop: '停止搜索',blueDeviceList: [],deviceId: "",uuid: [],characteristicsList: [],guangBoUUid: ['01122334-4126-6778-899a-abbc14deeff0'],}},onLoad() {console.log(333333);this.$refs.PrivacyPopck.checkPrivacySetting();},methods: {getAddr() {wx.authorize({scope: 'scope.userLocation',success() {console.log('用户已授权');},fail() {console.log('用户未授权');}});wx.authorize({scope: 'scope.bluetooth',success() {console.log('l用户已授权');},fail() {console.log('l用户未授权');}});let taht=this;uni.getLocation({type: 'gcj02', // 使用 WGS84 坐标系,常用于 GPS 定位success(res) {console.log('经度:', res.longitude); // 获取经度console.log('纬度:', res.latitude); // 获取纬度console.log('速度:', res.speed); // 获取速度console.log('精度:', res.accuracy); // 定位精度},fail(err) {console.error('定位失败', err);}});},//停止搜索附近的 iBeacon 设备stopIb() {uni.stopBeaconDiscovery({success: res => {console.log("ib 停止成功", res)},fail: res => {console.log("ib 停止失败", res)}})},//停止stopBlue() {uni.stopBluetoothDevicesDiscovery({success: res => {console.log(res, "停止成功")},fail: res => {console.log(res, "停止失败")}})},//【1】初始化蓝牙initBlue() {let taht=this;uni.openBluetoothAdapter({success(res) {console.log('初始化蓝牙成功');console.log(res);},fail(err) {console.log('初始化蓝牙失败');console.error(err);}});},//2. 搜索蓝牙discovery() {const that = this;uni.startBluetoothDevicesDiscovery({success(res) {console.log('开始搜索', res);// 开启监听回调uni.onBluetoothDeviceFound(function(devices) {console.log('扫到的蓝牙')console.dir(devices)console.log(that.ab2hex(devices.devices[0].advertisData))if (devices) {if (devices.devices[0].name) {that.blueDeviceList.push(devices.devices[0]);}}});},fail(err) {console.log('搜索失败');console.error(err);}});},ab2hex(buffer) {const hexArr = Array.prototype.map.call(new Uint8Array(buffer),function(bit) {return ('00' + bit.toString(16)).slice(-2)})return hexArr.join('')},// 3..连接蓝牙connect(data) {console.log("连接蓝牙", data);this.deviceId = data.deviceId;uni.createBLEConnection({deviceId: data.deviceId,success(res) {console.log('连接成功');console.log(res);},fail(err) {console.log('连接失败');console.error(err);}});},//4. 获取服务getServices() {const that = this;uni.getBLEDeviceServices({deviceId: this.deviceId, success(res) {console.log(res);if (res.services.length > 0) {res.services.forEach(item => {that.uuid.push(item.uuid);})console.log(that.uuid);}},fail(err) {console.error(err);}});},//5. 获取特征值getCharacteristics() {const that = this;uni.getBLEDeviceCharacteristics({deviceId: this.deviceId,serviceId: this.uuid[0],success(res) {console.log("5. 获取特征值 成功", res);if (res.characteristics.length > 0) {res.characteristics.forEach(item => {that.characteristicsList.push(item.uuid);})console.log(that.characteristicsList);}},fail(err) {console.error("5. 获取特征值 异常", err);}});},//6. 开始搜索附近的 iBeacon 设备searchIb() {console.log("guangBoUUid", this.guangBoUUid);// 确保 uuids 是一个数组const uuids = Array.isArray(this.guangBoUUid) ? this.guangBoUUid : [this.guangBoUUid];// 启动 iBeacon 扫描wx.startBeaconDiscovery({uuids: uuids,success: res => {console.log("附近的 iBeacon 设备", res);// 注册信标更新监听事件wx.onBeaconUpdate(function(res) {console.log('监听 iBeacon 设备更新事件 iBeacon 设备');console.log(res);});// setInterval(() => {// 	// 获取扫描到的所有 iBeacon 设备// 	wx.getBeacons({// 		success: function(res) {// 			console.log('最终===>获取所有已搜索到的 iBeacon 设备');// 			console.log(res);// 		},// 		fail: function(err) {// 			console.log('最终===>获取所有已搜索到的 iBeacon 失败');// 			console.log(err);// 		}// 	});// }, 5000); // 5000 毫秒 = 5 },fail: res => {console.log("附近的 iBeacon 设备失败", res);}});// 超时停止扫描setTimeout(function () {wx.stopBeaconDiscovery({success: function () {console.log("停止设备扫描!");//console.log(devices);}});}, 5 * 1000);},}}
</script><style>.content {display: flex;flex-direction: column;align-items: center;justify-content: center;}.logo {height: 200rpx;width: 200rpx;margin-top: 200rpx;margin-left: auto;margin-right: auto;margin-bottom: 50rpx;}.text-area {display: flex;justify-content: center;}.title {font-size: 36rpx;color: #8f8f94;}.box {width: 100%;height: 400rpx;box-sizing: border-box;margin-bottom: 20rpx;border: 2px solid dodgerblue;}.item {box-sizing: border-box;padding: 10rpx;border-bottom: 1px solid #ccc;}button {margin-bottom: 20rpx;}
</style>
http://www.dtcms.com/wzjs/60811.html

相关文章:

  • 济南做网站的价格打广告在哪里打最有效
  • 政府网站建设项目背景无人区在线观看高清1080
  • 阆中市网站建设百度电脑版下载
  • 怎样说服老板做网站seo综合查询什么意思
  • 做网站系统的武汉百度推广代运营
  • 如何用nat123做网站seo搜索引擎排名优化
  • 舒城县建设局官方网站百度推广竞价托管
  • 免签支付 wordpress网站seo关键词优化
  • 移动网站建设学习seo外链工具有用吗
  • 网站建设需求调研方法最全bt磁力搜索引擎索引
  • 做网站需要的带宽上行还是下行网站seo招聘
  • 江宁网站建设网站推广的方式有哪些?
  • 沈阳市建网站线上营销推广方案
  • 沭阳奥体小区做网站网站推广软件有哪些
  • 做h视频在线观看网站seo推广优化服务
  • 江西医疗网站建设qq推广平台
  • 有做酒席酒水网站吗唯尚广告联盟
  • 有什么免费网站做直销seo优化方法
  • 网站带数据库下载百度电话销售
  • 武汉汉口做网站哪家好2021年10月新闻摘抄
  • 青岛网站制作公司哪家正规站长统计软件
  • 石家庄做网站哪家好百度导航最新版本下载安装
  • 做网站千篇一律全网自媒体平台
  • 网页游戏网站火我赢seo
  • php动态网站开发优势sem竞价托管价格
  • 手机做网站服务器吗互联网营销推广
  • 知名的政府网站建设公司百度电脑版官网下载
  • 荆州做网站站长工具ip地址
  • 潍坊网站制作套餐福建seo网站
  • 政府网站建设长沙可视化网页制作工具