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

How to get mcc and mnc using modem_info.h ?

<environment>
- Windows10
- modem fw v1.2.0
- nrf v1.3.0

I try to get mnc and mcc data but no luck. Any help?

#include <zephyr.h>
#include <string.h>
#include <stdio.h>
#include <modem/modem_info.h>
#include <modem/lte_lc.h>

void main() {

    int ret;
    char rx_buf[MODEM_INFO_MAX_RESPONSE_SIZE];
    u16_t rx_buf_short;

    // Connect LTE first
    printk("LTE Link Connecting ...\n");
    ret = lte_lc_init_and_connect();
    if(ret < 0){
        printk("Error: lte_lc_init_and_connect\n");
        return;
    } else {
        printk("LTE Link Connected!\n");
    }

     // Init modem info
    ret = modem_info_init();
    if(ret < 0){
        printk("Error: modem_info_init\n");
        return;
    }
    
    // Get cell ID => this is successful
    ret = modem_info_string_get(MODEM_INFO_CELLID, rx_buf, MODEM_INFO_MAX_RESPONSE_SIZE);
    if(ret < 0){
        printk("Error: MODEM_INFO_CELLID\n");
        return;
    } else {
        printk("MODEM_INFO_CELLID = %s\n", rx_buf);
    }

    // Get MCC => Fail
    ret = modem_info_short_get(MODEM_INFO_MCC, &rx_buf_short);
    if(ret < 0){
        printk("Error: MODEM_INFO_MCC\n");
        return;
    } else {
        printk("MODEM_INFO_MCC = %u\n", rx_buf_short);
    }
    
    // Get MNC => Fail
    ret = modem_info_short_get(MODEM_INFO_MNC, &rx_buf_short);
    if(ret < 0){
        printk("Error: MODEM_INFO_MNC\n");
        return;
    } else {
        printk("MODEM_INFO_MNC = %u\n", rx_buf_short);
    }

    // Get TAC(tracking area code) => this is successful
    ret = modem_info_string_get(MODEM_INFO_AREA_CODE, rx_buf, MODEM_INFO_MAX_RESPONSE_SIZE);
    if(ret < 0){
        printk("Error: MODEM_INFO_AREA_CODE\n");
        return;
    } else {
        printk("MODEM_INFO_AREA_CODE = %s\n", rx_buf);
    }


    return;
}

I also tried it using modem_info_params_init and modem_info_params_get, but modem_info_params_get causes an error -11.

Parents
  • Hi! 

    Please take a look at this ticket and specifically Jan Tore's last comment and try his suggestion.

    If you're still having trouble, please provide your full code (so the prj.conf file and the CMakeLists.txt file).

    Best regards,

    Heidi

  • I've read the ticket. It's not clear what to do for me. 

    1. Changing .data_type to AT_PARAM_TYPE_STRING at lib/modem_info/modem_info.c:173
    2. read out MODEM_INFO_OPERATOR 
    3. get the concatenated MCC and MNC string

    Is this correct?

    In addition, modem_info_params_get give an error -11. 

    <main.c>

    #include <zephyr.h>
    #include <string.h>
    #include <stdio.h>
    #include <modem/modem_info.h>
    #include <modem/lte_lc.h>
    #include <modem/at_params.h>
    
    struct modem_param_info modem_param;
    
    void main() {
    
        int ret;
        char rx_buf[MODEM_INFO_MAX_RESPONSE_SIZE];
        u16_t rx_buf_short;
    
        // Connect LTE first
        printk("LTE Link Connecting ...\n");
        ret = lte_lc_init_and_connect();
        if(ret < 0){
            printk("Error: lte_lc_init_and_connect\n");
            return;
        } else {
            printk("LTE Link Connected!\n");
        }
    
        // Init modem info param
        ret = modem_info_params_init(&modem_param);
        if(ret != 0){
            printk("Error: modem_info_params_init\n");
            return;
        }
    
        // Stores all retrieved information
        ret = modem_info_params_get(&modem_param);
        if(ret != 0){
            printk("Error: modem_info_params_get, %d\n", ret); // ERROR
            return;
        }
        
        return;
    }

    <prj.conf>

    # General config
    CONFIG_ASSERT=y
    CONFIG_NEWLIB_LIBC=y
    
    # BSD library
    CONFIG_BSD_LIBRARY=y
    CONFIG_MODEM_INFO=y
    CONFIG_CJSON_LIB=y
    
    # AT host library
    CONFIG_AT_HOST_LIBRARY=n
    
    # Networking
    CONFIG_NETWORKING=y
    CONFIG_NET_NATIVE=n
    CONFIG_NET_SOCKETS_OFFLOAD=y
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_SOCKETS_POSIX_NAMES=y
    
    # LTE link control
    CONFIG_LTE_LINK_CONTROL=y
    CONFIG_LTE_LOCK_BANDS=y
    CONFIG_LTE_LOCK_BAND_MASK="10000000"
    CONFIG_LTE_NETWORK_MODE_LTE_M_GPS=y
    CONFIG_LTE_AUTO_INIT_AND_CONNECT=n
    CONFIG_LTE_EDRX_REQ=y
    CONFIG_LTE_EDRX_REQ_VALUE="0101"
    # 0101 81.92sec
    # 0110 102.4sec
    # 1000 143.36sec
    # 1001 163.84sec
    # 1010 327.68sec
    # 1011 655.36sec
    # 1100 1310.72sec
    
    # Stacks and heaps
    CONFIG_MAIN_STACK_SIZE=4096
    CONFIG_HEAP_MEM_POOL_SIZE=16384
    
    # SEGGER RTT
    CONFIG_PRINTK=y
    CONFIG_CONSOLE=y
    CONFIG_STDOUT_CONSOLE=y
    CONFIG_UART_CONSOLE=n
    CONFIG_RTT_CONSOLE=y
    CONFIG_USE_SEGGER_RTT=y
    

    <CMakeList.txt>

    #
    # Copyright (c) 2018 Nordic Semiconductor
    #
    # SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
    #
    cmake_minimum_required(VERSION 3.8.2)
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(get_cell_station_info)
    
    target_sources(app PRIVATE src/main.c)

  • Hi, I've tried testing your code but when I flash it to the nRF9160 DK, it won't start up. Zephyr isn't booting. 

    Are you using a custom board?

    Since I can't test and therefore can't reproduce the error, you'll have to do some debugging for us. 

    In the function modem_info_params_get, there are a few places that return -EAGAIN (-11), specifically line 164, line 178 and line 188. Please find out which one of these lines is returning the error. It would be useful to see where it's failing. 

  • >Are you using a custom board?

    No I'm using DK 0.9.0

  • Okay, were you able to do the debugging I asked for?

  • line 164 causes an error. 

    LOG_ERR("Network data not obtained: %d", ret);

    I put 10 sec sleep before modem_info_params_get, but same result.

  • Hello,

    have you found the reason for the error? Try debugging and see where in modem_info_params_get() the error occurs.

Reply Children
No Data
Related