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

lte_lc_system_mode_set(); not sticking

I want to change between LTE-M and NB-IOT, however lte_lc_system_mode_set(); is not actually changing the mode.

I am doing something like this

//lte_lc_system_mode_set(LTE_LC_SYSTEM_MODE_LTEM);
lte_lc_init();
//lte_lc_system_mode_set(LTE_LC_SYSTEM_MODE_LTEM);
lte_lc_connect();
	if (err)
	{
        //lte_lc_system_mode_set(LTE_LC_SYSTEM_MODE_LTEM);
	}
lte_lc_offline();

I can't rely on PSM/eDRX hence I am switching the modem on/off when I have to send something.

The Kconfig is set to NB-IOT with fallback disabled.

When lte_lc_connect() is called it ignores the mode setting and uses NB-IOT.

What do I have to do?

Parents
  • In lte_lc.c:

    enum lte_lc_system_mode current_network_mode = sys_mode_preferred;

    where sys_mode_preferred is declared const.

    So basically, lte_lc_system_mode_set() does not work with lte_lc_connect().

    Is this on purpose? It would be fairly easy to get the current system mode and use that instead of the const.

  • Hi Daniel,
    You cannot change the mode when the modem is active. (lte_lc_connect())
    The mode selection needs to be selected when the modem is offline. 
    So if you select the mode after you have set the modem in offline mode (lte_lc_offline) then you are good.



    Best regards,

    Martin L.

  • Please use our samples as reference, that implementation will not work. 
    e.g. lte_lc_init() should only be needed to be done once.

    Applications usually have it's own "modem_configure" function where this is set.

    You need to wait a bit after you have set the modem in offline mode. (it needs to de-attach from the network)

  • I got it to work with the 1.3.99 SDK - was a bug in 1.3.0 (I messed up and checked out the wrong repo when installing manually).

    I should add some funny things:

    With 1.3.99 I can shutdown the BSDlib (can't remember the command now) and poweroff the modem, which gives a connection timeout when trying to re-init/connect. However, if I just ignore the timeout error, I can still send data to my server thus not needing to power cycle the whole board.

    Isn't it funny that a connection is actually established even though a timeout error is returned?

    Anywho, I am not doing it like that now, just found it interesting Slight smile

    And I should add that my implementation actually does work - even though it is perhaps not intended to?

  • Hi Daniel,
    note: the name "1.3.99" just indicates the master branch which is constantly updated. 
    (E.g. whats in the master branch today will be available in the tagged v1.4.0 release).

    I am glad that you got it working.

    Could you explain more in detail what you are seeing and what you are doing so that I could possibly replicate this on my side.
    To check if this is intended behavior or if this could be something that we need to investigate and fix in NCS.

    Best regards,
    martin L.

  • This is close to what I am doing:

    int reset_modem(void)
    {
        printk("Power off modem\r\n");
        lte_lc_power_off();
        k_msleep(10000);
        printk("BSD shutdown\r\n");
        bsdlib_shutdown();
        printk("BSD init\r\n");
        bsdlib_init();
        printk("LTE init\r\n");
        lte_lc_init(); // Don't think this does anything
        printk("LTE normal\r\n");
        lte_lc_normal();
        printk("Offline modem\r\n");
        lte_lc_offline();
    
        if (get_systemmode() == 1) // This actually doesn't work beyond the first 3 iterations
        {
            printk("\r\nSwitch to NB-IoT\r\n");
            lte_lc_system_mode_set(LTE_LC_SYSTEM_MODE_NBIOT);
        }
        else
        {
            printk("\r\nSwitch to LTE-M\r\n");
            lte_lc_system_mode_set(LTE_LC_SYSTEM_MODE_LTEM);
        }
    
        k_msleep(2000);
        return 0;
    }
    
    err = bsdlib_init();
    err = at_cmd_init();
    err = at_notif_init();
    err = lte_lc_init();
    
    while (1)
    {
        err = lte_lc_connect();
        if (err)
        {
            printk("LTE timeout\r\n");
            rsrp = 0;
            lte_lc_system_mode_set(OTHERMODE); // Comment this line if using reset_modem()
        }
    
        rsrp = app_http_start(); // Custom function for sending HTTP data
    
        lte_lc_offline();
    
        //reset_modem();
    }

    It works with the switching only the first 3 times. However, even with the timeout, it continues to be able to send data to our server.

  • Hi Daniel,
    Your code seems very "overkill" and should be cut down a good bit.

    When "resetting" the modem you only need to put it first in "offline mode" (then change the systemmode if needed) and then set it in "normal mode" afterwords.

    You should not need to run the bsdlibshutdown and lte_lc_init etc. more than once. 

Reply Children
No Data
Related