iOS Question BLE (Objective-C) SDK for DFRobot Bluno

kc1

Member
Licensed User
Longtime User
I know little about Objective-C and BLE and hope someone would be kind enough to give me a hand :)

I bought a DFRobot Bluno with Accessory Shield to learn about BLE.

Bluno reference:
http://www.dfrobot.com/index.php?route=product/product&product_id=1044#.VeDEJDOFNaQ

Bluno Accessory Shield reference:
http://www.dfrobot.com/index.php?route=DFblog/blog&id=56

DFRobot is kind to provide sample code: https://github.com/DFRobot/BlunoBasicDemo/tree/master/IOS/BlunoBasicDemo
and source code for the Accessory Shield Demo: https://github.com/DFRobot/BlunoAccessoryShieldDemo

I got the demo built on a Mac and it worked well on my iPad and iPhone.

I bought B4i because I don't know much about Objective-C but I want to get up and running on iOS :)

At this time, I am having difficulties linking what I learnt from single-stepping the demo code in Objective-C and the B4i BLE Example.

I got bits and pieces of information, but I don't know how to paste them together to make it all work in B4i. OK, I admit I am not experienced with B4i either :D

From the Objective-C demo code, I got these pieces:
B4X:
[dsetValue:@"dfb0"forKey:@"DF xiaomi service UUID"];
[dsetValue:@"dfb1"forKey:@"DF xiaomi data UUID"];
[dsetValue:@"dfb1"forKey:@"DF xiaomi config UUID"];
where dsetValue is an NSMutableDictionary

I also got "configureSensorTag" as such:
B4X:
sCBUUID = df b0 10 80 80 9b 34 fb (returned from key "DF xiaomi service UUID”)
cCBUUID = df b1 10 80 80 9b 34 fb (returned from key "DF xiaomi config UUID”)

I found these 2 lines that could be helpful:
B4X:
#define kServiceID @"0000dfb0-0000-1000-8000-00805f9b34fb"
#define TI_BASE_LONG_UUID @"F0000000-0451-4000-B000-000000000000"

To read the potentiometer on the Accessory Shield, I found
B4X:
[self writeMessage:@"<KNOB>;"];

and the Bluno would return
<KNOB>196;

The two Objective-C functions used to Write to the Bluno:
B4X:
+(void)writeCharacteristic:(CBPeripheral*)peripheral sCBUUID:(CBUUID*)sCBUUID cCBUUID:(CBUUID*)cCBUUID data:(NSData*)data {
   // Sends data to BLE peripheral to process HID and send EHIF command to PC
   for(CBService*serviceinperipheral.services) {
       if([service.UUIDisEqual:sCBUUID]) {
           for(CBCharacteristic*characteristicinservice.characteristics) {
               if([characteristic.UUIDisEqual:cCBUUID]) {
                   /* EVERYTHING IS FOUND, WRITE characteristic ! */
                    [peripheralwriteValue:dataforCharacteristic:characteristictype:CBCharacteristicWriteWithResponse];
                   
                }
            }
        }
    }
}


- (void)writeMessage:(NSString*)msg
{
   if(!_bConnected)
    {
       return;
    }
   NSData* bytes = [msgdataUsingEncoding:NSUTF8StringEncoding];
    [BLEUtilitywriteCharacteristic:self.bleDevice.peripheralsCBUUID:[CBUUIDUUIDWithString:[self.bleDevice.setupDatavalueForKey:@"DF xiaomi service UUID"]]cCBUUID:[CBUUIDUUIDWithString:@"dfb1"]data:bytes];
}

By single-stepping the B4i BLE Example, I found 2 services on the Bluno:
180A
DFB0


Under service 180A, characteristics are available such as:
Model Number String, size = 8, 44462042 6C756E6F

Under service DFB0, I found 2 characteristics: DFB1 and DFB2.

I have no idea how they all relate to each other. Documentations I found on BLE didn't help much either.

I experimented with ReadData, ReadData2 and WriteData in B4i in an attempt to do an Objective-C equivalent of [self writeMessage:@"<KNOB>;"] to read the potentiometer value, but they failed. That's because I don't know what parameters to pass to those Subs.

Would someone point me in the right direction please :)

Thank you,
kc
 

kc1

Member
Licensed User
Longtime User
Erel,

Thank you for stepping in to help :)

This is the log I got from running the Accessory Shield Demo in Xcode:

2015-08-30 15:35:42.650 SimpleSample[3117:1127965] Found a BLE Device : <CBPeripheral: 0x15e5bef0, identifier = E828C2FA-FACB-6D8B-E7B1-64ED944E13B8, name = Bluno, state = disconnected>
2015-08-30 15:35:43.849 SimpleSample[3117:1127965] Service count:1
2015-08-30 15:35:44.029 SimpleSample[3117:1127965] didUpdateNotificationStateForCharacteristic DFB1, error = Error Domain=CBATTErrorDomain Code=10 "The attribute could not be found." UserInfo=0x15d60220 {NSLocalizedDescription=The attribute could not be found.}
2015-08-30 15:35:44.869 SimpleSample[3117:1127965] didWriteValueForCharacteristic DFB1 error = (null)
2015-08-30 15:35:44.869 SimpleSample[3117:1127965] didWriteData (null) ; error = (null)
2015-08-30 15:35:45.258 SimpleSample[3117:1127965] didWriteValueForCharacteristic DFB1 error = (null)
2015-08-30 15:35:45.260 SimpleSample[3117:1127965] didWriteData <3c4b4e4f 423e3336 303b> ; error = (null)
2015-08-30 15:35:45.408 SimpleSample[3117:1127965] didWriteValueForCharacteristic DFB1 error = (null)
2015-08-30 15:35:45.409 SimpleSample[3117:1127965] didWriteData <3c4b4e4f 423e3336 313b> ; error = (null)
2015-08-30 15:35:45.469 SimpleSample[3117:1127965] didWriteValueForCharacteristic DFB1 error = (null)
2015-08-30 15:35:45.470 SimpleSample[3117:1127965] didWriteData <3c48554d 49443e33 373b> ; error = (null)


The string 3c4b4e4f 423e3336 303b translates to <KNOB>360; which is the response I would expect from the Bluno board.

It looks to me the iOS device continues to request data from the Bluno board because it keeps updating the iOS screen with data as I turn the potentiometer knob. However, I can't tell from the Xcode log above how the request is sent. From what I gathered in the source code, the iOS device would have to send a command such as "<KNOB>;" to the Bluno to get the Bluno to reply with <KNOB>360;

Below is the B4i BLE Example log:
Application_Start
Application_Active
Found: Bluno, CE0B953B-0640-6804-0A93-F24D1600C857, RSSI = -49, (read only map) {
kCBAdvDataIsConnectable = 1;
}
Discovering services
Services discovery completed.
180A
DFB0
<B4IExceptionWrapper: Error Domain=caught_exception Code=0 "Error decoding data as string." UserInfo=0x1666fe20 {NSLocalizedDescription=Error decoding data as string.}>
<B4IExceptionWrapper: Error Domain=caught_exception Code=0 "Error decoding data as string." UserInfo=0x166801b0 {NSLocalizedDescription=Error decoding data as string.}>


Attached is a screenshot of the BLE Example when connected to the Bluno.

I am guessing I could do this to send the command to get a response:
B4X:
Dim d() As Byte
d = "<KNOB>;".GetBytes("UTF8")
manager.WriteData("dfb0", "dfb1", d)
Not sure how to proceed at this point to setup the command to the Bluno and then capture the response.

Need help :)

Thank you,
kc
 

Attachments

  • IMG_0001.PNG
    IMG_0001.PNG
    60.6 KB · Views: 368
Last edited:
Upvote 0

kc1

Member
Licensed User
Longtime User
Erel,

Thank you for pointing out manger.SetNotify!

I'm getting the results I want now!

I also found out (the hard way) that both service and characteristic strings are case sensitive, meaning I had to use uppercase characters in my calls:
manager.SetNotify("DFB0", "DFB1", True)

Thank you once again! Now I can move on :)
 
Upvote 0
Top