1 Star 0 Fork 10

zp_star / ohos-beacon-library

加入 Gitee
与超过 1000 万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README.md

ohos_beacon_library

简介

蓝牙工具,主要涉及信标区域监控以及信标设备测距

效果展示

动画

下载安装

npm install @ohos/ohos_beacon_library --save

OpenHarmony npm环境配置等更多内容,请参考 如何安装OpenHarmony npm包

使用说明

信标组件使用样例

1.在page页面中引入信标库必要的文件

import { Identifier, Region, BeaconParser, BeaconManager, RangeNotifier,Beacon } from '@ohos/ohos_beacon_library'
import bluetooth from '@ohos.bluetooth';

2.使用

- 启动测距
_this.beaconManager.addRangeNotifier(new class implements RangeNotifier {
    didRangeBeaconsInRegion(beacons: Array<Beacon>, region: Region): void {
        _this.beaconList = beacons
    }
});
_this.beaconManager.startRangingBeacons(region);

- 停止测距
this.beaconManager.stopRangingBeacons(new Region("myRangingUniqueId", null, null, null));

- 启动监控
_this.beaconManager.addMonitorNotifier(new class implements MonitorNotifier {
    INSIDE:number = 1
    OUTSIDE:number = 0

    didEnterRegion(region:Region):void {
        _this.enterRegionText = "I just saw a region: " + region.getUniqueId()
    }
    
    didExitRegion(region:Region):void {
        _this.enterRegionText = "I no longer see an beacon in Region:" + region.getUniqueId()
    }
    
    didDetermineStateForRegion(state:number, region:Region):void {
        _this.determineStateText = "I have just switched from seeing/not seeing beacons: " + state
    }
});
_this.beaconManager.startMonitoring(region);

- 停止监控
this.beaconManager.stopMonitoring(new Region("myMonitorUniqueId", null, null, null));

接口说明

@State private beaconManager: BeaconManager = BeaconManager.getInstanceForApplication()

  1. 当扫描到信标时的监控通知处理接口 .beaconManager.addMonitorNotifier(notifier:MonitorNotifier): void
  2. 开启信标监控,查找匹配region的beacons .beaconManager.startMonitoring(region:Region ):void
  3. 当扫描到信标时的距离通知处理接口 .beaconManager.addRangeNotifier(notifier:RangeNotifier):void
  4. 开启信标距离测算 .beaconManager.startRangingBeacons(region:Region):void
  5. 为信标解释器指定编码规则 new BeaconParser().setBeaconLayout(beaconLayout:String):void
  6. 将常见的数据类型封装为一个Identifier类型。 Identifier.parse(stringValue:String, desiredByteLength?:number):Identifier
  7. 根据uniqueId与其他参数的组合,构造匹配信标的字段条件。 Region(uniqueId: string, id1?: Identifier, id2?: Identifier, id3?: Identifier, identifiers?: Array<Identifier>, bluetoothAddress?: string)

兼容性

支持 OpenHarmony API version 8 及以上版本。

目录结构

|---- ohos_beacon_library  
|     |---- entry  # 示例代码文件夹
|     |---- ohos_beacon_library  # beacon库
|	      |----src
|             |----main
|                 |----ets
|                     |----components
|                         |---- beaconLibrary  # beacon库文件夹
|                             |---- client #客户端三种情况数据处理
|                             |---- distance 设备相关设置及距离配置逻辑
|                             |---- logging #日志相关逻辑
|                             |---- service #服务端处理逻辑
|                             |---- simulator #信标计算
|                             |---- startup #数据发送与接收
|                             |---- utils #工具类
|                             |---- AltBeacon.ets #建立信标通信
|                             |---- BeaconParser.ets #beacon数据包解析
|                         |---- bluetooth      # 蓝牙库
|                             |---- BleAdvertisement.ets #信标广播逻辑
|                             |---- Pdu.ets #蓝牙数据传递单元
|     |---- README.md  # 安装使用方法                    

贡献代码

使用过程中发现任何问题都可以提 Issue 给我们,当然,我们也非常欢迎你给我们发 PR

开源协议

本项目基于 Apache License 2.0 ,请自由地享受和参与开源。

简介

暂无描述 展开 收起
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/zpzpzpzp/ohos-beacon-library.git
git@gitee.com:zpzpzpzp/ohos-beacon-library.git
zpzpzpzp
ohos-beacon-library
ohos-beacon-library
master

搜索帮助