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

No Write Events Generated

I am currently following the tutorial for creating custom services (https://github.com/NordicPlayground/nRF5x-custom-ble-service-tutorial). The only differences to this example is that I am using SDK v17 and SoftDevice s140.

Everything has been going fine until I reach Step 6 - Handling the Write Event from the SoftDevice. For some reason, the write event is not generated when I send it through nRF connect. What does generate this event, however, is subscribing to the characteristic. Adding logs to the on_ble_evt handler shows that no event is generated on write, so it's not a case of incorrectly handling the event id.

Parents Reply Children
  • Ah, ok. In services_init() in main.c, you set the:

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cus_init.custom_value_char_attr_md.write_perm);

    (and read perm, equally)

    before you memset cus_init to 0. So basically, that would be like:

    uint8_t a = 14;
    uint8_t b = 15;
    
    a = 0;
    b = 0;
    
    uint8_t c = a + b;
    
    NRF_LOG_INFO("c = %d", c);  //expect c = 29, but you have c = 0.

    Try moving it at least after memset(&cus_init,0,sizeof(cus_init);

    but even maybe inside ble_cus_init(&m_cus, &cus_init);

    This is also a common mistake when you reach step 7 in your guide. Make sure that this snippet:

     /* This code belongs in services_init in main.c*/
    
        // Set the cus event handler
        cus_init.evt_handler                = on_cus_evt;

    is set after memset(&cus_init,0,sizeof(cus_init)); or you will experience some weird behavior. 

    Best regards,

    Edvin

  • You absolute hero. Thanks for that, it's working perfectly now.

Related