YUKAI / konashi-ios-sdk

konashi iOS SDK
http://konashi.ux-xu.com
Apache License 2.0
89 stars 37 forks source link

iOS9にするとkonashi1に接続してもreadyイベントがこない #83

Closed sagiii closed 9 years ago

sagiii commented 9 years ago

KNSPeripheralBaseImpl.mの、

CBService *s = [peripheral.services lastObject];
        if([service.UUID kns_isEqualToUUID:s.UUID]) {

この部分で、OSバージョンによって取得されるサービスの順序が変化してしまっているものと予想されます。

tfuru commented 9 years ago

konashi 1への接続時のログ

2015-09-25 14:19:17.405 KonashiFirmwareUpdater[1150:1058502] Connecting konashi#4-2014(UUID: 25E2DAF5-42EE-647F-B39D-1644D6D35AA4)
2015-09-25 14:19:17.521 KonashiFirmwareUpdater[1150:1058502] Connect to peripheral with UUID : 25E2DAF5-42EE-647F-B39D-1644D6D35AA4 successfull
2015-09-25 14:19:17.524 KonashiFirmwareUpdater[1150:1058502] Fetching characteristics for service with UUID : <180a>
2015-09-25 14:19:17.525 KonashiFirmwareUpdater[1150:1058502] Fetching characteristics for service with UUID : <180f>
2015-09-25 14:19:17.526 KonashiFirmwareUpdater[1150:1058502] Fetching characteristics for service with UUID : <ff00>
2015-09-25 14:19:17.540 KonashiFirmwareUpdater[1150:1058502] Characteristics of service with UUID : <180a> found
2015-09-25 14:19:17.540 KonashiFirmwareUpdater[1150:1058502] Found characteristic <2a24>
value: (null)
descriptors: (null)
properties: Read
isNotifying: 0
2015-09-25 14:19:17.541 KonashiFirmwareUpdater[1150:1058502] Found characteristic <2a27>
value: (null)
descriptors: (null)
properties: Read
isNotifying: 0
2015-09-25 14:19:17.541 KonashiFirmwareUpdater[1150:1058502] Found characteristic <2a26>
value: (null)
descriptors: (null)
properties: Read
isNotifying: 0
2015-09-25 14:19:17.541 KonashiFirmwareUpdater[1150:1058502] Found characteristic <2a28>
value: (null)
descriptors: (null)
properties: Read
isNotifying: 0
2015-09-25 14:19:17.541 KonashiFirmwareUpdater[1150:1058502] Found characteristic <2a29>
value: (null)
descriptors: (null)
properties: Read
isNotifying: 0
<<---- v2の場合 ココこで 'Finished discovering all services' characteristics'  が出力される

konashi 2への接続時のログ

2015-09-25 14:17:36.975 KonashiFirmwareUpdater[1146:1057911] Connecting konashi2-f01584(UUID: 1ADDAD7E-5D3D-A1B8-5EB6-E7B2E09F59ED)

2015-09-25 14:17:37.190 KonashiFirmwareUpdater[1146:1057911] Connect to peripheral with UUID : 1ADDAD7E-5D3D-A1B8-5EB6-E7B2E09F59ED successfull

2015-09-25 14:17:37.350 KonashiFirmwareUpdater[1146:1057911] Fetching characteristics for service with UUID : <180a>

2015-09-25 14:17:37.351 KonashiFirmwareUpdater[1146:1057911] Fetching characteristics for service with UUID : <180f>

2015-09-25 14:17:37.351 KonashiFirmwareUpdater[1146:1057911] Fetching characteristics for service with UUID : <229bff00 03fb40da 98a7b0de f65c2d4b>

2015-09-25 14:17:37.352 KonashiFirmwareUpdater[1146:1057911] Fetching characteristics for service with UUID : <3908d54f 0c554ea1 8fd18394 a172257d>

2015-09-25 14:17:37.352 KonashiFirmwareUpdater[1146:1057911] Fetching characteristics for service with UUID : <9e5d1e47 5c1343a0 863582ad 38a1386f>

2015-09-25 14:17:37.377 KonashiFirmwareUpdater[1146:1057911] Characteristics of service with UUID : <180a> found

2015-09-25 14:17:37.377 KonashiFirmwareUpdater[1146:1057911] Found characteristic <2a23>

value: (null)

descriptors: (null)

properties: Read

isNotifying: 0

2015-09-25 14:17:37.377 KonashiFirmwareUpdater[1146:1057911] Found characteristic <2a24>

value: (null)

descriptors: (null)

properties: Read

isNotifying: 0

2015-09-25 14:17:37.378 KonashiFirmwareUpdater[1146:1057911] Found characteristic <2a26>

value: (null)

descriptors: (null)

properties: Read

isNotifying: 0

2015-09-25 14:17:37.378 KonashiFirmwareUpdater[1146:1057911] Found characteristic <2a27>

value: (null)

descriptors: (null)

properties: Read

isNotifying: 0

2015-09-25 14:17:37.378 KonashiFirmwareUpdater[1146:1057911] Found characteristic <2a28>

value: <322e302e 3000>

descriptors: (null)

properties: Read

isNotifying: 0

2015-09-25 14:17:37.378 KonashiFirmwareUpdater[1146:1057911] Found characteristic <2a29>

value: (null)

descriptors: (null)

properties: Read

isNotifying: 0

2015-09-25 14:17:37.379 KonashiFirmwareUpdater[1146:1057911] Characteristics of service with UUID : <180f> found

2015-09-25 14:17:37.379 KonashiFirmwareUpdater[1146:1057911] Found characteristic <2a19>

value: (null)

descriptors: (null)

properties: Read

isNotifying: 0

2015-09-25 14:17:37.380 KonashiFirmwareUpdater[1146:1057911] Found characteristic <2a1a>

value: (null)

descriptors: (null)

properties: Read

isNotifying: 0

2015-09-25 14:17:37.380 KonashiFirmwareUpdater[1146:1057911] Found characteristic <2a3a>

value: (null)

descriptors: (null)

properties: Read

isNotifying: 0

2015-09-25 14:17:37.381 KonashiFirmwareUpdater[1146:1057911] Characteristics of service with UUID : <229bff00 03fb40da 98a7b0de f65c2d4b> found

2015-09-25 14:17:37.382 KonashiFirmwareUpdater[1146:1057911] Found characteristic <229b3000 03fb40da 98a7b0de f65c2d4b>

value: (null)

descriptors: (null)

properties: Read|WriteWithoutResponse

isNotifying: 0

2015-09-25 14:17:37.382 KonashiFirmwareUpdater[1146:1057911] Found characteristic <229b3001 03fb40da 98a7b0de f65c2d4b>

value: (null)

descriptors: (null)

properties: Read|WriteWithoutResponse

isNotifying: 0

2015-09-25 14:17:37.383 KonashiFirmwareUpdater[1146:1057911] Found characteristic <229b3002 03fb40da 98a7b0de f65c2d4b>

value: (null)

descriptors: (null)

properties: WriteWithoutResponse

isNotifying: 0

2015-09-25 14:17:37.383 KonashiFirmwareUpdater[1146:1057911] Found characteristic <229b3003 03fb40da 98a7b0de f65c2d4b>

value: (null)

descriptors: (null)

properties: Read|Notify

isNotifying: 0

2015-09-25 14:17:37.385 KonashiFirmwareUpdater[1146:1057911] Found characteristic <229b3004 03fb40da 98a7b0de f65c2d4b>

value: (null)

descriptors: (null)

properties: Read|WriteWithoutResponse

isNotifying: 0

2015-09-25 14:17:37.385 KonashiFirmwareUpdater[1146:1057911] Found characteristic <229b3005 03fb40da 98a7b0de f65c2d4b>

value: (null)

descriptors: (null)

properties: Read|WriteWithoutResponse

isNotifying: 0

2015-09-25 14:17:37.385 KonashiFirmwareUpdater[1146:1057911] Found characteristic <229b3006 03fb40da 98a7b0de f65c2d4b>

value: (null)

descriptors: (null)

properties: Read|WriteWithoutResponse

isNotifying: 0

2015-09-25 14:17:37.386 KonashiFirmwareUpdater[1146:1057911] Found characteristic <229b3007 03fb40da 98a7b0de f65c2d4b>

value: (null)

descriptors: (null)

properties: WriteWithoutResponse

isNotifying: 0

2015-09-25 14:17:37.388 KonashiFirmwareUpdater[1146:1057911] Found characteristic <229b3008 03fb40da 98a7b0de f65c2d4b>

value: (null)

descriptors: (null)

properties: Read

isNotifying: 0

2015-09-25 14:17:37.389 KonashiFirmwareUpdater[1146:1057911] Found characteristic <229b3009 03fb40da 98a7b0de f65c2d4b>

value: (null)

descriptors: (null)

properties: Read

isNotifying: 0

2015-09-25 14:17:37.389 KonashiFirmwareUpdater[1146:1057911] Found characteristic <229b300a 03fb40da 98a7b0de f65c2d4b>

value: (null)

descriptors: (null)

properties: Read

isNotifying: 0

2015-09-25 14:17:37.389 KonashiFirmwareUpdater[1146:1057911] Found characteristic <229b300b 03fb40da 98a7b0de f65c2d4b>

value: (null)

descriptors: (null)

properties: Read|WriteWithoutResponse

isNotifying: 0

2015-09-25 14:17:37.389 KonashiFirmwareUpdater[1146:1057911] Found characteristic <229b300c 03fb40da 98a7b0de f65c2d4b>

value: (null)

descriptors: (null)

properties: Read|WriteWithoutResponse

isNotifying: 0

2015-09-25 14:17:37.390 KonashiFirmwareUpdater[1146:1057911] Found characteristic <229b300d 03fb40da 98a7b0de f65c2d4b>

value: (null)

descriptors: (null)

properties: WriteWithoutResponse

isNotifying: 0

2015-09-25 14:17:37.390 KonashiFirmwareUpdater[1146:1057911] Found characteristic <229b300e 03fb40da 98a7b0de f65c2d4b>

value: (null)

descriptors: (null)

properties: WriteWithoutResponse

isNotifying: 0

2015-09-25 14:17:37.390 KonashiFirmwareUpdater[1146:1057911] Found characteristic <229b300f 03fb40da 98a7b0de f65c2d4b>

value: (null)

descriptors: (null)

properties: Read

isNotifying: 0

2015-09-25 14:17:37.394 KonashiFirmwareUpdater[1146:1057911] Found characteristic <229b3010 03fb40da 98a7b0de f65c2d4b>

value: (null)

descriptors: (null)

properties: Read|WriteWithoutResponse

isNotifying: 0

2015-09-25 14:17:37.394 KonashiFirmwareUpdater[1146:1057911] Found characteristic <229b3011 03fb40da 98a7b0de f65c2d4b>

value: (null)

descriptors: (null)

properties: Read|WriteWithoutResponse

isNotifying: 0

2015-09-25 14:17:37.394 KonashiFirmwareUpdater[1146:1057911] Found characteristic <229b3012 03fb40da 98a7b0de f65c2d4b>

value: (null)

descriptors: (null)

properties: Read|WriteWithoutResponse

isNotifying: 0

2015-09-25 14:17:37.394 KonashiFirmwareUpdater[1146:1057911] Found characteristic <229b3013 03fb40da 98a7b0de f65c2d4b>

value: (null)

descriptors: (null)

properties: Read|Notify

isNotifying: 0

2015-09-25 14:17:37.395 KonashiFirmwareUpdater[1146:1057911] Found characteristic <229b3014 03fb40da 98a7b0de f65c2d4b>

value: (null)

descriptors: (null)

properties: WriteWithoutResponse

isNotifying: 0

2015-09-25 14:17:37.396 KonashiFirmwareUpdater[1146:1057911] Found characteristic <229b3015 03fb40da 98a7b0de f65c2d4b>

value: (null)

descriptors: (null)

properties: Read|Notify

isNotifying: 0

2015-09-25 14:17:37.397 KonashiFirmwareUpdater[1146:1057911] Characteristics of service with UUID : <3908d54f 0c554ea1 8fd18394 a172257d> found

2015-09-25 14:17:37.397 KonashiFirmwareUpdater[1146:1057911] Found characteristic <0f7a29bb a9654279 8546b56e 981c008b>

value: (null)

descriptors: (null)

properties: Write|Notify|Indicate

isNotifying: 0

2015-09-25 14:17:37.397 KonashiFirmwareUpdater[1146:1057911] Found characteristic <8e922cce eec647b0 b46d0956 3a8da638>

value: (null)

descriptors: (null)

properties: Write

isNotifying: 0

2015-09-25 14:17:37.397 KonashiFirmwareUpdater[1146:1057911] Characteristics of service with UUID : <9e5d1e47 5c1343a0 863582ad 38a1386f> found

2015-09-25 14:17:37.398 KonashiFirmwareUpdater[1146:1057911] Found characteristic <e3dd50bf f7a74e99 838e570a 086c666b>

value: (null)

descriptors: (null)

properties: Write|Notify|Indicate

isNotifying: 0

2015-09-25 14:17:37.398 KonashiFirmwareUpdater[1146:1057911] Found characteristic <92e86c7a d9614091 b74f2409 e72efe36>

value: (null)

descriptors: (null)

properties: Write

isNotifying: 0

2015-09-25 14:17:37.398 KonashiFirmwareUpdater[1146:1057911] Found characteristic <347f7608 2e2d47eb 913b75d4 edc4de3b>

value: (null)

descriptors: (null)

properties: Read

isNotifying: 0

2015-09-25 14:17:37.398 KonashiFirmwareUpdater[1146:1057911] Finished discovering all services' characteristics

2015-09-25 14:17:37.438 KonashiFirmwareUpdater[1146:1057911] didUpdateValueForCharacteristic
tfuru commented 9 years ago

KNSPeripheralBaseImpl.m 見つかった peripheralのサービスUUID一覧と service の UUIDを比較して見つかったら 抜けるコードにすると konashi v1 でも動作するようです。 ※ そもそもココのこの判定の考え方が間違えていそう。

        BOOL f = NO;
        for(int i=0; i < peripheral.services.count; i++) {
            CBService *s = [peripheral.services objectAtIndex:i];
            if([service.UUID isEqual:s.UUID]){
                f = YES;
            }
        }

        //CBService *s = [peripheral.services objectAtIndex:(peripheral.services.count - 1)];
        //if([service.UUID kns_isEqualToUUID:s.UUID]) {
        if(f == YES) {
            KNS_LOG(@"Finished discovering all services' characteristics");
sagiii commented 9 years ago

iOS9と8以前で変化が生じているのはここ以外に原因があるかもしれません。 konashi-ios-sdk 3.0.1で上記トライしても改善しませんでした。 また、didDiscoverCharacteristicsForServiceはそのとき1回しか呼ばれず、

discoverされたサービス:
KonashiJs[2601:1690551] c-discovered service = <180a>

peripheral.servicesのメンバー:
2015-09-26 17:50:26.549 KonashiJs[2601:1690551] p services[0] = <180a>
2015-09-26 17:50:26.550 KonashiJs[2601:1690551] p services[1] = <180f>
2015-09-26 17:50:26.550 KonashiJs[2601:1690551] p services[2] = <ff00>

でした。

またiOS9においても8と同様、kns_discoverAllCharacteristicsで非同期に3つすべてのサービスへのdiscoverCharacteristicが行われており、最初のサービスしか見つからない理由がよくわかりません。

tfuru commented 9 years ago

batteryService 180F を discoverCharacteristics すると konashi 1は反応しなくなるようです。 試しに kns_discoverAllCharacteristics を下のように修正した所 Lチカ 出来ることを確認しました。 (このままだと konashi 2 では動かない )

確認端末 iPhone6Plus iOS9.0

CBPeripheral+Konashi.m

- (void) kns_discoverAllCharacteristics
{
    /*
    for (int i=0; i < self.services.count; i++) {
        CBService *s = [self.services objectAtIndex:i];
        KNS_LOG(@"Fetching characteristics for service with UUID : %@", [s.UUID kns_dataDescription]);
        [self discoverCharacteristics:nil forService:s];
    }
    */
    {
        //DeviceInfo 180a
        CBService *s = [self.services objectAtIndex:0];
        KNS_LOG(@"Fetching characteristics for service with UUID : %@", [s.UUID kns_dataDescription]);
        [self discoverCharacteristics:nil forService:s];
    }
    {
        //Konashi Service ff00
        CBService *s = [self.services objectAtIndex:2];
        KNS_LOG(@"Fetching characteristics for service with UUID : %@", [s.UUID kns_dataDescription]);
        [self discoverCharacteristics:nil forService:s];
    }
}
sagiii commented 9 years ago

konashi1かつiOS9の場合、didDiscoverCharacteristicsForService 1回しか発生しない また、battery service(peripheral.servicesの2つめに位置するサービス)をdiscoverCharacteristicしなければ、無事konashi serviceもdiscoverCharacterisitcされて、動作する。 → konashi1かつiOS9のばあいだけ、battery serviceをdiscoverしない、というのが解だと考えます。

0x0c commented 9 years ago

ご確認ください https://github.com/YUKAI/konashi-ios-sdk/pull/85