nrf9160 lte_handler() functuion not working properly

Hi,

I have using  lte_handler(const struct lte_lc_evt *const evt)  function to get the connection details.

I'm facing a problem when i remove the antenna its still show LTE connected  and pushing data to AWS but in AWS we are not getting any data after that i tried to reset the device then its showing LTE not available may i know why lte_handler not giving LTE not available after remove the antenna

static void lte_handler(const struct lte_lc_evt *const evt)
{
    switch (evt->type)
    {
    case LTE_LC_EVT_NW_REG_STATUS:
        if ((evt->nw_reg_status != LTE_LC_NW_REG_REGISTERED_HOME) &&
            (evt->nw_reg_status != LTE_LC_NW_REG_REGISTERED_ROAMING))
        {
            printk("Network registration status: %d\n", evt->nw_reg_status);
            if (!lte_connected)
            {
                break;
            }

            lte_connected = false;
            /* Notify main function that LTE is disconnected */
            lte_cb(LTE_CONNECTION_DISCONNECTED);
            if (k_delayed_work_remaining_get(&lte_reconnect_work) > 0)
            {
                printk("LTE Reconnect work already scheduled\n");
            }
            else
            {
                scheduleLTEReconnect(lte_reconnection_delay_s[atomic_get(
                    &lte_reconnection_attempts)]);
            }
            break;
        }

        printk("Network registration status: %s\n",
               evt->nw_reg_status == LTE_LC_NW_REG_REGISTERED_HOME
                   ? "Connected - home network"
                   : "Connected - roaming");
        /* Notify main function that LTE is connected */
        lte_cb(LTE_CONNECTION_CONNECTED);

        k_sem_give(&lte_connected_sem);
        k_delayed_work_cancel(&lte_reconnect_work);
        atomic_set(&lte_reconnection_attempts, 0);
        lte_connected = true;
        break;

    case LTE_LC_EVT_PSM_UPDATE:
        printk("PSM parameter update: TAU: %d, Active time: %d\n",
               evt->psm_cfg.tau, evt->psm_cfg.active_time);
        break;

    case LTE_LC_EVT_RRC_UPDATE:
        printk("RRC mode: %s\n", evt->rrc_mode == LTE_LC_RRC_MODE_CONNECTED
                                     ? "Connected"
                                     : "Idle");
        break;

    case LTE_LC_EVT_CELL_UPDATE:
        printk("LTE cell changed: Cell ID: %d, Tracking area: %d\n",
               evt->cell.id, evt->cell.tac);
        last_cellID = evt->cell.id;
        last_tac    = evt->cell.tac;
        break;

    case LTE_LC_EVT_EDRX_UPDATE:
    default:
        break;
    }
}

 if ((err = lte_lc_connect_async(lte_handler)) != NBIOT_ERROR_OK)
    {
        printk("Modem could not be configured, error: %d\n", err);
        errorHandler_process(err);
    }

Thanks 

Parents Reply Children
  • Hi,

    Do you have a new issue with manually switching between networks now?

    i'm not facing any issue in manual switching.

    i have testing the network signal by using lte link monitor in that i have seen signal stringth between (-99dBm to -105dBm) is it a good signal? 

  • Hi Bhanu,

    Sorry for the late reply, we are understaffed due to summer vacation.

    If you refer to the filed test result Table 3 in the below link, -99dBm to -105dBm is weak but should be enough for the device to build an LTE-M connection.

    (+) LTE-M vs NB-IoT Field Test: How Distance Affects Power Consumption - Blogs - Nordic Blog - Nordic DevZone (nordicsemi.com)

    Best regards,

    Charlie

  • Hi,

    as i told earlier modem is showing LTE connected but its not sending data to AWS.

    -99dBm to -105dBm is weak but should be enough for the device to build an LTE-M connection.

    is that signal is enough to send data to AWS?

    recently i found one issue when its disconnected to let its not connecting again.for your reference i'm sending my handler code please check it if need changes let me know.

    static void lteReconnectWorkFn(struct k_work *work)
    {
        printk("LTE Link Reconnecting");
    
        lte_cb(LTE_CONNECTION_RECONNECTING);
    
        /* Try to connect to LTE and if not connected within timeout schedule a
         * reconnect and switch off modem */
        lteConnect();
    }
    
    static void lte_handler(const struct lte_lc_evt *const evt)
    {
        printf("lte handler %d\n",evt->type);
        switch (evt->type)
        {
        case LTE_LC_EVT_NW_REG_STATUS:
            if ((evt->nw_reg_status != LTE_LC_NW_REG_REGISTERED_HOME) &&
                (evt->nw_reg_status != LTE_LC_NW_REG_REGISTERED_ROAMING))
            {
                printk("Network registration status: %d\n", evt->nw_reg_status);
                if (!lte_connected)
                {
                    break;
                }
    
                lte_connected = false;
                /* Notify main function that LTE is disconnected */
                lte_cb(LTE_CONNECTION_DISCONNECTED);
                if (k_delayed_work_remaining_get(&lte_reconnect_work) > 0)
                {
                    printk("LTE Reconnect work already scheduled\n");
                }
                else
                {
                    scheduleLTEReconnect(lte_reconnection_delay_s[atomic_get(
                        &lte_reconnection_attempts)]);
                }
                break;
            }
    
            printk("Network registration status: %s\n",
                   evt->nw_reg_status == LTE_LC_NW_REG_REGISTERED_HOME
                       ? "Connected - home network"
                       : "Connected - roaming");
            /* Notify main function that LTE is connected */
            lte_cb(LTE_CONNECTION_CONNECTED);
    
            k_sem_give(&lte_connected_sem);
            k_delayed_work_cancel(&lte_reconnect_work);
            atomic_set(&lte_reconnection_attempts, 0);
            lte_connected = true;
            break;
    
        case LTE_LC_EVT_PSM_UPDATE:
            printk("PSM parameter update: TAU: %d, Active time: %d\n",
                   evt->psm_cfg.tau, evt->psm_cfg.active_time);
            break;
    
        case LTE_LC_EVT_RRC_UPDATE:
            printk("RRC mode: %s\n", evt->rrc_mode == LTE_LC_RRC_MODE_CONNECTED
                                         ? "Connected"
                                         : "Idle");
            break;
    
        case LTE_LC_EVT_CELL_UPDATE:
            printk("LTE cell changed: Cell ID: %d, Tracking area: %d\n",
                   evt->cell.id, evt->cell.tac);
            last_cellID = evt->cell.id;
            last_tac    = evt->cell.tac;
            break;
    
        case LTE_LC_EVT_EDRX_UPDATE:
        default:
            break;
        }
    }
    
    static void lteConnect(void)
    {
        int err = ERROR_OK;
    
        if ((err = lte_lc_connect_async(lte_handler)) != ERROR_OK)
        {
            printk("Modem could not be configured, error: %d\n", err);
            err = NBIOT_ERROR_MODEM_CONFIG;
            errorHandler_process(err);
        }
    
        err = k_sem_take(&lte_connected_sem, K_SECONDS(CONFIG_LTE_NETWORK_TIMEOUT));
    
        if (err == -EAGAIN)
        {
            printk("LTE connection could not be established within timeout. "
                   "Schedule another attempt after sleeping\n");
    
            scheduleLTEReconnect(
                lte_reconnection_delay_s[atomic_get(&lte_reconnection_attempts)]);
    
            /*  get the current sytem mode from api and fallback */
            int error = ERROR_OK;
            error     = lte_lc_system_mode_get(&get_sys_mode_current);
            printk("Got mode %d \n", get_sys_mode_current);
            if (!error)
            {
                if (get_sys_mode_current == LTE_LC_SYSTEM_MODE_NBIOT)
                {
                    char buff[25];
                    at_cmd_write(at_cops_0,buff,sizeof(buff),NULL);
                    printf("err:%s\n",buff);
    
                    printk("Current mode is NB-IoT and changing it to LTE-CAT1 : ");
                    /*  Set the fallback MODE to LTE */
                    int result = lte_lc_system_mode_set(LTE_LC_SYSTEM_MODE_LTEM);
                    printf("result:%d\n",result);
                    if (!result)
                    {
                        printk("Set mode done\n");
                        /*  Sleep for a while just to give some time to change mode
                         Not given in Documantation but trial and error  */
                        k_msleep(5000);
                    }
                }
                else if (get_sys_mode_current == LTE_LC_SYSTEM_MODE_LTEM)
                {
    
                    char buff[25];
                    at_cmd_write(at_cops_0,buff,sizeof(buff),NULL);
                    printf("err:%s\n",buff);
       
                    printk("Current mode is LTE-CAT1 and changing it to NB-IoT : ");
                    /*  Set the fallback MODE to NB-IoT */
                    int result = lte_lc_system_mode_set(LTE_LC_SYSTEM_MODE_NBIOT);
                    printf("result:%d\n",result);
                    if (!result)
                    {
                        printk("Set mode done\n");
                        /*  Sleep for a while just to give some time to change mode
                        Not given in Documantation but trial and error  */
                        k_msleep(5000);
                    }
                }
            }
    
            /* Switch off modem until next reconnection attempt */
            modem_offline();
            return;
        }
    
        /* Setup Power Saving Mode */
        if ((err = setup_psm()) != NBIOT_ERROR_OK)
        {
            errorHandler_process(err);
        }
    
        return;
    }
    
    
    int modem_configure(struct k_work_q *work_q,
                        const lte_conn_event_notify lte_conn_cb, rsrp_cb_t rsrp_cb,
                        rsrq_cb_t rsrq_cb)
    {
        int err;
        struct nrf_in_addr dns;
    
        /* Copy to local variables */
        modem_work_q = work_q;
        lte_cb       = lte_conn_cb;
    
        if ((err = modem_info_rsrp_rsrq_register(rsrp_cb, rsrq_cb)) !=ERROR_OK)
        {
            printk("Could not subscribe to signal strength notifications\n");
            err = NBIOT_ERROR_MODEM_AT;
            return err;
        }
    
        if ((err = modem_enableConnectionStats()) != ERROR_OK)
        {
            printk("Could not enable connection statistics, error: %d\n", err);
            return err;
        }
    
        /* Use static IP as there was some problem resolving DNS */
        dns.s_addr = GOOGLE_DNS_SERVER;
        err        = nrf_setdnsaddr(2, &dns);
        printk("Set DNS Address (%d)\r\n", err);
    
        /* Init LTE Reconnection work */
        k_delayed_work_init(&lte_reconnect_work, lteReconnectWorkFn);
    
        /* Initialize LTE connection */
        printk("LTE Link Initializing...\n");
        err = lte_lc_init();
        if (err)
        {
            printk("Modem could not be initialized, error: %d\n", err);
            return NBIOT_ERROR_MODEM_LTE_INIT;
        }
    
        /* Notify that we are trying to connect to LTE network */
        lte_cb(LTE_CONNECTION_CONNECTING);
    
        /* send details to Data strucre in case connection has been established
         in nbt itself */
    
        lte_lc_system_mode_get(&get_sys_mode_current);
        sensor_config.network_mode = get_sys_mode_current;
    
        /* Try to connect to LTE and if not connected within timeout schedule a
         * reconnect and switch off modem */
        lteConnect();
    
        return err;
    }

    thanks

  • Hi Bhanu,

    bhanu prakash said:
    is that signal is enough to send data to AWS?

    I am not sure. If something wrong happened during the communication, the debug log and modem trace can give some clues.

    Best regards,

    Charlie

  • Hi,

    the debug log and modem trace can give some clues.

    as we are using custom board we can't able to take modem trace.

    recently i found one issue when its disconnected to let its not connecting again.for your reference i'm sending my handler code please check it if need changes let me know.

    what about network reconnecting. once its disconnected its not connecting to network after a rest only its connecting

Related