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

Thingy91: Wait until connected

Hi,

I am using the Thingy 91 and I have a program, where I first read GPS, then switch to NBIoT Mode and then send the data to a server.

However if I switch the Antenna to NBIoT Mode, I have to wait a certain amount of time until the Thingy 91 has connected to a NB-IoT tower. Otherwise there is an error and the program stops working. So I let the Thingy91 wait for 30 seconds and then it has hopefully connected, otherwise there is an error.

Is there an option to check if the Thingy91 has already connected to the NB-IoT Tower/the Internet?

Because then the program would be much more reliable and faster.

Thanks for your help and answers!

Parents
  • Hi,

    Adding a bit to Heidi's answer, if you want to use a higher level of abstraction in your application.

    nRF Connect SDK offers a convenience library for LTE link control: https://github.com/NordicPlayground/fw-nrfconnect-nrf/blob/master/include/lte_lc.h

    It offers, among other things, APIs to set modem's system mode and connect/disconnect to LTE network.
    To enable it, set CONFIG_LTE_LINK_CONTROL=y in your prj.conf and include the header file.
    If you don't want the library to automatically to connect to LTE network on boot, you need to set the following:
    CONFIG_LTE_AUTO_INIT_AND_CONNECT=n

    I think relevant functions for you to achieve what you want are for example:


    lte_lc_system_mode_set(LTE_LC_SYSTEM_MODE_GPS);
    
    lte_lc_normal();
    
    // Do GPS stuff
    
    lte_lc_offline();
    
    lte_lc_system_mode_set(LTE_LC_SYSTEM_MODE_NBIOT);
    
    // Blocking call, tries to connect for 10 minutes by default
    lte_lc_init_and_connect();
    
    // Wait for LTE connection...
    


    Best regards,

    Jan Tore

Reply
  • Hi,

    Adding a bit to Heidi's answer, if you want to use a higher level of abstraction in your application.

    nRF Connect SDK offers a convenience library for LTE link control: https://github.com/NordicPlayground/fw-nrfconnect-nrf/blob/master/include/lte_lc.h

    It offers, among other things, APIs to set modem's system mode and connect/disconnect to LTE network.
    To enable it, set CONFIG_LTE_LINK_CONTROL=y in your prj.conf and include the header file.
    If you don't want the library to automatically to connect to LTE network on boot, you need to set the following:
    CONFIG_LTE_AUTO_INIT_AND_CONNECT=n

    I think relevant functions for you to achieve what you want are for example:


    lte_lc_system_mode_set(LTE_LC_SYSTEM_MODE_GPS);
    
    lte_lc_normal();
    
    // Do GPS stuff
    
    lte_lc_offline();
    
    lte_lc_system_mode_set(LTE_LC_SYSTEM_MODE_NBIOT);
    
    // Blocking call, tries to connect for 10 minutes by default
    lte_lc_init_and_connect();
    
    // Wait for LTE connection...
    


    Best regards,

    Jan Tore

Children
Related