How to read a characteristic (e.g. in WICED Smart example "speed_test")

867 views Asked by At

I have two sides on my desk here:

A) a broadcom eval module, BCM920737TAG, with a broadcom bluetooth LE chip and a small cortex M0 MCU. I also have a terminal program running that shows trace text output from the module. This is programmed with broadcom's "WICED Smart IDE". There are some examples shipping with it. I'm currently using the speed_test example.

B) Xamarin iOS, from VisualStudio 2013 (and a Mac as build host), using their cross-platform BluetoothLE library Monkey.Robotics.

What I am trying to achieve: My eventual goal is sending a big chunk of data (~ 500 KB - I know it will be slow) from an iPhone (BLE client) to a custom device to be (BLE server). Since I can't just send 20-byte packet after packet without some sort of ACK from the receiver without corrupting data (correct?), and the Broadcom speed_test example offers to send an ACK via the control characteristic after a specified number of received packets, I use that example. Since Characteristic Descriptors seem currently broken in Monkey.Robotics on iOS(1), I commented-out the part in broadcom speed_test which checks for the config being set to ACK.

(1) that property in a discovered Characteristic remains null; there is an according thread at Xamarin forums, no fix

    else if (handle == HANDLE_SPEED_TEST_CHARACTERISTIC_DATA_VALUE)
{
    if (++speed_test.received_unacked == speed_test.num_to_receive_before_ack)
    {
        // TEST: do ACK notify w/o this config // if (speed_test.control_client_configuration & CCC_NOTIFICATION)
        {
            UINT8 result[1] = {0x01};
            bleprofile_sendNotification(HANDLE_SPEED_TEST_CHARACTERISTIC_CONTROL_VALUE, result, 1);
        }
        speed_test.received_unacked = 0;

- I also noticed in speed_test that the control characteristic had no "readable" flags, so I added them.

    //CHARACTERISTIC_UUID128_WRITABLE
CHARACTERISTIC_UUID128(HANDLE_SPEED_TEST_CHARACTERISTIC_CONTROL, HANDLE_SPEED_TEST_CHARACTERISTIC_CONTROL_VALUE,
        UUID_SPEED_TEST_CHARACTERISTIC_CONTROL_POINT,
    LEGATTDB_CHAR_PROP_NOTIFY | LEGATTDB_CHAR_PROP_WRITE | LEGATTDB_CHAR_PROP_READ,
    LEGATTDB_PERM_WRITE_REQ | LEGATTDB_PERM_READABLE, 2),

-

I modified the Monkey.Robotics BLEExplorer example. I added my own page that gets shown when a discovered device is selected, discovers its services & characteristics, and when they have the correct UUIDs, sends the "start test" command to the Broadcom module. It will then send a number of 20-byte data packets via the data characteristic, then send the "end test" command. The starting and ending of the speed_test is confirmed in the trace output my serial terminal, i.e. the broadcom module got this correctly. This works(2) as long I blindly send one packet after the next, with a command parameter for "start test" that effectively disables ACK. As soon as I set this to ACK every packet, and then try to ReadAsync() on the ICHaracteristic, problems start.

(2) well, the program ends far too early, i.e. all the data is probably not really received - hence why I think I need an ACK from the server side, which speed_test does by writing a value back in the control characteristic.

I cannot read the control characteristic back, though. An exception in the Xamarin project is thrown, because the characteristic does not have the CanRead flag set - despite me adding this on the broadcom side. I tried reading via ICharacteristic.ReadAsync().

What am I doing wrong? I will gladly provide more details when necessary.

1

There are 1 answers

0
user1847129 On

Duh. I am able to read the characteristics now, without changing anything further in the software. Turns out the iPhone was still caching the information about the broadcom module's characteristics and wasn't aware of my added "readable" flag. So I did this on the iPhone: - disable Bluetooth in system settings - shutdown the iPhone copletely - boot up the iPhone again - enable Bluetooth again Then it just worked...

Similar things are suggested here, but doing only one of the steps hadn't worked for me: https://bluegiga.zendesk.com/entries/22662197--TROUBLESHOOTING-GATT-database-service-and-characteristic-caching-on-iOS-and-Android