![](/img/trans.png)
[英]Xamarin iOS Bluetooth Low Energy - CBPeripheral.UpdatedCharacteristicValue reading TX characteristic shows unexpected data
[英]How to get data from body scale as CBPeripheral using BLE (Bluetooth Low Energy) on iOS
我剛開始使用藍牙,想通過藍牙從體重秤(型號:adeVital Analysis BA 1401)讀取身體成分測量值。
將iPhone設置為Central並將其連接到電子秤(即CBPeripheral)時,我可以讀取電子秤的設備信息,例如硬件修訂號,制造商等。但是我無法獲得實際的測量數據。
我遍歷了所有服務和特性並設置了通知標志。
[peripheral setNotifyValue:YES forCharacteristic:aCharacteristic]
對於每個特征。 和委托方法
- (void) peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
被正確調用。 當我檢查更新的外圍設備時,我發現:
<CBCharacteristic: 0x1740949b0, UUID = 8A82, properties = 0x20, value = <a1014711 f3000000 00000000 00000000 00000000>, notifying = YES>
這一切都在秤打開時發生(尚未測量任何東西)。 現在,當我踩秤並完成測量時,它會顯示一個藍牙圖標,指示數據傳輸,但是iOS應用程序未收到任何通知。 我想念什么?
總結如下:外設連接到中央並在測量之前更新特性,但是此后,不再發出通知。
更新后的CBCharacteristic中的值是否可以是我必須以某種方式訂閱以獲取實際數據的服務的UUID?
希望有人可以幫助我
編輯:
可能相關,以下是我收到的服務和特性:
Services:
"<CBService: 0x17407dc40, isPrimary = YES, UUID = Device Information>",
"<CBService: 0x174070f80, isPrimary = YES, UUID = 7802>"
Characteristics
"<CBCharacteristic: 0x1740959a0, UUID = Serial Number String, properties = 0x2, value = (null), notifying = NO>",
"<CBCharacteristic: 0x174095900, UUID = Hardware Revision String, properties = 0x2, value = (null), notifying = NO>",
"<CBCharacteristic: 0x1740952c0, UUID = Firmware Revision String, properties = 0x2, value = (null), notifying = NO>",
"<CBCharacteristic: 0x1740958b0, UUID = Manufacturer Name String, properties = 0x2, value = (null), notifying = NO>",
"<CBCharacteristic: 0x174095860, UUID = Software Revision String, properties = 0x2, value = (null), notifying = NO>"
"<CBCharacteristic: 0x170095ea0, UUID = 8A21, properties = 0x20, value = (null), notifying = NO>",
"<CBCharacteristic: 0x170095e50, UUID = 8A22, properties = 0x20, value = (null), notifying = NO>",
"<CBCharacteristic: 0x1700952c0, UUID = 8A20, properties = 0x2, value = (null), notifying = NO>",
"<CBCharacteristic: 0x170095e00, UUID = 8A81, properties = 0x8, value = (null), notifying = NO>",
"<CBCharacteristic: 0x170095db0, UUID = 8A82, properties = 0x20, value = (null), notifying = NO>"
編輯2:
CBCharacteristics具有以下屬性:
8A20 = Read
8A21 = Indicate
8A22 = Indicate
8A81 = Write
8A82 = Indicate
所有其他屬性均為BOOL NO
當我打開有關8A21、8A22和8A82的通知時,我一開始就從8A82收到了一個NSData,打開了比例尺(因此該點不能作為測量值)。 我假設實際測量數據正在通過8A21特性進行更新。 但是它不會通知我的代表,我也不知道為什么。
查看系統日志,您可以看到制造商的官方應用程序將日志溢出,如下所示:
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = receive push data(<a1018b3b 02000000 00000000 00000000 00000000>),with command(a1), from characteristic(8A82)
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = receive randomnumber (37456641)
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = next step is :operating_receive_random_number
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = next step is :operating_write_xor_results
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = write command with data:<200eff57 c5>
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = write command data((null)) to characteristic(8A81)
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = write success with status - operating_write_xor_results
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = next step is :operating_write_utc_time
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = write command with data:<02033b8b 0b>
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = write command data((null)) to characteristic(8A81)
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = write success with status - operating_write_utc_time
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = next step is :operating_write_disconnect
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = write command with data:<22>
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = write command data((null)) to characteristic(8A81)
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = write success with status - operating_write_disconnect
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = next step is :operating_uploaded_results_process
您需要首先將某些數據寫入特定的特征。 在我的情況下,該特性是8A81
我編寫了一個UTC時間代碼的字節數組,該代碼是通過無法在此處發布的算法生成的。 嘗試向其中寫入任何5字節長的數組/字符,看看會發生什么(例如: [1,1,1,1,1]
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.