简体   繁体   English

如何从LE蓝牙芯片获取UUID?

[英]How to get UUID from LE Bluetooth chip?

I have a chip, working on LE Bluetooth and transmitting it's UUID. 我有一个芯片,正在处理LE蓝牙并传输它的UUID。 I need to discover it from IOS app and get it's UUID. 我需要从IOS应用中发现它并获取它的UUID。 I know how to establish a connection between two IOS devices, but not with another chips. 我知道如何在两个IOS设备之间建立连接,但不能与另一个芯片建立连接。

Thanks! 谢谢!

You should check out Apple's CoreBluetooth Temperature Example . 您应该查看Apple的CoreBluetooth温度示例

First you will use the CBCentralManager to find the available Bluetooth Peripherals with the UUID you are looking for. 首先,您将使用CBCentralManager查找具有您要查找的UUID的可用蓝牙外围设备。 It's a lengthy process that requires delegates and I can't easily give you code snippets to do this. 这是一个漫长的过程,需要委托,而我不能轻易地向您提供代码片段来完成此任务。 It will look something like this. 它看起来像这样。

.h file will have these. Remember to add the CoreBluetooth Framework.
#import <CoreBluetooth/CoreBluetooth.h>
CBCentralManager * manager;
CBPeripheral * connected_peripheral;

(Change your UUID accordingly): (相应地更改您的UUID):

NSArray * services=[NSArray arrayWithObjects:
                    [CBUUID UUIDWithString:@"0bd51666-e7cb-469b-8e4d-2742f1ba77cc"],
                    nil
                    ];
[manager scanForPeripheralsWithServices:services options: [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:CBCentralManagerScanOptionAllowDuplicatesKey]];
[manager connectPeripheral:peripheral options:nil];

From there you know you have the right peripheral, but you still need to select it and stop the CBManager from continuing to scan for new devices. 从那里您知道您拥有正确的外围设备,但是仍然需要选择外围设备,并阻止CBManager继续扫描新设备。

- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral
{
    [manager stopScan];

    NSArray *keys = [NSArray arrayWithObjects:
                 [CBUUID UUIDWithString:@"0bd51666-e7cb-469b-8e4d-2742f1ba77cc"],
                 nil];
    NSArray *objects = [NSArray arrayWithObjects:
                    @"My UUID to find",
                    nil];

    serviceNames = [NSDictionary dictionaryWithObjects:objects forKeys:keys];

    [connected_peripheral setDelegate:self];
    [connected_peripheral discoverServices:[serviceNames allKeys]];

}

Now that you have told your peripheral to advertise what services it has, you'll have a delegate for parsing those services. 既然您已经告诉外围设备公布其拥有的服务,那么您将拥有一个用于解析这些服务的委托。

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error
{
    CBService *bluetoothService;
    for (bluetoothService in connected_peripheral.services) {
        if([bluetoothService.UUID isEqual:[CBUUID UUIDWithString:@"0bd51666-e7cb-469b-8e4d-2742f1ba77cc"]])
        {
            NSLog(@"This is my bluetooth Service to Connect to");
        }
}

I wish this process was easier to explain. 我希望这个过程更容易解​​释。 The best way to figure it out is to download Apple's Temperature Example and run it on your iPhone or iPad (it won't work in the simulator). 解决这个问题的最佳方法是下载Apple的Temperature Example并在iPhone或iPad上运行(在模拟器中无法运行)。 Even though you probably aren't broadcasting temperature it will find your Bluetooth LE device and will parse through the services it is broadcasting. 即使您可能没有广播温度,它也会找到您的Bluetooth LE设备并通过其广播的服务进行解析。 Placing breakpoints in the LeDiscovery.m file of that project should show you the steps needed to discover your Bluetooth LE chip from an iOS app. 在该项目的LeDiscovery.m文件中放置断点应该可以向您显示从iOS应用程序发现Bluetooth LE芯片所需的步骤。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM