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

ble_nus_string_send error

Hi, I am merging the Thingy app (Segger with softdevice s132_nrf52_4.0.5) with the UART example (taken from ble_app_uart in SDK 11). I have been fixing some errors before getting this error with ble_nus_string_send(&m_nus,data,length). I tracked in the debug and saw that p_nus->conn_handle = 0xFFFF and p_nusp_nus->is_notification_enabled= false.

This is the main loop:

        app_sched_execute();       
       
        err_code=ble_nus_string_send(&m_nus,data,length); /*data is random created by me*/
 
        if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
          {
              NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x.\n ", err_code);                   
          }
       
       
        if (!NRF_LOG_PROCESS()) // Process logs
        {
            power_manage();
        }

Everything works fine except that i cannot send data using ble_nus_string_send. (also if i run the ble_app_uart example alone, it works just fine).

Please give me some clues to fix this error. Many thanks.

Parents
  • p_nus->conn_handle = 0xFFFF

    I think that means you are not connected (or have lost the connection).

    How to properly post source code:

  • static void thingy_init(void)
    {
        uint32_t                 err_code;
        m_ui_init_t              ui_params;
        m_environment_init_t     env_params;
        m_motion_init_t          motion_params;
        m_ble_init_t             ble_params;
        batt_meas_init_t         batt_meas_init = BATT_MEAS_PARAM_CFG;
    
        ble_nus_init_t nus_init;
        memset(&nus_init, 0, sizeof(nus_init));
    
        nus_init.data_handler = nus_data_handler;
        
        
    
        /**@brief Initialize the TWI manager. */
        err_code = twi_manager_init(APP_IRQ_PRIORITY_THREAD);
        APP_ERROR_CHECK(err_code);
    
        /**@brief Initialize LED and button UI module. */
        ui_params.p_twi_instance = &m_twi_sensors;
        err_code = m_ui_init(&m_ble_service_handles[THINGY_SERVICE_UI],
                             &ui_params);
        APP_ERROR_CHECK(err_code);
    
        /**@brief Initialize environment module. */
        env_params.p_twi_instance = &m_twi_sensors;
        err_code = m_environment_init(&m_ble_service_handles[THINGY_SERVICE_ENVIRONMENT],
                                      &env_params);
        APP_ERROR_CHECK(err_code);
    
        /**@brief Initialize motion module. */
        motion_params.p_twi_instance = &m_twi_sensors;
    
        err_code = m_motion_init(&m_ble_service_handles[THINGY_SERVICE_MOTION],
                                 &motion_params);
        APP_ERROR_CHECK(err_code);
    
        err_code = m_sound_init(&m_ble_service_handles[THINGY_SERVICE_SOUND]);
        APP_ERROR_CHECK(err_code);
    
        /**@brief Initialize the battery measurement. */
        batt_meas_init.evt_handler = m_batt_meas_handler;
        err_code = m_batt_meas_init(&m_ble_service_handles[THINGY_SERVICE_BATTERY], &batt_meas_init);
        APP_ERROR_CHECK(err_code);    
    
        err_code = m_batt_meas_enable(BATT_MEAS_INTERVAL_MS);
        APP_ERROR_CHECK(err_code);
    
        /**@brief Initialize BLE handling module. */
        ble_params.evt_handler       = thingy_ble_evt_handler;
        ble_params.p_service_handles = m_ble_service_handles;
        ble_params.service_num       = THINGY_SERVICES_MAX;
    
        err_code = m_ble_init(&ble_params);
        APP_ERROR_CHECK(err_code);     
    
        err_code = m_ui_led_set_event(M_UI_BLE_DISCONNECTED);
        APP_ERROR_CHECK(err_code);
    
        err_code = ble_nus_init(&m_nus, &nus_init);
        APP_ERROR_CHECK(err_code);
    
    }
    
    //And my main function is like this:
    // Initialize.
        APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE);
       
        err_code = app_timer_init();
        APP_ERROR_CHECK(err_code);
        
        uart_init();
        
        board_init();     
        thingy_init(); 
    
        for (;;)
        {
        
            app_sched_execute();       
           
            err_code=ble_nus_string_send(&m_nus,data,length);
      
            if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
              {
                  NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x.\n ", err_code);                   
              } 
           
           
            if (!NRF_LOG_PROCESS()) // Process logs
            { 
                power_manage();
            }
        }
    

    Is my initialization failed somewhere and nus service cannot get a good conn_handle?

  • You said the ble_app_uart example works alone.

    So look at what that's doing, compare with what your system is doing ...

  • Yes, that is what i did. But the problem is the thingy app and the uart example use different SDKs. Even the uart examples themselves are different between different SDKs. In my problem, i used SDK 11 because it is best suit for the thingy app I am using downloaded from this link: https://devzone.nordicsemi.com/f/nordic-q-a/33599/thingy52-debugging-under-ses.

  • I do use the uart example in SDK v11 to integrate into thingy app.

    Can you give me a clue on solving my problem with ble_nus_string_send?

Reply Children
Related