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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從 BLE 設(shè)備接收數(shù)據(jù)?

如何從 BLE 設(shè)備接收數(shù)據(jù)?

猛跑小豬 2023-03-31 15:25:42
因此,我正在使用 Eclipse 開發(fā)一個 Java BLE Android 模塊(對模塊和 Appcelerator(制作 Android 應(yīng)用程序)進(jìn)行編碼)。我正在嘗試從 BLE 設(shè)備接收數(shù)據(jù)并將其顯示在 Android 手機(jī)上。我可以掃描設(shè)備并連接到它。但我真的,真的無法從它那里接收到任何數(shù)據(jù)。我已經(jīng)嘗試了至少 10 種不同的東西但是......主要問題是我不太了解 BLE API,而且我對 Java 有點菜鳥。誰能幫助可憐的人真正從設(shè)備中讀取數(shù)據(jù)?主要問題是設(shè)置藍(lán)牙特征 UUID(我有)。我只是不知道該怎么做...下面是模塊的代碼...public class AndroidbleModule extends KrollModule {      public static final String LCAT = "BLE";  private BluetoothManager btManager;  private BluetoothAdapter btAdapter;  private BluetoothDevice btDevice;  private TiApplication appContext;  private Activity activity;  private KrollFunction onFound;  private KrollFunction onConnections;  prvate BluetoothLeScanner btScanner;  private UUID uuid;  BluetoothGatt bluetoothGatt;  BluetoothGattCharacteristic btChar;  BluetoothGattCallbackHandler btData;  KrollDict kd;  Boolean isConnected = false;  BluetoothGatt connectedGatt;          private ScanCallback scanCallback = new ScanCallback() {  @Override  public void onScanResult(int callbackType, ScanResult result) {  BluetoothDevice device = result.getDevice();    if (device != null) {    BluetoothDeviceProxy btDeviceProxy = new   BluetoothDeviceProxy(device);    if (device.getName() != null) {      Log.d(LCAT, "Found: " + device.getName() + " " +   device.getAddress());      ArrayList<String> ids = new ArrayList<String>();        if (device.getUuids() != null) {             for (ParcelUuid id1 : device.getUuids()) {    ids.add(id1.toString());    }    }    btDevice = device;    kd = new KrollDict();    kd.put("name", btDevice.getName());    kd.put("macaddress", btDevice.getAddress());    fireEvent("nb_DevicesFound", kd);                          btScanner.stopScan(scanCallback);      }     }    }  };  我希望某個好心人會去天堂憐憫我,幫助我獲得那些甜蜜的數(shù)據(jù)字節(jié)。
查看完整描述

2 回答

?
蝴蝶不菲

TA貢獻(xiàn)1810條經(jīng)驗 獲得超4個贊

您的代碼中缺少的一件事是設(shè)置通知,以便 Central 可以收聽 Peripheral 的響應(yīng)。嘗試這樣的事情:


public void setNotifications() {

    BluetoothGattService service = bluetoothGatt.getService(SERVICE_UUID);

    BluetoothGattCharacteristic characteristic = service.getCharacteristic(CHARACTERISTIC_UUID);


    BluetoothGattDescriptor descriptor = characteristic.getDescriptor(DESCRIPTOR_UUID);

    descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);

    characteristic.addDescriptor(descriptor);

    characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);

    bluetoothGatt.writeDescriptor(descriptor);


    bluetoothGatt.setCharacteristicNotification(characteristic, true);

}

之后,您可以向設(shè)備發(fā)送命令并聽到它返回。


public void returnData(String data) {

    BluetoothGattService service = bluetoothGatt.getService(SERVICE_UUID);

    BluetoothGattCharacteristic characteristic = service.getCharacteristic(CHARACTERISTIC_UUID);

    String dataString = data;

    dataString.getBytes();

    writeCharacteristic.setValue(dataString);

    writeCharacteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);

    bluetoothGatt.writeCharacteristic(writeCharacteristic);

}


查看完整回答
反對 回復(fù) 2023-03-31
?
米脂

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

首先,閱讀藍(lán)牙概述。查看項目是否添加了藍(lán)牙權(quán)限。

這里的一個錯誤是isConnected=true設(shè)置得太早了,因為你可以認(rèn)為你是在發(fā)現(xiàn) ble 服務(wù)之后連接的(status == BluetoothGatt.GATT_SUCCESS)。否則無法讀寫特性。

一個很好的起點可以是這個來自谷歌的回購協(xié)議。這是一個舊項目,我不確定您是否必須更新一些依賴項才能使其編譯,但這并不重要。

建立連接并開始讀取字節(jié)很容易,但是如果你想與 ble 設(shè)備建立可靠的連接,由于 android 碎片化和制造商不遵循藍(lán)牙規(guī)范,這可能非常困難,幾乎不可能使藍(lán)牙低適用于所有設(shè)備的能量。

一旦你開始閱讀一些字節(jié),我建議你通過這個視頻學(xué)習(xí)一些重要的技巧。如果你想更深入,請仔細(xì)閱讀這個關(guān)于 ble 的精彩資源。

一旦你開始對 ble 感到絕望,可能是閱讀這個已知問題列表的好時機(jī)

最后,您會發(fā)現(xiàn)在 android 中使用 ble low energy 可以做的最好的事情是使用開源庫,例如 Nordic semiconductor ble 庫RxAndroid Ble。

但在使用 ble 庫之前,最好先了解該庫在做什么并了解您為什么需要它。

編輯:我從未使用過 appcelerator,但這里有一個用于 appcelerator titanium 的藍(lán)牙模塊


查看完整回答
反對 回復(fù) 2023-03-31
?
Helenr

TA貢獻(xiàn)1780條經(jīng)驗 獲得超4個贊

您的客戶端特征配置描述符的 uuid 有誤。它應(yīng)該是 00002902-0000-1000-8000-00805f9b34fb 但你寫了 6E400002-B5A3-F393-E0A9-E50E24DCCA9E。



查看完整回答
反對 回復(fù) 2023-03-31
  • 2 回答
  • 0 關(guān)注
  • 226 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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