This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Custom service discovery on iOS

Hi,

I searched here for a while and I couldn't find the answer. I implemented custom service by referencing nAN-36 and the github code. For some reasons, the github code didn't work for me. So ported the code to the example project able_app_proximity. I got everything working as I wanted with Master Control Pannel. However, I can not discover my custom service when I do peripheral.discoverServices(nil) in iOS or in light blue app. I can only discover these 4 service (shown as uuid) 1804, 1802, 1803, Battery.

 static void advertising_init(uint8_t adv_flags)
 {
      uint32_t      err_code;
      ble_advdata_t advdata;
      ble_advdata_t scanrsp;

      ble_uuid_t adv_uuids[] =
      {
          {LBS_UUID_SERVICE,                 m_lbs.uuid_type}
      };

      m_advertising_mode = BLE_NO_ADV;

      // Build and set advertising data
      memset(&advdata, 0, sizeof(advdata));

      advdata.name_type               = BLE_ADVDATA_FULL_NAME;
      advdata.include_appearance      = true;
      advdata.flags                   = adv_flags;

      memset(&scanrsp, 0, sizeof(scanrsp));
      scanrsp.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
      scanrsp.uuids_complete.p_uuids  = adv_uuids;

      err_code = ble_advdata_set(&advdata, &scanrsp);
      APP_ERROR_CHECK(err_code);
 }

I assume I am missing something in advertising. So I put my advertising_init in main.c here. Is there anyone knows how to discover custom service in iOS? Another question is how do I get rid of those default services like 1804, 1802, 1803, Battery since I am not using it anyway?

Thanks.

  • Are you sure you don't want to find out why the code from GitHub didn't work? If you are, please add a new question explaining what didn't work.

    Anyways, the content of the advertising packet doesn't determine what services that are included in the GATT server, but it can advertise none, some, or all, of the services you have included in your GATT server.

    You can see what services that are added to the GATT server by examining services_init() in the main loop of ble_app_proximity, so you can get rid of them there. Since you do not know how to get rid of them, I suspect you have not added your proprietary service correctly. But you say that you got everything working in Master Control Panel, so maybe my suspicion is incorrect. If it is, maybe this is something to do with bonding? Have you tried to forget device under Bluetooth settings?

    Can you please edit your question to include how you ported your proprietary service into ble_app_proximity?

  • Many custom service examples from this Blog. All examples are updated to SDK 8. Blinky_be example : Control all gpio pins on the nRF51. Uart example : Bi directional using single characteristic. LMXDisplay_ble : Send text message to a LED matrix multi-display.

  • Thanks. These are very good example. I solved my problem by removing the bond in iOS' setting.

  • OK, I retried the custom example today with Master Control Panel, it worked. The time that didn't work is that I was not using Master Control Panel.

    My custom service did work after I remove the bound in the settings. That makes me curious about How bonding works? How about the authentication? Is there any documentation that I could read about?

    Thanks.

  • Documentation regarding bonding is spread out in the Bluetooth Core specification (and Devzone), I suggest you try to read about it there, and add a question if anything is unclear. These MSC's may also be useful. When you bond the GATT client can cache the attribute information, this is what you experienced before you removed the bond. Attribute Caching is described in Vol 3, Part G, Section 2.5.2 in the Bluetooth Core specification v4.2.

Related