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

How to discover custom service of peripheral

Hi, Nordic staff.

I'm working with Central device using S132.

There is a peripheral device using S112 in Nordic. I didn't make this peripheral.

My question is that is it possible to discover above service and some characteristics uuid from S132 central?

If possible, can tell me how should I do?

Best regards.

Parents
  • Do you know the service UUID & char. in peripheral side? If yes, you may define it in your code. If not, you may sniff the peripheral and try the service UUID and the characteristics data format. Sometimes the service UUID will be in advertisement data package.

  • Thank you. That's why I made it separately.
    Is this the right way to do it?
    But it hasn't been resolved...
    What should I do... ...TT.

    void MJR_c_on_db_disc_evt(ble_nus_c_t * p_ble_nus_c, ble_db_discovery_evt_t * p_evt)
    {
        ble_nus_c_evt_t nus_c_evt;
        memset(&nus_c_evt,0,sizeof(ble_nus_c_evt_t));
    
        ble_gatt_db_char_t * p_chars = p_evt->params.discovered_db.charateristics;
    
        // Check if the NUS was discovered.
        if (    (p_evt->evt_type == BLE_DB_DISCOVERY_COMPLETE)
            &&  (p_evt->params.discovered_db.srv_uuid.uuid == MJR_LE_SERVICE_UUID)
            &&  (p_evt->params.discovered_db.srv_uuid.type == NUS_SERVICE_UUID_TYPE))
        {
            uint32_t i;
            for (i = 0; i < p_evt->params.discovered_db.char_count; i++)
            {
                switch (p_chars[i].characteristic.uuid.uuid)
                {
                    case MJR_LE_NOTIFYCATION_UUID:
    
                        nus_c_evt.handles.nus_rx_handle = p_chars[i].characteristic.handle_value;
                        break;
    
                    case MJR_LE_WRITE_NO_RESPONSE_UUID:
    
                        nus_c_evt.handles.nus_tx_handle = p_chars[i].characteristic.handle_value;
                        nus_c_evt.handles.nus_tx_cccd_handle = p_chars[i].cccd_handle;
                        break;
    
                    default:
                        break;
                }
            }
            if (p_ble_nus_c->evt_handler != NULL)
            {
                nus_c_evt.conn_handle = p_evt->conn_handle;
                nus_c_evt.evt_type    = BLE_NUS_C_EVT_DISCOVERY_COMPLETE;
                p_ble_nus_c->evt_handler(p_ble_nus_c, &nus_c_evt);
            }
        }
    }

    static void db_disc_handler(ble_db_discovery_evt_t * p_evt)
    {
        
        // ble_nus_c_on_db_disc_evt(&m_ble_nus_c, p_evt);
        MJR_c_on_db_disc_evt(&m_ble_nus_c, p_evt);
    
    }

  • And your ble_evt_handler ()  should be ex:

    Depend on your case

    static void gatt_c_evt_handler(ble_gatt_c_t * p_gatt_c, ble_gatt_c_evt_t * p_gatt_c_evt)
    {
    switch (p_gatt_c_evt->evt_type)
    {
    case BLE_GATT_C_EVT_DISCOVERY_COMPLETE:
    {
    ret_code_t err_code;

    NRF_LOG_INFO("BBQ BLE probe service discovered on conn_handle 0x%x\r\n",
    p_gatt_c_evt->conn_handle);

    err_code = app_button_enable();
    APP_ERROR_CHECK(err_code);

    // GATT service discovered. Enable notification of Read.
    err_code = ble_gatt_c_read1_notif_enable(p_gatt_c);
    APP_ERROR_CHECK(err_code);
    err_code = ble_gatt_c_read2_notif_enable(p_gatt_c);
    APP_ERROR_CHECK(err_code);

    } break; // BLE_GATT_C_EVT_DISCOVERY_COMPLETE

    case BLE_GATT_C_EVT_TEMPERATURE_NOTIFICATION:
    {
    data_state ^= p_gatt_c_evt->params.button.button_state;
    NRF_LOG_INFO("Link 0x%x, Data state changed on peer to 0x%x\r\n",
    p_gatt_c_evt->conn_handle,
    data_state);
    if (temp_T1>=0)
    {
    BLE_probe[p_gatt_c_evt->conn_handle].probe_T1 = temp_T1*10;
    }
    else
    {
    BLE_probe[p_gatt_c_evt->conn_handle].probe_T1 = 4000+abs(temp_T1)*10;
    }
    if (temp_T2>=0)
    {
    BLE_probe[p_gatt_c_evt->conn_handle].probe_T2 = temp_T2*10;
    }
    else
    {
    BLE_probe[p_gatt_c_evt->conn_handle].probe_T2 = 4000+abs(temp_T2)*10;
    }
    BLE_probe[p_gatt_c_evt->conn_handle].respon_time = temp_respon_time;
    if (data_state==0xff)
    {
    bsp_board_led_on(LEDBUTTON_LED);
    }
    else
    {
    bsp_board_led_off(LEDBUTTON_LED);
    }

    } break; // BLE_GATT_C_EVT_BUTTON_NOTIFICATION

    case BLE_GATT_C_EVT_STATUS_NOTIFICATION:
    {
    char temp_str[64]={0};
    if (p_gatt_c_evt->params.button.button_state==0)
    {
    strcpy(temp_str,"Battery good.");
    BLE_probe[p_gatt_c_evt->conn_handle].batt_status = 0xff;
    }
    else
    {
    strcpy(temp_str,"Low Battery.");
    BLE_probe[p_gatt_c_evt->conn_handle].batt_status = 0x00;
    }
    NRF_LOG_INFO("Link 0x%x, Battery status: %s\r\n",
    p_gatt_c_evt->conn_handle,
    (uint32_t)temp_str);
    check_sum=0;
    check_sum = BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[5]+BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[4]+BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[3]
    +BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[2]+BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[1]+BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[0]
    +BLE_probe[p_gatt_c_evt->conn_handle].ble_name[0]+BLE_probe[p_gatt_c_evt->conn_handle].ble_name[1]+BLE_probe[p_gatt_c_evt->conn_handle].ble_name[2]
    +BLE_probe[p_gatt_c_evt->conn_handle].ble_name[3]+BLE_probe[p_gatt_c_evt->conn_handle].ble_name[4]+BLE_probe[p_gatt_c_evt->conn_handle].connect_ID
    +BLE_probe[p_gatt_c_evt->conn_handle].disconn_code+(BLE_probe[p_gatt_c_evt->conn_handle].probe_T1>>8)+(BLE_probe[p_gatt_c_evt->conn_handle].probe_T1&0xff)
    +(BLE_probe[p_gatt_c_evt->conn_handle].probe_T2>>8)+(BLE_probe[p_gatt_c_evt->conn_handle].probe_T2&0xff)+BLE_probe[p_gatt_c_evt->conn_handle].batt_status
    +BLE_probe[p_gatt_c_evt->conn_handle].respon_time;
    sprintf(uart_tx_buff,"CT probe%d=%02x%02x%02x%02x%02x%02x,%s,%d,%x,%x,%x,%x,%x,%x\r\n",p_gatt_c_evt->conn_handle+1,BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[5],
    BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[4],BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[3],BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[2],BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[1],BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[0],
    BLE_probe[p_gatt_c_evt->conn_handle].ble_name,BLE_probe[p_gatt_c_evt->conn_handle].connect_ID,BLE_probe[p_gatt_c_evt->conn_handle].disconn_code,BLE_probe[p_gatt_c_evt->conn_handle].probe_T1,BLE_probe[p_gatt_c_evt->conn_handle].probe_T2,
    BLE_probe[p_gatt_c_evt->conn_handle].batt_status,BLE_probe[p_gatt_c_evt->conn_handle].respon_time,check_sum);
    uart_serial_tx((uint8_t *)uart_tx_buff,strlen(uart_tx_buff));
    //dbt_printf("%s",uart_tx_buff);
    } break; // BLE_GATT_C_EVT_STATUS_NOTIFICATION

    default:
    // No implementation needed.
    break;
    }
    }

Reply
  • And your ble_evt_handler ()  should be ex:

    Depend on your case

    static void gatt_c_evt_handler(ble_gatt_c_t * p_gatt_c, ble_gatt_c_evt_t * p_gatt_c_evt)
    {
    switch (p_gatt_c_evt->evt_type)
    {
    case BLE_GATT_C_EVT_DISCOVERY_COMPLETE:
    {
    ret_code_t err_code;

    NRF_LOG_INFO("BBQ BLE probe service discovered on conn_handle 0x%x\r\n",
    p_gatt_c_evt->conn_handle);

    err_code = app_button_enable();
    APP_ERROR_CHECK(err_code);

    // GATT service discovered. Enable notification of Read.
    err_code = ble_gatt_c_read1_notif_enable(p_gatt_c);
    APP_ERROR_CHECK(err_code);
    err_code = ble_gatt_c_read2_notif_enable(p_gatt_c);
    APP_ERROR_CHECK(err_code);

    } break; // BLE_GATT_C_EVT_DISCOVERY_COMPLETE

    case BLE_GATT_C_EVT_TEMPERATURE_NOTIFICATION:
    {
    data_state ^= p_gatt_c_evt->params.button.button_state;
    NRF_LOG_INFO("Link 0x%x, Data state changed on peer to 0x%x\r\n",
    p_gatt_c_evt->conn_handle,
    data_state);
    if (temp_T1>=0)
    {
    BLE_probe[p_gatt_c_evt->conn_handle].probe_T1 = temp_T1*10;
    }
    else
    {
    BLE_probe[p_gatt_c_evt->conn_handle].probe_T1 = 4000+abs(temp_T1)*10;
    }
    if (temp_T2>=0)
    {
    BLE_probe[p_gatt_c_evt->conn_handle].probe_T2 = temp_T2*10;
    }
    else
    {
    BLE_probe[p_gatt_c_evt->conn_handle].probe_T2 = 4000+abs(temp_T2)*10;
    }
    BLE_probe[p_gatt_c_evt->conn_handle].respon_time = temp_respon_time;
    if (data_state==0xff)
    {
    bsp_board_led_on(LEDBUTTON_LED);
    }
    else
    {
    bsp_board_led_off(LEDBUTTON_LED);
    }

    } break; // BLE_GATT_C_EVT_BUTTON_NOTIFICATION

    case BLE_GATT_C_EVT_STATUS_NOTIFICATION:
    {
    char temp_str[64]={0};
    if (p_gatt_c_evt->params.button.button_state==0)
    {
    strcpy(temp_str,"Battery good.");
    BLE_probe[p_gatt_c_evt->conn_handle].batt_status = 0xff;
    }
    else
    {
    strcpy(temp_str,"Low Battery.");
    BLE_probe[p_gatt_c_evt->conn_handle].batt_status = 0x00;
    }
    NRF_LOG_INFO("Link 0x%x, Battery status: %s\r\n",
    p_gatt_c_evt->conn_handle,
    (uint32_t)temp_str);
    check_sum=0;
    check_sum = BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[5]+BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[4]+BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[3]
    +BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[2]+BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[1]+BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[0]
    +BLE_probe[p_gatt_c_evt->conn_handle].ble_name[0]+BLE_probe[p_gatt_c_evt->conn_handle].ble_name[1]+BLE_probe[p_gatt_c_evt->conn_handle].ble_name[2]
    +BLE_probe[p_gatt_c_evt->conn_handle].ble_name[3]+BLE_probe[p_gatt_c_evt->conn_handle].ble_name[4]+BLE_probe[p_gatt_c_evt->conn_handle].connect_ID
    +BLE_probe[p_gatt_c_evt->conn_handle].disconn_code+(BLE_probe[p_gatt_c_evt->conn_handle].probe_T1>>8)+(BLE_probe[p_gatt_c_evt->conn_handle].probe_T1&0xff)
    +(BLE_probe[p_gatt_c_evt->conn_handle].probe_T2>>8)+(BLE_probe[p_gatt_c_evt->conn_handle].probe_T2&0xff)+BLE_probe[p_gatt_c_evt->conn_handle].batt_status
    +BLE_probe[p_gatt_c_evt->conn_handle].respon_time;
    sprintf(uart_tx_buff,"CT probe%d=%02x%02x%02x%02x%02x%02x,%s,%d,%x,%x,%x,%x,%x,%x\r\n",p_gatt_c_evt->conn_handle+1,BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[5],
    BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[4],BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[3],BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[2],BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[1],BLE_probe[p_gatt_c_evt->conn_handle].ble_mac[0],
    BLE_probe[p_gatt_c_evt->conn_handle].ble_name,BLE_probe[p_gatt_c_evt->conn_handle].connect_ID,BLE_probe[p_gatt_c_evt->conn_handle].disconn_code,BLE_probe[p_gatt_c_evt->conn_handle].probe_T1,BLE_probe[p_gatt_c_evt->conn_handle].probe_T2,
    BLE_probe[p_gatt_c_evt->conn_handle].batt_status,BLE_probe[p_gatt_c_evt->conn_handle].respon_time,check_sum);
    uart_serial_tx((uint8_t *)uart_tx_buff,strlen(uart_tx_buff));
    //dbt_printf("%s",uart_tx_buff);
    } break; // BLE_GATT_C_EVT_STATUS_NOTIFICATION

    default:
    // No implementation needed.
    break;
    }
    }

Children
No Data
Related