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

Send Data to sensor after ble disconnected

Hi nordic community

I am trying to send stop command to my device(which is connected to my NRF 52840) from my ble module(NRF 52480) after my android disconnected from the ble module. so i put the stop command function in the BLE_GAP_EVT_DISCONNECTED event occurs. But my ble module doesn't send the data to my device.

I am using ble_app_uart example

SDK: nRF5_SDK_15.2.0_9412b96

Softdevice: 132_nrf52_6.1.0_softdevice.hex

case BLE_GAP_EVT_DISCONNECTED:
            // LED indication will be changed when advertising starts.
            printf ("report 0\r");
            stop_command_init();
            m_conn_handle = BLE_CONN_HANDLE_INVALID;
            isConnected = false;
            NRF_LOG_INFO("GAP Disconnected");
            sd_nvic_SystemReset();
            break;
 

here is the stop command function

static void Data_init(void)
{
       static const uint8_t Stop_com[] = "STOP";
        size_t length = sizeof(Stop_com) / sizeof(Stop_com[0]);
        int i;
        uint32_t   err_code;
        memset (lastCommand, 0, 256);
        strncpy (lastCommand, (char *) Stop_com,length-1);

        for (i = 0; i < length-1; i++)
        {
            do
            {
                err_code = app_uart_put(Stop_com[i]);
               // NRF_LOG_INFO("Data ver is set to 0x%X(%d)", Events[i],length-1);
                if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
                {
                    NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
                    APP_ERROR_CHECK(err_code);
                }
            } while (err_code == NRF_ERROR_BUSY);
        }
        
        while (app_uart_put('\r') == NRF_ERROR_BUSY);
        NRF_LOG_INFO("Command sent %s (%d)", Stop_com,length-1);
}

Parents
  • Hi Nahom,

    I would need more information regarding your application, it's not obvious from the code that you've shared where data_init() is called but i presume that it's called in stop_command_init()? 

    • Are you getting any log output on the terminal at all? Does the printf line in the ble event handler successfully print? Have you configured the terminal correctly? What backend are you using for the logger module?
    • Have you tried stepping through the code with the debugger and see if the program asserts? If it does, what error code is returned?
    • Can you see any activity on the UART lines that are connected to your device? 

    regards

    Jared 

Reply
  • Hi Nahom,

    I would need more information regarding your application, it's not obvious from the code that you've shared where data_init() is called but i presume that it's called in stop_command_init()? 

    • Are you getting any log output on the terminal at all? Does the printf line in the ble event handler successfully print? Have you configured the terminal correctly? What backend are you using for the logger module?
    • Have you tried stepping through the code with the debugger and see if the program asserts? If it does, what error code is returned?
    • Can you see any activity on the UART lines that are connected to your device? 

    regards

    Jared 

Children
No Data
Related