1

同じサービスと特性を持つ複数の BLE デバイスがあります。複数のデバイスをスキャンして接続できます。接続後、コマンドを送信してそれぞれを区別しようとしましたが、うまくいきません。単一のデバイスで完全に機能します。ソケット接続のようなものですか?同様に、サーバーは子スレッドを生成し、各クライアントはスレッドを介して接続を維持できます。各デバイスを識別する方法に関するヒントをいくつか提供してください。

私が作成した CBCentralManager インスタンスはシングルトンです。

+ (id) sharedInstance
{
    static BLEConnectionManager *this   = nil;

    if (!this)  {
        this = [[BLEConnectionManager alloc] init];
    }
    else  {
        [this scanDevice];
    }

    return this;
}

-(void) scanDevice {
    [centralManager scanForPeripheralsWithServices:nil options:0];
}

- (id) init
{
    centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
    peripherals = [[NSMutableArray alloc] init];

    [centralManager scanForPeripheralsWithServices:nil options:0];
    return self;
}

===編集

これはうまくいきますか?デバイスごとに接続を確立した後、Apple が提供する temperatureSensor の例のような didConnectPeripheral 委任メソッドでインスタンス処理サービスと特性を作成します。したがって、各デバイスは個別に接続を維持します。

- (void) centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral  
{
    service = [[[LeTemperatureAlarmService alloc] initWithPeripheral:peripheral  controller:peripheralDelegate] autorelease];
[service start];
}
4

0 に答える 0