title: undefined error with calling ble_gatts_count_cfg function
body: <p>I am programing my esp32 to be able to advertise my custom services/characteristics. I am failry new to esp idf and I am struggling to program bluetooth using nimBLE. during building,there is no error thrown but while monitoring, i receive the following error from the function in main:</p>
  <pre><code>I (391) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
  I (397) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
  I (403) heap_init: At 3FFC49F0 len 0001B610 (109 KiB): DRAM
  I (409) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
  I (415) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
  I (422) heap_init: At 40096DB0 len 00009250 (36 KiB): IRAM
  I (429) spi_flash: detected chip: generic
  I (433) spi_flash: flash io: dio
  I (438) cpu_start: Starting scheduler on PRO CPU.
  I (0) cpu_start: Starting scheduler on APP CPU.
  I (484) BTDM_INIT: BT controller compile version [1342a48]
  I (484) system_api: Base MAC address is not set
  I (484) system_api: read default base MAC address from EFUSE
  I (494) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
  ESP_ERROR_CHECK failed: esp_err_t 0x3 (ERROR) at 0x4008e6f4
  0x4008e6f4: _esp_error_check_failed at C:/Users/Kanimba/Desktop/esp-idf/components/esp_common/src/esp_err.c:41
  
  file: &quot;../main/main.c&quot; line 35
  func: app_main
  expression: gatt_svrs_init()
  
  abort() was called at PC 0x4008e6f7 on core 0
  0x4008e6f7: _esp_error_check_failed at C:/Users/Kanimba/Desktop/esp-idf/components/esp_common/src/esp_err.c:42
  
  
  Backtrace:0x4008f64b:0x3ffbc340 0x4008fe1d:0x3ffbc360 0x400951f2:0x3ffbc380 0x4008e6f7:0x3ffbc3f0 0x400d5a86:0x3ffbc410 0x401205ed:0x3ffbc430 0x40092e45:0x3ffbc450
  0x4008f64b: panic_abort at C:/Users/Kanimba/Desktop/esp-idf/components/esp_system/panic.c:356
  
  0x4008fe1d: esp_system_abort at C:/Users/Kanimba/Desktop/esp-idf/components/esp_system/system_api.c:112
  
  0x400951f2: abort at C:/Users/Kanimba/Desktop/esp-idf/components/newlib/abort.c:46
  
  0x4008e6f7: _esp_error_check_failed at C:/Users/Kanimba/Desktop/esp-idf/components/esp_common/src/esp_err.c:42
  
  0x400d5a86: app_main at C:\Users\Kanimba\Desktop\work_project\esp\embedded-test-ble\build/../main/main.c:35 (discriminator 1)
  
  0x401205ed: main_task at C:/Users/Kanimba/Desktop/esp-idf/components/freertos/port/port_common.c:133 (discriminator 2)
  
  0x40092e45: vPortTaskWrapper at C:/Users/Kanimba/Desktop/esp-idf/components/freertos/port/xtensa/port.c:168
  </code></pre>
  <p>whereby gatt_svrs_init() is called to initializes the following;</p>
  <pre><code>int gatt_svrs_init(void) {
    int rc;
  
    ble_svc_gap_init();
    ble_svc_gatt_init();
  
    rc = ble_gatts_count_cfg(gatt_svsc);
    if (rc != 0) {
      return rc;
    }
  
    rc = ble_gatts_add_svcs(gatt_svsc);
    if (rc != 0) {
      return rc;
    }
    return 0;
  }
  </code></pre>
  <p>my main,c file looks like this</p>
  <pre><code>#include &quot;config.h&quot;
  #include &quot;gatt_svr.h&quot;
  
  #include &quot;esp_log.h&quot;
  #include &quot;esp_nimble_hci.h&quot;
  #include &quot;freertos/FreeRTOS.h&quot;
  #include &quot;freertos/task.h&quot;
  #include &quot;nvs_flash.h&quot;
  
  void app_main() {
  
    int rc;
    /* initalise non-valatile storage NVS*/
    esp_err_t ret = nvs_flash_init();
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES ||
        ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
      ESP_ERROR_CHECK(nvs_flash_erase());
      ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK(ret);
  
    /* initialise nimble */
    ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init());
  
    /* initialise apache port to nimble */
    nimble_port_init();
  
    /*Initialize the NimBLE host configuration */
    ble_hs_cfg.reset_cb = ble_on_reset;
    ble_hs_cfg.sync_cb = ble_on_sync;
    ble_hs_cfg.gatts_register_cb = gatt_svr_register_cb;
    ble_hs_cfg.store_status_cb =
        ble_store_util_status_rr; // said to not be useful, need to do more,
  
    ESP_ERROR_CHECK(gatt_svrs_init());
    // assert(rc == 0);
  
    /*set the default device name*/
    ESP_ERROR_CHECK(ble_svc_gap_device_name_set(DEVICE_NAME));
  
    // storing configuration &quot;quite not sure how this function works&quot;
    ble_store_config_init();
  
    nimble_port_freertos_init(host_task);
  }
  </code></pre>
  <p>and the structure of the service:</p>
  <pre><code>static const struct ble_gatt_svc_def gatt_svsc[] = {
      {/* Device info service/ SIG */
       .type = BLE_GATT_SVC_TYPE_PRIMARY,
       .uuid = BLE_UUID16_DECLARE(DEVICE_INFO_SERVICE),
       .characteristics =
           (struct ble_gatt_chr_def[]){
               {/* manufacturer name characteristic */
                .uuid = BLE_UUID16_DECLARE(MANUFACTURER_NAME),
                .flags = BLE_GATT_CHR_F_READ,
                .access_cb = gatt_svr_access_device_info},
               {/*serial number characteristic */
                .uuid = BLE_UUID16_DECLARE(DEVICE_SERIAL_NUMBER),
                .flags = BLE_GATT_CHR_F_READ,
                .access_cb = gatt_svr_access_device_info},
               {/*software version characteristic */
                .uuid = BLE_UUID16_DECLARE(SOFTWARE_VERSION),
                .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_ENC,
                .access_cb = gatt_svr_access_device_info},
               {0}}},
      {.type = BLE_GATT_SVC_TYPE_PRIMARY,
       .uuid = &amp;DEVICE_STATE_SERVICE.u,
       .characteristics =
           (struct ble_gatt_chr_def[]){{
                                           /* manufacturer name characteristic
                                            */
                                           .uuid = &amp;CURRENT_SPECTRUM.u,
                                           .flags = BLE_GATT_CHR_F_READ,
                                       },
                                       {
                                           /* manufacturer name characteristic
                                            */
                                           .uuid = &amp;DEVICE_TEMPERATURE.u,
                                           .flags = BLE_GATT_CHR_F_READ,
                                       },
                                       {
                                           /* manufacturer name characteristic
                                            */
                                           .uuid = &amp;CURRENT_INTESITY.u,
                                           .flags = BLE_GATT_CHR_F_READ,
                                       },
                                       {0}}},
      {.type = BLE_GATT_SVC_TYPE_PRIMARY,
       .uuid = &amp;MANUAL_SERVICE.u,
       .characteristics =
           (struct ble_gatt_chr_def[]){{
                                           /* manula spectrum characteristic */
                                           .uuid = &amp;MANUAL_SPECTRUM.u,
                                           .flags = BLE_GATT_CHR_F_READ,
                                       },
                                       {
                                           /* light intensity characteristic */
                                           .uuid = &amp;LIGHT_INTESITY.u,
                                           .flags = BLE_GATT_CHR_F_READ,
                                       },
                                       {
                                           /* manual power characteristic */
                                           .uuid = &amp;MANUAL_POWER.u,
                                           .flags = BLE_GATT_CHR_F_READ,
                                       },
                                       {0}}},
      {.type = BLE_GATT_SVC_TYPE_PRIMARY,
       .uuid = &amp;SCHEDULER_SERVICE.u,
       .characteristics =
           (struct ble_gatt_chr_def[]){{
                                           /* Start_stage characteristic */
                                           .uuid = &amp;STAGE_START.u,
                                           .flags = BLE_GATT_CHR_F_WRITE,
                                       },
                                       {
                                           /* start day hours characteristic */
                                           .uuid = &amp;DAY_START_HOURS.u,
                                           .flags = BLE_GATT_CHR_F_WRITE,
                                       },
                                       {
                                           /* manufacturer name characteristic
                                            */
                                           .uuid = &amp;DAY_END_HOURS.u,
                                           .flags = BLE_GATT_CHR_F_WRITE,
                                       },
                                       {
                                           /* Light intensity characteristic */
                                           .uuid = &amp;LIGHT_INTESITY.u,
                                           .flags = BLE_GATT_CHR_F_WRITE,
                                       },
                                       {0}}},
      {0}};
  </code></pre>