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);
}

  • 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 

  • sorry about data_init() it is writing mistake it is suppose to be stop_command_init(). Everything is working fine when the ble connected my ble model start sending command to my device and my device send the response data to the ble model then from ble module to my android. but when i get disconnected my android from the ble model, my device keep sending data to the ble model unless i send stop command from the ble model to it. so i decided to send the stop command after the ble model is disconnected from the android. but nothing is happen even no error. I think the SPI communication with the device is depend on the ble event that why when disconnect event happen all the communication is stop. am I correct?

  • Hi Nahom,

    Just to be sure that I understand you correctly: the module should send a stop signal to device to stop sending messages when the android device disconnects from the module. But the problem is that it keeps sending messages to the module after the android device has disconnected.

    1. The first step is to step through the code using the debugger and verify that stop_command_init() is called once the Android device disconnects (i.e BLE_GAP_EVT_DISCONNECTED event is generated).
    2. The next step is to check that the module sends the stop signal over the SPI data line. You can do this by either using a logical analyzer or oscilloscope. 

    If issue persists, then the problem is probably at your device. 

    best regards

    Jared 

Related