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

Passing Characteristic data to Function

Hello,

I am having strange issue. I'm getting some data from custom service and characteristic. I can see the data being received is correct. However, if I try to pass the data to some other function in another file, the characteristic stops receiving data. Although the mobile app (nRFConnect) shows data saved, but I can not see data being received on the log. Here is the code snippet:

void scr_on_write(ble_ss_t * p_scr_service, ble_evt_t const * p_ble_evt)
{
    ble_gatts_evt_write_t const * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
    

    if (   (p_evt_write->handle == p_scr_service->char_handles.value_handle))
        //&& (p_evt_write->len == 3)) No limit to the number of bytes.
        //&& (p_rgb_service->rgb_write_handler != NULL))
    {
        //p_led_service->led_write_handler(p_ble_evt->evt.gap_evt.conn_handle, p_led_service, p_evt_write->data[0]);
        NRF_LOG_INFO("Length of script data: %d", p_evt_write->len);
        NRF_LOG_INFO("Script Data starts:");
        NRF_LOG_HEXDUMP_INFO(p_evt_write->data, p_evt_write->len);
        NRF_LOG_INFO("End of script data.");

        // write script data into flash 
        record_update_scr(p_evt_write->data, p_evt_write->len);
   
    }
    else if (   (p_evt_write->handle == p_scr_service->char_handles_1.value_handle)
        && (p_evt_write->len == 1)) 
    {
        NRF_LOG_INFO("Script start/stop: %X", p_evt_write->data[0]);
        set_script_start_flag(p_evt_write->data[0]);
        // save the event and data
        scr_evt_write = p_evt_write;
    }
}

The set_script_start_flag() function simply saves data into a global variable (within that file). If I comment out this function, everything works fine and I can see data in the log. If un-commented, once I send data to this characteristic, all characteristics in all services stop receiving data. 

I have also tried copying p_evt_write globally and later using p_evt_write->data but this also creates problems. What am I missing?

uint8_t global_flag=0;

set_script_start_flag(uint8_t data){
    global_flag = data;
}

Parents Reply Children
No Data
Related