using nRF51-DK
I'm a noob and currently trying to implement a custom service by modifying the 'Heart Rate Service' example which inclued the 'BAS' which is battery status notification service(from what I understand, anyway).
I've been debugging using a few LEDs connected to pin 5 and 6. Basically, I just configure these two led pin to be SET at the beginning of main() function and then turn them off at specific points in the code to see if it ever reaches there.
Through this method, I have been able to turn off the led when a connection is established. This one could be done by inserting a single line to turn off the led inside the "ble_bas_on_ble_evt" cases like below:
void ble_bas_on_ble_evt(ble_bas_t * p_bas, ble_evt_t * p_ble_evt)
{
if (p_bas == NULL || p_ble_evt == NULL)
{
return;
}
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
nrf_gpio_pin_clear(DEBUGLED1); // added
on_connect(p_bas, p_ble_evt);
break;
case BLE_GAP_EVT_DISCONNECTED:
on_disconnect(p_bas, p_ble_evt);
break;
case BLE_GATTS_EVT_WRITE:
on_write(p_bas, p_ble_evt);
break;
default:
// No implementation needed.
break;
}
}
Now, I modified the battery_level_char_add() a little bit so that the battery level attribute value could be 'written' as well. (Originally, only read was available)
char_md.char_props.read = 1;
char_md.char_props.write=1; // added this line to make it writable
I have confirmed that this modification alone was sufficient(i believe so) for me to connect to nRF51-DK with my smartphone through the 'nRF Master Control' app and write some random battery level value (ex: 3%, 9%).
Now here's the real problem: Since the values that I insert from my smartphone app is 'WRITING', I assumed it would definitely trigger a 'BLE_GATTS_EVT_WRITE' in the nRF51-DK(peripheral) side.
Therefore, with my "ble_bas_on_ble_evt" code modified to turn off the led when 'BLE_GATTS_EVT_WRITE' occurs, was expected to work.
void ble_bas_on_ble_evt(ble_bas_t * p_bas, ble_evt_t * p_ble_evt)
{
if (p_bas == NULL || p_ble_evt == NULL)
{
return;
}
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
on_connect(p_bas, p_ble_evt);
break;
case BLE_GAP_EVT_DISCONNECTED:
on_disconnect(p_bas, p_ble_evt);
break;
case BLE_GATTS_EVT_WRITE:
nrf_gpio_pin_clear(DEBUGLED1); // added
on_write(p_bas, p_ble_evt);
break;
default:
// No implementation needed.
break;
}
}
However, with this modification, the led does not turn off even when I write new battery level values.
Could someone point out some things that I could have missed?