ब्लूटूथ लो एनर्जी (BLE) अधिकांश समय स्लीप मोड में रहकर बिजली की बचत करता है। यह केवल विज्ञापन और छोटे कनेक्शन बनाने के लिए जागता है, इसलिए विज्ञापन बिजली की खपत और डेटा ट्रांसफर बैंडविड्थ दोनों को प्रभावित करते हैं।
ब्लूटूथ 5 विज्ञापन एक्सटेंशन
एंड्रॉइड 8.0 ब्लूटूथ 5 को सपोर्ट करता है, जो BLE के लिए प्रसारण सुधार और लचीला डेटा विज्ञापन प्रदान करता है। ब्लूटूथ 5 BLE फिजिकल लेयर्स (PHYs) को सपोर्ट करता है जो ब्लूटूथ 4.2 की कम बिजली खपत को बनाए रखता है और उपयोगकर्ताओं को बढ़ी हुई बैंडविड्थ या रेंज चुनने देता है। अधिक जानकारी ब्लूटूथ 5 कोर विशिष्टताओं में पाई जा सकती है।
कार्यान्वयन
संगत ब्लूटूथ नियंत्रकों के साथ एंड्रॉइड 8.0 चलाने वाले उपकरणों के लिए नई ब्लूटूथ 5 सुविधाएं स्वचालित रूप से उपलब्ध हैं। यह जांचने के लिए कि कोई डिवाइस ब्लूटूथ 5 सुविधाओं का समर्थन करता है या नहीं, इन BluetoothAdapter
विधियों का उपयोग करें:
-
isLe2MPhySupported()
-
isLeCodedPhySupported()
-
isLeExtendedAdvertisingSupported()
-
isLePeriodicAdvertisingSupported()
विज्ञापन सुविधाओं को अक्षम करने के लिए, चिप-सेट समर्थन को अक्षम करने के लिए ब्लूटूथ चिप विक्रेता के साथ काम करें।
ब्लूटूथ PHY एक दूसरे से भिन्न हैं, और प्रत्येक PHY का व्यवहार ब्लूटूथ SIG द्वारा पूर्वनिर्धारित होता है। डिफ़ॉल्ट रूप से, एंड्रॉइड 8.0 ब्लूटूथ 4.2 से ब्लूटूथ LE 1M PHY का उपयोग करता है। android.bluetooth.le
पैकेज इन एपीआई के माध्यम से ब्लूटूथ 5 विज्ञापन सुविधाओं को उजागर करता है:
-
AdvertisingSet
-
AdvertisingSetCallback
-
AdvertisingSetParameters
-
PeriodicAdvertisingParameters
android.bluetooth.le.BluetoothLeAdvertiser
में startAdvertisingSet()
विधि का उपयोग करके ब्लूटूथ विज्ञापन सेटिंग्स को संशोधित करने के लिए एक AdvertisingSet
बनाएं। भले ही ब्लूटूथ 5 या इसकी विज्ञापन सुविधाओं के लिए समर्थन अक्षम हो, एपीआई सुविधाएं LE 1M PHY पर भी लागू हो सकती हैं।
उदाहरण
यह उदाहरण ऐप विज्ञापन के लिए ब्लूटूथ LE 1M PHY का उपयोग करता है:
// Start legacy advertising. Works for devices with 5.x controllers, // and devices that support multi-advertising. void example1() { BluetoothLeAdvertiser advertiser = BluetoothAdapter.getDefaultAdapter().getBluetoothLeAdvertiser(); AdvertisingSetParameters parameters = (new AdvertisingSetParameters.Builder()) .setLegacyMode(true) // True by default, but set here as a reminder. .setConnectable(true) .setInterval(AdvertisingSetParameters.INTERVAL_HIGH) .setTxPowerLevel(AdvertisingSetParameters.TX_POWER_MEDIUM) .build(); AdvertiseData data = (new AdvertiseData.Builder()).setIncludeDeviceName(true).build(); AdvertisingSetCallback callback = new AdvertisingSetCallback() { @Override public void onAdvertisingSetStarted(AdvertisingSet advertisingSet, int txPower, int status) { Log.i(LOG_TAG, "onAdvertisingSetStarted(): txPower:" + txPower + " , status: " + status); currentAdvertisingSet = advertisingSet; } @Override public void onAdvertisingDataSet(AdvertisingSet advertisingSet, int status) { Log.i(LOG_TAG, "onAdvertisingDataSet() :status:" + status); } @Override public void onScanResponseDataSet(AdvertisingSet advertisingSet, int status) { Log.i(LOG_TAG, "onScanResponseDataSet(): status:" + status); } @Override public void onAdvertisingSetStopped(AdvertisingSet advertisingSet) { Log.i(LOG_TAG, "onAdvertisingSetStopped():"); } }; advertiser.startAdvertisingSet(parameters, data, null, null, null, callback); // After onAdvertisingSetStarted callback is called, you can modify the // advertising data and scan response data: currentAdvertisingSet.setAdvertisingData(new AdvertiseData.Builder(). setIncludeDeviceName(true).setIncludeTxPowerLevel(true).build()); // Wait for onAdvertisingDataSet callback... currentAdvertisingSet.setScanResponseData(new AdvertiseData.Builder().addServiceUuid(new ParcelUuid(UUID.randomUUID())).build()); // Wait for onScanResponseDataSet callback... // When done with the advertising: advertiser.stopAdvertisingSet(callback); }
यह उदाहरण ऐप विज्ञापन के लिए BLE 2M PHY का उपयोग करता है। ऐप पहले यह जांचता है कि डिवाइस इस्तेमाल की जा रही सुविधाओं का समर्थन करता है या नहीं। यदि विज्ञापन सुविधाएँ समर्थित हैं, तो ऐप BLE 2M PHY को प्राथमिक PHY के रूप में कॉन्फ़िगर करता है। जबकि 2M PHY सक्रिय है, विज्ञापन ब्लूटूथ 4.x नियंत्रकों का समर्थन नहीं करता है, इसलिए setLegacyMode
को false
पर सेट किया गया है। यह उदाहरण विज्ञापन करते समय मापदंडों को संशोधित करता है और विज्ञापन को रोकता भी है।
void example2() { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); BluetoothLeAdvertiser advertiser = BluetoothAdapter.getDefaultAdapter().getBluetoothLeAdvertiser(); // Check if all features are supported if (!adapter.isLe2MPhySupported()) { Log.e(LOG_TAG, "2M PHY not supported!"); return; } if (!adapter.isLeExtendedAdvertisingSupported()) { Log.e(LOG_TAG, "LE Extended Advertising not supported!"); return; } int maxDataLength = adapter.getLeMaximumAdvertisingDataLength(); AdvertisingSetParameters.Builder parameters = (new AdvertisingSetParameters.Builder()) .setLegacyMode(false) .setInterval(AdvertisingSetParameters.INTERVAL_HIGH) .setTxPowerLevel(AdvertisingSetParameters.TX_POWER_MEDIUM) .setPrimaryPhy(BluetoothDevice.PHY_LE_1M) .setSecondaryPhy(BluetoothDevice.PHY_LE_2M); AdvertiseData data = (new AdvertiseData.Builder()).addServiceData(new ParcelUuid(UUID.randomUUID()), "You should be able to fit large amounts of data up to maxDataLength. This goes up to 1650 bytes. For legacy advertising this would not work".getBytes()).build(); AdvertisingSetCallback callback = new AdvertisingSetCallback() { @Override public void onAdvertisingSetStarted(AdvertisingSet advertisingSet, int txPower, int status) { Log.i(LOG_TAG, "onAdvertisingSetStarted(): txPower:" + txPower + " , status: " + status); currentAdvertisingSet = advertisingSet; } @Override public void onAdvertisingSetStopped(AdvertisingSet advertisingSet) { Log.i(LOG_TAG, "onAdvertisingSetStopped():"); } }; advertiser.startAdvertisingSet(parameters.build(), data, null, null, null, callback); // After the set starts, you can modify the data and parameters of currentAdvertisingSet. currentAdvertisingSet.setAdvertisingData((new AdvertiseData.Builder()).addServiceData(new ParcelUuid(UUID.randomUUID()), "Without disabling the advertiser first, you can set the data, if new data is less than 251 bytes long.".getBytes()).build()); // Wait for onAdvertisingDataSet callback... // Can also stop and restart the advertising currentAdvertisingSet.enableAdvertising(false, 0, 0); // Wait for onAdvertisingEnabled callback... currentAdvertisingSet.enableAdvertising(true, 0, 0); // Wait for onAdvertisingEnabled callback... // Or modify the parameters - i.e. lower the tx power currentAdvertisingSet.enableAdvertising(false, 0, 0); // Wait for onAdvertisingEnabled callback... currentAdvertisingSet.setAdvertisingParameters(parameters.setTxPowerLevel (AdvertisingSetParameters.TX_POWER_LOW).build()); // Wait for onAdvertisingParametersUpdated callback... currentAdvertisingSet.enableAdvertising(true, 0, 0); // Wait for onAdvertisingEnabled callback... // When done with the advertising: advertiser.stopAdvertisingSet(callback); }
सत्यापन
ब्लूटूथ 5 के साथ डिवाइस संगतता को सत्यापित करने के लिए लागू ब्लूटूथ उत्पाद परीक्षण चलाएँ।
एओएसपी में एंड्रॉइड कॉम्स टेस्ट सूट (एसीटीएस) शामिल है, जिसमें ब्लूटूथ 5 के लिए परीक्षण शामिल हैं। ब्लूटूथ 5 के लिए एसीटीएस tools/test/connectivity/acts/tests/google/ble/bt5
में पाए जा सकते हैं।