简体   繁体   English

Android信标库| IBeacon-使用移动设备广告多个信标

[英]Android Beacon Library | IBeacon - Advertising multiple beacons using Mobile device

I am using the Android beacon library with, version - 我正在将Android信标库与版本-

compile 'org.altbeacon:android-beacon-library:2.15.1'

I am trying to develop one APK for transmitting multiple beacons from my mobile device. 我正在尝试开发一个APK,用于从移动设备传输多个信标。 I need to perform this to test or POC to test, how many beacons a reader can read at a time. 我需要执行此测试或POC来测试读者一次可以读取多少个信标。

I am using the below code to transmit the BLE messages with Android Beacon Library. 我正在使用以下代码通过Android Beacon库传输BLE消息。

btn_transmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (isBluetoothEnabled)
                {
                    try
                    {
                        String  customUuid = "";
                        for(int i=0;i<=50;i++)
                        {
                            if( i < 10){
                                customUuid = "99999999-b00"+i+"-4807-b747-9aee23508620";
                            } else if ( i < 999){
                                customUuid = "99999999-b0"+i+"-4807-b747-9aee23508620";
                            }

                            Thread.sleep(5000);
                            trasmitClick(customUuid);
                            beaconTransmitter = null;
                        }
                    }
                    catch(Exception e)
                    {
                        Toast.makeText(BeaconTransmitterActivity.this, "Something went wronggg", Toast.LENGTH_LONG).show();
                    }
                }
                else
                    Toast.makeText(BeaconTransmitterActivity.this, "Check your bluetooth connection", Toast.LENGTH_LONG).show();
            }
        });

Here above I am dynamically trying to create 50 new Id's to transmit the beacons. 在此上面,我正在动态尝试创建50个新ID以传输信标。

Method to createBeacon and transmit its advertisements 创建信标并传输其广告的方法

 public void trasmitClick(String customUuid) {

        if (beaconTransmitter == null) {

            String major, minor, uuid;

            uuid = customUuid;
            major = etMajorValue.getText().toString().trim();
            minor = etMinorValue.getText().toString().trim();

            if (TextUtils.isEmpty(uuid))
                uuid = customUuid;
            if (TextUtils.isEmpty(major))
                major = "8";
            if (TextUtils.isEmpty(minor))
                minor = "2";

            currentType=beaconLayout;
            currentuuid=uuid;
            currentmajorValue=major;
            currentminorValue=minor;

            beacon = new Beacon.Builder()
                    .setId1(uuid)
                    .setId2(major)
                    .setId3(minor)
                   //.setManufacturer(0x0118) // It is for AltBeacon.  Change this for other beacon layouts
                    .setManufacturer(0x004C)
                    .setTxPower(-59)
                    //.setDataFields(Arrays.asList(new Long[]{6l, 7l})) // Remove this for beacon layouts without d: fields
                    .build();

            // Change the layout below for other beacon types

            beaconParser = new BeaconParser()
                    .setBeaconLayout(parserLayout[beaconLayout]);

            beaconTransmitter = new BeaconTransmitter(getApplicationContext(), beaconParser);
            beaconTransmitter.startAdvertising(beacon, new AdvertiseCallback() {
                @Override
                public void onStartSuccess(AdvertiseSettings settingsInEffect) {
                    super.onStartSuccess(settingsInEffect);
                }

                @Override
                public void onStartFailure(int errorCode) {
                    super.onStartFailure(errorCode);
                }
            });
            btn_transmit.setText("Stop Advertising");
            btn_apply.setEnabled(false);


        } else {
            beaconTransmitter.startAdvertising();
            beaconTransmitter = null;
            btn_transmit.setText("Start Advertising");
            btn_apply.setEnabled(false);
        }

    }

I am able to make this code work, but what is the result is I am able to transmit only 4 messages, the rest of the messages are not being visible in the simulator. 我可以使此代码正常工作,但是结果是我只能传输4条消息,其余消息在模拟器中不可见。

I am trying to find if the library has some limitations or I am wrong above. 我正在尝试查找图书馆是否有某些限制,或者我在上面是错的。 Well I am novice in Android coding. 好吧,我是Android编码的新手。

Below is the result that I can get in my simulator: 以下是我可以在模拟器中得到的结果: 在此处输入图片说明

I would like to know how can I transmit 50 messages in one go. 我想知道如何一次性发送50条消息。

This is most certainly a limitation of the Bluetooth chip on your mobile phone. 这无疑是手机上蓝牙芯片的限制。 Different device models have different advertising limits. 不同的设备型号具有不同的广告限制。 The Huawei P9 Lite, for example can transmit only one advertisement at a time. 例如,华为P9 Lite一次只能发送一个广告。 The Nexus 5x can advertise 10 or more. Nexus 5x可以宣传10个或更多。 It is unlikely that many phone models (if any) support 50 simultaneous advertisements. 许多电话型号(如果有)不可能同时支持50个广告。

There is no way to know the limit programmatically, as the OS provides no API to query this limit -- you just have to try. 由于操作系统没有提供API来查询此限制,因此无法以编程方式知道该限制-您只需尝试一下即可。 You can check when you get an error advertising by putting code in the onStartFailure callback. 您可以通过将代码放入onStartFailure回调中来检查何时收到错误广告。

You might also use the [BeaconScope](( https://play.google.com/store/apps/details?id=com.davidgyoungtech.beaconscanner ) app to test this. But remember that transmission limits are device-wide. If one app is advertising a beacon, that takes one advertisement slot away from the next app. And no, there is no way to know if other apps are advertising. 您也可以使用[BeaconScope](( https://play.google.com/store/apps/details?id=com.davidgyoungtech.beaconscanner )应用程序进行测试。但是请记住,传输限制在整个设备范围内。如果一个应用程序正在广告信标,它距离下一个应用程序一个广告位,而且没有办法知道其他应用程序是否在广告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM