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

Feeding data into the BDS example

I've recently been playing around with Bluetooth Developer Studio, and I can see it's potential despite it having a few annoying bugs.

I've set up a custom service by re-purposing the Battery Service for now (For some reason I couldn't get an exact copy of the battery service to actually send any sort of data value despite my best efforts). Now I'm trying to figure out how to actually pass data from read from the TWI into these characteristics and have them update.

I can't seem to understand where I should be putting data to make this happen. Am I missing something obvious here?

  • What problems did you have with the battery service? In the generated code you can set the battery level with ble_bas_battery_level_set(), which is defined in ble_bas.c. I just tested by adding the battery service (unmodified) to a design with the heart rate profile, and what I set with ble_bas_battery_level_set() is what I read as the attribute value in Master Control Panel.

  • Thanks for your reply Einar.

    The battery service and characteristic itself work completely fine. Where I noticed an issue was when I set up a customer service and characteristic, that looked identical to the BAS in everything but the UUID. In this case getting the characteristic field values through the master control panel did not send back a value for the 'custom' copy of the characteristic.

    Perhaps there's something under the surface that I'm not able to add manually, but I made sure I had the correct descriptors present as well as the field. What I'm seeing now is a plugin error when I try to rebuild this from scratch, however.

    Also, thanks for the tip on the value setting function. I have noticed my custom characteristics based on the BAS generate a function like this also. I'm having trouble implementing it in main.c however. is this the wrong place to invoke the function?

  • I see. I also have problems getting proper code generated for a custom BAS. I will report the problem to the software team. To be honest there are many issues with Nordic's BDS plugin at the moment, and I do not know when an update will be available.

    Regarding the ble_bas_battery_level_set() function for the battery service, it can be called from anywhere. However you need to pass a pointer to the instance of ble_bas_t (m_bas), which is a static variable in service_if.c, so you have to wrap it somehow. For a hackish solution you could always just make it non-static, and declare it as extern in main.c and access it directly.

  • I'll give that a go. What you say I would need to 'wrap it somehow', what do you mean? And I assume that the function is meant to be utilised, so what would be the correct way to do that without having to implement a hackish solution? Is the fact that it has to be hackish just another thing down to the way the code is generated by the plugin?

  • My feeling is that BDS with the Nordic plugin can be good for experimenting, but not for generating code for real products. At least not in its current state.

    What I meant with wrapping it was that you could make a battery_level_set() function in service_if.c and add the prototype to the corresponding header file that is included in main.c. Then you could call that from main. It could look something like this:

    uint32_t battery_level_set(uint8_t level)
    {
        ble_bas_battery_level_t batlev;
        batlev.level = level;
        return ble_bas_battery_level_set(&m_bas, &batlev);
    }
    

    I must admit that I have not played that much with BDS, but yes, I think the need for this is down to the way code is generated by the plugin, and that it makes it not so interesting for development (at least for now).

Related