iOS Question how to set the uuid and characteristics as nordic uart for an ios ble peripheral?

lutz ebner

Member
Licensed User
Hello,
i would like to set the UUID to "6e400001-b5a3-f393-e0a9-e50e24dcca9e" (Nordic UART Service) for an iphone working as Ble peripheral. The Characteristics for read "6e400003-b5a3-f393-e0a9-e50e24dcca9e" and write "6e400002-b5a3-f393-e0a9-e50e24dcca9e" should also be set. Does anyone have any idea?

In B4A I have adapted the library BlePeripheral2.java and that works. A nrf52832 configured as Central can connect to the Android smart phone and exchange data without any problems. Is there a similar possibility for IOS?

Thanks and greetings
Lutz
 

lutz ebner

Member
Licensed User
Hi Erel,

yes, i am very adventurous. thanks for the source. I think I have identified the places where the code needs to be changed. Do you agree with me?
but how to compile? I have no mac, i have only the hosted builder.

Regards
Lutz

Objective-C:
- (void)Start: (NSString *)Name {
    CBMutableService *service1 = [[CBMutableService alloc] initWithType:[CBUUID UUIDWithString:@"6e400001-b5a3-f393-e0a9-e50e24dcca9e"] primary:true];
    CBMutableCharacteristic *char1 = [[CBMutableCharacteristic alloc]
            initWithType:[CBUUID UUIDWithString:@"6e400003-b5a3-f393-e0a9-e50e24dcca9e"]
            properties:CBCharacteristicPropertyRead | CBCharacteristicPropertyNotify
                    value:nil permissions:CBAttributePermissionsReadable ];
    CBMutableCharacteristic *char2 = [[CBMutableCharacteristic alloc]
            initWithType:[CBUUID UUIDWithString:@"6e400002-b5a3-f393-e0a9-e50e24dcca9e"]
              properties:CBCharacteristicPropertyWrite
                   value:nil permissions:CBAttributePermissionsWriteable ];
    service1.characteristics = @[char1, char2];
    [B4IObjectWrapper getMap:OBJ][@"readChar"] = char1;
    [OBJ addService:service1];
    [OBJ startAdvertising:@{CBAdvertisementDataLocalNameKey: Name, CBAdvertisementDataServiceUUIDsKey: @[service1.UUID]}];
}
 
Last edited:
Upvote 0

lutz ebner

Member
Licensed User
difficult but not impossible? Can you show me how? Or I send you the modified B4IPeripheralManager.m and you compile it for me and send me back the result? But only if it is not too much effort for you.
 
Upvote 0

aminoacid

Active Member
Licensed User
Longtime User
Here's a thought..... you could "rent" a MAC through a cloud service, install XCODE and compile it. Never tried this service for a MAC but here is one:


Some of these cloud services often give you a free one month trial.
 
Upvote 0

lutz ebner

Member
Licensed User
Thanks for the tip. The question remains: what do I have to do to create a modified iBle library. Can you please describe the procedure? Or is there a tutorial here in the forum? Many, many thanks.
 
Upvote 0

lutz ebner

Member
Licensed User
the code compiles without errors, but the iPhone as a peripheral is not visible. Can someone please support?



B4X:
#If OBJC

//Import the CoreBluetooth library
#import <CoreBluetooth/CoreBluetooth.h>

//Method to configure iPhone as BLE Peripheral
inline void ConfigureAsPeripheral() {
    // Erstellen Sie eine CBPeripheralManager-Instanz
    CBPeripheralManager *peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:nil queue:nil];

    //Create a CBMutableService instance for the Nordic UART service
    CBUUID *nordicUARTServiceUUID = [CBUUID UUIDWithString:@"6E400001-B5A3-F393-E0A9-E50E24DCCA9E"];
    CBMutableService *nordicUARTService = [[CBMutableService alloc] initWithType:nordicUARTServiceUUID primary:YES];

    //Create a CBMutableCharacteristic instance for the TX Characteristic
    CBUUID *txCharacteristicUUID = [CBUUID UUIDWithString:@"6E400002-B5A3-F393-E0A9-E50E24DCCA9E"];
    CBMutableCharacteristic *txCharacteristic = [[CBMutableCharacteristic alloc] initWithType:txCharacteristicUUID properties:CBCharacteristicPropertyWriteWithoutResponse value:nil permissions:CBAttributePermissionsWriteable];

    //Create a CBMutableCharacteristic instance for the RX Characteristic
    CBUUID *rxCharacteristicUUID = [CBUUID UUIDWithString:@"6E400003-B5A3-F393-E0A9-E50E24DCCA9E"];
    CBMutableCharacteristic *rxCharacteristic = [[CBMutableCharacteristic alloc] initWithType:rxCharacteristicUUID properties:CBCharacteristicPropertyNotify value:nil permissions:CBAttributePermissionsReadable];

    //Add the characteristic to the service
    [nordicUARTService setCharacteristics:@[txCharacteristic, rxCharacteristic]];

    //Create an NSDictionary instance for your advertising information
    NSDictionary *advertisementData = @{CBAdvertisementDataLocalNameKey:@"Your Device Name", CBAdvertisementDataServiceUUIDsKey:@[nordicUARTServiceUUID]};

    //Start the advertising as Peripheral
    [peripheralManager startAdvertising:advertisementData];
}

#End If

Sub Button1_Click
    ' Aufruf der Inline-Objective-C-Funktion
    ConfigureAsPeripheral
End Sub
 
Upvote 0
Top