<?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>Connecting an nRF9160 to AWS</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/46764/connecting-an-nrf9160-to-aws</link><description>Hello, 
 I&amp;#39;m attempting to connect the nRF9160 DK to our AWS IoT account. I&amp;#39;ve been following the information in this question: https://devzone.nordicsemi.com/f/nordic-q-a/44528/switch-cloud-endpoint-from-nordic-aws-to-our-own-aws-account but I&amp;#39;m having</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 30 May 2019 16:11:05 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/46764/connecting-an-nrf9160-to-aws" /><item><title>RE: Connecting an nRF9160 to AWS</title><link>https://devzone.nordicsemi.com/thread/190092?ContentTypeID=1</link><pubDate>Thu, 30 May 2019 16:11:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:af9fcd1d-d17b-43e9-9ff8-f05480673b29</guid><dc:creator>MJD093</dc:creator><description>&lt;p&gt;Thanks H&amp;aring;kon&lt;/p&gt;
&lt;p&gt;I can confirm that the nRF9160 is sending data to our AWS EC2 instance via the NB-IoT network.&lt;/p&gt;
&lt;p&gt;Many thanks for your support.&lt;/p&gt;
&lt;p&gt;Michael&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting an nRF9160 to AWS</title><link>https://devzone.nordicsemi.com/thread/189820?ContentTypeID=1</link><pubDate>Wed, 29 May 2019 09:23:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fc94bcbe-970a-456e-8e17-f4a74730aa37</guid><dc:creator>MJD093</dc:creator><description>[quote userid="2115" url="~/f/nordic-q-a/46764/connecting-an-nrf9160-to-aws/189794"]CONFIG_MAIN_STACK_SIZE=4096[/quote]
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Ok so that solved the hard fault error but the main program still doesn&amp;#39;t seem to load into the main loop. Device boots up Zephyr and then, nothing. Link Monitor just ends there. No printk for the application starting nor any other printks for errors or ones added to check liveness.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;10 NRF_EGU2		Non-Secure	OK
11 NRF_TWIM2		Non-Secure	OK
12 NRF_SPIM3		Non-Secure	OK
13 NRF_TIMER0		Non-Secure	OK
14 NRF_TIMER1		Non-Secure	OK
15 NRF_TIMER2		Non-Secure	OK
16 NRF_SAADC		Non-Secure	OK
17 NRF_GPIOTE1		Non-Secure	OK

SPM: NS image at 0x8000
SPM: NS MSP at 0x20023688
SPM: NS reset vector at 0xd8fd
SPM: prepare to jump to Non-Secure image.
***** Booting Zephyr OS v1.14.99-ncs1-3-g3c4f27282002 *****&lt;/pre&gt;&lt;/p&gt;
[quote userid="2115" url="~/f/nordic-q-a/46764/connecting-an-nrf9160-to-aws/189794"]Have you removed all the socket APIs, and used the nrf_* prefixed function calls?[/quote]
&lt;p&gt;I believe so yes, I have edited all socket commands to use the nrf_* prefixed versions found in nrf_socket.h. &amp;lt;net/sockets&amp;gt; has been removed and should flag errors if I try to call any non-nrf_* socket commands.&lt;/p&gt;
&lt;p&gt;I have been doing some reading into the Socket API and in any example, this is the way the connect API is called and its arguments are set. Not sure why it would return EINVAL.&lt;/p&gt;
[quote userid="2115" url="~/f/nordic-q-a/46764/connecting-an-nrf9160-to-aws/189794"]&amp;nbsp;This is due to byte ordering on ARM vs. x86. The function in firmware is correct for ARM LE arch.[/quote]
&lt;p&gt;Ok, I have returned that function back to the way it is set in the ftp example.&lt;/p&gt;
[quote userid="2115" url="~/f/nordic-q-a/46764/connecting-an-nrf9160-to-aws/189794"]&amp;nbsp;No nrf_* prefixed structs or function calls? I am very unsure what this errno is, as there&amp;#39;s nothing that should set it to this value. How are you printing the errno?[/quote]
&lt;p&gt;None. As mentioned before, in this example I no longer include nrf_socket.h so all references to nrf_* prefixed commands cause compilation errors.&lt;/p&gt;
&lt;p&gt;Unless I&amp;#39;m mistaken, errno is just an int value that is defined in errno.h to represent different error types. So I have just been printing err and errno as:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;	printk(&amp;quot;Attempting to establish connection to EC2\n&amp;quot;);
	do {
		err = connect(UDP_Socket, (struct sockaddr *)&amp;amp;UDP_sockaddr, sizeof(UDP_sockaddr));
	} while (err &amp;lt; 0 &amp;amp;&amp;amp; errno == EAGAIN);

		printk(&amp;quot;Connect Error: %d:%d\n&amp;quot;, err, errno);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;When in the code for the nrf_* prefixed version, it returns this value, err = -1 and errno = 22:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Timer trigger for UDPSend!
Socket ID: 2
Socket created for transfer
Attempting to establish connection to EC2
Connect Error: -1:22
Failure to establish connection via nrf_connect, closing socket&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;When in the code for the non-nrf_* version, it returns this value, err = -1 and errno = 134:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Socket ID: 2
Socket created for transfer
Attempting to establish connection to EC2
Connect Error: -1:134
Failure to establish connection via nrf_connect, closing socket&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;EDIT:&lt;/p&gt;
&lt;p&gt;I think I got the error. This is UDP and connect() is supposed to auto return immediately under DGRAM. It&amp;#39;s not supposed to take any time to connect so blocking isn&amp;#39;t necessary as all connect() does for UDP is assign a destination address to the socket without attempting to request a connection and receive an ACK back. Blocking makes sense from the examples as they used TCP Sockets.&lt;/p&gt;
&lt;p&gt;As for the connect() failing with err = -1, I believe it was the line:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;struct sockaddr_in *UDP_sockaddr = &amp;amp;my_sockaddr;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Removing the * and making a sole struct with [struct sockaddr_in UDP_sockaddr] seems to let err = 0 and errno = 0.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;	int err;
	int UDP_Socket;

	// Sets up UDP Socket information
	struct sockaddr_in UDP_sockaddr;
	UDP_sockaddr.sin_port						=		htons(xxxx);              	/**&amp;lt; Port, in network byte order */
	UDP_sockaddr.sin_family 				=		AF_INET;            				/**&amp;lt; Socket family, IPv4 socket */
	UDP_sockaddr.sin_addr.s_addr	  = 	inet_addr(xx,xx,xxx,xx);		/**&amp;lt; IPv4 address, in hex format */
	printk(&amp;quot;IP address: %x\n&amp;quot;, UDP_sockaddr.sin_addr.s_addr);

	UDP_Socket = socket(AF_INET, SOCK_DGRAM, 0); //Opens UDP socket using UDP protocols&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I am also curious if errno is actually cleared between functions as send() will fail on my test kit as it can&amp;#39;t actually attach to a network to execute the send() command. As send() fails it reports errno as 114 which then appears for the connect() function&amp;#39;s errno when it is called again, Setting errno = 0 after the send() function errors out shows that errno still is 0 (and not 114) when connect is called during the next timer trigger.&lt;/p&gt;
&lt;p&gt;The new Link Monitor output is:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;16 NRF_SAADC		Non-Secure	OK
17 NRF_GPIOTE1		Non-Secure	OK

SPM: NS image at 0x8000
SPM: NS MSP at 0x200232e8
SPM: NS reset vector at 0xd97d
SPM: prepare to jump to Non-Secure image.
***** Booting Zephyr OS v1.14.99-ncs1-3-g3c4f27282002 *****
UDP_Test Application started
Socket ID: 2
Sending AT command: AT+CFUN=4
Modem response: OK
Sending AT command: AT%XSYSTEMMODE=0,1,0,0
Modem response: OK
Sending AT command: AT%XMAGPIO
Modem response: OK
Sending AT command: AT+CFUN=1
Modem response: OK
Modem enabled
IP address: XXXXXXXX
Socket created for init
Socket ID: 2
Attempting to establish connection to EC2
Connect Error: 0:0
Config and Connect Successful
Socket ID: 2
Socket created for transfer
Attempting to establish connection to EC2
Connect Error: 0:0
Send socket connected
Error sending Hello AWS
 to IP XXXXXXXX
Send Error: -1:114
Dropping into main while loop
Timer trigger for UDPSend!
Socket ID: 2
Socket created for transfer
Attempting to establish connection to EC2
Connect Error: 0:0
Send socket connected
Error sending Timer Trigger
 to IP XXXXXXXX
Send Error: -1:114
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Happily, this has also solved the issue where sockets would start to fail to be created (even though the sockets were closing after failing out) after about 7 timer calls. I hope to be able to test this bit of code soon when the remote kit in an NB-IoT area is available tomorrow. Will update when I test it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting an nRF9160 to AWS</title><link>https://devzone.nordicsemi.com/thread/189794?ContentTypeID=1</link><pubDate>Wed, 29 May 2019 08:44:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2e2519bd-22fa-4b6d-8173-60e293f7c8e2</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;&amp;nbsp;&lt;/p&gt;
[quote user="MJD093"]I tried the ftp example, both as it is in the repo and edited. The code doesn&amp;#39;t make it past boot up. The printk() line for the application start does not get sent to the link monitor, program just hard faults again. Error fault address at 0x0[/quote]
&lt;p&gt;&amp;nbsp;Sorry, this is an issue with the newer code base, where it requires a higher stack size for the main thread. Could you try to add this line to the prj.conf and see if it helps?&lt;/p&gt;
&lt;p&gt;CONFIG_MAIN_STACK_SIZE=4096&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="MJD093"]I have gone back to my original program that was giving back the errno 134. Taking what you said, I have removed all &amp;lt;net/socket&amp;gt; commands and used only the nrf_socket library. The code now reports an errno of 22 which I believe is EINVAL (invalid argument) so at least it&amp;#39;s not erroring an unknown value for errno.[/quote]
&lt;p&gt;Have you removed all the socket APIs, and used the nrf_* prefixed function calls?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="MJD093"]Also, a question about the ftp code. In that code there is a converter for IP to Hex, inet_addr(). I implimented this into my code and printed the result to find that the IP address was backwards from what I expected it to be using manual conversion or something like &lt;a href="https://www.browserling.com/tools/ip-to-hex"&gt;https://www.browserling.com/tools/ip-to-hex&lt;/a&gt; . I have amended the function to put the bytes in the order I would expect but just want to check, is it supposed to be that way or is that an oversight in this checkout?[/quote]
&lt;p&gt;&amp;nbsp;This is due to byte ordering on ARM vs. x86. The function in firmware is correct for ARM LE arch.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="MJD093"]I made a seperate version of the code that uses only the net/sockets.h library (like all examples of the nRF9160&amp;#39;s data transfer capablities), it is doing the same as before, errno is 134 again. I&amp;#39;m not sure what else needs to be done to make this code block until connection.[/quote]
&lt;p&gt;&amp;nbsp;No nrf_* prefixed structs or function calls? I am very unsure what this errno is, as there&amp;#39;s nothing that should set it to this value. How are you printing the errno?&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: Connecting an nRF9160 to AWS</title><link>https://devzone.nordicsemi.com/thread/189551?ContentTypeID=1</link><pubDate>Tue, 28 May 2019 09:52:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:52628ddf-9081-4203-9a34-7e353b73a91c</guid><dc:creator>MJD093</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I tried the ftp example, both as it is in the repo and edited. The code doesn&amp;#39;t make it past boot up. The printk() line for the application start does not get sent to the link monitor, program just hard faults again. Error fault address at 0x0&lt;/p&gt;
&lt;p&gt;You are correct, my provider does not support anything other than a whitelisted IP address given to them in advance.&lt;/p&gt;
&lt;p&gt;I have gone back to my original program that was giving back the errno 134. Taking what you said, I have removed all &amp;lt;net/socket&amp;gt; commands and used only the nrf_socket library. The code now reports an errno of 22 which I believe is EINVAL (invalid argument) so at least it&amp;#39;s not erroring an unknown value for errno.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;***** Booting Zephyr OS v1.14.99-ncs1-3-g3c4f27282002 *****
UDP_Test Application started
Socket ID: 2
Modem enabled
Socket created for init
Socket ID: 2
Attempting to establish connection to EC2
Connect Error: -1:22
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Arguments passed to blocking_connect():&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;	int err;
	int UDP_Socket;
	ssize_t bytes_sent;

	struct nrf_sockaddr_in my_sockaddr; // memset if not populating everything
	struct nrf_sockaddr_in *UDP_sockaddr = &amp;amp;my_sockaddr;
	UDP_sockaddr-&amp;gt;sin_len 					=		sizeof(struct nrf_sockaddr_in);			/**&amp;lt; Length of this data structure */
	UDP_sockaddr-&amp;gt;sin_port					=		NRF_HTONS(xxxxx);              	        /**&amp;lt; Port, in network byte order */
	UDP_sockaddr-&amp;gt;sin_family 				=		NRF_AF_INET;            				/**&amp;lt; Socket family, IPv4 socket */
	UDP_sockaddr-&amp;gt;sin_addr.s_addr	  = 	0xXXXXXXXX;							    /**&amp;lt; IPv4 address, in hex format */

	UDP_Socket = nrf_socket(NRF_AF_INET, NRF_SOCK_DGRAM, 0);
	printk(&amp;quot;Socket ID: %d\n&amp;quot;, UDP_Socket);
	if (UDP_Socket == -1)
	{
		printk(&amp;quot;Socket failed to open\n&amp;quot;);
		return -EFAULT;
	}
	else
	{
		printk(&amp;quot;Socket created for transfer\n&amp;quot;);
	}

	err = blocking_connect(UDP_Socket, (struct nrf_sockaddr *)&amp;amp;UDP_sockaddr, sizeof(struct nrf_sockaddr_in));&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I also want to check the required prj.conf in case this is also causing issues; apologises if this is all wrong, never used this kind of file structure before and I&amp;#39;m piecing it together with what I learn from the other examples. Unlike the other examples, I&amp;#39;m not calling Link Control as the code should manually init the modem (it needs to be able to do this to change between NB-IoT and GPS later). The one I&amp;#39;m currently using is:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;# Use the development test RNG (not for production)
CONFIG_TEST_RANDOM_GENERATOR=y

# Networking, enable networking APIs
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_SOCKETS=y

# Allow Socket APIs to use POSIX names like socket(), send(), etc
# Careful with close(), close() only works on sockets when enabled
CONFIG_NET_SOCKETS_POSIX_NAMES=y

# BSD library
CONFIG_BSD_LIBRARY=y

# Main thread, reuse init stack
CONFIG_MAIN_THREAD_PRIORITY=7
CONFIG_MAIN_STACK_SIZE=4096

# Available memory for k_malloc
CONFIG_HEAP_MEM_POOL_SIZE=1024

# Enable stdout for printfs
CONFIG_STDOUT_CONSOLE=y

# Logging
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=4

# Build with newlib c library
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y

# Enable non-secure firmware as Normal mode
CONFIG_TRUSTED_EXECUTION_NONSECURE=y
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Also, a question about the ftp code. In that code there is a converter for IP to Hex, inet_addr(). I implimented this into my code and printed the result to find that the IP address was backwards from what I expected it to be using manual conversion or something like &lt;a href="https://www.browserling.com/tools/ip-to-hex"&gt;https://www.browserling.com/tools/ip-to-hex&lt;/a&gt; . I have amended the function to put the bytes in the order I would expect but just want to check, is it supposed to be that way or is that an oversight in this checkout?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Michael&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;EDIT:&lt;/p&gt;
&lt;p&gt;I made a seperate version of the code that uses only the net/sockets.h library (like all examples of the nRF9160&amp;#39;s data transfer capablities), it is doing the same as before, errno is 134 again. I&amp;#39;m not sure what else needs to be done to make this code block until connection.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting an nRF9160 to AWS</title><link>https://devzone.nordicsemi.com/thread/189279?ContentTypeID=1</link><pubDate>Mon, 27 May 2019 11:12:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:065104cf-7687-44a2-9c57-414c5212e0aa</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;the getaddrinfo fails, indicating that your telecom provider might not&amp;nbsp;provide DNS.&lt;/p&gt;
&lt;p&gt;You could try the ftp example in the same repository, as it hardcodes the IP to ftp.uninett.no.&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: Connecting an nRF9160 to AWS</title><link>https://devzone.nordicsemi.com/thread/189025?ContentTypeID=1</link><pubDate>Fri, 24 May 2019 11:53:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c69768bb-b91e-4c28-90e3-fb1fceca1524</guid><dc:creator>MJD093</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I copied across the files for the ntp example and ran it as it is in the repo.&lt;/p&gt;
&lt;p&gt;Did it require a specific checkout of the supporting repos (Zephyr, MCUBoot, nrfxlib)?&lt;/p&gt;
&lt;p&gt;Running it as is ended with a bus fault after getaddrinfo. Never made it to socket creation.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;***** Booting Zephyr OS v1.14.99-ncs1-3-g3c4f27282002 *****
Flash region		Domain		Permissions
00 0x00000 0x08000 	Secure		rwxl
01 0x08000 0x10000 	Non-Secure	rwxl
02 0x10000 0x18000 	Non-Secure	rwxl
03 0x18000 0x20000 	Non-Secure	rwxl
04 0x20000 0x28000 	Non-Secure	rwxl
05 0x28000 0x30000 	Non-Secure	rwxl
06 0x30000 0x38000 	Non-Secure	rwxl
07 0x38000 0x40000 	Non-Secure	rwxl
08 0x40000 0x48000 	Non-Secure	rwxl
09 0x48000 0x50000 	Non-Secure	rwxl
10 0x50000 0x58000 	Non-Secure	rwxl
11 0x58000 0x60000 	Non-Secure00 	Non-Secure	rwxl
13 0x68000 0x70000 	Non-Secure	rwxl
14 0x70000 0x78000 	Non-Secure	rwxl
15 0x78000 0x80000 	Non-Secure	rwxl
16 0x80000 0x88000 	Non-Secure	rwxl
17 0x88000 0x90000 	Non-Secure	rwxl
18 0x90000 0x98000 	Non-Secure	rwxl
19 0x98000 0xa0000 	Non-Secure	rwxl
20 0xa0000 0xa8000 	Non-Secure	rwxl
21 0xa8000 0xb0000 	Non-Secure	rwxl
22 0xb0000 0xb8000 	Non-Secure	rwxl
23 0xb8000 0xc0000 	Non-Secure	rwxl
24 0xc0000 0xc8000 	Non-Secure	rwxl
25 0xc8000 0xd0000 	Non-Secure	rwxl
26 0xd0000 0xd8000 	Non-Secure	rwxl
27 0xd8000 0xe0000 	Non-Secure	rwxl
28 0xe0000 0xe8000 	Non-Secure	rwxl
29 0xe8000 0xf0000 	Non-Secure	rwxl
30 0xf0000 0xf8000 	Non-Secure	rwxl
31 0xf8000 0x100000 	Non-Secure	rwxl

SRAM region		Domain		Permissions
00 0x00000 0x02000	Secure		rwxl
01 0x02000 0x04000	Secure		rwxl
02 0x04000 0x06000	Secure		rwxl
03 0x06000 0x08000	Secure		rwxl
04 0x08000 0x0a000	Secure		rwxl
05 0x0a000 0x0c000	Secure		rwxl
06 0x0c000 0x0e000	Secure		rwxl
07 0x0e000 0x10000	Secure		rwxl
08 0x10000 0x12000	Non-Secure	rwxl
09 0x12000 0x14000	Non-Secure	rwxl
10 0x14000 0x16000	Non-Secure	rwxl
11 0x16000 0x18000	Non-Secure	rwxl
12 0x18000 0x1a000	Non-Secure	rwxl
13 0x1a000 0x1c000	Non-Secure	rwxl
14 0x1c000 0x1e000	Non-Secure	rwxl
15 0x1e000 0x20000	Non-Secure	rwxl
16 0x20000 0x22000	Non-Secure	rwxl
17 0x22000 0x24000	Non-Secure	rwxl
18 0x24000 0x26000	Non-Secure	rwxl
19 0x26000 0x28000	Non-Secure	rwxl
20 0x28000 0x2a000	Non-Secure	rwxl
21 0x2a000 0x2c000	Non-Secure	rwxl
22 0x2c000 0x2e000	Non-Secure	rwxl
23 0x2e000 0x30000	Non-Secure	rwxl
24 0x30000 0x32000	Non-Secure	rwxl
25 0x32000 0x34000	Non-Secure	rwxl
26 0x34000 0x36000	Non-Secure	rwxl
27 0x36000 0x38000	Non-Secure	rwxl
28 0x38000 0x3a000	Non-Secure	rwxl
29 0x3a000 0x3c000	Non-Secure	rwxl
30 0x3c000 0x3e000	Non-Secure	rwxl
31 0x3e000 0x40000	Non-Secure	rwxl

Peripheral		Domain		Status
00 NRF_P0		Non-Secure	OK
01 NRF_CLOCK		Non-Secure	OK
02 NRF_RTC1		Non-Secure	OK
03 NRF_NVMC		Non-Secure	OK
04 NRF_UARTE1		Non-Secure	OK
05 NRF_UARTE2		Secure		SKIP
06 NRF_IPC		Non-Secure	OK
07 NRF_VMC		Non-Secure	OK
08 NRF_FPU		Non-Secure	OK
09 NRF_EGU1		Non-Secure	OK
10 NRF_EGU2		Non-Secure	OK
11 NRF_TWIM2		Non-Secure	OK
12 NRF_SPIM3		Non-Secure	OK
13 NRF_TIMER0		Non-Secure	OK
14 NRF_TIMER1		Non-Secure	OK
15 NRF_TIMER2		Non-Secure	OK
16 NRF_SAADC		Non-Secure	OK
17 NRF_GPIOTE1		Non-Secure	OK

SPM: NS image at 0x8000
SPM: NS MSP at 0x200232d0
SPM: NS reset vector at 0xedd9
SPM: prepare to jump to Non-Secure image.
***** Booting Zephyr OS v1.14.99-ncs1-3-g3c4f27282002 *****
getaddrinfo err: 22

Exception occurred in Secure State
***** HARD FAULT *****
  Fault escalation (see below)
***** BUS FAULT *****
  Precise data bus error
  BFAR Address: 0x50008120
***** Hardware exception *****
Current thread ID = 0x2002026c
Faulting instruction address = 0xd904
Fatal fault in ISR! Spinning...&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting an nRF9160 to AWS</title><link>https://devzone.nordicsemi.com/thread/189012?ContentTypeID=1</link><pubDate>Fri, 24 May 2019 11:00:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7de2cee5-a94b-47e9-8c9c-386b7aa32bb8</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;Sorry for not catching this before, but you are mixing the nrf_socket.h and the zephyr socket API. They do not play well together and needs translation (see nrf91_sockets.c for more detailed info).&lt;/p&gt;
&lt;p&gt;The include &amp;quot;net/socket.h&amp;quot; is also a bit suspicious, as you want to use the socket offloading, thus the translation between nrf and zephyr API. When you are calling socket() (and other calls), I am unsure which function you are calling in the background. This could be the network stacks socket implementation, which will not work with the nRF9160, or it could be the socket offloading (thus going into nrf91_sockets.c) which would have a mismatch of the structs.&lt;/p&gt;
&lt;p&gt;Could you instead try the ntp example and see if that works?&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: Connecting an nRF9160 to AWS</title><link>https://devzone.nordicsemi.com/thread/189006?ContentTypeID=1</link><pubDate>Fri, 24 May 2019 09:47:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6f82485d-40ec-4696-9716-3243800742d9</guid><dc:creator>MJD093</dc:creator><description>&lt;p&gt;Hello again,&lt;/p&gt;
&lt;p&gt;I haven&amp;#39;t been able to test the network as of yet but have been noting a few issues with the program. It has expanded over the past week to include some commented out section of the GPS sample code, (the goal is to design a device that will swap between LTE and GPS as needed) but this is all unneeded at the moment as the deployed DK is using old modem FW and can&amp;#39;t use the AT command AT%XSYSTEMMODE. So all it really can do for now is turn itself off and on to test the AT command socket.&lt;/p&gt;
&lt;p&gt;I have noticed that the code just skips past the blocking do-while loop that I copied from the UDP example you linked to in your last reply. Rather than blocking while the errno is -EAGAIN, it auto fails after one attempt connection attempt. errno is coming back with error number 134.&lt;/p&gt;
&lt;p&gt;The code also for some reason stops being able to open sockets. I orginally thought this was due to me not closing sockets correctly when erroring out of the connect attempts thus running out of sockets but it actually doesn&amp;#39;t appear to be the issue. Adding a print out for UDP_Socket shows that the Socket ID is always 2 (not sure why socket 1 isn&amp;#39;t the first socket).&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*
 * Copyright (c) 2018 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
 */

#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;uart.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;bsd.h&amp;gt;
#include &amp;lt;net/socket.h&amp;gt;

//#include &amp;quot;certificates.h&amp;quot;
//#include &amp;quot;provisions/provision.h&amp;quot;
#include &amp;quot;../../../../../nrfxlib/bsdlib/include/nrf_socket.h&amp;quot;

#define AT_XSYSTEMMODE_GPS 			&amp;quot;AT\%XSYSTEMMODE=0,0,1,0&amp;quot;
#define AT_MAGPIO_GPS      			&amp;quot;AT\%XMAGPIO=1,0,0,1,1,1574,1577&amp;quot;
#define AT_CFUN_ON        			&amp;quot;AT+CFUN=1&amp;quot;
#define AT_XSYSTEMMODE_LTE			&amp;quot;AT\%XSYSTEMMODE=0,1,0,0&amp;quot;
#define AT_CFUN_OFF							&amp;quot;AT+CFUN=4&amp;quot;
#define AT_MAGPIO_CLEAR					&amp;quot;AT\%XMAGPIO&amp;quot;

//static const char     at_commands_GPS[][31]  = { AT_CFUN_OFF, AT_XSYSTEMMODE_GPS, AT_MAGPIO_GPS, AT_CFUN_ON };
static const char			at_commands_Init[][31] = { AT_CFUN_OFF, AT_CFUN_ON };
//static const char			at_commands_LTE[][31]  = { AT_CFUN_OFF, AT_XSYSTEMMODE_GPS, AT_MAGPIO_CLEAR, AT_CFUN_ON };
//static int            fd;

// static char           nmea_strings[10][NRF_GNSS_NMEA_MAX_LEN];
// static u32_t          nmea_string_cnt;
//
// static bool           got_first_fix;
// static bool           update_terminal;
// static u64_t          fix_timestamp;
// nrf_gnss_data_frame_t last_fix;
static int 						modem_init_flag;
static int 						data_to_send = 0;

#if defined(CONFIG_BSD_LIBRARY)

/**@brief Recoverable BSD library error. */
void bsd_recoverable_error_handler(uint32_t err)
{
	printk(&amp;quot;bsdlib recoverable error: %lu\n&amp;quot;, err);
}

/**@brief Irrecoverable BSD library error. */
void bsd_irrecoverable_error_handler(uint32_t err)
{
	printk(&amp;quot;bsdlib irrecoverable error: %lu\n&amp;quot;, err);

	__ASSERT_NO_MSG(false);
}

#endif /* defined(CONFIG_BSD_LIBRARY) */

// #if defined(CONFIG_BSD_LIBRARY) //Includes nrf secure key manager code, not impliment yet
// #include &amp;quot;nrf_inbuilt_key.h&amp;quot;
// #endif

int blocking_connect(int fd, struct sockaddr *local_addr, socklen_t len)
{
	int err;

	printk(&amp;quot;Attempting to establish connection to EC2\n&amp;quot;);
	do {
		err = connect(fd, local_addr, len);
	} while (err &amp;lt; 0 &amp;amp;&amp;amp; errno == EAGAIN);

	return err;
}

static int enable_modem(void)
{
	int  at_sock;
	int  bytes_sent;
	int  bytes_received;
	char buf[2];

	at_sock = socket(AF_LTE, 0, NPROTO_AT);

	if (at_sock &amp;lt; 0) {
		return -1;
	}

	for (int i = 0; i &amp;lt; ARRAY_SIZE(at_commands_Init); i++) {
		bytes_sent = send(at_sock, at_commands_Init[i],
				  strlen(at_commands_Init[i]), 0);

		if (bytes_sent &amp;lt; 0) {
			close(at_sock);
			return -1;
		}

		do {
			bytes_received = recv(at_sock, buf, 2, 0);
		} while (bytes_received == 0);

		if (memcmp(buf, &amp;quot;OK&amp;quot;, 2) != 0) {
			close(at_sock);
			return -1;
		}
	}
	printk(&amp;quot;Modem enabled&amp;quot;);
	close(at_sock);

	return 0;
}

// static int swap_to_lte(void)
// {
// 	int  at_sock;
// 	int  bytes_sent;
// 	int  bytes_received;
// 	char buf[2];
//
// 	at_sock = nrf_socket(AF_LTE, 0, NPROTO_AT);
// 	if (at_sock &amp;lt; 0) {
// 		return -1;
// 	}
//
// 	for (int i = 0; i &amp;lt; ARRAY_SIZE(at_commands_LTE); i++) {
// 		bytes_sent = nrf_send(at_sock, at_commands_LTE[i],
// 				  strlen(at_commands_LTE[i]), 0);
//
// 		if (bytes_sent &amp;lt; 0) {
// 			nrf_close(at_sock);
// 			return -1;
// 		}
//
// 		do {
// 			bytes_received = nrf_recv(at_sock, buf, 2, 0);
// 		} while (bytes_received == 0);
//
// 		if (memcmp(buf, &amp;quot;OK&amp;quot;, 2) != 0) {
// 			nrf_close(at_sock);
// 			return -1;
// 		}
// 	}
//
// 	nrf_close(at_sock);
//
// 	return 0;
// }
//
// static int swap_to_gps(void)
// {
// 	int  at_sock;
// 	int  bytes_sent;
// 	int  bytes_received;
// 	char buf[2];
//
// 	at_sock = nrf_socket(AF_LTE, 0, NPROTO_AT);
// 	if (at_sock &amp;lt; 0) {
// 		return -1;
// 	}
//
// 	for (int i = 0; i &amp;lt; ARRAY_SIZE(at_commands_GPS); i++) {
// 		bytes_sent = nrf_send(at_sock, at_commands_GPS[i],
// 				  strlen(at_commands_GPS[i]), 0);
//
// 		if (bytes_sent &amp;lt; 0) {
// 			nrf_close(at_sock);
// 			return -1;
// 		}
//
// 		do {
// 			bytes_received = nrf_recv(at_sock, buf, 2, 0);
// 		} while (bytes_received == 0);
//
// 		if (memcmp(buf, &amp;quot;OK&amp;quot;, 2) != 0) {
// 			nrf_close(at_sock);
// 			return -1;
// 		}
// 	}
//
// 	nrf_close(at_sock);
//
// 	return 0;
// }

// static int init_app(void)
// {
// 	u16_t fix_retry     = 0;
// 	u16_t fix_interval  = 1;
// 	u16_t nmea_mask     = NRF_CONFIG_NMEA_GSV_MASK |
// 			      NRF_CONFIG_NMEA_GSA_MASK |
// 			      NRF_CONFIG_NMEA_GLL_MASK |
// 			      NRF_CONFIG_NMEA_GGA_MASK |
// 			      NRF_CONFIG_NMEA_RMC_MASK;
// 	int   retval;
//
// 	if (swap_to_gps() != 0) {
// 		printk(&amp;quot;Failed to enable GPS\n&amp;quot;);
// 		return -1;
// 	}
//
// 	fd = nrf_socket(NRF_AF_LOCAL, NRF_SOCK_DGRAM, NRF_PROTO_GNSS);
//
// 	if (fd &amp;gt;= 0) {
// 		printk(&amp;quot;Socket created\n&amp;quot;);
// 	} else {
// 		printk(&amp;quot;Could not init socket (err: %d)\n&amp;quot;, fd);
// 		return -1;
// 	}
//
// 	retval = nrf_setsockopt(fd,
// 				NRF_SOL_GNSS,
// 				NRF_SO_GNSS_FIX_RETRY,
// 				&amp;amp;fix_retry,
// 				sizeof(uint16_t));
//
// 	if (retval != 0) {
// 		printk(&amp;quot;Failed to set fix retry value\n&amp;quot;);
// 		return -1;
// 	}
//
// 	retval = nrf_setsockopt(fd,
// 				NRF_SOL_GNSS,
// 				NRF_SO_GNSS_FIX_INTERVAL,
// 				&amp;amp;fix_interval,
// 				sizeof(uint16_t));
//
// 	if (retval != 0) {
// 		printk(&amp;quot;Failed to set fix interval value\n&amp;quot;);
// 		return -1;
// 	}
//
// 	retval = nrf_setsockopt(fd,
// 				NRF_SOL_GNSS,
// 				NRF_SO_GNSS_NMEA_MASK,
// 				&amp;amp;nmea_mask,
// 				sizeof(uint16_t));
//
// 	if (retval != 0) {
// 		printk(&amp;quot;Failed to set nmea mask\n&amp;quot;);
// 		return -1;
// 	}
//
// 	retval = nrf_setsockopt(fd,
// 				NRF_SOL_GNSS,
// 				NRF_SO_GNSS_START,
// 				NULL,
// 				0);
//
// 	if (retval != 0) {
// 		printk(&amp;quot;Failed to start GPS\n&amp;quot;);
// 		return -1;
// 	}
//
// 	return 0;
// }

/**@brief Configures modem to test connection. Blocks until link is
 * successfully established. Creates a UDP socket and connects to
 * AWS EC2 instance
 */
static int UDP_Socket_Config_and_Connect(void)
{
	int err;
	int UDP_Socket;

	// Sets up UDP Socket information
	struct nrf_sockaddr_in my_sockaddr; // memset if not populating everything
	struct nrf_sockaddr_in *UDP_sockaddr = &amp;amp;my_sockaddr;

	UDP_sockaddr-&amp;gt;sin_len 					=		sizeof(struct nrf_sockaddr_in);			/**&amp;lt; Length of this data structure */
	UDP_sockaddr-&amp;gt;sin_port					=		NRF_HTONS(xxxxx);              	        /**&amp;lt; Port, in network byte order */
	UDP_sockaddr-&amp;gt;sin_family 				=		NRF_AF_INET;            				/**&amp;lt; Socket family, IPv4 socket */
	UDP_sockaddr-&amp;gt;sin_addr.s_addr	  = 	0xXXXXXXXX;							    /**&amp;lt; IPv4 address, in hex format */

	UDP_Socket = socket(NRF_AF_INET, NRF_SOCK_DGRAM, 0); //Opens UDP socket using UDP protocols
	if (UDP_Socket == -1) {
		printk(&amp;quot;Socket failed to open\n&amp;quot;);
		return -EFAULT;
	}
	printk(&amp;quot;Socket created for init\n&amp;quot;);

	err = blocking_connect(UDP_Socket, (struct sockaddr *)&amp;amp;UDP_sockaddr, sizeof(UDP_sockaddr)); //Tests connection to UDP IPv4 address
	if(err &amp;lt; 0)
	{
		printk(&amp;quot;Failure to establish connection via nrf_connect, closing socket\n&amp;quot;);
		close(UDP_Socket);
		return err;
	}
	close(UDP_Socket);
	printk(&amp;quot;Config and Connect Successful\n&amp;quot;);
	return err;
}

/**@brief Sends a test UDP packet to AWS. Uses non-blocking mode. */

static int UDP_Send(char *UDP_buff)
{
	int err;
	int UDP_Socket;
	ssize_t bytes_sent;

	struct nrf_sockaddr_in my_sockaddr; // memset if not populating everything
	struct nrf_sockaddr_in *UDP_sockaddr = &amp;amp;my_sockaddr;
	UDP_sockaddr-&amp;gt;sin_len 					=		sizeof(struct nrf_sockaddr_in);			/**&amp;lt; Length of this data structure */
	UDP_sockaddr-&amp;gt;sin_port					=		NRF_HTONS(xxxxx);              	        /**&amp;lt; Port, in network byte order */
	UDP_sockaddr-&amp;gt;sin_family 				=		NRF_AF_INET;            				/**&amp;lt; Socket family, IPv4 socket */
	UDP_sockaddr-&amp;gt;sin_addr.s_addr	  = 	0xXXXXXXXX;							    /**&amp;lt; IPv4 address, in hex format */

	UDP_Socket = socket(NRF_AF_INET, NRF_SOCK_DGRAM, 0);
	printk(&amp;quot;Socket ID: %d\n&amp;quot;, UDP_Socket);
	if (UDP_Socket == -1)
	{
		printk(&amp;quot;Socket failed to open\n&amp;quot;);
		return -EFAULT;
	}
	else
	{
		printk(&amp;quot;Socket created for transfer\n&amp;quot;);
	}

	err = blocking_connect(UDP_Socket, (struct sockaddr *)&amp;amp;UDP_sockaddr, sizeof(UDP_sockaddr));

	if (err &amp;lt; 0)
	{
		printk(&amp;quot;Failure to establish connection via nrf_connect, closing socket\n&amp;quot;);
		close(UDP_Socket);
		return err;
	}
	else
	{
		printk(&amp;quot;Send socket connected\n&amp;quot;);
	}

	bytes_sent = send(UDP_Socket, UDP_buff, strlen(UDP_buff), NRF_MSG_WAITALL); //Sends UDP Buffer to AWS EC2 with blocking flag

	if (bytes_sent &amp;lt; 0)
	{
		printk(&amp;quot;Error sending %s to IP %lu\n&amp;quot;, UDP_buff, UDP_sockaddr-&amp;gt;sin_addr.s_addr);
		close(UDP_Socket);
		err = -1;
		return err;
	}
	else
	{
		printk(&amp;quot;Sent %08x bytes to IP %lu\n&amp;quot;, bytes_sent, UDP_sockaddr-&amp;gt;sin_addr.s_addr);
	}
	close(UDP_Socket);
	return err;
}

// int process_gps_data(nrf_gnss_data_frame_t *gps_data)
// {
// 	int retval;
//
// 	retval = nrf_recv(fd, gps_data, sizeof(nrf_gnss_data_frame_t), NRF_MSG_DONTWAIT);
//
// 	if (retval &amp;gt; 0) {
//
// 		switch (gps_data-&amp;gt;data_id) {
// 		case NRF_GNSS_PVT_DATA_ID:
//
// 			if ((gps_data-&amp;gt;pvt.flags &amp;amp;
// 				NRF_GNSS_PVT_FLAG_FIX_VALID_BIT)
// 				== NRF_GNSS_PVT_FLAG_FIX_VALID_BIT) {
//
// 				if (!got_first_fix) {
// 					got_first_fix = true;
// 				}
//
// 				fix_timestamp = k_uptime_get();
// 				memcpy(&amp;amp;last_fix, gps_data, sizeof(nrf_gnss_data_frame_t));
//
// 				nmea_string_cnt = 0;
// 				update_terminal = true;
// 			}
// 			break;
//
// 		case NRF_GNSS_NMEA_DATA_ID:
// 			if (nmea_string_cnt &amp;lt; 10) {
// 				memcpy(nmea_strings[nmea_string_cnt++],
// 				       gps_data-&amp;gt;nmea,
// 				       retval);
// 			}
// 			break;
//
// 		default:
// 			break;
// 		}
// 	}
//
// 	return retval;
// }

//Set up Zephyr 10 second timer that will call UDP_Send
struct k_timer modemretry_timer;
void modem_retry(struct k_timer *timer_1)
{
	int err;
	printk(&amp;quot;Retrying the modem!\n&amp;quot;);
	err = enable_modem();
	if(err!=0)
	{
		modem_init_flag=0;
	}
	else
	{
		modem_init_flag=1;
	}
}

//Set up Zephyr 10 second timer that will call UDP_Send
struct k_timer UDPSend_timer;
void UDP_Resend(struct k_timer *timer_2)
{
	data_to_send = 1;
	printk(&amp;quot;Timer trigger for UDPSend!\n&amp;quot;);
}

void main(void)
{
	int error;

	printk(&amp;quot;UDP_Test Application started\n&amp;quot;);

	char *Buff = &amp;quot;Hello AWS\n&amp;quot;;
	char *Buff_Timer = &amp;quot;Timer Trigger\n&amp;quot;;

	error=enable_modem();
	if(error != 0)
	{
		printk(&amp;quot;Failed to initialise the modem\n&amp;quot;);
		modem_init_flag=0;
		//Initialize and activate timer
		while(modem_init_flag==0)
		{
			k_timer_init(&amp;amp;modemretry_timer, modem_retry, NULL);
			k_timer_start(&amp;amp;modemretry_timer, K_SECONDS(10), K_SECONDS(10));
		}
		k_timer_stop(&amp;amp;modemretry_timer);
	}
	UDP_Socket_Config_and_Connect(); //Test UDP connection
	UDP_Send(Buff);

	//swap_to_gps();
	//init_app();
	//swap_to_lte();
	printk(&amp;quot;Dropping into main while loop\n&amp;quot;);
	k_timer_init(&amp;amp;UDPSend_timer, UDP_Resend, NULL);
	k_timer_start(&amp;amp;UDPSend_timer, K_SECONDS(10), K_SECONDS(10));

	while(true)
	{
		if (data_to_send == 1)
		{
			//UDP_Socket_Config_and_Connect(); //Test UDP connection
			UDP_Send(Buff_Timer);
			data_to_send = 0;
		}
		k_sleep(K_MSEC(10));
		/* Put CPU to idle to save power */
		k_cpu_idle();
	}
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;***** Booting Zephyr OS v1.14.99-ncs1-3-g3c4f27282002 *****
Flash region		Domain		Permissions
00 0x00000 0x08000 	Secure		rwxl
01 0x08000 0x10000 	Non-Secure	rwxl
02 0x10000 0x18000 	Non-Secure	rwxl
03 0x18000 0x20000 	Non-Secure	rwxl
04 0x20000 0x28000 	Non-Secure	rwxl
05 0x28000 0x30000 	Non-Secure	rwxl
06 0x30000 0x38000 	Non-Secure	rwxl
07 0x38000 0x40000 	Non-Secure	rwxl
08 0x40000 0x48000 	Non-Secure	rwxl
09 0x48000 0x50000 	Non-Secure	rwxl
10 0x50000 0x58000 	Non-Secure	rwxl
11 0x58000 0x60000 	Non-Secure	rwxl
12 0x60000 0x68000 	Non-Secure	rwxl
13 0x68000 0x70000 	Non-Secure	rwxl
14 0x70000 0x78000 	Non-Secure	rwxl
15 0x78000 0x80000 	Non-Secure	rwxl
16 0x80000 0x88000 	Non-Secure	rwxl
17 0x88000 0x90000 	Non-Secure	rwxl
18 0x90000 0x98000 	Non-Secure	rwxl
19 0x98000 0xa0000 	Non-Secure	rwxl
20 0xa0000 0xa8000 	Non-Secure	rwxl
21 0xa8000 0xb0000 	Non-Secure	rwxl
22 0xb0000 0xb8000 	Non-Secure	rwxl
23 0xb8000 0xc0000 	Non-Secure	rwxl
24 0xc0000 0xc8000 	Non-Secure	rwxl
25 0xc8000 0xd0000 	Non-Secure	rwxl
26 0xd0000 0xd8000 	Non-Secure	rwxl
27 0xd8000 0xe0000 	Non-Secure	rwxl
28 0xe0000 0xe8000 	Non-Secure	rwxl
29 0xe8000 0xf0000 	Non-Secure	rwxl
30 0xf0000 0xf8000 	Non-Secure	rwxl
31 0xf8000 0x100000 	Non-Secure	rwxl

SRAM region		Domain		Permissions
00 0x00000 0x02000	Secure		rwxl
01 0x02000 0x04000	Secure		rwxl
02 0x04000 0x06000	Secure		rwxl
03 0x06000 0x08000	Secure		rwxl
04 0x08000 0x0a000	Secure		rwxl
05 0x0a000 0x0c000	Secure		rwxl
06 0x0c000 0x0e000	Secure		rwxl
07 0x0e000 0x10000	Secure		rwxl
08 0x10000 0x12000	Non-Secure	rwxl
09 0x12000 0x14000	Non-Secure	rwxl
10 0x14000 0x16000	Non-Secure	rwxl
11 0x16000 0x18000	Non-Secure	rwxl
12 0x18000 0x1a000	Non-Secure	rwxl
13 0x1a000 0x1c000	Non-Secure	rwxl
14 0x1c000 0x1e000	Non-Secure	rwxl
15 0x1e000 0x20000	Non-Secure	rwxl
16 0x20000 0x22000	Non-Secure	rwxl
17 0x22000 0x24000	Non-Secure	rwxl
18 0x24000 0x26000	Non-Secure	rwxl
19 0x26000 0x28000	Non-Secure	rwxl
20 0x28000 0x2a000	Non-Secure	rwxl
21 0x2a000 0x2c000	Non-Secure	rwxl
22 0x2c000 0x2e000	Non-Secure	rwxl
23 0x2e000 0x30000	Non-Secure	rwxl
24 0x30000 0x32000	Non-Secure	rwxl
25 0x32000 0x34000	Non-Secure	rwxl
26 0x34000 0x36000	Non-Secure	rwxl
27 0x36000 0x38000	Non-Secure	rwxl
28 0x38000 0x3a000	Non-Secure	rwxl
29 0x3a000 0x3c000	Non-Secure	rwxl
30 0x3c000 0x3e000	Non-Secure	rwxl
31 0x3e000 0x40000	Non-Secure	rwxl

Peripheral		Domain		Status
00 NRF_P0		Non-Secure	OK
01 NRF_CLOCK		Non-Secure	OK
02 NRF_RTC1		Non-Secure	OK
03 NRF_NVMC		Non-Secure	OK
04 NRF_UARTE1		Non-Secure	OK
05 NRF_UARTE2		Secure		SKIP
06 NRF_IPC		Non-Secure	OK
07 NRF_VMC		Non-Secure	OK
08 NRF_FPU		Non-Secure	OK
09 NRF_EGU1		Non-Secure	OK
10 NRF_EGU2		Non-Secure	OK
11 NRF_TWIM2		Non-Secure	OK
12 NRF_SPIM3		Non-Secure	OK
13 NRF_TIMER0		Non-Secure	OK
14 NRF_TIMER1		Non-Secure	OK
15 NRF_TIMER2		Non-Secure	OK
16 NRF_SAADC		Non-Secure	OK
17 NRF_GPIOTE1		Non-Secure	OK

SPM: NS image at 0x8000
SPM: NS MSP at 0x20023308
SPM: NS reset vector at 0xd915
SPM: prepare to jump to Non-Secure image.
***** Booting Zephyr OS v1.14.99-ncs1-3-g3c4f27282002 *****
UDP_Test Application started
Modem enabledSocket created for init
Failure to establish connection via nrf_connect, closing socket
Socket ID: 2
Socket created for transfer
Attempting to establish connection to EC2
Failure to establish connection via nrf_connect, closing socket
Dropping into main while loop
Timer trigger for UDPSend!
Socket ID: 2
Socket created for transfer
Attempting to establish connection to EC2
Failure to establish connection via nrf_connect, closing socket
Timer trigger for UDPSend!
Socket ID: 2
Socket created for transfer
Attempting to establish connection to EC2
Failure to establish connection via nrf_connect, closing socket
Timer trigger for UDPSend!
Socket ID: 2
Socket created for transfer
Attempting to establish connection to EC2
Failure to establish connection via nrf_connect, closing socket
Timer trigger for UDPSend!
Socket ID: 2
Socket created for transfer
Attempting to establish connection to EC2
Failure to establish connection via nrf_connect, closing socket
Timer trigger for UDPSend!
Socket ID: 2
Socket created for transfer
Attempting to establish connection to EC2
Failure to establish connection via nrf_connect, closing socket
Timer trigger for UDPSend!
Socket ID: 2
Socket created for transfer
Attempting to establish connection to EC2
Failure to establish connection via nrf_connect, closing socket
Timer trigger for UDPSend!
Socket ID: -1
Socket failed to open
Timer trigger for UDPSend!
Socket ID: -1
Socket failed to open
Timer trigger for UDPSend!
Socket ID: -1
Socket failed to open
Timer trigger for UDPSend!
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting an nRF9160 to AWS</title><link>https://devzone.nordicsemi.com/thread/187041?ContentTypeID=1</link><pubDate>Tue, 14 May 2019 14:41:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bd7538de-8073-4879-b94e-72bafa2e21ac</guid><dc:creator>MJD093</dc:creator><description>&lt;p&gt;I see. Thank you, I&amp;#39;ll have a look through the udp-example. It will be a few days before the EC2 IP is whitelisted.&lt;/p&gt;
&lt;p&gt;I will update when the network is available to test the code.&lt;/p&gt;
&lt;p&gt;Many thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting an nRF9160 to AWS</title><link>https://devzone.nordicsemi.com/thread/187040?ContentTypeID=1</link><pubDate>Tue, 14 May 2019 14:38:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:caaaa83d-93e0-44f6-afe3-5f03fc8c9fb8</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;The code looks ok. I have an udp-example here (the bind is strictly not needed):&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/Rallare/fw-nrfconnect-nrf/blob/nrf9160_samples/samples/nrf9160/ntp/src/main.c"&gt;https://github.com/Rallare/fw-nrfconnect-nrf/blob/nrf9160_samples/samples/nrf9160/ntp/src/main.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;H&amp;aring;kon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting an nRF9160 to AWS</title><link>https://devzone.nordicsemi.com/thread/187031?ContentTypeID=1</link><pubDate>Tue, 14 May 2019 14:28:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a8ab0de2-a58e-4e5e-b26b-f443f365cc4b</guid><dc:creator>MJD093</dc:creator><description>&lt;p&gt;Hi,&lt;span class="parent"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Thank you, that allowed the code to pass through the struct without faulting.&lt;/p&gt;
&lt;p&gt;I have tweeked the code slightly as the timer was causing an instruction fault (first time I&amp;#39;ve seen that as I use that timer code in other Zephyr nrf91 samples, I have removed it for now as it wasn&amp;#39;t really needed). I have edited nrf_connect as even though there was no network for it to connect to, it was still returning 0 on err.&lt;/p&gt;
&lt;p&gt;Is this the correct way for nrf_connect to be called? It now fails out as expected for no network connection.&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**@brief Configures modem to test connection. Blocks until link is
 * successfully established. Creates a UDP socket and connects to
 * AWS EC2 instance
 */
static int UDP_Socket_Config_and_Connect(void)
{
	int err;
	int UDP_Socket;

	// Sets up UDP Socket information
	struct nrf_sockaddr_in my_sockaddr; // memset if not populating everything
	struct nrf_sockaddr_in *UDP_sockaddr = &amp;amp;my_sockaddr;

	UDP_sockaddr-&amp;gt;sin_len 					=		sizeof(struct nrf_sockaddr_in);			/**&amp;lt; Length of this data structure */
	UDP_sockaddr-&amp;gt;sin_port					=		NRF_HTONS(xxxxx);              	        /**&amp;lt; Port, in network byte order */
	UDP_sockaddr-&amp;gt;sin_family 				=		NRF_AF_INET;            				/**&amp;lt; Socket family, IPv4 socket */
	UDP_sockaddr-&amp;gt;sin_addr.s_addr	  = 	0xXXXXXXXX;							    /**&amp;lt; IPv4 address, in hex format */

	UDP_Socket = nrf_socket(NRF_AF_INET, NRF_SOCK_DGRAM, NRF_IPPROTO_UDP); //Opens UDP socket using UDP protocols
	if (UDP_Socket == -1) {
		printk(&amp;quot;Socket failed to open\n&amp;quot;);
		return -EFAULT;
	}
	printk(&amp;quot;Socket created for init\n&amp;quot;);

	err = nrf_connect(UDP_Socket, (struct sockaddr *)&amp;amp;UDP_sockaddr, sizeof(UDP_sockaddr)); //Tests connection to UDP IPv4 address
	if(err &amp;lt; 0)
	{
		printk(&amp;quot;Failure to establish connection via nrf_connect, closing socket\n&amp;quot;);
		nrf_close(UDP_Socket);
		return err;
	}
	nrf_close(UDP_Socket);
	printk(&amp;quot;Config and Connect Successful\n&amp;quot;);
	return err;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting an nRF9160 to AWS</title><link>https://devzone.nordicsemi.com/thread/186913?ContentTypeID=1</link><pubDate>Tue, 14 May 2019 10:28:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ce1bd45e-80d1-40cf-a174-93c0ec8bf5d1</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;This code looks like trouble:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;struct nrf_sockaddr_in *UDP_sockaddr;
printk(&amp;quot;code checkpoint 0\n&amp;quot;);
UDP_sockaddr-&amp;gt;sin_len 					=		sizeof(struct nrf_sockaddr_in);			/**&amp;lt; Length of this data structure */
printk(&amp;quot;code checkpoint 1\n&amp;quot;);
UDP_sockaddr-&amp;gt;sin_port					=		NRF_HTONS(xxxxx);              	        /**&amp;lt; Port, in network byte order */
printk(&amp;quot;code checkpoint 2\n&amp;quot;);
UDP_sockaddr-&amp;gt;sin_family 				=		NRF_AF_INET;            				/**&amp;lt; Socket family, IPv4 socket */
printk(&amp;quot;code checkpoint 3\n&amp;quot;);
UDP_sockaddr-&amp;gt;sin_addr.s_addr	    	= 	    0xXXXXXXXX;							    /**&amp;lt; IPv4 address, in hex format */
printk(&amp;quot;code checkpoint 4\n&amp;quot;);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you try this instead?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;struct nrf_sockaddr_in my_sockaddr; // memset if not populating everything
struct nrf_sockaddr_in *UDP_sockaddr = &amp;amp;my_sockaddr;
printk(&amp;quot;code checkpoint 0\n&amp;quot;);
UDP_sockaddr-&amp;gt;sin_len 					=		sizeof(struct nrf_sockaddr_in);			/**&amp;lt; Length of this data structure */
printk(&amp;quot;code checkpoint 1\n&amp;quot;);
UDP_sockaddr-&amp;gt;sin_port					=		NRF_HTONS(xxxxx);              	        /**&amp;lt; Port, in network byte order */
printk(&amp;quot;code checkpoint 2\n&amp;quot;);
UDP_sockaddr-&amp;gt;sin_family 				=		NRF_AF_INET;            				/**&amp;lt; Socket family, IPv4 socket */
printk(&amp;quot;code checkpoint 3\n&amp;quot;);
UDP_sockaddr-&amp;gt;sin_addr.s_addr	    	= 	    0xXXXXXXXX;							    /**&amp;lt; IPv4 address, in hex format */
printk(&amp;quot;code checkpoint 4\n&amp;quot;);&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: Connecting an nRF9160 to AWS</title><link>https://devzone.nordicsemi.com/thread/186894?ContentTypeID=1</link><pubDate>Tue, 14 May 2019 09:25:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8da319c7-c1b7-49a9-aa1b-5826e761848a</guid><dc:creator>MJD093</dc:creator><description>&lt;p&gt;Apologises for the delayed response. I have identified the issue with the connection. Turns out the network provider requires a whitelisted IP address that is incompatible with the dynamic IPs of AWS IoT Core.&lt;/p&gt;
&lt;p&gt;As the device I am using is deployed in another area of the UK, I can&amp;#39;t manually update the modem to the latest version without risking something going wrong. I&amp;#39;d rather avoid updating the modem at this moment if I can get away with it. The device is hooked up to a Raspberry Pi with internet access which can faciliate re-flashing with JLinkExe but hasn&amp;#39;t been set up with the modem update tools.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve been busy figuring out a counter to this issue and have decided to take a different path and use the BSD library to create a UDP connection to a static IP bounded EC2 instance on AWS. I have encountered a different problem with setting up this kind of connection however.&lt;/p&gt;
&lt;p&gt;The code compiles but the nRF9160 reports back a hard fault when the code is loaded onto the device. It will run the code until the UDP IPv4 socket information structure (struct nrf_sockaddr_in) is populated. I&amp;#39;ve tried to follow what examples I have found of this structure in the ncs repo but I seem to be missing something.&lt;/p&gt;
&lt;p&gt;This is were it appears the code gets to before hard fault, I placed printks to figure out where the code reaches before faulting:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**@brief Configures modem to test connection. Blocks until link is
 * successfully established. Creates a UDP socket and connects to
 * AWS EC2 instance
 */
static int UDP_Socket_Config_and_Connect(void)
{
	int err;
	int UDP_Socket;

	// Sets up UDP Socket information
	struct nrf_sockaddr_in *UDP_sockaddr;
			printk(&amp;quot;code checkpoint 0\n&amp;quot;);
	UDP_sockaddr-&amp;gt;sin_len 					=		sizeof(struct nrf_sockaddr_in);			/**&amp;lt; Length of this data structure */
			printk(&amp;quot;code checkpoint 1\n&amp;quot;);
	UDP_sockaddr-&amp;gt;sin_port					=		NRF_HTONS(xxxxx);              	        /**&amp;lt; Port, in network byte order */
			printk(&amp;quot;code checkpoint 2\n&amp;quot;);
	UDP_sockaddr-&amp;gt;sin_family 				=		NRF_AF_INET;            				/**&amp;lt; Socket family, IPv4 socket */
			printk(&amp;quot;code checkpoint 3\n&amp;quot;);
	UDP_sockaddr-&amp;gt;sin_addr.s_addr	    	= 	    0xXXXXXXXX;							    /**&amp;lt; IPv4 address, in hex format */
			printk(&amp;quot;code checkpoint 4\n&amp;quot;);

	UDP_Socket = nrf_socket(NRF_AF_LTE, NRF_SOCK_DGRAM, NRF_IPPROTO_UDP); //Opens UDP socket using UDP protocols
	if (UDP_Socket == -1) {
		printk(&amp;quot;Socket failed to open\n&amp;quot;);
		return -EFAULT;
	}
	printk(&amp;quot;Socket created for init\n&amp;quot;);

	err = nrf_connect(UDP_Socket, UDP_sockaddr, UDP_sockaddr-&amp;gt;sin_len); //Tests connection to UDP IPv4 address
	if(err)
	{
		printk(&amp;quot;Failure to establish connection via nrf_connect, closing socket\n&amp;quot;);
		close(UDP_Socket);
	}
	close(UDP_Socket);
	printk(&amp;quot;Config and Connect Successful\n&amp;quot;);
	return err;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This is the UART information when the device resets until faulting:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Flash region		Domain		Permissions
00 0x00000 0x02000 	Secure		rwxl
01 0x02000 0x04000 	Non-Secure	rwxl
02 0x04000 0x06000 	Non-Secure	rwxl
03 0x06000 0x08000 	Non-Secure	rwxl
04 0x08000 0x0a000 	Non-Secure	rwxl
05 0x0a000 0x0c000 	Non-Secure	rwxl
06 0x0c000 0x0e000 	Non-Secure	rwxl
07 0x0e000 0x10000 	Non-Secure	rwxl
08 0x10000 0x12000 	Non-Secure	rwxl
09 0x12000 0x14000 	Non-Secure	rwxl
10 0x14000 0x16000 	Non-Secure	rwxl
11 0x16000 0x18000 	Non-Secure	rwxl
12 0x18000 0x1a000 	Non-Secure	rwxl
13 0x1a00ecure	rwxl
14 0x1c000 0x1e000 	Non-Secure	rwxl
15 0x1e000 0x20000 	Non-Secure	rwxl
16 0x20000 0x22000 	Non-Secure	rwxl
17 0x22000 0x24000 	Non-Secure	rwxl
18 0x24000 0x26000 	Non-Secure	rwxl
19 0x26000 0x28000 	Non-Secure	rwxl
20 0x28000 0x2a000 	Non-Secure	rwxl
21 0x2a000 0x2c000 	Non-Secure	rwxl
22 0x2c000 0x2e000 	Non-Secure	rwxl
23 0x2e000 0x30000 	Non-Secure	rwxl
24 0x30000 0x32000 	Non-Secure	rwxl
25 0x32000 0x34000 	Non-Secure	rwxl
26 0x34000 0x36000 	Non-Secure	rwxl
27 0x36000 0x38000 	Non-Secure	rwxl
28 0x38000 0x3a000 	Non-Secure	rwxl
29 0x3a000 0x3c000 	Non-Secure	rwxl
30 0x3c000 0x3e000 	Non-Secure	rwxl
31 0x3e000 0x40000 	Non-Secure	rwxl

SRAM region		Domain		Permissions
00 0x00000 0x01000	Secure		rwxl
01 0x01000 0x02000	Secure		rwxl
02 0x02000 0x03000	Secure		rwxl
03 0x03000 0x04000	Secure		rwxl
04 0x04000 0x05000	Secure		rwxl
05 0x05000 0x06000	Secure		rwxl
06 0x06000 0x07000	Secure		rwxl
07 0x07000 0x08000	Secure		rwxl
08 0x08000 0x09000	Non-Secure	rwxl
09 0x09000 0x0a000	Non-Secure	rwxl
10 0x0a000 0x0b000	Non-Secure	rwxl
11 0x0b000 0x0c000	Non-Secure	rwxl
12 0x0c000 0x0d000	Non-Secure	rwxl
13 0x0d000 0x0e000	Non-Secure	rwxl
14 0x0e000 0x0f000	Non-Secure	rwxl
15 0x0f000 0x10000	Non-Secure	rwxl
16 0x10000 0x11000	Non-Secure	rwxl
17 0x11000 0x12000	Non-Secure	rwxl
18 0x12000 0x13000	Non-Secure	rwxl
19 0x13000 0x14000	Non-Secure	rwxl
20 0x14000 0x15000	Non-Secure	rwxl
21 0x15000 0x16000	Non-Secure	rwxl
22 0x16000 0x17000	Non-Secure	rwxl
23 0x17000 0x18000	Non-Secure	rwxl
24 0x18000 0x19000	Non-Secure	rwxl
25 0x19000 0x1a000	Non-Secure	rwxl
26 0x1a000 0x1b000	Non-Secure	rwxl
27 0x1b000 0x1c000	Non-Secure	rwxl
28 0x1c000 0x1d000	Non-Secure	rwxl
29 0x1d000 0x1e000	Non-Secure	rwxl
30 0x1e000 0x1f000	Non-Secure	rwxl
31 0x1f000 0x20000	Non-Secure	rwxl

Peripheral		Domain		Status
00 NRF_P0		Non-Secure	OK
01 NRF_CLOCK		Non-Secure	OK
02 NRF_RTC1		Non-Secure	OK
03 NRF_NVMC		Non-Secure	OK
04 NRF_UARTE1		Non-Secure	OK
05 NRF_UARTE2		Secure		SKIP
06 NRF_IPC		Non-Secure	OK
07 NRF_VMC		Non-Secure	OK
08 NRF_FPU		Non-Secure	ERROR
09 NRF_EGU1		Non-Secure	OK
10 NRF_EGU2		Non-Secure	OK
11 NRF_TWIM2		Non-Secure	OK
12 NRF_SPIM3		Non-Secure	OK
13 NRF_TIMER0		Non-Secure	OK
14 NRF_TIMER1		Non-Secure	OK
15 NRF_TIMER2		Non-Secure	OK
16 NRF_SAADC		Non-Secure	OK
17 NRF_GPIOTE1		Non-Secure	OK

SPM: MSP_NS 20022e00
SPM: prepare to jump to Non-Secure image
***** Booting Zephyr OS v1.13.99-ncs1-6044-g4eaddb50e90b *****
UDP_Test Application started
code checkpoint 0
Exception occurred in Secure State
***** HARD FAULT *****
  Fault escalation (see below)
***** BUS FAULT *****
  Precise data bus error
  BFAR Address: 0x50008120
***** Hardware exception *****
Current thread ID = 0x20020150
Faulting instruction address = 0x93da
Fatal fault in ISR! Spinning...&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This is main.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2018 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
 */

#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;uart.h&amp;gt;
#include &amp;lt;string.h&amp;gt;

//#include &amp;quot;certificates.h&amp;quot;
//#include &amp;quot;provisions/provision.h&amp;quot;
#include &amp;quot;../../../../../nrfxlib/bsdlib/include/nrf_socket.h&amp;quot;

#if defined(CONFIG_BSD_LIBRARY)

/**@brief Recoverable BSD library error. */
void bsd_recoverable_error_handler(uint32_t err)
{
	printk(&amp;quot;bsdlib recoverable error: %u\n&amp;quot;, err);
}

/**@brief Irrecoverable BSD library error. */
void bsd_irrecoverable_error_handler(uint32_t err)
{
	printk(&amp;quot;bsdlib irrecoverable error: %u\n&amp;quot;, err);

	__ASSERT_NO_MSG(false);
}

#endif /* defined(CONFIG_BSD_LIBRARY) */

// #if defined(CONFIG_BSD_LIBRARY) //Includes nrf secure key manager code, not impliment yet
// #include &amp;quot;nrf_inbuilt_key.h&amp;quot;
// #endif

/**@brief Configures modem to test connection. Blocks until link is
 * successfully established. Creates a UDP socket and connects to
 * AWS EC2 instance
 */
static int UDP_Socket_Config_and_Connect(void)
{
	int err;
	int UDP_Socket;

	// Sets up UDP Socket information
	struct nrf_sockaddr_in *UDP_sockaddr;
			printk(&amp;quot;code checkpoint 0\n&amp;quot;);
	UDP_sockaddr-&amp;gt;sin_len 					=		sizeof(struct nrf_sockaddr_in);						/**&amp;lt; Length of this data structure */
			printk(&amp;quot;code checkpoint 1\n&amp;quot;);
	UDP_sockaddr-&amp;gt;sin_port					=		NRF_HTONS(xxxxx);              	/**&amp;lt; Port, in network byte order */
			printk(&amp;quot;code checkpoint 2\n&amp;quot;);
	UDP_sockaddr-&amp;gt;sin_family 				=		NRF_AF_INET;            				/**&amp;lt; Socket family, IPv4 socket */
			printk(&amp;quot;code checkpoint 3\n&amp;quot;);
	UDP_sockaddr-&amp;gt;sin_addr.s_addr		= 	0xXXXXXXXX;											/**&amp;lt; IPv4 address, in hex format */
			printk(&amp;quot;code checkpoint 4\n&amp;quot;);

	UDP_Socket = nrf_socket(NRF_AF_LTE, NRF_SOCK_DGRAM, NRF_IPPROTO_UDP); //Opens UDP socket using UDP protocols
	if (UDP_Socket == -1) {
		printk(&amp;quot;Socket failed to open\n&amp;quot;);
		return -EFAULT;
	}
	printk(&amp;quot;Socket created for init\n&amp;quot;);

	err = nrf_connect(UDP_Socket, UDP_sockaddr, UDP_sockaddr-&amp;gt;sin_len); //Tests connection to UDP IPv4 address
	if(err)
	{
		printk(&amp;quot;Failure to establish connection via nrf_connect, closing socket\n&amp;quot;);
		close(UDP_Socket);
	}
	close(UDP_Socket);
	printk(&amp;quot;Config and Connect Successful\n&amp;quot;);
	return err;
}

/**@brief Sends a test UDP packet to AWS. Uses non-blocking mode. */

static int UDP_Send(const char *UDP_buff)
{
	int err;
	int UDP_Socket;

	struct nrf_sockaddr_in *UDP_sockaddr;
	UDP_sockaddr-&amp;gt;sin_family =		NRF_AF_INET;            				/**&amp;lt; Socket family. */
	UDP_sockaddr-&amp;gt;sin_port		=		NRF_HTONS(xxxxx);              	/**&amp;lt; Port, in network byte order. */
	UDP_sockaddr-&amp;gt;sin_addr.s_addr		= 	0xXXXXXXXX;								/**&amp;lt; IPv4 address. */
	UDP_sockaddr-&amp;gt;sin_len 		=		sizeof(struct nrf_sockaddr_in);						/**&amp;lt; Length of this data structure. */

	UDP_Socket = nrf_socket(NRF_AF_LTE, NRF_SOCK_DGRAM, NRF_IPPROTO_UDP);
	if (UDP_Socket == -1) {
		printk(&amp;quot;Socket failed to open\n&amp;quot;);
		return -EFAULT;
	}
	printk(&amp;quot;Socket created for transfer\n&amp;quot;);

	err = nrf_connect(UDP_Socket, UDP_sockaddr, UDP_sockaddr-&amp;gt;sin_len);
	if(err)
	{
		printk(&amp;quot;Failure to establish connection via nrf_connect, closing socket\n&amp;quot;);
		close(UDP_Socket);
	}
	printk(&amp;quot;Send socket connected\n&amp;quot;);
	return err;

	err = nrf_send(UDP_Socket, UDP_buff, strlen(UDP_buff), NRF_MSG_DONTWAIT); //Sends UDP Buffer to AWS EC2 with non-blocking flag
	if (err)
	{
		printk(&amp;quot;Error sending %s to IP %08x\n&amp;quot;, UDP_buff, UDP_sockaddr-&amp;gt;sin_addr.s_addr);
		close(UDP_Socket);
	}
	printk(&amp;quot;Sent %s to IP %08x\n&amp;quot;, UDP_buff, UDP_sockaddr-&amp;gt;sin_addr.s_addr);
}

void main(void)
{
	printk(&amp;quot;UDP_Test Application started\n&amp;quot;);

	const char Buff[] = &amp;quot;Hello World\n&amp;quot;;

	//Set up Zephyr 10 second timer that will call UDP_Send
	struct k_timer my_timer;
	void my_work_handler(struct k_timer *timer_1)
	{
		UDP_Send(Buff);
		printk(&amp;quot;timer triggered!\n&amp;quot;);
	}

	UDP_Socket_Config_and_Connect(); //Test UDP connection

	//Initialize and activate timer
	k_timer_init(&amp;amp;my_timer, my_work_handler, NULL);
	k_timer_start(&amp;amp;my_timer, K_SECONDS(10), K_SECONDS(10));

	while(true)
	{
		k_sleep(K_MSEC(10));
		/* Put CPU to idle to save power */
		k_cpu_idle();
	}
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;EDIT: I should clarify, I have one DK deployed in an area of NB-IoT coverage that can be re-flashed remotely. I have a second DK beside me that I can use to test flashes operate as expected, but without any NB-IoT coverage in this area, before taking the merged zephyr hex file and remotely flashing using JLinkExe.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting an nRF9160 to AWS</title><link>https://devzone.nordicsemi.com/thread/184846?ContentTypeID=1</link><pubDate>Thu, 02 May 2019 11:24:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:709a6317-a1d0-438f-9ee0-6fa602fa72ca</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;You are using \r\n as the line ending (normal is \n only), but both shall be accepted by the nrf_inbuilt API.&lt;/p&gt;
&lt;p&gt;I do not see any problems specific to your implementation, but what you could do is to verify that you have the latest modem installed, which can be found here:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.nordicsemi.com/Products/Low-power-cellular-IoT/nRF9160/Download#infotabs"&gt;https://www.nordicsemi.com/Products/Low-power-cellular-IoT/nRF9160/Download#infotabs&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Do you always get the same error message, even if you try several times? if you enter debug mode, and debug the function mqtt_transport_socket_tls.c::mqtt_client_tls_connect(), which function returns the err?&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>