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

How to know if we have an IP address

Hello,

I am using the modem callback:

typedef void(*lte_lc_evt_handler_t)(const struct lte_lc_evt *const evt);

To check if the modem is connected using the following code:

if evt->type == LTE_LC_EVT_NW_REG_STATUS
    isConnected = evt->nw_reg_status == LTE_LC_NW_REG_REGISTERED_HOME;

However, as far as I understood this only indicates that the modem radio is on, it does not indicate that the modem has an IP address and can connect to a server. To have this details, I need to use the AT command  CGPADDR.

Is there any way I can update the callback to make sure the modem got an IP address? I do not need to know which address it received.

Thanks

Parents
  • Hi,

     

    If you enable notifications in AT+CGEREP, you should get a notification when the default PDN connection has changed from the +CGEV notification:

    https://infocenter.nordicsemi.com/topic/ref_at_commands/REF/at_commands/packet_domain/cgev.html?cp=2_1_6_2

     

    Here's an example from at_client:

    +CGEV: ME PDN ACT 0
    +CGEV: IPV6 0
    
    # manually querying
    AT+CGDCONT?
    +CGDCONT: 0,"IPV4V6","telenor.iot","10.x.y.z 1234:1234:1234::1234",0,0
    OK

     

    Kind regards,

    Håkon

  • Hello Håkon,

    Thanks for your reply. I do not get how I can get this information in the callback

    typedef void(*lte_lc_evt_handler_t)(const struct lte_lc_evt *const evt);

    lte_lc_evt seems to give me only access to:

    struct lte_lc_evt {
    	enum lte_lc_evt_type type;
    	union {
    		enum lte_lc_nw_reg_status nw_reg_status;
    		enum lte_lc_rrc_mode rrc_mode;
    		struct lte_lc_psm_cfg psm_cfg;
    		struct lte_lc_edrx_cfg edrx_cfg;
    		struct lte_lc_cell cell;
    	};
    };

    What would be the event type I should look for?

    LTE_LC_EVT_NW_REG_STATUS
    LTE_LC_EVT_PSM_UPDATE
    LTE_LC_EVT_EDRX_UPDATE
    LTE_LC_EVT_RRC_UPDATE
    LTE_LC_EVT_CELL_UPDATE

    Also, is there any higher level function that enables  AT+CGEREP, notifications?

  • Hi,

     

    Depraz said:
    Thanks for your reply. I do not get how I can get this information in the callback

    The lte_lc library unfortunately does not return CGEV notifications. I'll input this internally as a feature request. 

     

    Depraz said:
    Also, is there any higher level function that enables  AT+CGEREP, notifications?

     You can use the at_notif library and register your own handler specifically filtering for the +CGEV notifications:

    #include <modem/at_cmd.h>
    #include <modem/at_notif.h>
    
    static void at_handler(void *context, const char *response)
    {
    	if (response == NULL) {
    		printk("Response buffer is NULL-pointer");
    		return;
    	}
    	const char * cgev_notification_filter = "+CGEV:";
    	if (strncmp(cgev_notification_filter, response, strlen(cgev_notification_filter)) == 0) {
    		printk("Match for +CGEV notification\n");
    		printk("Received notification %s\n", response);
    	}
    
    }
    
    /* Place these calls after bsdlib init, but before lte_lc_init_and_connect() */
    err = at_notif_register_handler(NULL, at_handler);
    if (err) {
    	printk("Failed to initialize AT nofitication handler, err %d\n", err);
    	return err;
    }
    err = at_cmd_write("AT+CGEREP=1", NULL, 0, NULL);
    if (err) {
    	printk("Unable to send AT command, err %d\n", err);
    	return err;
    }

     

    I implemented the above simplistic filtering in https_client (ncs v1.4.2), here's a patch file:

    cgev_notifications.patch

     

    store this .patch file to ../path/to/ncs/nrf/ and apply it using git:

    git apply cgev_notifications.patch

     

    Here's the output from the sample:

    *** Booting Zephyr OS build v2.4.0-ncs2  ***
    HTTPS client sample started
    Provisioning certificate
    Waiting for network.. Match for +CGEV notification
    Received notification +CGEV: ME PDN ACT 0
    
    OK
    Match for +CGEV notification
    Received notification +CGEV: IPV6 0
    
    Connecting to google.com
    Sent 64 bytes
    Received 892 bytes
    
    >        HTTP/1.1 200 OK
    
    Finished, closing socket.
    
    

     

    Kind regards,

    Håkon

Reply Children
No Data
Related