第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Android BluetoothGatt 類編寫特性屬性檢查始終為 false

Android BluetoothGatt 類編寫特性屬性檢查始終為 false

當(dāng)年話下 2023-06-04 10:29:04
我想創(chuàng)建一個(gè) android 應(yīng)用程序,以便連接 ESP32 板并從中檢索數(shù)據(jù),以及使用低功耗藍(lán)牙通信將值發(fā)送到板的能力。我有一個(gè)內(nèi)置 BLE 服務(wù)器的 ESP32 板。我已經(jīng)實(shí)現(xiàn)了具有以下特征的自定義服務(wù)。/* define the characteristic and it's propeties */BLECharacteristic dataCharacteristic(    BLEUUID((uint16_t)0x1A00),    BLECharacteristic::PROPERTY_READ |    BLECharacteristic::PROPERTY_WRITE |        BLECharacteristic::PROPERTY_NOTIFY);我在 android 應(yīng)用程序中成功實(shí)現(xiàn)了所有掃描、讀取和通知功能,但是在編寫 BluetoothGatt.writeCharacteristic 時(shí)總是在第一個(gè)條件中返回 false:  if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0                && (characteristic.getProperties()                & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) == 0) {            return false;        }在調(diào)試 android 應(yīng)用程序時(shí),characteristic.getProperties() 始終為 18。 public boolean writeCharacteristic(BluetoothGattCharacteristic characteristic) {        if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0                && (characteristic.getProperties()                & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) == 0) {            return false;        }        if (VDBG) Log.d(TAG, "writeCharacteristic() - uuid: " + characteristic.getUuid());        if (mService == null || mClientIf == 0 || characteristic.getValue() == null) return false;        BluetoothGattService service = characteristic.getService();        if (service == null) return false;        BluetoothDevice device = service.getDevice();        if (device == null) return false;        synchronized (mDeviceBusy) {            if (mDeviceBusy) return false;            mDeviceBusy = true;        }        try {            mService.writeCharacteristic(mClientIf, device.getAddress(),                    characteristic.getInstanceId(), characteristic.getWriteType(),                    AUTHENTICATION_NONE, characteristic.getValue());        } catch (RemoteException e) {            Log.e(TAG, "", e);            mDeviceBusy = false;            return false;        }        return true;    }
查看完整描述

1 回答

?
一只名叫tom的貓

TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超3個(gè)贊

經(jīng)過大量搜索和嘗試各種方法來實(shí)現(xiàn) android 應(yīng)用程序和內(nèi)置 BLE 服務(wù)器的 ESP32 板的上述通信,我找到了解決方案。


在我所有的測(cè)試中,我通過以下方式使用 UUID:


在 ESP32 中聲明特征 uuid


Characteristic_UUID = BLEUUID((uint16_t) 0x1A00))

并使用從android搜索這個(gè)uuid


Characteristic _UUID = convertFromInteger (0x1A00)

convertFromInteger 函數(shù):


    public UUID convertFromInteger (int i) 

    {

        final long MSB = 0x0000000000001000L;

        final long LSB = 0x800000805f9b34fbL;

        long value = i & 0xFFFFFFFF;

        return new UUID (MSB | (value << 32), LSB);

    }

當(dāng)我遵循一個(gè)教程時(shí)找到了解決方案,在該教程中我注意到了 uuid 以及與我使用的 uuid 的區(qū)別。當(dāng)我用隨機(jī)生成的 uuid 替換我的舊 uuid 時(shí),例如“cff6dbb0-996f-427b-9618-9e131a1d6d3f”,整個(gè)BLE 服務(wù)器的 writeCharacteristic 過程沒有任何問題。


查看完整回答
反對(duì) 回復(fù) 2023-06-04
  • 1 回答
  • 0 關(guān)注
  • 204 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)