ব্লুটুথ কম শক্তির বিজ্ঞাপন

ব্লুটুথ লো এনার্জি (BLE) বেশিরভাগ সময় স্লিপ মোডে থাকার মাধ্যমে শক্তি সংরক্ষণ করে। এটি শুধুমাত্র বিজ্ঞাপন এবং সংক্ষিপ্ত সংযোগ করার জন্য জেগে ওঠে, তাই বিজ্ঞাপনগুলি বিদ্যুৎ খরচ এবং ডেটা স্থানান্তর ব্যান্ডউইথ উভয়কেই প্রভাবিত করে।

ব্লুটুথ 5 বিজ্ঞাপন এক্সটেনশন

Android 8.0 ব্লুটুথ 5 সমর্থন করে, যা BLE এর জন্য সম্প্রচারের উন্নতি এবং নমনীয় ডেটা বিজ্ঞাপন প্রদান করে। ব্লুটুথ 5 BLE ফিজিক্যাল লেয়ার (PHYs) সমর্থন করে যা ব্লুটুথ 4.2 এর হ্রাস পাওয়ার খরচ ধরে রাখে এবং ব্যবহারকারীদের বর্ধিত ব্যান্ডউইথ বা পরিসর বেছে নিতে দেয়। ব্লুটুথ 5 কোর স্পেসিফিকেশনে আরও তথ্য পাওয়া যাবে।

বাস্তবায়ন

নতুন ব্লুটুথ 5 বৈশিষ্ট্যগুলি সামঞ্জস্যপূর্ণ ব্লুটুথ কন্ট্রোলার সহ Android 8.0 চালিত ডিভাইসগুলির জন্য স্বয়ংক্রিয়ভাবে উপলব্ধ। একটি ডিভাইস ব্লুটুথ 5 বৈশিষ্ট্য সমর্থন করে কিনা তা পরীক্ষা করতে এই BluetoothAdapter পদ্ধতিগুলি ব্যবহার করুন:

  • isLe2MPhySupported()
  • isLeCodedPhySupported()
  • isLeExtendedAdvertisingSupported()
  • isLePeriodicAdvertisingSupported()

বিজ্ঞাপন বৈশিষ্ট্যগুলি অক্ষম করতে, চিপ-সেট সমর্থন অক্ষম করতে ব্লুটুথ চিপ বিক্রেতার সাথে কাজ করুন৷

ব্লুটুথ PHY গুলি একে অপরের থেকে আলাদা, এবং প্রতিটি PHY-এর আচরণ ব্লুটুথ SIG দ্বারা পূর্বনির্ধারিত। ডিফল্টরূপে, Android 8.0 Bluetooth LE 1M PHY ব্যবহার করে, Bluetooth 4.2 থেকে। android.bluetooth.le প্যাকেজ এই APIগুলির মাধ্যমে ব্লুটুথ 5 বিজ্ঞাপন বৈশিষ্ট্যগুলিকে প্রকাশ করে:

  • AdvertisingSet
  • AdvertisingSetCallback
  • AdvertisingSetParameters
  • PeriodicAdvertisingParameters

android.bluetooth.le.BluetoothLeAdvertiserstartAdvertisingSet() পদ্ধতি ব্যবহার করে ব্লুটুথ বিজ্ঞাপন সেটিংস পরিবর্তন করতে একটি AdvertisingSet তৈরি করুন। এমনকি যদি ব্লুটুথ 5 বা এর বিজ্ঞাপন বৈশিষ্ট্যের জন্য সমর্থন নিষ্ক্রিয় করা হয়, API বৈশিষ্ট্যগুলি LE 1M PHY-তেও প্রযোজ্য হতে পারে৷

উদাহরণ

এই উদাহরণ অ্যাপটি বিজ্ঞাপনের জন্য Bluetooth 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 সক্রিয় থাকাকালীন, বিজ্ঞাপনটি Bluetooth 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);
}

প্রতিপাদন

Bluetooth 5 এর সাথে ডিভাইসের সামঞ্জস্যতা যাচাই করতে প্রযোজ্য ব্লুটুথ পণ্য পরীক্ষা চালান।

AOSP-এ Android Comms Test Suite (ACTS) রয়েছে, যার মধ্যে ব্লুটুথ 5-এর পরীক্ষা রয়েছে। ব্লুটুথ 5-এর জন্য ACTS পরীক্ষাগুলি tools/test/connectivity/acts/tests/google/ble/bt5 এ পাওয়া যাবে।