<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to know if we have an IP address</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/71535/how-to-know-if-we-have-an-ip-address</link><description>Hello, 
 I am using the modem callback: 
 
 To check if the modem is connected using the following code: 
 
 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</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 11 Feb 2021 17:27:41 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/71535/how-to-know-if-we-have-an-ip-address" /><item><title>RE: How to know if we have an IP address</title><link>https://devzone.nordicsemi.com/thread/294054?ContentTypeID=1</link><pubDate>Thu, 11 Feb 2021 17:27:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:07a6f66f-6d30-4242-970a-38cc3564897d</guid><dc:creator>Depraz</dc:creator><description>&lt;p&gt;Thanks a lot&amp;nbsp;&lt;span&gt;H&amp;aring;kon!&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to know if we have an IP address</title><link>https://devzone.nordicsemi.com/thread/294051?ContentTypeID=1</link><pubDate>Thu, 11 Feb 2021 16:54:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:01f03191-fac1-492e-9200-89339a0d6ea8</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Depraz"]Thanks for your reply. I do not get how I can get this information in the callback[/quote]
&lt;p&gt;The lte_lc library unfortunately does not return CGEV notifications. I&amp;#39;ll input this internally as a feature request.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Depraz"]&lt;span&gt;Also, is there any higher level function that enables&amp;nbsp;&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/ref_at_commands/REF/at_commands/packet_domain/cgerep.html?cp=2_1_6_1"&gt;AT+CGEREP&lt;/a&gt;, notifications&lt;/span&gt;?[/quote]
&lt;p&gt;&amp;nbsp;You can use the at_notif library and register your own handler specifically filtering for the +CGEV notifications:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;modem/at_cmd.h&amp;gt;
#include &amp;lt;modem/at_notif.h&amp;gt;

static void at_handler(void *context, const char *response)
{
	if (response == NULL) {
		printk(&amp;quot;Response buffer is NULL-pointer&amp;quot;);
		return;
	}
	const char * cgev_notification_filter = &amp;quot;+CGEV:&amp;quot;;
	if (strncmp(cgev_notification_filter, response, strlen(cgev_notification_filter)) == 0) {
		printk(&amp;quot;Match for +CGEV notification\n&amp;quot;);
		printk(&amp;quot;Received notification %s\n&amp;quot;, 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(&amp;quot;Failed to initialize AT nofitication handler, err %d\n&amp;quot;, err);
	return err;
}
err = at_cmd_write(&amp;quot;AT+CGEREP=1&amp;quot;, NULL, 0, NULL);
if (err) {
	printk(&amp;quot;Unable to send AT command, err %d\n&amp;quot;, err);
	return err;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I implemented the above simplistic filtering in https_client (ncs v1.4.2), here&amp;#39;s a patch file:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/cgev_5F00_notifications.patch"&gt;devzone.nordicsemi.com/.../cgev_5F00_notifications.patch&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;store this .patch file to ../path/to/ncs/nrf/ and apply it using git:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;git apply cgev_notifications.patch&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s the output from the sample:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;*** 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

&amp;gt;        HTTP/1.1 200 OK

Finished, closing socket.

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to know if we have an IP address</title><link>https://devzone.nordicsemi.com/thread/293970?ContentTypeID=1</link><pubDate>Thu, 11 Feb 2021 12:07:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4f380376-8cd4-4338-a683-df717e35732d</guid><dc:creator>Depraz</dc:creator><description>&lt;p&gt;Hello&amp;nbsp;&lt;span&gt;H&amp;aring;kon,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks for your reply. I do not get how I can get this information in the callback&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;typedef void(*lte_lc_evt_handler_t)(const struct lte_lc_evt *const evt);&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;lte_lc_evt seems to give me only access to:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;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;
	};
};&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;What would be the event type I should look for?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;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&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Also, is there any higher level function that enables&amp;nbsp;&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/ref_at_commands/REF/at_commands/packet_domain/cgerep.html?cp=2_1_6_1"&gt;AT+CGEREP&lt;/a&gt;, notifications&lt;/span&gt;?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to know if we have an IP address</title><link>https://devzone.nordicsemi.com/thread/293966?ContentTypeID=1</link><pubDate>Thu, 11 Feb 2021 12:00:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c4bf3047-2198-44ea-8b48-ee9df70ddb32</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you enable notifications in &lt;a href="https://infocenter.nordicsemi.com/topic/ref_at_commands/REF/at_commands/packet_domain/cgerep.html?cp=2_1_6_1"&gt;AT+CGEREP&lt;/a&gt;, you should get a notification when the default PDN connection has changed from the +CGEV notification:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ref_at_commands/REF/at_commands/packet_domain/cgev.html?cp=2_1_6_2"&gt;https://infocenter.nordicsemi.com/topic/ref_at_commands/REF/at_commands/packet_domain/cgev.html?cp=2_1_6_2&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s an example from at_client:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;+CGEV: ME PDN ACT 0
+CGEV: IPV6 0

# manually querying
AT+CGDCONT?
+CGDCONT: 0,&amp;quot;IPV4V6&amp;quot;,&amp;quot;telenor.iot&amp;quot;,&amp;quot;10.x.y.z 1234:1234:1234::1234&amp;quot;,0,0
OK&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>