簡體   English   中英

嘗試通過藍牙LE將多個設備連接到android設備

[英]Trying to connect multiple devices via Bluetooth LE to android device

問題

我正在嘗試將多個Bluetooth LE設備(心率監視器)連接到我的android設備。 我能夠掃描並連接到它們。 它們流式傳輸很好,只是當我輸出通知時,它在一個傳感器的數據與另一個傳感器的數據之間跳轉。

對於該項目的大部分內容,我基本上都使用 GitHub源代碼。 在項目中,他們使用一項服務(稱為BluetoothLeService)。 在我的項目中,我創建了兩個服務,彼此之間幾乎是重復的,除了一個處理一個用戶的呼叫,另一個處理另一個用戶的呼叫。

我正在將此輸出輸出到控制台:

07-27 21:14:01.786 9062-9062 / com.example.android.aware D / BluetoothGatt:setCharacteristicNotification()-uuid:00002a37-0000-1000-8000-00805f9b34fb enable:true

07-27 21:14:01.786 9062-9062 / com.example.android.aware D / BluetoothLeService2:嘗試使用現有的mBluetoothGatt進行連接。 該錯誤來自BLS2

07-27 21:14:01.796 9062-10009 / com.example.android.aware D / BluetoothGatt:onClientConnectionState()-status = 133 clientIf = 7 device = E3:64:43:37:D2:AA

07-27 21:14:01.796 9062-10009 / com.example.android.aware I / BluetoothLeService2:已與GATT服務器斷開連接。

07-27 21:14:01.796 9062-9062 / com.example.android.aware D / BluetoothGatt:setCharacteristicNotification()-uuid:00002a37-0000-1000-8000-00805f9b34fb enable:true

07-27 21:14:01.816 9062-9062 / com.example.android.aware D / BluetoothLeService:嘗試使用現有的mBluetoothGatt進行連接。 該錯誤來自BLS1

07-27 21:14:01.826 9062-10009 / com.example.android.aware D / BluetoothGatt:onClientConnectionState()-status = 133 clientIf = 6 device = 00:22:D0:41:CA:B6

07-27 21:14:01.826 9062-10009 / com.example.android.aware I / BluetoothLeService:已與GATT服務器斷開連接。


嘗試次數

  • 我試圖在SampleGattAttributes類中添加一個新的CLIENT_CHARACTERISTIC_CONFIG(稱為CLIENT_CHARACTERISTIC_CONFIG2)字符串,這在以下代碼片段(來自服務類)中起作用:

      BluetoothGattDescriptor descriptor = characteristic .getDescriptor(UUID .fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG)); 


我認為問題就像控制台所說的那樣,與兩個服務中稱為mBluetoothGatt的變量(這是BluetoothGatt類型的對象)有關。 我的想法是這樣的:

我沒有看到您引用的源代碼,但是您是否為每個連接存儲了不同的BluetoothGattCallback或返回值? 我的意思是您如何判斷這兩種設備? connectGatt將返回BluetoothGattCallback實例以通知狀態,或者您可以使用該實例進行進一步的操作,例如,了解連接狀態等。

我通過基於設備地址輸出數據解決了這個問題。

因此,我不只是吐出通知,而是輸入一個條件(是DisplayData()方法),說:“嘿,只有在這是我們要在這里尋找其輸出的設備時,才在這里輸出。”

當然,這些設備不是時間同步的,但是當您使用時間記錄日志時,會有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM