What are the prerequisites to get the ICCID

Hi,

I would like to know what are the prerequisites to get the ICCID of the sim card:

    int err = 0;

    LOG_INF("Initializing modem library");
    /* initialize the modem library */
    err = nrf_modem_lib_init(NORMAL_MODE);
    if (err)
    {
        LOG_ERR("nrf_modem_lib_init error: %i", err);
    }

    /* register callbacks */
    lte_lc_register_handler(on_modem_lte_lc_event);

    err = nrf_modem_at_printf("AT%%CESQ=1");
    if (err)
    {
        LOG_ERR("nrf_modem_at_printf(CESQ): %i", err);
        return;
    }

    /* initialize info structures, this will contain the SIM card numbers as well */
    err = modem_info_init();
    if (err)
    {
        LOG_ERR("Failed to initialize modem info!");
        return;
    }

    LOG_INF("Changing functional mode");
    modem_get_info(INFO_IMEI); <=== in this internal function I can get the IMEI at this stage

    char temp_char[24] = {0};
    err = nrf_modem_at_cmd(temp_char, sizeof(temp_char), "AT%%XICCID");
    if(err == 0)
    {
        LOG_INF("AT cmd ICCID:    %s", temp_char);
    }
    else
    {
        LOG_ERR("AT cmd ICCID failed %d", err); <=== I always get here with error 65536
    }


This is the code I use, nothing special. I can get the IMEI of the modem but not the ICCID, I always get error 65536 which does not really make sense to me (= 0x10000, which is also not a negative nr).

Question is what do I need more to get the ICCID?
At this moment I do a lte_lc_init_and_connect, but that feels like overkill, just to get the ICCID...

Kind regards

Parents
  • I noticed here  Incorrect ICCID value from modem_infothat they are talking about CFUN 41 (Sim card only)

    So I did this change:

        // Set the modem to activate only the UICC (SIM card)
        err = lte_lc_func_mode_set(LTE_LC_FUNC_MODE_ACTIVATE_UICC);
        if (err) {
            LOG_ERR("Failed to activate UICC, error: %d", err);
            return;
        }
        /* initialize info structures, this will contain the SIM card numbers as well */
        err = modem_info_init();
        if (err)
        {
            LOG_ERR("Failed to initialize modem info!");
            return;
        }
        // Retrieve the ICCID
        char iccid[24] = {0};
        err = modem_info_string_get(MODEM_INFO_ICCID, iccid, sizeof(iccid));
        if (err < 0) {
            LOG_ERR("Failed to get ICCID, error: %d", err);
        } else {
            LOG_INF("ICCID: %s", iccid);
        }

    before modem_info_init i set lte_lc_func_mode_set(LTE_LC_FUNC_MODE_ACTIVATE_UICC) and after modem_info_init I readout the ICCID:​modem_info_string_get(MODEM_INFO_ICCID, iccid, sizeof(iccid))

    And this seems to work.

    I'm not sure if this is the proper way of doing it, but it seems to work... Not sure if I should set function mode back to off before starting connection.

  • Hi,

    SIM card needs to be activated to be able to read UICCID. You can look at CFUN set command and lte_lc_func_mode API.
    "Full functionality" corresponds to LTE_LC_FUNC_MODE_NORMAL, "Activates LTE without changing GNSS" (CFUN=21) corresponds to LTE_LC_FUNC_MODE_ACTIVATE_LTE and "Activates UICC" corresponds to LTE_LC_FUNC_MODE_ACTIVATE_UICC. All these 3 modes can accomplish UICC initialization.

    lseg said:
    I'm not sure if this is the proper way of doing it, but it seems to work

    This is good news. Your method seems to be OK.

    lseg said:
    Not sure if I should set function mode back to off before starting connection.

    When you use nrf_modem_lib_init(), it initializes the Modem library in normal operating mode.

    Best regards,
    Dejan

Reply
  • Hi,

    SIM card needs to be activated to be able to read UICCID. You can look at CFUN set command and lte_lc_func_mode API.
    "Full functionality" corresponds to LTE_LC_FUNC_MODE_NORMAL, "Activates LTE without changing GNSS" (CFUN=21) corresponds to LTE_LC_FUNC_MODE_ACTIVATE_LTE and "Activates UICC" corresponds to LTE_LC_FUNC_MODE_ACTIVATE_UICC. All these 3 modes can accomplish UICC initialization.

    lseg said:
    I'm not sure if this is the proper way of doing it, but it seems to work

    This is good news. Your method seems to be OK.

    lseg said:
    Not sure if I should set function mode back to off before starting connection.

    When you use nrf_modem_lib_init(), it initializes the Modem library in normal operating mode.

    Best regards,
    Dejan

Children
No Data
Related