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

sim iccid

Hello,

How can I read out the ICCID of the sim card?

I've tried to do it with AT%XICCID, getting error on this.


AT+CRSM=176,12258,0,0,10


+CRSM: 144,0,"98740006819041410210"


OK


the above works, but then the returned data is shifted, which makes it alittle complex to handle.

Any ideas?

Im using the at_client to test with,

NCS ver 1.4

- David

  • What is the modem firmware version you are using? The AT%XICCID command is only supported by 1.1.3 and 1.2.x.

    What is the error you are receiving from AT%XICCID ?

    On devices with older modem firmware (like 1.1.1) I have flipped the ICCID string received from that CRSM command with this function: https://github.com/nrfconnect/sdk-nrf/blob/master/lib/modem_info/modem_info.c#L351-L363

  • Hello,

    So I upgraded the modem firmware to 1.2.x, now Im able to use the command "AT%XICCID" and its response looks correct, but when I try to implement this in the AT_client example and print to console, the returned data is srumbled.

    /*
     * Copyright (c) 2018 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
     */
    
    #include <zephyr.h>
    #include <stdio.h>
    #include <drivers/uart.h>
    #include <string.h>
    
    /**@brief Recoverable BSD library error. */
    void bsd_recoverable_error_handler(uint32_t err)
    {
    	printk("bsdlib recoverable error: %u\n", err);
    }
    
    void main(void)
    {
    	printk("The AT host sample started\n");
            int buf1[100];
            char buf2[100];
            char buf3[100];
    
            at_cmd_write("AT%XICCID", //AT+CEREG?
                       buf1,
                       100,
                       NULL);
            k_sleep(K_MSEC(2000)); 
            printk("ANSWER %s\r\n", buf2);
            k_sleep(K_MSEC(100));
            at_cmd_write("AT%XICCID", //AT+CEREG?
                       buf1,
                       100,
                       NULL);
              
            printk("ANSWER %s\r\n", buf3);
            k_sleep(K_MSEC(2000)); 
            at_cmd_write("AT%XVBAT", //AT+CEREG?
                         buf1,
                         100,
                         NULL);
              
                printk("ANSWER %s\r\n", buf1);
    }

    Regards, David

  • Hi,

    I might found some mistakes in your code. With AT%XICCID command you are trying to get the response into buf1 and then print buf2 & buf3. Just make sure you are trying to print out the same buffer that you have used with a sent AT command.

  • Hey Ziirou,

    Im not sure that is the issue, 

    Maybe it has something to do with formatting the returned data correctly for print function?

    David

  • I modified your code a little and now it's working for me at least.

    /*
     * Copyright (c) 2018 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
     */
    
    #include <zephyr.h>
    #include <stdio.h>
    #include <drivers/uart.h>
    #include <string.h>
    
    /**@brief Recoverable BSD library error. */
    void bsd_recoverable_error_handler(uint32_t err)
    {
    	printk("bsdlib recoverable error: %u\n", err);
    }
    
    void main(void)
    {
    	printk("The AT host sample started\n");
    	uint8_t buffer[100];
    
    	at_cmd_write("AT%XICCID", //AT+CEREG?
    			buffer,
    			100,
    			NULL);
    	printk("ANSWER %s", buffer);
    
    	at_cmd_write("AT%XVBAT", //AT+CEREG?
    			buffer,
    			100,
    			NULL);
    	printk("ANSWER %s", buffer);
    }
    

Related