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

issues with nus uart service

Hi All,

Just wondering if i'm doing the right thing here. 

So i am using the example of the central device to get started.The idea i'm trying to do is to use the central to connect to a peripheral based on the advertisement data. When certain flags are present in the advertisements, it connects, sends a command to the connected peripheral, and then disconnects.

My issue is that it (generally) sends the right command and collects the data, but after disconnecting it doesn't seem to send the command rather from what i see - it just sends 0's. 

i'm using just the command sd_ble_gap_disconnect to d/c the peripheral. Is that correct?

Thanks

Grant

Parents
  • Hi Grant!

    I don't know if you are doing the right thing, but I'll do my best to help you find out.

    First of all, could you provide some more information for me?

    - Which SDK and softdevice versions are you working with?
    - Which device are you working with?

    What do you mean by this:

    but after disconnecting it doesn't seem to send the command rather from what i see - it just sends 0's.

    Which command are you expecting after the central being disconnected?

    Best regards,
    Joakim.

  • Hi Joakim, 

    So i'm on the latest SDK - 14.2.0 and the softdevice is a 132 version 5(?) i downloaded the latest stuff i guess as i only started on this project mid dec. 

    So in my ble_nus_c_evt_handler i wait until the discovery of the service is complete, then try and send a command to the peripheral and i start an app timer, and everytime i get new data it resets the timer so i can disconnect after a period of in-activity. 

    So once i call the sd_ble_gap_disconnect command i assume that the peripheral is now d/c from the central and i don't have to do anything else? So when the central connects to the peripheral again its like starting fresh. 

    static void ble_nus_c_evt_handler(ble_nus_c_t * p_ble_nus_c, ble_nus_c_evt_t const * p_ble_nus_evt)
    {
        ret_code_t err_code;
        
        switch (p_ble_nus_evt->evt_type)
        {
            case BLE_NUS_C_EVT_DISCOVERY_COMPLETE:
                printf("Discovery complete.");
                NRF_LOG_INFO("Discovery complete.");
                err_code = ble_nus_c_handles_assign(p_ble_nus_c, p_ble_nus_evt->conn_handle, &p_ble_nus_evt->handles);
                APP_ERROR_CHECK(err_code);
    
                err_code = ble_nus_c_tx_notif_enable(p_ble_nus_c);
                APP_ERROR_CHECK(err_code);
                
                printf("handles %d, %d, %d\n", 
                       p_ble_nus_c->handles.nus_rx_handle,
                       p_ble_nus_c->handles.nus_tx_cccd_handle,
                       p_ble_nus_c->handles.nus_tx_handle);
                NRF_LOG_INFO("Connected to device with Nordic UART Service.");
    
                  err_code = ble_nus_c_string_send(&m_ble_nus_c, command, sizeof(command));
                  APP_ERROR_CHECK(err_code);      
    
                  // Start our disconnection timer going
                  uart_timer_restart(p_ble_nus_c);       
                  
                } else {
                  printf("unknown channel flag - disconnecting\n");
                  sd_ble_gap_disconnect(p_ble_nus_evt->conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
                }            
                break;
    
            case BLE_NUS_C_EVT_NUS_TX_EVT:
                // Show to screen the rx'd data
                for(int i = 0; i < p_ble_nus_evt->data_len; i++) { 
                  printf("%02X", p_ble_nus_evt->p_data[i]);
                }
                
                // Restart our timer for disconnection
                uart_timer_restart(p_ble_nus_c);       
    
                break;
    
            case BLE_NUS_C_EVT_DISCONNECTED:
                NRF_LOG_INFO("Disconnected.");
                printf("Disconnected\n");
                scan_start();
                break;
        }
    }

    i don't think i'm doing anything strange, 

    Thanks

    Grant

  • Think that we've solved our problem, turns out the peripheral that i was connecting to had issues. Slight smile

    Grant

  • Ok. I'm glad to hear that you found the cause of your problems.

    Be sure to let me know if you still have any problems.

    Best of luck with your project.

    Cheers,
    Joakim.

Reply Children
No Data
Related