<?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 send data to own AWS server using Cloud Client sample ?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/69840/how-to-send-data-to-own-aws-server-using-cloud-client-sample</link><description>HI All 
 Actually I need to send GPS data to own AWS server so from here I setup AWS server and use cloud client sample and follow the step 
 like 
 1) change the cloud backend to the AWS_IOT 
 2) Enable AWS IOT setting and added ID, HOSTNAME and SEC</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 23 Jan 2021 07:41:12 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/69840/how-to-send-data-to-own-aws-server-using-cloud-client-sample" /><item><title>RE: How to send data to own AWS server using Cloud Client sample ?</title><link>https://devzone.nordicsemi.com/thread/290846?ContentTypeID=1</link><pubDate>Sat, 23 Jan 2021 07:41:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:13444cca-8f4a-4636-b237-503dc4dfb436</guid><dc:creator>jaydip kavaiya</dc:creator><description>&lt;p&gt;HI Oyvind&lt;/p&gt;
&lt;p&gt;Thanks you for your Support and all valuable answer&lt;/p&gt;
&lt;p&gt;problem is solved, Now I get the GPS data and also send to my AWS server&lt;/p&gt;
&lt;p&gt;for just now I am only doing basic not use PSM mode(for PSM mode definitely need your help),&lt;/p&gt;
&lt;p&gt;but from use of below step I did it successfully.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Step 1: Init_app as it is use in GPS sample code&lt;/p&gt;
&lt;p&gt;Step 2: Get GPS data after some time (3 min)&lt;/p&gt;
&lt;p&gt;Step 3: Close the GPS socket&lt;/p&gt;
&lt;p&gt;Step 4:&amp;nbsp; send this command&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(i) AT+CFUN=4&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(ii) AT%XSYSTEMMODE=1,0,0,0&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(iii) AT+CFUN=1&amp;quot;&lt;/p&gt;
&lt;p&gt;Step 5: Modem confgi as it is in AWS sample code&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks &amp;amp; Regards&lt;/p&gt;
&lt;p&gt;Jaydip Kavaiya&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send data to own AWS server using Cloud Client sample ?</title><link>https://devzone.nordicsemi.com/thread/289723?ContentTypeID=1</link><pubDate>Mon, 18 Jan 2021 12:46:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f763688f-c7f2-4821-a88f-af10acf7fd79</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote user="jaydip kavaiya"] The only problem with modem LTE configuration.[/quote]
&lt;p&gt;What is the issue with the modem configuration?&lt;/p&gt;
[quote user="jaydip kavaiya"]&lt;p&gt; As per your suggestion I use PSM mode so get GPS data and after send data to AWS&amp;nbsp;&lt;/p&gt;
&lt;p&gt;in Modem_configuration getting error.&lt;/p&gt;[/quote]
&lt;p&gt;Can you please provide the error code you get?&lt;br /&gt;&lt;br /&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send data to own AWS server using Cloud Client sample ?</title><link>https://devzone.nordicsemi.com/thread/289543?ContentTypeID=1</link><pubDate>Sat, 16 Jan 2021 05:51:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6456658c-0993-4477-8c8e-a5a78b2ba237</guid><dc:creator>jaydip kavaiya</dc:creator><description>&lt;p&gt;Hi Oyvind&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I Tried many way to send GPS data to AWS server but not get any data.&lt;/p&gt;
&lt;p&gt;I follow this step&lt;/p&gt;
&lt;p&gt;1] Run GPS sample and AWS_IOT sample seperatly work perfect for me.&lt;/p&gt;
&lt;p&gt;2] Merge both code with all file (like main.c file, config file, Prj.conf file sample yml file) successfully compile and build.&lt;/p&gt;
&lt;p&gt;3] The only problem with modem LTE configuration.&lt;/p&gt;
&lt;p&gt;4] As per your suggestion I use PSM mode so get GPS data and after send data to AWS&amp;nbsp;&lt;/p&gt;
&lt;p&gt;in Modem_configuration getting error.&lt;/p&gt;
&lt;p&gt;5] Can you please tell me how to config.&lt;/p&gt;
&lt;p&gt;its so greatful and thankful to me&lt;/p&gt;
&lt;p&gt;In This code got GPS data complete and when move to AWS modem is not configure.&lt;/p&gt;
&lt;p&gt;This is Kconfig&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#
# Copyright (c) 2020 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#

menu &amp;quot;GPS sample&amp;quot;

config APP_VERSION
	string &amp;quot;Application version&amp;quot;
	default &amp;quot;v1.0.0&amp;quot;

config LTE_POWER_SAVING_MODE
	bool &amp;quot;Request Power Saving Mode (PSM) from cellular network&amp;quot;

config PUBLICATION_INTERVAL_SECONDS
	int &amp;quot;Interval in seconds that the sample will publish data&amp;quot;
	default 60

config CONNECTION_RETRY_TIMEOUT_SECONDS
	int &amp;quot;Number of seconds between each AWS IoT connection retry&amp;quot;
	default 20

config GPS_SAMPLE_NMEA_ONLY
	bool &amp;quot;Output only NMEA strings&amp;quot;
	help
	  Outputs only NMEA strings from the GPS.

choice GPS_SAMPLE_ANTENNA
	default GPS_SAMPLE_ANTENNA_ONBOARD
	prompt &amp;quot;Select which antenna to use for GPS&amp;quot;

config GPS_SAMPLE_ANTENNA_ONBOARD
	bool &amp;quot;Use onboard antenna&amp;quot;

config GPS_SAMPLE_ANTENNA_EXTERNAL
	bool &amp;quot;Use external antenna&amp;quot;

endchoice

endmenu

menu &amp;quot;Zephyr Kernel&amp;quot;
source &amp;quot;Kconfig.zephyr&amp;quot;
endmenu
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This is prj.conf&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#GPS
# Copyright (c) 2019 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#
CONFIG_BSD_LIBRARY=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
CONFIG_AT_CMD=y
CONFIG_AT_NOTIF=y

# Enable SUPL client support
CONFIG_SUPL_CLIENT_LIB=n

# Networking
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y

# Disable native network stack to save some memory
CONFIG_NET_NATIVE=n

# Main thread
CONFIG_HEAP_MEM_POOL_SIZE=4096
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

# Application
CONFIG_GPS_SAMPLE_NMEA_ONLY=n

# General config
CONFIG_NCS_SAMPLES_DEFAULTS=y
CONFIG_REBOOT=y

# LTE link control
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_NETWORK_MODE_LTE_M=y
CONFIG_LTE_AUTO_INIT_AND_CONNECT=n
CONFIG_LTE_PSM_REQ_RPTAU=&amp;quot;00011111&amp;quot;
CONFIG_LTE_PSM_REQ_RAT=&amp;quot;00000010&amp;quot;
CONFIG_LTE_POWER_SAVING_MODE=y

# Download client (needed by AWS FOTA)
CONFIG_DOWNLOAD_CLIENT=y
CONFIG_DOWNLOAD_CLIENT_STACK_SIZE=4096

# MCUBOOT
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_MCUBOOT_IMG_MANAGER=y

# Image manager
CONFIG_IMG_MANAGER=y
CONFIG_FLASH=y
CONFIG_IMG_ERASE_PROGRESSIVELY=y

# AWS FOTA
CONFIG_AWS_FOTA=y
CONFIG_FOTA_DOWNLOAD=y
CONFIG_DFU_TARGET=y

# CJSON
CONFIG_CJSON_LIB=y

# Date Time library
CONFIG_DATE_TIME=y

# Modem information
CONFIG_MODEM_INFO=y


# BSD library
CONFIG_BSD_LIBRARY_SYS_INIT=y

# AT Host
CONFIG_AT_HOST_LIBRARY=y

# AWS IoT library
CONFIG_AWS_IOT=y
CONFIG_AWS_IOT_CLIENT_ID_STATIC=&amp;quot;nrf-352656101076381&amp;quot;
CONFIG_AWS_IOT_BROKER_HOST_NAME=&amp;quot;a6i4ulevbqzm-ats.iot.us-east-2.amazonaws.com&amp;quot;
CONFIG_AWS_IOT_SEC_TAG=200
CONFIG_AWS_IOT_APP_SUBSCRIPTION_LIST_COUNT=2
CONFIG_AWS_IOT_TOPIC_UPDATE_DELTA_SUBSCRIBE=y
CONFIG_AWS_IOT_CONNECTION_POLL_THREAD=y
CONFIG_AWS_IOT_LAST_WILL=y
CONFIG_AWS_IOT_TOPIC_GET_ACCEPTED_SUBSCRIBE=y
CONFIG_AWS_IOT_TOPIC_GET_REJECTED_SUBSCRIBE=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;
#define AT_Normal           &amp;quot;AT+CFUN=4&amp;quot;
#define AT_XSYSTEMMODE      &amp;quot;AT\%XSYSTEMMODE=1,0,1,0&amp;quot;
#define AT_ACTIVATE_GPS     &amp;quot;AT+CFUN=31&amp;quot;
#define AT_ACTIVATE_LTE     &amp;quot;AT+CFUN=21&amp;quot;
#define AT_DEACTIVATE_LTE   &amp;quot;AT+CFUN=20&amp;quot;

#define GNSS_INIT_AND_START 1
#define GNSS_STOP           2
#define GNSS_RESTART        3

#define AT_CMD_SIZE(x) (sizeof(x) - 1)

#ifdef CONFIG_BOARD_THINGY91_NRF9160NS
#define AT_MAGPIO      &amp;quot;AT\%XMAGPIO=1,1,1,7,1,746,803,2,698,748,2,1710,2200,&amp;quot; \
			&amp;quot;3,824,894,4,880,960,5,791,849,7,1565,1586&amp;quot;
#ifdef CONFIG_GPS_SAMPLE_ANTENNA_ONBOARD
#define AT_COEX0       &amp;quot;AT\%XCOEX0=1,1,1565,1586&amp;quot;
#elif CONFIG_GPS_SAMPLE_ANTENNA_EXTERNAL
#define AT_COEX0       &amp;quot;AT\%XCOEX0&amp;quot;
#endif
#endif /* CONFIG_BOARD_THINGY91_NRF9160NS */

static const char update_indicator[] = {&amp;#39;\\&amp;#39;, &amp;#39;|&amp;#39;, &amp;#39;/&amp;#39;, &amp;#39;-&amp;#39;};
static const char *const at_commands[] = {
	AT_Normal,
        AT_XSYSTEMMODE,
#if defined(CONFIG_BOARD_NRF9160DK_NRF9160NS) || \
	defined(CONFIG_BOARD_THINGY91_NRF9160NS)
	AT_MAGPIO,
	AT_COEX0,
#endif
	AT_ACTIVATE_GPS
};


static int modem_configure(void)
{
	int err = 0;

	if (IS_ENABLED(CONFIG_LTE_AUTO_INIT_AND_CONNECT)) {
		/* Do nothing, modem is already turned on
		 * and connected.
		 */
	} else {
		printk(&amp;quot;Connecting to LTE network. This may take minutes.&amp;quot;);

#if defined(CONFIG_LTE_POWER_SAVING_MODE)
		err = lte_lc_psm_req(true);
		if (err) {
			printk(&amp;quot;PSM request failed, error: %d&amp;quot;, err);
			return err;
		}

		printk(&amp;quot;PSM mode requested&amp;quot;);
#endif

		err = lte_lc_init_and_connect();
		if (err) {
			printk(&amp;quot;LTE link could not be established, error: %d&amp;quot;,
				err);
			return err;
		}

		printk(&amp;quot;Connected to LTE network&amp;quot;);
	}

	return err;
}

// static void modem_configure(void)
// {
	// int err;

	// if (IS_ENABLED(CONFIG_LTE_AUTO_INIT_AND_CONNECT)) {
		// /* Do nothing, modem is already configured and LTE connected. */
	// } else {
		// err = lte_lc_init_and_connect_async(lte_handler);
		// if (err) {
			// printk(&amp;quot;Modem could not be configured, error: %d\n&amp;quot;,
				// err);
			// return;
		// }
	// }
 // }

static void at_configure(void)
{
	int err;

	err = at_notif_init();
	__ASSERT(err == 0, &amp;quot;AT Notify could not be initialized.&amp;quot;);
	err = at_cmd_init();
	__ASSERT(err == 0, &amp;quot;AT CMD could not be established.&amp;quot;);
}

static void bsd_lib_modem_dfu_handler(void)
{
	int err;

	err = bsdlib_init();

	switch (err) {
	case MODEM_DFU_RESULT_OK:
		printk(&amp;quot;Modem update suceeded, reboot\n&amp;quot;);
		sys_reboot(SYS_REBOOT_COLD);
		break;
	case MODEM_DFU_RESULT_UUID_ERROR:
	case MODEM_DFU_RESULT_AUTH_ERROR:
		printk(&amp;quot;Modem update failed, error: %d\n&amp;quot;, err);
		printk(&amp;quot;Modem will use old firmware\n&amp;quot;);
		sys_reboot(SYS_REBOOT_COLD);
		break;
	case MODEM_DFU_RESULT_HARDWARE_ERROR:
	case MODEM_DFU_RESULT_INTERNAL_ERROR:
		printk(&amp;quot;Modem update malfunction, error: %d, reboot\n&amp;quot;, err);
		sys_reboot(SYS_REBOOT_COLD);
		break;
	default:
		break;
	}

	at_configure();
}
#endif

static int app_topics_subscribe(void)
{
	int err;
	static char custom_topic[75] = &amp;quot;$aws/things/nrf-352656101076381/shadow/GPS&amp;quot;;
	static char custom_topic_2[75] = &amp;quot;$aws/things/nrf-352656101076381/shadow/delta&amp;quot;;

	const struct aws_iot_topic_data topics_list[APP_TOPICS_COUNT] = {
		[0].str = custom_topic,
		[0].len = strlen(custom_topic),
		[1].str = custom_topic_2,
		[1].len = strlen(custom_topic_2)
	};

	err = aws_iot_subscription_topics_add(topics_list,
					      ARRAY_SIZE(topics_list));
	if (err) {
		printk(&amp;quot;aws_iot_subscription_topics_add, error: %d\n&amp;quot;, err);
	}

	return err;
}

static void date_time_event_handler(const struct date_time_evt *evt)
{
	switch (evt-&amp;gt;type) {
	case DATE_TIME_OBTAINED_MODEM:
		printk(&amp;quot;DATE_TIME_OBTAINED_MODEM\n&amp;quot;);
		break;
	case DATE_TIME_OBTAINED_NTP:
		printk(&amp;quot;DATE_TIME_OBTAINED_NTP\n&amp;quot;);
		break;
	case DATE_TIME_OBTAINED_EXT:
		printk(&amp;quot;DATE_TIME_OBTAINED_EXT\n&amp;quot;);
		break;
	case DATE_TIME_NOT_OBTAINED:
		printk(&amp;quot;DATE_TIME_NOT_OBTAINED\n&amp;quot;);
		break;
	default:
		break;
	}

	/** Do not depend on obtained time, continue upon any event from the
	 *  date time library.
	 */
	k_sem_give(&amp;amp;date_time_obtained);
}


void nrf_modem_recoverable_error_handler(uint32_t error)
{
	printf(&amp;quot;Err: %lu\n&amp;quot;, (unsigned long)error);
}

static int setup_modem(void)
{
	for (int i = 0; i &amp;lt; ARRAY_SIZE(at_commands); i++) {

		if (at_cmd_write(at_commands[i], NULL, 0, NULL) != 0) {
			return -1;
		}
	}

	return 0;
}

static int gnss_ctrl(uint32_t ctrl)
{
	int retval;

	nrf_gnss_fix_retry_t    fix_retry    = 0;
	nrf_gnss_fix_interval_t fix_interval = 1;
	nrf_gnss_delete_mask_t	delete_mask  = 0;
	nrf_gnss_nmea_mask_t	nmea_mask    = NRF_GNSS_NMEA_GSV_MASK |
					       NRF_GNSS_NMEA_GSA_MASK |
					       NRF_GNSS_NMEA_GLL_MASK |
					       NRF_GNSS_NMEA_GGA_MASK |
					       NRF_GNSS_NMEA_RMC_MASK;

	if (ctrl == GNSS_INIT_AND_START) {
		gnss_fd = nrf_socket(NRF_AF_LOCAL,
				     NRF_SOCK_DGRAM,
				     NRF_PROTO_GNSS);

		if (gnss_fd &amp;gt;= 0) {
			printk(&amp;quot;GPS Socket created\n&amp;quot;);
		} else {
			printk(&amp;quot;Could not init socket (err: %d)\n&amp;quot;, gnss_fd);
			return -1;
		}

		retval = nrf_setsockopt(gnss_fd,
					NRF_SOL_GNSS,
					NRF_SO_GNSS_FIX_RETRY,
					&amp;amp;fix_retry,
					sizeof(fix_retry));
		if (retval != 0) {
			printk(&amp;quot;Failed to set fix retry value\n&amp;quot;);
			return -1;
		}

		retval = nrf_setsockopt(gnss_fd,
					NRF_SOL_GNSS,
					NRF_SO_GNSS_FIX_INTERVAL,
					&amp;amp;fix_interval,
					sizeof(fix_interval));
		if (retval != 0) {
			printk(&amp;quot;Failed to set fix interval value\n&amp;quot;);
			return -1;
		}

		retval = nrf_setsockopt(gnss_fd,
					NRF_SOL_GNSS,
					NRF_SO_GNSS_NMEA_MASK,
					&amp;amp;nmea_mask,
					sizeof(nmea_mask));
		if (retval != 0) {
			printk(&amp;quot;Failed to set nmea mask\n&amp;quot;);
			return -1;
		}
	}

	if ((ctrl == GNSS_INIT_AND_START) ||
	    (ctrl == GNSS_RESTART)) {
		retval = nrf_setsockopt(gnss_fd,
					NRF_SOL_GNSS,
					NRF_SO_GNSS_START,
					&amp;amp;delete_mask,
					sizeof(delete_mask));
		if (retval != 0) {
			printk(&amp;quot;Failed to start GPS\n&amp;quot;);
			return -1;
		}
	}

	if (ctrl == GNSS_STOP) {
		retval = nrf_setsockopt(gnss_fd,
					NRF_SOL_GNSS,
					NRF_SO_GNSS_STOP,
					&amp;amp;delete_mask,
					sizeof(delete_mask));
		if (retval != 0) {
			printk(&amp;quot;Failed to stop GPS\n&amp;quot;);
			return -1;
		}
	}

	return 0;
}

static int init_app(void)
{
	int retval;

	if (setup_modem() != 0) {
		printk(&amp;quot;Failed to initialize modem\n&amp;quot;);
		return -1;
	}

	retval = gnss_ctrl(GNSS_INIT_AND_START);

	return retval;
}

static void print_satellite_stats(nrf_gnss_data_frame_t *pvt_data)
{
	uint8_t  tracked          = 0;
	uint8_t  in_fix           = 0;
	uint8_t  unhealthy        = 0;

	for (int i = 0; i &amp;lt; NRF_GNSS_MAX_SATELLITES; ++i) {

		if ((pvt_data-&amp;gt;pvt.sv[i].sv &amp;gt; 0) &amp;amp;&amp;amp;
		    (pvt_data-&amp;gt;pvt.sv[i].sv &amp;lt; 33)) {

			tracked++;

			if (pvt_data-&amp;gt;pvt.sv[i].flags &amp;amp;
					NRF_GNSS_SV_FLAG_USED_IN_FIX) {
				in_fix++;
			}

			if (pvt_data-&amp;gt;pvt.sv[i].flags &amp;amp;
					NRF_GNSS_SV_FLAG_UNHEALTHY) {
				unhealthy++;
			}
		}
	}

	printk(&amp;quot;Tracking: %d Using: %d Unhealthy: %d\n&amp;quot;, tracked,
							 in_fix,
							 unhealthy);
}

static void print_gnss_stats(nrf_gnss_data_frame_t *pvt_data)
{
	if (pvt_data-&amp;gt;pvt.flags &amp;amp; NRF_GNSS_PVT_FLAG_DEADLINE_MISSED) {
		printk(&amp;quot;GNSS notification deadline missed\n&amp;quot;);
	}
	if (pvt_data-&amp;gt;pvt.flags &amp;amp; NRF_GNSS_PVT_FLAG_NOT_ENOUGH_WINDOW_TIME) {
		printk(&amp;quot;GNSS operation blocked by insufficient time windows\n&amp;quot;);
	}
}

static void print_fix_data(nrf_gnss_data_frame_t *pvt_data)
{
	printf(&amp;quot;Longitude:  %f\n&amp;quot;, pvt_data-&amp;gt;pvt.longitude);
	printf(&amp;quot;Latitude:   %f\n&amp;quot;, pvt_data-&amp;gt;pvt.latitude);
	printf(&amp;quot;Altitude:   %f\n&amp;quot;, pvt_data-&amp;gt;pvt.altitude);
	printf(&amp;quot;Speed:      %f\n&amp;quot;, pvt_data-&amp;gt;pvt.speed);
	printf(&amp;quot;Heading:    %f\n&amp;quot;, pvt_data-&amp;gt;pvt.heading);
	printk(&amp;quot;Date:       %02u-%02u-%02u\n&amp;quot;, pvt_data-&amp;gt;pvt.datetime.year,
					       pvt_data-&amp;gt;pvt.datetime.month,
					       pvt_data-&amp;gt;pvt.datetime.day);
	printk(&amp;quot;Time (UTC): %02u:%02u:%02u\n&amp;quot;, pvt_data-&amp;gt;pvt.datetime.hour,
					       pvt_data-&amp;gt;pvt.datetime.minute,
					      pvt_data-&amp;gt;pvt.datetime.seconds);
}

static void print_nmea_data(void)
{
	for (int i = 0; i &amp;lt; nmea_string_cnt; ++i) {
		printk(&amp;quot;%s&amp;quot;, nmea_strings[i]);
	}
}

int process_gps_data(nrf_gnss_data_frame_t *gps_data)
{
	int retval;

	retval = nrf_recv(gnss_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:
			memcpy(&amp;amp;last_pvt,
			       gps_data,
			       sizeof(nrf_gnss_data_frame_t));
			nmea_string_cnt = 0;
			got_fix = false;

			if (gps_data-&amp;gt;pvt.flags
					&amp;amp; NRF_GNSS_PVT_FLAG_FIX_VALID_BIT) {

				got_fix = true;
				fix_timestamp = k_uptime_get();
			}
			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;

		case NRF_GNSS_AGPS_DATA_ID:
			break;

		default:
			break;
		}
	}

	return retval;
}

void get_gps(void)
{
    

}

void main(void)
{
	int err;
	uint8_t		      cnt = 0;
	nrf_gnss_data_frame_t gps_data;
	
	bool set = true;
    
	printk(&amp;quot;Starting GPS application\n&amp;quot;);

	if (init_app() != 0) {
		//return -1;
	}
        while (set) {

		do {
			/* Loop until we don&amp;#39;t have more
			 * data to read
			 */
		} while (process_gps_data(&amp;amp;gps_data) &amp;gt; 0);

		if (IS_ENABLED(CONFIG_GPS_SAMPLE_NMEA_ONLY)) {
			print_nmea_data();
			nmea_string_cnt = 0;
		} else {
			printk(&amp;quot;\033[1;1H&amp;quot;);
			printk(&amp;quot;\033[2J&amp;quot;);
			print_satellite_stats(&amp;amp;last_pvt);
			print_gnss_stats(&amp;amp;last_pvt);
			printk(&amp;quot;---------------------------------\n&amp;quot;);

			if (!got_fix) {
				printk(&amp;quot;Seconds since last fix: %lld\n&amp;quot;,
				       (k_uptime_get() - fix_timestamp) / 1000);
				cnt++;
				printk(&amp;quot;Searching [%c]\n&amp;quot;,
				       update_indicator[cnt%4]);
			} else {
				print_fix_data(&amp;amp;last_pvt);
				set = false;
			}

			printk(&amp;quot;\nNMEA strings:\n\n&amp;quot;);
			print_nmea_data();
			printk(&amp;quot;---------------------------------&amp;quot;);
		}

		k_msleep(500);
	}
	
	printk(&amp;quot;The AWS IoT sample started, version: %s\n&amp;quot;, CONFIG_APP_VERSION);

	cJSON_Init();

#if defined(CONFIG_BSD_LIBRARY)
	bsd_lib_modem_dfu_handler();
#endif

	err = aws_iot_init(NULL, aws_iot_event_handler);
	if (err) {
		printk(&amp;quot;AWS IoT library could not be initialized, error: %d\n&amp;quot;,
		       err);
	}

	/** Subscribe to customizable non-shadow specific topics
	 *  to AWS IoT backend.
	 */
	err = app_topics_subscribe();
	if (err) {
		printk(&amp;quot;Adding application specific topics failed, error: %d\n&amp;quot;,
			err);
	}

	work_init();

#if defined(CONFIG_BSD_LIBRARY)
	modem_configure();

	err = modem_info_init();
	if (err) {
		printk(&amp;quot;Failed initializing modem info module, error: %d\n&amp;quot;,
			err);
	}

	k_sem_take(&amp;amp;lte_connected, K_FOREVER);
#endif


	date_time_update_async(date_time_event_handler);

	err = k_sem_take(&amp;amp;date_time_obtained, K_SECONDS(DATE_TIME_TIMEOUT_S));
	if (err) {
		printk(&amp;quot;Date time, no callback event within %d seconds\n&amp;quot;,
			DATE_TIME_TIMEOUT_S);
	}

	k_delayed_work_submit(&amp;amp;connect_work, K_NO_WAIT);
    get_gps();
        
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks &amp;amp; Regards&lt;/p&gt;
&lt;p&gt;Jaydip&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send data to own AWS server using Cloud Client sample ?</title><link>https://devzone.nordicsemi.com/thread/288153?ContentTypeID=1</link><pubDate>Fri, 08 Jan 2021 11:57:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f8a1eec5-c755-4c6c-a6ba-32b42d12c9a1</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;I&amp;#39;ve talked to our R&amp;amp;D team. It&amp;#39;s possible to&amp;nbsp;use the agps sample that we have in NCS and configure it to use aws_iot lib as a cloud backend instead of the default nRF Cloud backend. This requires an AWS account and &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/include/net/aws_iot.html?highlight=aws_iot#aws-iot"&gt;proper setup found in the documentation for aws_iot&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The A-GPS sample states:&lt;br /&gt;&amp;quot;&lt;em&gt;The A-GPS sample demonstrates how the&amp;nbsp;&lt;a href="https://nrfcloud.com/"&gt;nRF Cloud&lt;/a&gt;&amp;nbsp;Assisted GPS (&lt;a href="https://en.wikipedia.org/wiki/Assisted_GPS"&gt;A-GPS&lt;/a&gt;) feature or an external&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/include/supl_os_client.html#supl-client"&gt;&lt;span&gt;SUPL client&lt;/span&gt;&lt;/a&gt;&amp;nbsp;can be used to implement A-GPS in your application. The sample uses the generic A-GPS library, which allows the selection of different A-GPS sources via the&amp;nbsp;&lt;a title="(in Kconfig reference v&amp;amp;nbsp;)" href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/kconfig/CONFIG_AGPS_SRC_SUPL.html#cmdoption-arg-CONFIG_AGPS_SRC_SUPL"&gt;&lt;code&gt;&lt;span&gt;CONFIG_AGPS_SRC_SUPL&lt;/span&gt;&lt;/code&gt;&lt;/a&gt;&amp;nbsp;configurable option. By default,&amp;nbsp;&lt;a href="https://nrfcloud.com/"&gt;nRF Cloud&lt;/a&gt;&lt;/em&gt;&lt;span&gt;&lt;em&gt;&amp;nbsp;is used for A-GPS and cloud communication&lt;/em&gt;&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;In terms of using SUPL you have to change the default AGPS source by setting &lt;em&gt;CONFIG_AGPS_SRC_SUPL=y. &lt;/em&gt;You&amp;nbsp;also need to import the SUPL library into their NCS tree. Please &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/include/supl_os_client.html?highlight=supl#supl-client-and-supl-client-os-integration"&gt;see the SUPL documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;-Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send data to own AWS server using Cloud Client sample ?</title><link>https://devzone.nordicsemi.com/thread/288136?ContentTypeID=1</link><pubDate>Fri, 08 Jan 2021 10:42:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:855a4350-32c3-4fcc-a1e0-fe10c0a8fc44</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;My initial answer is yes. However, the nRF Cloud A-GPS does not work with AWS. I am discussing the issue and will get back to you within the day.&lt;br /&gt;&lt;br /&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send data to own AWS server using Cloud Client sample ?</title><link>https://devzone.nordicsemi.com/thread/288077?ContentTypeID=1</link><pubDate>Fri, 08 Jan 2021 06:24:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f63fb1d2-f691-41e3-8690-618808a772ef</guid><dc:creator>jaydip kavaiya</dc:creator><description>&lt;p&gt;Hello Oyvind&lt;/p&gt;
&lt;p&gt;I know in this situation little hard to take time for given answer and Thank you for your fast reply&lt;/p&gt;
&lt;p&gt;but pls if you can ans and suggest me for step of above question its very helpful me.&lt;/p&gt;
&lt;p&gt;and I still stuck where from I started this case and near to deadline from my project.&lt;/p&gt;
&lt;p&gt;Thanks &amp;amp; Regards&lt;/p&gt;
&lt;p&gt;Jaydip Kavaiya&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send data to own AWS server using Cloud Client sample ?</title><link>https://devzone.nordicsemi.com/thread/287946?ContentTypeID=1</link><pubDate>Thu, 07 Jan 2021 12:34:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ef631636-5449-4437-8767-51cd5fa938d7</guid><dc:creator>jaydip kavaiya</dc:creator><description>&lt;p&gt;Thanks Oyvind&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Can I use Agps sample with AWS_IOT from where i know AGPS uses nRF cloud so&lt;/p&gt;
&lt;p&gt;we need to configure AWS with nRF so is it possible?&lt;/p&gt;
&lt;p&gt;or can you give me step for merging AGPS with AWS_IoT.?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks &amp;amp; Regrads&lt;/p&gt;
&lt;p&gt;JAYDIP&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send data to own AWS server using Cloud Client sample ?</title><link>https://devzone.nordicsemi.com/thread/287933?ContentTypeID=1</link><pubDate>Thu, 07 Jan 2021 11:44:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:767808ad-280c-449d-a98c-a79020673cde</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;As long as the modem/LTE is in RRC Idle mode or power saving mode (PSM), or when the LTE modem is completely deactivated, you can use the GPS. Once you have the GPS coordinates, you must&amp;nbsp; deactivate GPS and exit RRC Idle mode or PSM, or activate the modem, in order to send data. Make sure that you &lt;a href="https://infocenter.nordicsemi.com/topic/ref_at_commands/REF/at_commands/packet_domain/cscon_read.html"&gt;wait for +CSCON: 1 indicating that you are connected.&lt;/a&gt;&amp;nbsp;Then, once you are connected to the network and verified connection to AWS cloud, you should be able to send data to you AWS server. After you have sent data, you will need to go back to PSM and active GPS again.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send data to own AWS server using Cloud Client sample ?</title><link>https://devzone.nordicsemi.com/thread/287917?ContentTypeID=1</link><pubDate>Thu, 07 Jan 2021 10:51:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:031eed9f-80a7-485c-87df-a9fb821d762e</guid><dc:creator>jaydip kavaiya</dc:creator><description>&lt;p&gt;Thanks Oyvind,&lt;/p&gt;
&lt;p&gt;OK I read this so,Now can you pleas suggest me&amp;nbsp;how can get and send GPS data to AWS server continuously.&lt;/p&gt;
&lt;p&gt;Regrads&lt;/p&gt;
&lt;p&gt;Jaydip&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send data to own AWS server using Cloud Client sample ?</title><link>https://devzone.nordicsemi.com/thread/287909?ContentTypeID=1</link><pubDate>Thu, 07 Jan 2021 10:29:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f117baf9-a81a-43dc-99dc-fa81c34cc877</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Looking at your output. You are aware that GPS and LTE do not work at the same time?&lt;br /&gt;&lt;br /&gt;2021-01-07T09:34:58.217Z DEBUG modem &amp;lt;&amp;lt; Starting GPS application&lt;br /&gt;2021-01-07T09:34:58.234Z DEBUG modem &amp;lt;&amp;lt; GPS Socket created&lt;br /&gt;2021-01-07T09:34:58.268Z DEBUG modem &amp;lt;&amp;lt; E: Could not send AT command, error: -8&lt;br /&gt;2021-01-07T09:34:58.271Z DEBUG modem &amp;lt;&amp;lt; Modem could not be configured, error: -8&lt;br /&gt;&lt;br /&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf9160/gps.html?resultof=%22%67%70%73%22%20%22%67%70%22%20"&gt;From the GPS Receiver chapter&lt;/a&gt;&lt;br /&gt;&lt;em&gt;&amp;quot;The&amp;nbsp;GPS&amp;nbsp;receiver supports&amp;nbsp;GPS&amp;nbsp;L1 C/A reception. Operation is time multiplexed with LTE modem, and it is possible to obtain the&amp;nbsp;GPS&amp;nbsp;position either while the LTE is in RRC Idle mode or power saving mode (PSM), or when the LTE modem is completely deactivated.&amp;quot;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send data to own AWS server using Cloud Client sample ?</title><link>https://devzone.nordicsemi.com/thread/287887?ContentTypeID=1</link><pubDate>Thu, 07 Jan 2021 09:54:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a002b18a-e5e9-40f5-990f-5dbabdd88b73</guid><dc:creator>jaydip kavaiya</dc:creator><description>[quote userid="77062" url="~/f/nordic-q-a/69840/how-to-send-data-to-own-aws-server-using-cloud-client-sample/287878#287878"]I&amp;#39;m not able to compile. Can you please share full project?[/quote]
&lt;p&gt;Sure, Thanks you for your fast reply I stuck at this point.&lt;/p&gt;
&lt;p&gt;1.main.c&lt;/p&gt;
&lt;p&gt;2.prj.conf&lt;/p&gt;
&lt;p&gt;3.Kconfig&lt;/p&gt;
&lt;p&gt;4 sample.yaml&lt;/p&gt;
&lt;p&gt;5 CMakeLists&lt;/p&gt;
&lt;p&gt;6. Logfile&lt;/p&gt;
&lt;p&gt;I use GPS sample so rest are as it is.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*
 * Copyright (c) 2019 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
 */

#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;nrf_socket.h&amp;gt;
#include &amp;lt;net/socket.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;

#include &amp;lt;modem/lte_lc.h&amp;gt;
#include &amp;lt;modem/bsdlib.h&amp;gt;
#include &amp;lt;modem/at_cmd.h&amp;gt;
#include &amp;lt;modem/at_notif.h&amp;gt;
#include &amp;lt;modem/modem_info.h&amp;gt;
#include &amp;lt;bsd.h&amp;gt;

#include &amp;lt;net/aws_iot.h&amp;gt;
#include &amp;lt;power/reboot.h&amp;gt;
#include &amp;lt;date_time.h&amp;gt;
#include &amp;lt;dfu/mcuboot.h&amp;gt;
#include &amp;lt;cJSON.h&amp;gt;
#include &amp;lt;cJSON_os.h&amp;gt;

#ifdef CONFIG_SUPL_CLIENT_LIB
#include &amp;lt;supl_os_client.h&amp;gt;
#include &amp;lt;supl_session.h&amp;gt;
#include &amp;quot;supl_support.h&amp;quot;
#endif

#define AT_XSYSTEMMODE      &amp;quot;AT\%XSYSTEMMODE=1,0,1,0&amp;quot;
#define AT_ACTIVATE_GPS     &amp;quot;AT+CFUN=31&amp;quot;
#define AT_ACTIVATE_LTE     &amp;quot;AT+CFUN=21&amp;quot;
#define AT_DEACTIVATE_LTE   &amp;quot;AT+CFUN=20&amp;quot;

#define GNSS_INIT_AND_START 1
#define GNSS_STOP           2
#define GNSS_RESTART        3

#define AT_CMD_SIZE(x) (sizeof(x) - 1)

#ifdef CONFIG_BOARD_NRF9160DK_NRF9160NS
#define AT_MAGPIO      &amp;quot;AT\%XMAGPIO=1,0,0,1,1,1574,1577&amp;quot;
#ifdef CONFIG_GPS_SAMPLE_ANTENNA_ONBOARD
#define AT_COEX0       &amp;quot;AT\%XCOEX0=1,1,1565,1586&amp;quot;
#elif CONFIG_GPS_SAMPLE_ANTENNA_EXTERNAL
#define AT_COEX0       &amp;quot;AT\%XCOEX0&amp;quot;
#endif
#endif /* CONFIG_BOARD_NRF9160DK_NRF9160NS */

#ifdef CONFIG_BOARD_THINGY91_NRF9160NS
#define AT_MAGPIO      &amp;quot;AT\%XMAGPIO=1,1,1,7,1,746,803,2,698,748,2,1710,2200,&amp;quot; \
			&amp;quot;3,824,894,4,880,960,5,791,849,7,1565,1586&amp;quot;
#ifdef CONFIG_GPS_SAMPLE_ANTENNA_ONBOARD
#define AT_COEX0       &amp;quot;AT\%XCOEX0=1,1,1565,1586&amp;quot;
#elif CONFIG_GPS_SAMPLE_ANTENNA_EXTERNAL
#define AT_COEX0       &amp;quot;AT\%XCOEX0&amp;quot;
#endif
#endif /* CONFIG_BOARD_THINGY91_NRF9160NS */

static const char update_indicator[] = {&amp;#39;\\&amp;#39;, &amp;#39;|&amp;#39;, &amp;#39;/&amp;#39;, &amp;#39;-&amp;#39;};
static const char *const at_commands[] = {
	AT_XSYSTEMMODE,
#if defined(CONFIG_BOARD_NRF9160DK_NRF9160NS) || \
	defined(CONFIG_BOARD_THINGY91_NRF9160NS)
	AT_MAGPIO,
	AT_COEX0,
#endif
	AT_ACTIVATE_GPS
};

static int                   gnss_fd;
static char                  nmea_strings[10][NRF_GNSS_NMEA_MAX_LEN];
static uint32_t                 nmea_string_cnt;

static bool                  got_fix;
static uint64_t                 fix_timestamp;
static nrf_gnss_data_frame_t last_pvt;

K_SEM_DEFINE(lte_ready, 0, 1);

BUILD_ASSERT(!IS_ENABLED(CONFIG_LTE_AUTO_INIT_AND_CONNECT),
		&amp;quot;This sample does not support LTE auto-init and connect&amp;quot;);

#define APP_TOPICS_COUNT CONFIG_AWS_IOT_APP_SUBSCRIPTION_LIST_COUNT

/* Timeout in seconds in which the application will wait for an initial event
 * from the date time library.
 */
#define DATE_TIME_TIMEOUT_S 15

static struct k_delayed_work shadow_update_work;
static struct k_delayed_work connect_work;
static struct k_delayed_work shadow_update_version_work;

K_SEM_DEFINE(lte_connected, 0, 1);
K_SEM_DEFINE(date_time_obtained, 0, 1);

void bsd_recoverable_error_handler(uint32_t error)
{
	printf(&amp;quot;Err: %lu\n&amp;quot;, (unsigned long)error);
}

static int setup_modem(void)
{
	for (int i = 0; i &amp;lt; ARRAY_SIZE(at_commands); i++) {

		if (at_cmd_write(at_commands[i], NULL, 0, NULL) != 0) {
			return -1;
		}
	}

	return 0;
}

#ifdef CONFIG_SUPL_CLIENT_LIB
/* Accepted network statuses read from modem */
static const char status1[] = &amp;quot;+CEREG: 1&amp;quot;;
static const char status2[] = &amp;quot;+CEREG:1&amp;quot;;
static const char status3[] = &amp;quot;+CEREG: 5&amp;quot;;
static const char status4[] = &amp;quot;+CEREG:5&amp;quot;;

static void wait_for_lte(void *context, const char *response)
{
	if (!memcmp(status1, response, AT_CMD_SIZE(status1)) ||
		!memcmp(status2, response, AT_CMD_SIZE(status2)) ||
		!memcmp(status3, response, AT_CMD_SIZE(status3)) ||
		!memcmp(status4, response, AT_CMD_SIZE(status4))) {
		k_sem_give(&amp;amp;lte_ready);
	}
}

static int activate_lte(bool activate)
{
	if (activate) {
		if (at_cmd_write(AT_ACTIVATE_LTE, NULL, 0, NULL) != 0) {
			return -1;
		}

		at_notif_register_handler(NULL, wait_for_lte);
		if (at_cmd_write(&amp;quot;AT+CEREG=2&amp;quot;, NULL, 0, NULL) != 0) {
			return -1;
		}

		k_sem_take(&amp;amp;lte_ready, K_FOREVER);

		at_notif_deregister_handler(NULL, wait_for_lte);
		if (at_cmd_write(&amp;quot;AT+CEREG=0&amp;quot;, NULL, 0, NULL) != 0) {
			return -1;
		}
	} else {
		if (at_cmd_write(AT_DEACTIVATE_LTE, NULL, 0, NULL) != 0) {
			return -1;
		}
	}

	return 0;
}
#endif

static int gnss_ctrl(uint32_t ctrl)
{
	int retval;

	nrf_gnss_fix_retry_t    fix_retry    = 0;
	nrf_gnss_fix_interval_t fix_interval = 1;
	nrf_gnss_delete_mask_t	delete_mask  = 0;
	nrf_gnss_nmea_mask_t	nmea_mask    = NRF_GNSS_NMEA_GSV_MASK |
					       NRF_GNSS_NMEA_GSA_MASK |
					       NRF_GNSS_NMEA_GLL_MASK |
					       NRF_GNSS_NMEA_GGA_MASK |
					       NRF_GNSS_NMEA_RMC_MASK;

	if (ctrl == GNSS_INIT_AND_START) {
		gnss_fd = nrf_socket(NRF_AF_LOCAL,
				     NRF_SOCK_DGRAM,
				     NRF_PROTO_GNSS);

		if (gnss_fd &amp;gt;= 0) {
			printk(&amp;quot;GPS Socket created\n&amp;quot;);
		} else {
			printk(&amp;quot;Could not init socket (err: %d)\n&amp;quot;, gnss_fd);
			return -1;
		}

		retval = nrf_setsockopt(gnss_fd,
					NRF_SOL_GNSS,
					NRF_SO_GNSS_FIX_RETRY,
					&amp;amp;fix_retry,
					sizeof(fix_retry));
		if (retval != 0) {
			printk(&amp;quot;Failed to set fix retry value\n&amp;quot;);
			return -1;
		}

		retval = nrf_setsockopt(gnss_fd,
					NRF_SOL_GNSS,
					NRF_SO_GNSS_FIX_INTERVAL,
					&amp;amp;fix_interval,
					sizeof(fix_interval));
		if (retval != 0) {
			printk(&amp;quot;Failed to set fix interval value\n&amp;quot;);
			return -1;
		}

		retval = nrf_setsockopt(gnss_fd,
					NRF_SOL_GNSS,
					NRF_SO_GNSS_NMEA_MASK,
					&amp;amp;nmea_mask,
					sizeof(nmea_mask));
		if (retval != 0) {
			printk(&amp;quot;Failed to set nmea mask\n&amp;quot;);
			return -1;
		}
	}

	if ((ctrl == GNSS_INIT_AND_START) ||
	    (ctrl == GNSS_RESTART)) {
		retval = nrf_setsockopt(gnss_fd,
					NRF_SOL_GNSS,
					NRF_SO_GNSS_START,
					&amp;amp;delete_mask,
					sizeof(delete_mask));
		if (retval != 0) {
			printk(&amp;quot;Failed to start GPS\n&amp;quot;);
			return -1;
		}
	}

	if (ctrl == GNSS_STOP) {
		retval = nrf_setsockopt(gnss_fd,
					NRF_SOL_GNSS,
					NRF_SO_GNSS_STOP,
					&amp;amp;delete_mask,
					sizeof(delete_mask));
		if (retval != 0) {
			printk(&amp;quot;Failed to stop GPS\n&amp;quot;);
			return -1;
		}
	}

	return 0;
}

static int init_app(void)
{
	int retval;


	if (setup_modem() != 0) {
		printk(&amp;quot;Failed to initialize modem\n&amp;quot;);
		return -1;
	}

	retval = gnss_ctrl(GNSS_INIT_AND_START);

	return retval;
}

static void print_satellite_stats(nrf_gnss_data_frame_t *pvt_data)
{
	uint8_t  tracked          = 0;
	uint8_t  in_fix           = 0;
	uint8_t  unhealthy        = 0;

	for (int i = 0; i &amp;lt; NRF_GNSS_MAX_SATELLITES; ++i) {

		if ((pvt_data-&amp;gt;pvt.sv[i].sv &amp;gt; 0) &amp;amp;&amp;amp;
		    (pvt_data-&amp;gt;pvt.sv[i].sv &amp;lt; 33)) {

			tracked++;

			if (pvt_data-&amp;gt;pvt.sv[i].flags &amp;amp;
					NRF_GNSS_SV_FLAG_USED_IN_FIX) {
				in_fix++;
			}

			if (pvt_data-&amp;gt;pvt.sv[i].flags &amp;amp;
					NRF_GNSS_SV_FLAG_UNHEALTHY) {
				unhealthy++;
			}
		}
	}

	printk(&amp;quot;Tracking: %d Using: %d Unhealthy: %d\n&amp;quot;, tracked,
							 in_fix,
							 unhealthy);
}

static void print_gnss_stats(nrf_gnss_data_frame_t *pvt_data)
{
	if (pvt_data-&amp;gt;pvt.flags &amp;amp; NRF_GNSS_PVT_FLAG_DEADLINE_MISSED) {
		printk(&amp;quot;GNSS notification deadline missed\n&amp;quot;);
	}
	if (pvt_data-&amp;gt;pvt.flags &amp;amp; NRF_GNSS_PVT_FLAG_NOT_ENOUGH_WINDOW_TIME) {
		printk(&amp;quot;GNSS operation blocked by insufficient time windows\n&amp;quot;);
	}
}

static void print_fix_data(nrf_gnss_data_frame_t *pvt_data)
{
	printf(&amp;quot;Longitude:  %f\n&amp;quot;, pvt_data-&amp;gt;pvt.longitude);
	printf(&amp;quot;Latitude:   %f\n&amp;quot;, pvt_data-&amp;gt;pvt.latitude);
	printf(&amp;quot;Altitude:   %f\n&amp;quot;, pvt_data-&amp;gt;pvt.altitude);
	printf(&amp;quot;Speed:      %f\n&amp;quot;, pvt_data-&amp;gt;pvt.speed);
	printf(&amp;quot;Heading:    %f\n&amp;quot;, pvt_data-&amp;gt;pvt.heading);
	printk(&amp;quot;Date:       %02u-%02u-%02u\n&amp;quot;, pvt_data-&amp;gt;pvt.datetime.year,
					       pvt_data-&amp;gt;pvt.datetime.month,
					       pvt_data-&amp;gt;pvt.datetime.day);
	printk(&amp;quot;Time (UTC): %02u:%02u:%02u\n&amp;quot;, pvt_data-&amp;gt;pvt.datetime.hour,
					       pvt_data-&amp;gt;pvt.datetime.minute,
					      pvt_data-&amp;gt;pvt.datetime.seconds);
}

static void print_nmea_data(void)
{
	for (int i = 0; i &amp;lt; nmea_string_cnt; ++i) {
		printk(&amp;quot;%s&amp;quot;, nmea_strings[i]);
	}
}

int process_gps_data(nrf_gnss_data_frame_t *gps_data)
{
	int retval;

	retval = nrf_recv(gnss_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:
			memcpy(&amp;amp;last_pvt,
			       gps_data,
			       sizeof(nrf_gnss_data_frame_t));
			nmea_string_cnt = 0;
			got_fix = false;

			if ((gps_data-&amp;gt;pvt.flags &amp;amp;
				NRF_GNSS_PVT_FLAG_FIX_VALID_BIT)
				== NRF_GNSS_PVT_FLAG_FIX_VALID_BIT) {

				got_fix = true;
				fix_timestamp = k_uptime_get();
			}
			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;

		case NRF_GNSS_AGPS_DATA_ID:
#ifdef CONFIG_SUPL_CLIENT_LIB
			printk(&amp;quot;\033[1;1H&amp;quot;);
			printk(&amp;quot;\033[2J&amp;quot;);
			printk(&amp;quot;New AGPS data requested, contacting SUPL server, flags %d\n&amp;quot;,
			       gps_data-&amp;gt;agps.data_flags);
			gnss_ctrl(GNSS_STOP);
			activate_lte(true);
			printk(&amp;quot;Established LTE link\n&amp;quot;);
			if (open_supl_socket() == 0) {
				printf(&amp;quot;Starting SUPL session\n&amp;quot;);
				supl_session(&amp;amp;gps_data-&amp;gt;agps);
				printk(&amp;quot;Done\n&amp;quot;);
				close_supl_socket();
			}
			activate_lte(false);
			gnss_ctrl(GNSS_RESTART);
			k_sleep(K_MSEC(2000));
#endif
			break;

		default:
			break;
		}
	}

	return retval;
}

#ifdef CONFIG_SUPL_CLIENT_LIB
int inject_agps_type(void *agps,
		     size_t agps_size,
		     nrf_gnss_agps_data_type_t type,
		     void *user_data)
{
	ARG_UNUSED(user_data);
	int retval = nrf_sendto(gnss_fd,
				agps,
				agps_size,
				0,
				&amp;amp;type,
				sizeof(type));

	if (retval != 0) {
		printk(&amp;quot;Failed to send AGNSS data, type: %d (err: %d)\n&amp;quot;,
		       type,
		       errno);
		return -1;
	}

	printk(&amp;quot;Injected AGPS data, flags: %d, size: %d\n&amp;quot;, type, agps_size);

	return 0;
}
#endif




static int json_add_obj(cJSON *parent, const char *str, cJSON *item)
{
	cJSON_AddItemToObject(parent, str, item);

	return 0;
}

static int json_add_str(cJSON *parent, const char *str, const char *item)
{
	cJSON *json_str;

	json_str = cJSON_CreateString(item);
	if (json_str == NULL) {
		return -ENOMEM;
	}

	return json_add_obj(parent, str, json_str);
}

static int json_add_number(cJSON *parent, const char *str, double item)
{
	cJSON *json_num;

	json_num = cJSON_CreateNumber(item);
	if (json_num == NULL) {
		return -ENOMEM;
	}

	return json_add_obj(parent, str, json_num);
}

static int shadow_update(bool version_number_include)
{
	int err;
	char *message;
	int64_t message_ts;
	int16_t bat_voltage = 0;

	err = date_time_now(&amp;amp;message_ts);
	if (err) {
		printk(&amp;quot;date_time_now, error: %d\n&amp;quot;, err);
		return err;
	}

#if defined(CONFIG_BSD_LIBRARY)
	/* Request battery voltage data from the modem. */
	err = modem_info_short_get(MODEM_INFO_BATTERY, &amp;amp;bat_voltage);
	if (err != sizeof(bat_voltage)) {
		printk(&amp;quot;modem_info_short_get, error: %d\n&amp;quot;, err);
		return err;
	}
#endif

	cJSON *root_obj = cJSON_CreateObject();
	cJSON *state_obj = cJSON_CreateObject();
	cJSON *reported_obj = cJSON_CreateObject();

	if (root_obj == NULL || state_obj == NULL || reported_obj == NULL) {
		cJSON_Delete(root_obj);
		cJSON_Delete(state_obj);
		cJSON_Delete(reported_obj);
		err = -ENOMEM;
		return err;
	}

	if (version_number_include) {
		err = json_add_str(reported_obj, &amp;quot;app_version&amp;quot;,
				    CONFIG_APP_VERSION);
	} else {
		err = 0;
	}

	err += json_add_number(reported_obj, &amp;quot;batv&amp;quot;, bat_voltage);
	err += json_add_number(reported_obj, &amp;quot;ts&amp;quot;, message_ts);
	err += json_add_obj(state_obj, &amp;quot;reported&amp;quot;, reported_obj);
	err += json_add_obj(root_obj, &amp;quot;state&amp;quot;, state_obj);

	if (err) {
		printk(&amp;quot;json_add, error: %d\n&amp;quot;, err);
		goto cleanup;
	}

	message = cJSON_Print(root_obj);
	if (message == NULL) {
		printk(&amp;quot;cJSON_Print, error: returned NULL\n&amp;quot;);
		err = -ENOMEM;
		goto cleanup;
	}

	struct aws_iot_data tx_data = {
		.qos = MQTT_QOS_0_AT_MOST_ONCE,
		.topic.type = AWS_IOT_SHADOW_TOPIC_UPDATE,
		.ptr = message,
		.len = strlen(message)
	};

	printk(&amp;quot;Publishing: %s to AWS IoT broker\n&amp;quot;, message);

	err = aws_iot_send(&amp;amp;tx_data);
	if (err) {
		printk(&amp;quot;aws_iot_send, error: %d\n&amp;quot;, err);
	}

	cJSON_FreeString(message);

cleanup:

	cJSON_Delete(root_obj);

	return err;
}

static void connect_work_fn(struct k_work *work)
{
	int err;

	err = aws_iot_connect(NULL);
	if (err) {
		printk(&amp;quot;aws_iot_connect, error: %d\n&amp;quot;, err);
	}

	printk(&amp;quot;Next connection retry in %d seconds\n&amp;quot;,
	       CONFIG_CONNECTION_RETRY_TIMEOUT_SECONDS);

	k_delayed_work_submit(&amp;amp;connect_work,
			K_SECONDS(CONFIG_CONNECTION_RETRY_TIMEOUT_SECONDS));
}

static void shadow_update_work_fn(struct k_work *work)
{
	int err;

	err = shadow_update(false);
	if (err) {
		printk(&amp;quot;shadow_update, error: %d\n&amp;quot;, err);
	}

	printk(&amp;quot;Next data publication in %d seconds\n&amp;quot;,
	       CONFIG_PUBLICATION_INTERVAL_SECONDS);

	k_delayed_work_submit(&amp;amp;shadow_update_work,
			      K_SECONDS(CONFIG_PUBLICATION_INTERVAL_SECONDS));
}

static void shadow_update_version_work_fn(struct k_work *work)
{
	int err;

	err = shadow_update(true);
	if (err) {
		printk(&amp;quot;shadow_update, error: %d\n&amp;quot;, err);
	}
}

static void print_received_data(const char *buf, const char *topic,
				size_t topic_len)
{
	char *str = NULL;
	cJSON *root_obj = NULL;

	root_obj = cJSON_Parse(buf);
	if (root_obj == NULL) {
		printk(&amp;quot;cJSON Parse failure&amp;quot;);
		return;
	}

	str = cJSON_Print(root_obj);
	if (str == NULL) {
		printk(&amp;quot;Failed to print JSON object&amp;quot;);
		goto clean_exit;
	}

	printf(&amp;quot;Data received from AWS IoT console:\nTopic: %.*s\nMessage: %s\n&amp;quot;,
	       topic_len, topic, str);

	cJSON_FreeString(str);

clean_exit:
	cJSON_Delete(root_obj);
}

void aws_iot_event_handler(const struct aws_iot_evt *const evt)
{
	switch (evt-&amp;gt;type) {
	case AWS_IOT_EVT_CONNECTING:
		printk(&amp;quot;AWS_IOT_EVT_CONNECTING\n&amp;quot;);
		break;
	case AWS_IOT_EVT_CONNECTED:
		printk(&amp;quot;AWS_IOT_EVT_CONNECTED\n&amp;quot;);

		k_delayed_work_cancel(&amp;amp;connect_work);

		if (evt-&amp;gt;data.persistent_session) {
			printk(&amp;quot;Persistent session enabled\n&amp;quot;);
		}

#if defined(CONFIG_BSD_LIBRARY)
		/** Successfully connected to AWS IoT broker, mark image as
		 *  working to avoid reverting to the former image upon reboot.
		 */
		boot_write_img_confirmed();
#endif

		/** Send version number to AWS IoT broker to verify that the
		 *  FOTA update worked.
		 */
		k_delayed_work_submit(&amp;amp;shadow_update_version_work, K_NO_WAIT);

		/** Start sequential shadow data updates.
		 */
		k_delayed_work_submit(&amp;amp;shadow_update_work,
				K_SECONDS(CONFIG_PUBLICATION_INTERVAL_SECONDS));

#if defined(CONFIG_BSD_LIBRARY)
		int err = lte_lc_psm_req(true);
		if (err) {
			printk(&amp;quot;Requesting PSM failed, error: %d\n&amp;quot;, err);
		}
#endif
		break;
	case AWS_IOT_EVT_READY:
		printk(&amp;quot;AWS_IOT_EVT_READY\n&amp;quot;);
		break;
	case AWS_IOT_EVT_DISCONNECTED:
		printk(&amp;quot;AWS_IOT_EVT_DISCONNECTED\n&amp;quot;);
		k_delayed_work_cancel(&amp;amp;shadow_update_work);

		if (k_delayed_work_pending(&amp;amp;connect_work)) {
			break;
		}

		k_delayed_work_submit(&amp;amp;connect_work, K_NO_WAIT);
		break;
	case AWS_IOT_EVT_DATA_RECEIVED:
		printk(&amp;quot;AWS_IOT_EVT_DATA_RECEIVED\n&amp;quot;);
		print_received_data(evt-&amp;gt;data.msg.ptr, evt-&amp;gt;data.msg.topic.str,
				    evt-&amp;gt;data.msg.topic.len);
		break;
	case AWS_IOT_EVT_FOTA_START:
		printk(&amp;quot;AWS_IOT_EVT_FOTA_START\n&amp;quot;);
		break;
	case AWS_IOT_EVT_FOTA_ERASE_PENDING:
		printk(&amp;quot;AWS_IOT_EVT_FOTA_ERASE_PENDING\n&amp;quot;);
		printk(&amp;quot;Disconnect LTE link or reboot\n&amp;quot;);
#if defined(CONFIG_BSD_LIBRARY)
		err = lte_lc_offline();
		if (err) {
			printk(&amp;quot;Error disconnecting from LTE\n&amp;quot;);
		}
#endif
		break;
	case AWS_IOT_EVT_FOTA_ERASE_DONE:
		printk(&amp;quot;AWS_FOTA_EVT_ERASE_DONE\n&amp;quot;);
		printk(&amp;quot;Reconnecting the LTE link&amp;quot;);
#if defined(CONFIG_BSD_LIBRARY)
		err = lte_lc_connect();
		if (err) {
			printk(&amp;quot;Error connecting to LTE\n&amp;quot;);
		}
#endif
		break;
	case AWS_IOT_EVT_FOTA_DONE:
		printk(&amp;quot;AWS_IOT_EVT_FOTA_DONE\n&amp;quot;);
		printk(&amp;quot;FOTA done, rebooting device\n&amp;quot;);
		aws_iot_disconnect();
		sys_reboot(0);
		break;
	case AWS_IOT_EVT_FOTA_DL_PROGRESS:
		printk(&amp;quot;AWS_IOT_EVT_FOTA_DL_PROGRESS, (%d%%)&amp;quot;,
		       evt-&amp;gt;data.fota_progress);
	case AWS_IOT_EVT_ERROR:
		printk(&amp;quot;AWS_IOT_EVT_ERROR, %d\n&amp;quot;, evt-&amp;gt;data.err);
		break;
	default:
		printk(&amp;quot;Unknown AWS IoT event type: %d\n&amp;quot;, evt-&amp;gt;type);
		break;
	}
}

static void work_init(void)
{
	k_delayed_work_init(&amp;amp;shadow_update_work, shadow_update_work_fn);
	k_delayed_work_init(&amp;amp;connect_work, connect_work_fn);
	k_delayed_work_init(&amp;amp;shadow_update_version_work,
			    shadow_update_version_work_fn);
}

#if defined(CONFIG_BSD_LIBRARY)
static void lte_handler(const struct lte_lc_evt *const evt)
{
	switch (evt-&amp;gt;type) {
	case LTE_LC_EVT_NW_REG_STATUS:
		if ((evt-&amp;gt;nw_reg_status != LTE_LC_NW_REG_REGISTERED_HOME) &amp;amp;&amp;amp;
		     (evt-&amp;gt;nw_reg_status != LTE_LC_NW_REG_REGISTERED_ROAMING)) {
			break;
		}

		printk(&amp;quot;Network registration status: %s\n&amp;quot;,
			evt-&amp;gt;nw_reg_status == LTE_LC_NW_REG_REGISTERED_HOME ?
			&amp;quot;Connected - home network&amp;quot; : &amp;quot;Connected - roaming&amp;quot;);

		k_sem_give(&amp;amp;lte_connected);
		break;
	case LTE_LC_EVT_PSM_UPDATE:
		printk(&amp;quot;PSM parameter update: TAU: %d, Active time: %d\n&amp;quot;,
			evt-&amp;gt;psm_cfg.tau, evt-&amp;gt;psm_cfg.active_time);
		break;
	case LTE_LC_EVT_EDRX_UPDATE: {
		char log_buf[60];
		ssize_t len;

		len = snprintf(log_buf, sizeof(log_buf),
			       &amp;quot;eDRX parameter update: eDRX: %f, PTW: %f&amp;quot;,
			       evt-&amp;gt;edrx_cfg.edrx, evt-&amp;gt;edrx_cfg.ptw);
		if (len &amp;gt; 0) {
			printk(&amp;quot;%s\n&amp;quot;, log_buf);
		}
		break;
	}
	case LTE_LC_EVT_RRC_UPDATE:
		printk(&amp;quot;RRC mode: %s\n&amp;quot;,
			evt-&amp;gt;rrc_mode == LTE_LC_RRC_MODE_CONNECTED ?
			&amp;quot;Connected&amp;quot; : &amp;quot;Idle&amp;quot;);
		break;
	case LTE_LC_EVT_CELL_UPDATE:
		printk(&amp;quot;LTE cell changed: Cell ID: %d, Tracking area: %d\n&amp;quot;,
			evt-&amp;gt;cell.id, evt-&amp;gt;cell.tac);
		break;
	default:
		break;
	}
}

static void modem_configure(void)
{
	int err = 0;

	if (IS_ENABLED(CONFIG_LTE_AUTO_INIT_AND_CONNECT))
	{
		/* Do nothing, modem is already configured and LTE connected. */
	}
	else
	{	err = lte_lc_init_and_connect_async(lte_handler);
		//err = lte_lc_psm_req(true);
		if (err)
		{
			printk(&amp;quot;Modem could not be configured, error: %d\n&amp;quot;,err);
			return;
		}
	}
}

static void at_configure(void)
{
	int err;

	err = at_notif_init();
	__ASSERT(err == 0, &amp;quot;AT Notify could not be initialized.&amp;quot;);
	err = at_cmd_init();
	__ASSERT(err == 0, &amp;quot;AT CMD could not be established.&amp;quot;);
}

static void bsd_lib_modem_dfu_handler(void)
{
	int err;

	err = bsdlib_init();

	switch (err) {
	case MODEM_DFU_RESULT_OK:
		printk(&amp;quot;Modem update suceeded, reboot\n&amp;quot;);
		sys_reboot(SYS_REBOOT_COLD);
		break;
	case MODEM_DFU_RESULT_UUID_ERROR:
	case MODEM_DFU_RESULT_AUTH_ERROR:
		printk(&amp;quot;Modem update failed, error: %d\n&amp;quot;, err);
		printk(&amp;quot;Modem will use old firmware\n&amp;quot;);
		sys_reboot(SYS_REBOOT_COLD);
		break;
	case MODEM_DFU_RESULT_HARDWARE_ERROR:
	case MODEM_DFU_RESULT_INTERNAL_ERROR:
		printk(&amp;quot;Modem update malfunction, error: %d, reboot\n&amp;quot;, err);
		sys_reboot(SYS_REBOOT_COLD);
		break;
	default:
		break;
	}

	at_configure();
}
#endif

static int app_topics_subscribe(void)
{
	int err;
	static char custom_topic[75] = &amp;quot;$aws/things/nrf-352656101080789/shadow/update&amp;quot;;
	static char custom_topic_2[75] = &amp;quot;$aws/things/nrf-352656101080789/shadow/delta&amp;quot;;

	const struct aws_iot_topic_data topics_list[APP_TOPICS_COUNT] = {
		[0].str = custom_topic,
		[0].len = strlen(custom_topic),
		[1].str = custom_topic_2,
		[1].len = strlen(custom_topic_2)
	};

	err = aws_iot_subscription_topics_add(topics_list,
					      ARRAY_SIZE(topics_list));
	if (err) {
		printk(&amp;quot;aws_iot_subscription_topics_add, error: %d\n&amp;quot;, err);
	}

	return err;
}

static void date_time_event_handler(const struct date_time_evt *evt)
{
	switch (evt-&amp;gt;type) {
	case DATE_TIME_OBTAINED_MODEM:
		printk(&amp;quot;DATE_TIME_OBTAINED_MODEM\n&amp;quot;);
		break;
	case DATE_TIME_OBTAINED_NTP:
		printk(&amp;quot;DATE_TIME_OBTAINED_NTP\n&amp;quot;);
		break;
	case DATE_TIME_OBTAINED_EXT:
		printk(&amp;quot;DATE_TIME_OBTAINED_EXT\n&amp;quot;);
		break;
	case DATE_TIME_NOT_OBTAINED:
		printk(&amp;quot;DATE_TIME_NOT_OBTAINED\n&amp;quot;);
		break;
	default:
		break;
	}

	/** Do not depend on obtained time, continue upon any event from the
	 *  date time library.
	 */
	k_sem_give(&amp;amp;date_time_obtained);
}

void aws_iot1(void)
{
	int err;
       
	printk(&amp;quot;The AWS IoT sample started, version: %s\n&amp;quot;, CONFIG_APP_VERSION);

	cJSON_Init();

#if defined(CONFIG_BSD_LIBRARY)
	bsd_lib_modem_dfu_handler();
#endif

	err = aws_iot_init(NULL, aws_iot_event_handler);
	if (err) {
		printk(&amp;quot;AWS IoT library could not be initialized, error: %d\n&amp;quot;,
		       err);
	}

	/** Subscribe to customizable non-shadow specific topics
	 *  to AWS IoT backend.
	 */
	err = app_topics_subscribe();
	if (err) {
		printk(&amp;quot;Adding application specific topics failed, error: %d\n&amp;quot;,
			err);
	}

	work_init();
	
// #if defined(CONFIG_BSD_LIBRARY)
	// modem_configure();

	// err = modem_info_init();
	// if (err) {
		// printk(&amp;quot;Failed initializing modem info module, error: %d\n&amp;quot;,
			// err);
	// }

	// k_sem_take(&amp;amp;lte_connected, K_FOREVER);
// #endif


	date_time_update_async(date_time_event_handler);

	err = k_sem_take(&amp;amp;date_time_obtained, K_SECONDS(DATE_TIME_TIMEOUT_S));
	if (err) {
		printk(&amp;quot;Date time, no callback event within %d seconds\n&amp;quot;,
			DATE_TIME_TIMEOUT_S);
	}

	k_delayed_work_submit(&amp;amp;connect_work, K_NO_WAIT);
}

int main(void)
{		
	nrf_gnss_data_frame_t gps_data;
	uint8_t		      cnt = 0;
	int err;

#ifdef CONFIG_SUPL_CLIENT_LIB
	static struct supl_api supl_api = {
		.read       = supl_read,
		.write      = supl_write,
		.handler    = inject_agps_type,
		.logger     = supl_logger,
		.counter_ms = k_uptime_get
	};
#endif

	printk(&amp;quot;Starting GPS application\n&amp;quot;);

	if (init_app() != 0) {
		return -1;
	}
	
#if defined(CONFIG_BSD_LIBRARY)
	modem_configure();

	err = modem_info_init();
	if (err) {
		printk(&amp;quot;Failed initializing modem info module, error: %d\n&amp;quot;,
			err);
	}

	k_sem_take(&amp;amp;lte_connected, K_FOREVER);
#endif
	
	
#ifdef CONFIG_SUPL_CLIENT_LIB
	int rc = supl_init(&amp;amp;supl_api);

	if (rc != 0) {
		return rc;
	}
#endif

	aws_iot1();

	printk(&amp;quot;Getting GPS data...\n&amp;quot;);

	while (1) {

		do {
			/* Loop until we don&amp;#39;t have more
			 * data to read
			 */
		} while (process_gps_data(&amp;amp;gps_data) &amp;gt; 0);

		if (IS_ENABLED(CONFIG_GPS_SAMPLE_NMEA_ONLY)) {
			print_nmea_data();
			nmea_string_cnt = 0;
		} else {
			printk(&amp;quot;\033[1;1H&amp;quot;);
			printk(&amp;quot;\033[2J&amp;quot;);
			print_satellite_stats(&amp;amp;last_pvt);
			print_gnss_stats(&amp;amp;last_pvt);
			printk(&amp;quot;---------------------------------\n&amp;quot;);

			if (!got_fix) {
				printk(&amp;quot;Seconds since last fix: %lld\n&amp;quot;,
				       (k_uptime_get() - fix_timestamp) / 1000);
				cnt++;
				printk(&amp;quot;Searching [%c]\n&amp;quot;,
				       update_indicator[cnt%4]);
			} else {
				print_fix_data(&amp;amp;last_pvt);
				
			}

			printk(&amp;quot;\nNMEA strings:\n\n&amp;quot;);
			print_nmea_data();
			printk(&amp;quot;---------------------------------&amp;quot;);
			
			
		}

		k_sleep(K_MSEC(500));
	}

	return 0;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#GPS
# Copyright (c) 2019 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#
CONFIG_BSD_LIBRARY=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
CONFIG_AT_CMD=y
CONFIG_AT_NOTIF=y

# Enable SUPL client support
CONFIG_SUPL_CLIENT_LIB=n

# Networking
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y

# Disable native network stack to save some memory
CONFIG_NET_NATIVE=n

# Main thread
CONFIG_HEAP_MEM_POOL_SIZE=4096
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

# Application
CONFIG_GPS_SAMPLE_NMEA_ONLY=n

# General config
CONFIG_NCS_SAMPLES_DEFAULTS=y
CONFIG_REBOOT=y

# LTE link control
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_NETWORK_MODE_LTE_M_GPS=y
CONFIG_LTE_AUTO_INIT_AND_CONNECT=n
#CONFIG_LTE_PSM_REQ_RPTAU=&amp;quot;00011111&amp;quot;
#CONFIG_LTE_PSM_REQ_RAT=&amp;quot;00000010&amp;quot;
#CONFIG_LTE_POWER_SAVING_MODE=y

# Download client (needed by AWS FOTA)
CONFIG_DOWNLOAD_CLIENT=y
CONFIG_DOWNLOAD_CLIENT_STACK_SIZE=4096

# MCUBOOT
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_MCUBOOT_IMG_MANAGER=y

# Image manager
CONFIG_IMG_MANAGER=y
CONFIG_FLASH=y
CONFIG_IMG_ERASE_PROGRESSIVELY=y

# AWS FOTA
CONFIG_AWS_FOTA=y
CONFIG_FOTA_DOWNLOAD=y
CONFIG_DFU_TARGET=y

# CJSON
CONFIG_CJSON_LIB=y

# Date Time library
CONFIG_DATE_TIME=y

# Modem information
CONFIG_MODEM_INFO=y


# BSD library
CONFIG_BSD_LIBRARY_SYS_INIT=y

# AT Host
CONFIG_AT_HOST_LIBRARY=y

# AWS IoT library
CONFIG_AWS_IOT=y
CONFIG_AWS_IOT_CLIENT_ID_STATIC=&amp;quot;nrf-352656101080789&amp;quot;
CONFIG_AWS_IOT_BROKER_HOST_NAME=&amp;quot;a6i4ulevbqzm-ats.iot.us-east-2.amazonaws.com&amp;quot;
CONFIG_AWS_IOT_SEC_TAG=201
CONFIG_AWS_IOT_APP_SUBSCRIPTION_LIST_COUNT=2
CONFIG_AWS_IOT_TOPIC_UPDATE_DELTA_SUBSCRIBE=y
CONFIG_AWS_IOT_CONNECTION_POLL_THREAD=y
CONFIG_AWS_IOT_LAST_WILL=y
CONFIG_AWS_IOT_TOPIC_GET_ACCEPTED_SUBSCRIBE=y
CONFIG_AWS_IOT_TOPIC_GET_REJECTED_SUBSCRIBE=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;
2021-01-07T09:34:57.690Z DEBUG modem &amp;lt;&amp;lt; *** Booting Zephyr OS build v2.4.0-ncs1-1710-g5a7b4eb71047  ***
2021-01-07T09:34:57.727Z DEBUG modem &amp;lt;&amp;lt; Flash regionsDomainPermissions
2021-01-07T09:34:57.732Z DEBUG modem &amp;lt;&amp;lt; 00 02 0x00000 0x18000 Securerwxl
2021-01-07T09:34:57.736Z DEBUG modem &amp;lt;&amp;lt; 03 31 0x18000 0x100000 Non-Securerwxl
2021-01-07T09:34:57.741Z DEBUG modem &amp;lt;&amp;lt; Non-secure callable region 0 placed in flash region 2 with size 32.
2021-01-07T09:34:57.984Z DEBUG modem &amp;lt;&amp;lt; SRAM regionDomainPermissions
2021-01-07T09:34:58.017Z DEBUG modem &amp;lt;&amp;lt; 00 07 0x00000 0x10000 Securerwxl
2021-01-07T09:34:58.024Z DEBUG modem &amp;lt;&amp;lt; 08 31 0x10000 0x40000 Non-Securerwxl
2021-01-07T09:34:58.031Z DEBUG modem &amp;lt;&amp;lt; PeripheralDomainStatus
2021-01-07T09:34:58.038Z DEBUG modem &amp;lt;&amp;lt; 00 NRF_P0               Non-SecureOK
2021-01-07T09:34:58.044Z DEBUG modem &amp;lt;&amp;lt; 01 NRF_CLOCK            Non-SecureOK
2021-01-07T09:34:58.049Z DEBUG modem &amp;lt;&amp;lt; 02 NRF_RTC0             Non-SecureOK
2021-01-07T09:34:58.053Z DEBUG modem &amp;lt;&amp;lt; 03 NRF_RTC1             Non-SecureOK
2021-01-07T09:34:58.059Z DEBUG modem &amp;lt;&amp;lt; 04 NRF_NVMC             Non-SecureOK
2021-01-07T09:34:58.064Z DEBUG modem &amp;lt;&amp;lt; 05 NRF_UARTE1           Non-SecureOK
2021-01-07T09:34:58.071Z DEBUG modem &amp;lt;&amp;lt; 06 NRF_UARTE2           SecureSKIP
2021-01-07T09:34:58.079Z DEBUG modem &amp;lt;&amp;lt; 07 NRF_TWIM2            Non-SecureOK
2021-01-07T09:34:58.091Z DEBUG modem &amp;lt;&amp;lt; 08 NRF_SPIM3            Non-SecureOK
2021-01-07T09:34:58.096Z DEBUG modem &amp;lt;&amp;lt; 09 NRF_TIMER0           Non-SecureOK
2021-01-07T09:34:58.102Z DEBUG modem &amp;lt;&amp;lt; 10 NRF_TIMER1           Non-SecureOK
2021-01-07T09:34:58.107Z DEBUG modem &amp;lt;&amp;lt; 11 NRF_TIMER2           Non-SecureOK
2021-01-07T09:34:58.118Z DEBUG modem &amp;lt;&amp;lt; 12 NRF_SAADC            Non-SecureOK
2021-01-07T09:34:58.126Z DEBUG modem &amp;lt;&amp;lt; 13 NRF_PWM0             Non-SecureOK
2021-01-07T09:34:58.139Z DEBUG modem &amp;lt;&amp;lt; 14 NRF_PWM1             Non-SecureOK
2021-01-07T09:34:58.141Z DEBUG modem &amp;lt;&amp;lt; 15 NRF_PWM2             Non-SecureOK
2021-01-07T09:34:58.142Z DEBUG modem &amp;lt;&amp;lt; 16 NRF_PWM3             Non-SecureOK
2021-01-07T09:34:58.143Z DEBUG modem &amp;lt;&amp;lt; 17 NRF_WDT              Non-SecureOK
2021-01-07T09:34:58.145Z DEBUG modem &amp;lt;&amp;lt; 18 NRF_IPC              Non-SecureOK
2021-01-07T09:34:58.146Z DEBUG modem &amp;lt;&amp;lt; 19 NRF_VMC              Non-SecureOK
2021-01-07T09:34:58.148Z DEBUG modem &amp;lt;&amp;lt; 20 NRF_FPU              Non-SecureOK
2021-01-07T09:34:58.149Z DEBUG modem &amp;lt;&amp;lt; 21 NRF_EGU1             Non-SecureOK
2021-01-07T09:34:58.150Z DEBUG modem &amp;lt;&amp;lt; 22 NRF_EGU2             Non-SecureOK
2021-01-07T09:34:58.152Z DEBUG modem &amp;lt;&amp;lt; 23 NRF_DPPIC            Non-SecureOK
2021-01-07T09:34:58.155Z DEBUG modem &amp;lt;&amp;lt; 24 NRF_GPIOTE1          Non-SecureOK
2021-01-07T09:34:58.156Z DEBUG modem &amp;lt;&amp;lt; 25 NRF_REGULATORS       Non-SecureOK
2021-01-07T09:34:58.161Z DEBUG modem &amp;lt;&amp;lt; SPM: NS image at 0x18200
2021-01-07T09:34:58.162Z DEBUG modem &amp;lt;&amp;lt; SPM: NS MSP at 0x2002a4a0
2021-01-07T09:34:58.164Z DEBUG modem &amp;lt;&amp;lt; SPM: NS reset vector at 0x1e6e9
2021-01-07T09:34:58.165Z DEBUG modem &amp;lt;&amp;lt; SPM: prepare to jump to Non-Secure image.
2021-01-07T09:34:58.196Z DEBUG modem &amp;lt;&amp;lt; *** Booting Zephyr OS build v2.4.0-ncs1-1710-g5a7b4eb71047  ***
2021-01-07T09:34:58.217Z DEBUG modem &amp;lt;&amp;lt; Starting GPS application
2021-01-07T09:34:58.234Z DEBUG modem &amp;lt;&amp;lt; GPS Socket created
2021-01-07T09:34:58.268Z DEBUG modem &amp;lt;&amp;lt; E: Could not send AT command, error: -8
2021-01-07T09:34:58.271Z DEBUG modem &amp;lt;&amp;lt; Modem could not be configured, error: -8
&lt;/pre&gt;&lt;pre class="ui-code" data-mode="text"&gt;#
# Copyright (c) 2020 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#

menu &amp;quot;GPS sample&amp;quot;

config APP_VERSION
	string &amp;quot;Application version&amp;quot;
	default &amp;quot;v1.0.0&amp;quot;

config PUBLICATION_INTERVAL_SECONDS
	int &amp;quot;Interval in seconds that the sample will publish data&amp;quot;
	default 60

config CONNECTION_RETRY_TIMEOUT_SECONDS
	int &amp;quot;Number of seconds between each AWS IoT connection retry&amp;quot;
	default 20

config GPS_SAMPLE_NMEA_ONLY
	bool &amp;quot;Output only NMEA strings&amp;quot;
	help
	  Outputs only NMEA strings from the GPS.

choice GPS_SAMPLE_ANTENNA
	default GPS_SAMPLE_ANTENNA_ONBOARD
	prompt &amp;quot;Select which antenna to use for GPS&amp;quot;

config GPS_SAMPLE_ANTENNA_ONBOARD
	bool &amp;quot;Use onboard antenna&amp;quot;

config GPS_SAMPLE_ANTENNA_EXTERNAL
	bool &amp;quot;Use external antenna&amp;quot;

endchoice

endmenu

menu &amp;quot;Zephyr Kernel&amp;quot;
source &amp;quot;Kconfig.zephyr&amp;quot;
endmenu
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;sample:
  name: GPS sample
tests:
  samples.nrf9160.gps:
    build_only: true
    build_on_all: true
    platform_allow: nrf9160dk_nrf9160ns thingy91_nrf9160ns
    tags: ci_build

sample:
  name: AWS IoT sample
tests:
  samples.nrf9160.aws_iot:
    build_only: true
    build_on_all: true
    platform_allow: nrf9160dk_nrf9160ns thingy91_nrf9160ns
    tags: ci_build&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#
# Copyright (c) 2019 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#

cmake_minimum_required(VERSION 3.13.1)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(gps_socket_sample)

zephyr_library_sources(src/main.c)

zephyr_library_sources_ifdef(
  CONFIG_SUPL_CLIENT_LIB
  src/supl_support.c
)
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;At this point i was tried from last 3 days and stuck at this point, all this error are releted to modem configuration.&lt;/p&gt;
&lt;p&gt;Thanks again.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send data to own AWS server using Cloud Client sample ?</title><link>https://devzone.nordicsemi.com/thread/287878?ContentTypeID=1</link><pubDate>Thu, 07 Jan 2021 09:08:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ccb932a9-1dff-4b78-9dd1-4a049738db04</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;I&amp;#39;m not able to compile. Can you please share full project?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send data to own AWS server using Cloud Client sample ?</title><link>https://devzone.nordicsemi.com/thread/287850?ContentTypeID=1</link><pubDate>Thu, 07 Jan 2021 08:02:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e68e14b1-f2c9-48df-b5bd-6cba6208b76a</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Do you know what AT command is failing? Can you provide the full log from your application?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I will try you application here as well.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send data to own AWS server using Cloud Client sample ?</title><link>https://devzone.nordicsemi.com/thread/287840?ContentTypeID=1</link><pubDate>Thu, 07 Jan 2021 07:15:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ed9e5b9d-1c26-4cbb-93f8-ff74cb5a9ef4</guid><dc:creator>jaydip kavaiya</dc:creator><description>&lt;p&gt;Hi Oyvind&lt;/p&gt;
&lt;p&gt;Thanks for you valuable time and replay.&lt;/p&gt;
&lt;p&gt;I run normal GPS and AWS_IOT example&amp;nbsp;&lt;span&gt;separately and both work fine.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Now merge GPS with AWS_IOT example. with this file&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;main.c, prj.config, kconfig, sample yaml. Build successfully run&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Just need to know about modem configuration for this&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Try this step&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;1 init_app --&amp;gt; Setup Modem --&amp;gt; At commads&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;2 Modem configuration for lte&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Error is could not send AT commands -8&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;this is main.c&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*
 * Copyright (c) 2019 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
 */

#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;nrf_socket.h&amp;gt;
#include &amp;lt;net/socket.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;

#include &amp;lt;modem/lte_lc.h&amp;gt;
#include &amp;lt;modem/bsdlib.h&amp;gt;
#include &amp;lt;modem/at_cmd.h&amp;gt;
#include &amp;lt;modem/at_notif.h&amp;gt;
#include &amp;lt;modem/modem_info.h&amp;gt;
#include &amp;lt;bsd.h&amp;gt;

#include &amp;lt;net/aws_iot.h&amp;gt;
#include &amp;lt;power/reboot.h&amp;gt;
#include &amp;lt;date_time.h&amp;gt;
#include &amp;lt;dfu/mcuboot.h&amp;gt;
#include &amp;lt;cJSON.h&amp;gt;
#include &amp;lt;cJSON_os.h&amp;gt;

#ifdef CONFIG_SUPL_CLIENT_LIB
#include &amp;lt;supl_os_client.h&amp;gt;
#include &amp;lt;supl_session.h&amp;gt;
#include &amp;quot;supl_support.h&amp;quot;
#endif

#define AT_XSYSTEMMODE      &amp;quot;AT\%XSYSTEMMODE=1,0,1,0&amp;quot;
#define AT_ACTIVATE_GPS     &amp;quot;AT+CFUN=31&amp;quot;
#define AT_ACTIVATE_LTE     &amp;quot;AT+CFUN=21&amp;quot;
#define AT_DEACTIVATE_LTE   &amp;quot;AT+CFUN=20&amp;quot;

#define GNSS_INIT_AND_START 1
#define GNSS_STOP           2
#define GNSS_RESTART        3

#define AT_CMD_SIZE(x) (sizeof(x) - 1)

#ifdef CONFIG_BOARD_NRF9160DK_NRF9160NS
#define AT_MAGPIO      &amp;quot;AT\%XMAGPIO=1,0,0,1,1,1574,1577&amp;quot;
#ifdef CONFIG_GPS_SAMPLE_ANTENNA_ONBOARD
#define AT_COEX0       &amp;quot;AT\%XCOEX0=1,1,1565,1586&amp;quot;
#elif CONFIG_GPS_SAMPLE_ANTENNA_EXTERNAL
#define AT_COEX0       &amp;quot;AT\%XCOEX0&amp;quot;
#endif
#endif /* CONFIG_BOARD_NRF9160DK_NRF9160NS */

#ifdef CONFIG_BOARD_THINGY91_NRF9160NS
#define AT_MAGPIO      &amp;quot;AT\%XMAGPIO=1,1,1,7,1,746,803,2,698,748,2,1710,2200,&amp;quot; \
			&amp;quot;3,824,894,4,880,960,5,791,849,7,1565,1586&amp;quot;
#ifdef CONFIG_GPS_SAMPLE_ANTENNA_ONBOARD
#define AT_COEX0       &amp;quot;AT\%XCOEX0=1,1,1565,1586&amp;quot;
#elif CONFIG_GPS_SAMPLE_ANTENNA_EXTERNAL
#define AT_COEX0       &amp;quot;AT\%XCOEX0&amp;quot;
#endif
#endif /* CONFIG_BOARD_THINGY91_NRF9160NS */

static const char update_indicator[] = {&amp;#39;\\&amp;#39;, &amp;#39;|&amp;#39;, &amp;#39;/&amp;#39;, &amp;#39;-&amp;#39;};
static const char *const at_commands[] = {
	AT_XSYSTEMMODE,
#if defined(CONFIG_BOARD_NRF9160DK_NRF9160NS) || \
	defined(CONFIG_BOARD_THINGY91_NRF9160NS)
	AT_MAGPIO,
	AT_COEX0,
#endif
	AT_ACTIVATE_GPS
};

static int                   gnss_fd;
static char                  nmea_strings[10][NRF_GNSS_NMEA_MAX_LEN];
static uint32_t                 nmea_string_cnt;

static bool                  got_fix;
static uint64_t                 fix_timestamp;
static nrf_gnss_data_frame_t last_pvt;

K_SEM_DEFINE(lte_ready, 0, 1);

BUILD_ASSERT(!IS_ENABLED(CONFIG_LTE_AUTO_INIT_AND_CONNECT),
		&amp;quot;This sample does not support LTE auto-init and connect&amp;quot;);

#define APP_TOPICS_COUNT CONFIG_AWS_IOT_APP_SUBSCRIPTION_LIST_COUNT

/* Timeout in seconds in which the application will wait for an initial event
 * from the date time library.
 */
#define DATE_TIME_TIMEOUT_S 15

static struct k_delayed_work shadow_update_work;
static struct k_delayed_work connect_work;
static struct k_delayed_work shadow_update_version_work;

K_SEM_DEFINE(lte_connected, 0, 1);
K_SEM_DEFINE(date_time_obtained, 0, 1);

void bsd_recoverable_error_handler(uint32_t error)
{
	printf(&amp;quot;Err: %lu\n&amp;quot;, (unsigned long)error);
}

static int setup_modem(void)
{
	for (int i = 0; i &amp;lt; ARRAY_SIZE(at_commands); i++) {

		if (at_cmd_write(at_commands[i], NULL, 0, NULL) != 0) {
			return -1;
		}
	}

	return 0;
}

#ifdef CONFIG_SUPL_CLIENT_LIB
/* Accepted network statuses read from modem */
static const char status1[] = &amp;quot;+CEREG: 1&amp;quot;;
static const char status2[] = &amp;quot;+CEREG:1&amp;quot;;
static const char status3[] = &amp;quot;+CEREG: 5&amp;quot;;
static const char status4[] = &amp;quot;+CEREG:5&amp;quot;;

static void wait_for_lte(void *context, const char *response)
{
	if (!memcmp(status1, response, AT_CMD_SIZE(status1)) ||
		!memcmp(status2, response, AT_CMD_SIZE(status2)) ||
		!memcmp(status3, response, AT_CMD_SIZE(status3)) ||
		!memcmp(status4, response, AT_CMD_SIZE(status4))) {
		k_sem_give(&amp;amp;lte_ready);
	}
}

static int activate_lte(bool activate)
{
	if (activate) {
		if (at_cmd_write(AT_ACTIVATE_LTE, NULL, 0, NULL) != 0) {
			return -1;
		}

		at_notif_register_handler(NULL, wait_for_lte);
		if (at_cmd_write(&amp;quot;AT+CEREG=2&amp;quot;, NULL, 0, NULL) != 0) {
			return -1;
		}

		k_sem_take(&amp;amp;lte_ready, K_FOREVER);

		at_notif_deregister_handler(NULL, wait_for_lte);
		if (at_cmd_write(&amp;quot;AT+CEREG=0&amp;quot;, NULL, 0, NULL) != 0) {
			return -1;
		}
	} else {
		if (at_cmd_write(AT_DEACTIVATE_LTE, NULL, 0, NULL) != 0) {
			return -1;
		}
	}

	return 0;
}
#endif

static int gnss_ctrl(uint32_t ctrl)
{
	int retval;

	nrf_gnss_fix_retry_t    fix_retry    = 0;
	nrf_gnss_fix_interval_t fix_interval = 1;
	nrf_gnss_delete_mask_t	delete_mask  = 0;
	nrf_gnss_nmea_mask_t	nmea_mask    = NRF_GNSS_NMEA_GSV_MASK |
					       NRF_GNSS_NMEA_GSA_MASK |
					       NRF_GNSS_NMEA_GLL_MASK |
					       NRF_GNSS_NMEA_GGA_MASK |
					       NRF_GNSS_NMEA_RMC_MASK;

	if (ctrl == GNSS_INIT_AND_START) {
		gnss_fd = nrf_socket(NRF_AF_LOCAL,
				     NRF_SOCK_DGRAM,
				     NRF_PROTO_GNSS);

		if (gnss_fd &amp;gt;= 0) {
			printk(&amp;quot;GPS Socket created\n&amp;quot;);
		} else {
			printk(&amp;quot;Could not init socket (err: %d)\n&amp;quot;, gnss_fd);
			return -1;
		}

		retval = nrf_setsockopt(gnss_fd,
					NRF_SOL_GNSS,
					NRF_SO_GNSS_FIX_RETRY,
					&amp;amp;fix_retry,
					sizeof(fix_retry));
		if (retval != 0) {
			printk(&amp;quot;Failed to set fix retry value\n&amp;quot;);
			return -1;
		}

		retval = nrf_setsockopt(gnss_fd,
					NRF_SOL_GNSS,
					NRF_SO_GNSS_FIX_INTERVAL,
					&amp;amp;fix_interval,
					sizeof(fix_interval));
		if (retval != 0) {
			printk(&amp;quot;Failed to set fix interval value\n&amp;quot;);
			return -1;
		}

		retval = nrf_setsockopt(gnss_fd,
					NRF_SOL_GNSS,
					NRF_SO_GNSS_NMEA_MASK,
					&amp;amp;nmea_mask,
					sizeof(nmea_mask));
		if (retval != 0) {
			printk(&amp;quot;Failed to set nmea mask\n&amp;quot;);
			return -1;
		}
	}

	if ((ctrl == GNSS_INIT_AND_START) ||
	    (ctrl == GNSS_RESTART)) {
		retval = nrf_setsockopt(gnss_fd,
					NRF_SOL_GNSS,
					NRF_SO_GNSS_START,
					&amp;amp;delete_mask,
					sizeof(delete_mask));
		if (retval != 0) {
			printk(&amp;quot;Failed to start GPS\n&amp;quot;);
			return -1;
		}
	}

	if (ctrl == GNSS_STOP) {
		retval = nrf_setsockopt(gnss_fd,
					NRF_SOL_GNSS,
					NRF_SO_GNSS_STOP,
					&amp;amp;delete_mask,
					sizeof(delete_mask));
		if (retval != 0) {
			printk(&amp;quot;Failed to stop GPS\n&amp;quot;);
			return -1;
		}
	}

	return 0;
}

static int init_app(void)
{
	int retval;


	if (setup_modem() != 0) {
		printk(&amp;quot;Failed to initialize modem\n&amp;quot;);
		return -1;
	}

	retval = gnss_ctrl(GNSS_INIT_AND_START);

	return retval;
}

static void print_satellite_stats(nrf_gnss_data_frame_t *pvt_data)
{
	uint8_t  tracked          = 0;
	uint8_t  in_fix           = 0;
	uint8_t  unhealthy        = 0;

	for (int i = 0; i &amp;lt; NRF_GNSS_MAX_SATELLITES; ++i) {

		if ((pvt_data-&amp;gt;pvt.sv[i].sv &amp;gt; 0) &amp;amp;&amp;amp;
		    (pvt_data-&amp;gt;pvt.sv[i].sv &amp;lt; 33)) {

			tracked++;

			if (pvt_data-&amp;gt;pvt.sv[i].flags &amp;amp;
					NRF_GNSS_SV_FLAG_USED_IN_FIX) {
				in_fix++;
			}

			if (pvt_data-&amp;gt;pvt.sv[i].flags &amp;amp;
					NRF_GNSS_SV_FLAG_UNHEALTHY) {
				unhealthy++;
			}
		}
	}

	printk(&amp;quot;Tracking: %d Using: %d Unhealthy: %d\n&amp;quot;, tracked,
							 in_fix,
							 unhealthy);
}

static void print_gnss_stats(nrf_gnss_data_frame_t *pvt_data)
{
	if (pvt_data-&amp;gt;pvt.flags &amp;amp; NRF_GNSS_PVT_FLAG_DEADLINE_MISSED) {
		printk(&amp;quot;GNSS notification deadline missed\n&amp;quot;);
	}
	if (pvt_data-&amp;gt;pvt.flags &amp;amp; NRF_GNSS_PVT_FLAG_NOT_ENOUGH_WINDOW_TIME) {
		printk(&amp;quot;GNSS operation blocked by insufficient time windows\n&amp;quot;);
	}
}

static void print_fix_data(nrf_gnss_data_frame_t *pvt_data)
{
	printf(&amp;quot;Longitude:  %f\n&amp;quot;, pvt_data-&amp;gt;pvt.longitude);
	printf(&amp;quot;Latitude:   %f\n&amp;quot;, pvt_data-&amp;gt;pvt.latitude);
	printf(&amp;quot;Altitude:   %f\n&amp;quot;, pvt_data-&amp;gt;pvt.altitude);
	printf(&amp;quot;Speed:      %f\n&amp;quot;, pvt_data-&amp;gt;pvt.speed);
	printf(&amp;quot;Heading:    %f\n&amp;quot;, pvt_data-&amp;gt;pvt.heading);
	printk(&amp;quot;Date:       %02u-%02u-%02u\n&amp;quot;, pvt_data-&amp;gt;pvt.datetime.year,
					       pvt_data-&amp;gt;pvt.datetime.month,
					       pvt_data-&amp;gt;pvt.datetime.day);
	printk(&amp;quot;Time (UTC): %02u:%02u:%02u\n&amp;quot;, pvt_data-&amp;gt;pvt.datetime.hour,
					       pvt_data-&amp;gt;pvt.datetime.minute,
					      pvt_data-&amp;gt;pvt.datetime.seconds);
}

static void print_nmea_data(void)
{
	for (int i = 0; i &amp;lt; nmea_string_cnt; ++i) {
		printk(&amp;quot;%s&amp;quot;, nmea_strings[i]);
	}
}

int process_gps_data(nrf_gnss_data_frame_t *gps_data)
{
	int retval;

	retval = nrf_recv(gnss_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:
			memcpy(&amp;amp;last_pvt,
			       gps_data,
			       sizeof(nrf_gnss_data_frame_t));
			nmea_string_cnt = 0;
			got_fix = false;

			if ((gps_data-&amp;gt;pvt.flags &amp;amp;
				NRF_GNSS_PVT_FLAG_FIX_VALID_BIT)
				== NRF_GNSS_PVT_FLAG_FIX_VALID_BIT) {

				got_fix = true;
				fix_timestamp = k_uptime_get();
			}
			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;

		case NRF_GNSS_AGPS_DATA_ID:
#ifdef CONFIG_SUPL_CLIENT_LIB
			printk(&amp;quot;\033[1;1H&amp;quot;);
			printk(&amp;quot;\033[2J&amp;quot;);
			printk(&amp;quot;New AGPS data requested, contacting SUPL server, flags %d\n&amp;quot;,
			       gps_data-&amp;gt;agps.data_flags);
			gnss_ctrl(GNSS_STOP);
			activate_lte(true);
			printk(&amp;quot;Established LTE link\n&amp;quot;);
			if (open_supl_socket() == 0) {
				printf(&amp;quot;Starting SUPL session\n&amp;quot;);
				supl_session(&amp;amp;gps_data-&amp;gt;agps);
				printk(&amp;quot;Done\n&amp;quot;);
				close_supl_socket();
			}
			activate_lte(false);
			gnss_ctrl(GNSS_RESTART);
			k_sleep(K_MSEC(2000));
#endif
			break;

		default:
			break;
		}
	}

	return retval;
}

#ifdef CONFIG_SUPL_CLIENT_LIB
int inject_agps_type(void *agps,
		     size_t agps_size,
		     nrf_gnss_agps_data_type_t type,
		     void *user_data)
{
	ARG_UNUSED(user_data);
	int retval = nrf_sendto(gnss_fd,
				agps,
				agps_size,
				0,
				&amp;amp;type,
				sizeof(type));

	if (retval != 0) {
		printk(&amp;quot;Failed to send AGNSS data, type: %d (err: %d)\n&amp;quot;,
		       type,
		       errno);
		return -1;
	}

	printk(&amp;quot;Injected AGPS data, flags: %d, size: %d\n&amp;quot;, type, agps_size);

	return 0;
}
#endif




static int json_add_obj(cJSON *parent, const char *str, cJSON *item)
{
	cJSON_AddItemToObject(parent, str, item);

	return 0;
}

static int json_add_str(cJSON *parent, const char *str, const char *item)
{
	cJSON *json_str;

	json_str = cJSON_CreateString(item);
	if (json_str == NULL) {
		return -ENOMEM;
	}

	return json_add_obj(parent, str, json_str);
}

static int json_add_number(cJSON *parent, const char *str, double item)
{
	cJSON *json_num;

	json_num = cJSON_CreateNumber(item);
	if (json_num == NULL) {
		return -ENOMEM;
	}

	return json_add_obj(parent, str, json_num);
}

static int shadow_update(bool version_number_include)
{
	int err;
	char *message;
	int64_t message_ts;
	int16_t bat_voltage = 0;

	err = date_time_now(&amp;amp;message_ts);
	if (err) {
		printk(&amp;quot;date_time_now, error: %d\n&amp;quot;, err);
		return err;
	}

#if defined(CONFIG_BSD_LIBRARY)
	/* Request battery voltage data from the modem. */
	err = modem_info_short_get(MODEM_INFO_BATTERY, &amp;amp;bat_voltage);
	if (err != sizeof(bat_voltage)) {
		printk(&amp;quot;modem_info_short_get, error: %d\n&amp;quot;, err);
		return err;
	}
#endif

	cJSON *root_obj = cJSON_CreateObject();
	cJSON *state_obj = cJSON_CreateObject();
	cJSON *reported_obj = cJSON_CreateObject();

	if (root_obj == NULL || state_obj == NULL || reported_obj == NULL) {
		cJSON_Delete(root_obj);
		cJSON_Delete(state_obj);
		cJSON_Delete(reported_obj);
		err = -ENOMEM;
		return err;
	}

	if (version_number_include) {
		err = json_add_str(reported_obj, &amp;quot;app_version&amp;quot;,
				    CONFIG_APP_VERSION);
	} else {
		err = 0;
	}

	err += json_add_number(reported_obj, &amp;quot;batv&amp;quot;, bat_voltage);
	err += json_add_number(reported_obj, &amp;quot;ts&amp;quot;, message_ts);
	err += json_add_obj(state_obj, &amp;quot;reported&amp;quot;, reported_obj);
	err += json_add_obj(root_obj, &amp;quot;state&amp;quot;, state_obj);

	if (err) {
		printk(&amp;quot;json_add, error: %d\n&amp;quot;, err);
		goto cleanup;
	}

	message = cJSON_Print(root_obj);
	if (message == NULL) {
		printk(&amp;quot;cJSON_Print, error: returned NULL\n&amp;quot;);
		err = -ENOMEM;
		goto cleanup;
	}

	struct aws_iot_data tx_data = {
		.qos = MQTT_QOS_0_AT_MOST_ONCE,
		.topic.type = AWS_IOT_SHADOW_TOPIC_UPDATE,
		.ptr = message,
		.len = strlen(message)
	};

	printk(&amp;quot;Publishing: %s to AWS IoT broker\n&amp;quot;, message);

	err = aws_iot_send(&amp;amp;tx_data);
	if (err) {
		printk(&amp;quot;aws_iot_send, error: %d\n&amp;quot;, err);
	}

	cJSON_FreeString(message);

cleanup:

	cJSON_Delete(root_obj);

	return err;
}

static void connect_work_fn(struct k_work *work)
{
	int err;

	err = aws_iot_connect(NULL);
	if (err) {
		printk(&amp;quot;aws_iot_connect, error: %d\n&amp;quot;, err);
	}

	printk(&amp;quot;Next connection retry in %d seconds\n&amp;quot;,
	       CONFIG_CONNECTION_RETRY_TIMEOUT_SECONDS);

	k_delayed_work_submit(&amp;amp;connect_work,
			K_SECONDS(CONFIG_CONNECTION_RETRY_TIMEOUT_SECONDS));
}

static void shadow_update_work_fn(struct k_work *work)
{
	int err;

	err = shadow_update(false);
	if (err) {
		printk(&amp;quot;shadow_update, error: %d\n&amp;quot;, err);
	}

	printk(&amp;quot;Next data publication in %d seconds\n&amp;quot;,
	       CONFIG_PUBLICATION_INTERVAL_SECONDS);

	k_delayed_work_submit(&amp;amp;shadow_update_work,
			      K_SECONDS(CONFIG_PUBLICATION_INTERVAL_SECONDS));
}

static void shadow_update_version_work_fn(struct k_work *work)
{
	int err;

	err = shadow_update(true);
	if (err) {
		printk(&amp;quot;shadow_update, error: %d\n&amp;quot;, err);
	}
}

static void print_received_data(const char *buf, const char *topic,
				size_t topic_len)
{
	char *str = NULL;
	cJSON *root_obj = NULL;

	root_obj = cJSON_Parse(buf);
	if (root_obj == NULL) {
		printk(&amp;quot;cJSON Parse failure&amp;quot;);
		return;
	}

	str = cJSON_Print(root_obj);
	if (str == NULL) {
		printk(&amp;quot;Failed to print JSON object&amp;quot;);
		goto clean_exit;
	}

	printf(&amp;quot;Data received from AWS IoT console:\nTopic: %.*s\nMessage: %s\n&amp;quot;,
	       topic_len, topic, str);

	cJSON_FreeString(str);

clean_exit:
	cJSON_Delete(root_obj);
}

void aws_iot_event_handler(const struct aws_iot_evt *const evt)
{
	switch (evt-&amp;gt;type) {
	case AWS_IOT_EVT_CONNECTING:
		printk(&amp;quot;AWS_IOT_EVT_CONNECTING\n&amp;quot;);
		break;
	case AWS_IOT_EVT_CONNECTED:
		printk(&amp;quot;AWS_IOT_EVT_CONNECTED\n&amp;quot;);

		k_delayed_work_cancel(&amp;amp;connect_work);

		if (evt-&amp;gt;data.persistent_session) {
			printk(&amp;quot;Persistent session enabled\n&amp;quot;);
		}

#if defined(CONFIG_BSD_LIBRARY)
		/** Successfully connected to AWS IoT broker, mark image as
		 *  working to avoid reverting to the former image upon reboot.
		 */
		boot_write_img_confirmed();
#endif

		/** Send version number to AWS IoT broker to verify that the
		 *  FOTA update worked.
		 */
		k_delayed_work_submit(&amp;amp;shadow_update_version_work, K_NO_WAIT);

		/** Start sequential shadow data updates.
		 */
		k_delayed_work_submit(&amp;amp;shadow_update_work,
				K_SECONDS(CONFIG_PUBLICATION_INTERVAL_SECONDS));

#if defined(CONFIG_BSD_LIBRARY)
		int err = lte_lc_psm_req(true);
		if (err) {
			printk(&amp;quot;Requesting PSM failed, error: %d\n&amp;quot;, err);
		}
#endif
		break;
	case AWS_IOT_EVT_READY:
		printk(&amp;quot;AWS_IOT_EVT_READY\n&amp;quot;);
		break;
	case AWS_IOT_EVT_DISCONNECTED:
		printk(&amp;quot;AWS_IOT_EVT_DISCONNECTED\n&amp;quot;);
		k_delayed_work_cancel(&amp;amp;shadow_update_work);

		if (k_delayed_work_pending(&amp;amp;connect_work)) {
			break;
		}

		k_delayed_work_submit(&amp;amp;connect_work, K_NO_WAIT);
		break;
	case AWS_IOT_EVT_DATA_RECEIVED:
		printk(&amp;quot;AWS_IOT_EVT_DATA_RECEIVED\n&amp;quot;);
		print_received_data(evt-&amp;gt;data.msg.ptr, evt-&amp;gt;data.msg.topic.str,
				    evt-&amp;gt;data.msg.topic.len);
		break;
	case AWS_IOT_EVT_FOTA_START:
		printk(&amp;quot;AWS_IOT_EVT_FOTA_START\n&amp;quot;);
		break;
	case AWS_IOT_EVT_FOTA_ERASE_PENDING:
		printk(&amp;quot;AWS_IOT_EVT_FOTA_ERASE_PENDING\n&amp;quot;);
		printk(&amp;quot;Disconnect LTE link or reboot\n&amp;quot;);
#if defined(CONFIG_BSD_LIBRARY)
		err = lte_lc_offline();
		if (err) {
			printk(&amp;quot;Error disconnecting from LTE\n&amp;quot;);
		}
#endif
		break;
	case AWS_IOT_EVT_FOTA_ERASE_DONE:
		printk(&amp;quot;AWS_FOTA_EVT_ERASE_DONE\n&amp;quot;);
		printk(&amp;quot;Reconnecting the LTE link&amp;quot;);
#if defined(CONFIG_BSD_LIBRARY)
		err = lte_lc_connect();
		if (err) {
			printk(&amp;quot;Error connecting to LTE\n&amp;quot;);
		}
#endif
		break;
	case AWS_IOT_EVT_FOTA_DONE:
		printk(&amp;quot;AWS_IOT_EVT_FOTA_DONE\n&amp;quot;);
		printk(&amp;quot;FOTA done, rebooting device\n&amp;quot;);
		aws_iot_disconnect();
		sys_reboot(0);
		break;
	case AWS_IOT_EVT_FOTA_DL_PROGRESS:
		printk(&amp;quot;AWS_IOT_EVT_FOTA_DL_PROGRESS, (%d%%)&amp;quot;,
		       evt-&amp;gt;data.fota_progress);
	case AWS_IOT_EVT_ERROR:
		printk(&amp;quot;AWS_IOT_EVT_ERROR, %d\n&amp;quot;, evt-&amp;gt;data.err);
		break;
	default:
		printk(&amp;quot;Unknown AWS IoT event type: %d\n&amp;quot;, evt-&amp;gt;type);
		break;
	}
}

static void work_init(void)
{
	k_delayed_work_init(&amp;amp;shadow_update_work, shadow_update_work_fn);
	k_delayed_work_init(&amp;amp;connect_work, connect_work_fn);
	k_delayed_work_init(&amp;amp;shadow_update_version_work,
			    shadow_update_version_work_fn);
}

#if defined(CONFIG_BSD_LIBRARY)
static void lte_handler(const struct lte_lc_evt *const evt)
{
	switch (evt-&amp;gt;type) {
	case LTE_LC_EVT_NW_REG_STATUS:
		if ((evt-&amp;gt;nw_reg_status != LTE_LC_NW_REG_REGISTERED_HOME) &amp;amp;&amp;amp;
		     (evt-&amp;gt;nw_reg_status != LTE_LC_NW_REG_REGISTERED_ROAMING)) {
			break;
		}

		printk(&amp;quot;Network registration status: %s\n&amp;quot;,
			evt-&amp;gt;nw_reg_status == LTE_LC_NW_REG_REGISTERED_HOME ?
			&amp;quot;Connected - home network&amp;quot; : &amp;quot;Connected - roaming&amp;quot;);

		k_sem_give(&amp;amp;lte_connected);
		break;
	case LTE_LC_EVT_PSM_UPDATE:
		printk(&amp;quot;PSM parameter update: TAU: %d, Active time: %d\n&amp;quot;,
			evt-&amp;gt;psm_cfg.tau, evt-&amp;gt;psm_cfg.active_time);
		break;
	case LTE_LC_EVT_EDRX_UPDATE: {
		char log_buf[60];
		ssize_t len;

		len = snprintf(log_buf, sizeof(log_buf),
			       &amp;quot;eDRX parameter update: eDRX: %f, PTW: %f&amp;quot;,
			       evt-&amp;gt;edrx_cfg.edrx, evt-&amp;gt;edrx_cfg.ptw);
		if (len &amp;gt; 0) {
			printk(&amp;quot;%s\n&amp;quot;, log_buf);
		}
		break;
	}
	case LTE_LC_EVT_RRC_UPDATE:
		printk(&amp;quot;RRC mode: %s\n&amp;quot;,
			evt-&amp;gt;rrc_mode == LTE_LC_RRC_MODE_CONNECTED ?
			&amp;quot;Connected&amp;quot; : &amp;quot;Idle&amp;quot;);
		break;
	case LTE_LC_EVT_CELL_UPDATE:
		printk(&amp;quot;LTE cell changed: Cell ID: %d, Tracking area: %d\n&amp;quot;,
			evt-&amp;gt;cell.id, evt-&amp;gt;cell.tac);
		break;
	default:
		break;
	}
}

static void modem_configure(void)
{
	int err = 0;

	if (IS_ENABLED(CONFIG_LTE_AUTO_INIT_AND_CONNECT))
	{
		/* Do nothing, modem is already configured and LTE connected. */
	}
	else
	{	err = lte_lc_init_and_connect_async(lte_handler);
		err = lte_lc_psm_req(true);
		if (err)
		{
			printk(&amp;quot;Modem could not be configured, error: %d\n&amp;quot;,err);
			return;
		}
	}
}

static void at_configure(void)
{
	int err;

	err = at_notif_init();
	__ASSERT(err == 0, &amp;quot;AT Notify could not be initialized.&amp;quot;);
	err = at_cmd_init();
	__ASSERT(err == 0, &amp;quot;AT CMD could not be established.&amp;quot;);
}

static void bsd_lib_modem_dfu_handler(void)
{
	int err;

	err = bsdlib_init();

	switch (err) {
	case MODEM_DFU_RESULT_OK:
		printk(&amp;quot;Modem update suceeded, reboot\n&amp;quot;);
		sys_reboot(SYS_REBOOT_COLD);
		break;
	case MODEM_DFU_RESULT_UUID_ERROR:
	case MODEM_DFU_RESULT_AUTH_ERROR:
		printk(&amp;quot;Modem update failed, error: %d\n&amp;quot;, err);
		printk(&amp;quot;Modem will use old firmware\n&amp;quot;);
		sys_reboot(SYS_REBOOT_COLD);
		break;
	case MODEM_DFU_RESULT_HARDWARE_ERROR:
	case MODEM_DFU_RESULT_INTERNAL_ERROR:
		printk(&amp;quot;Modem update malfunction, error: %d, reboot\n&amp;quot;, err);
		sys_reboot(SYS_REBOOT_COLD);
		break;
	default:
		break;
	}

	at_configure();
}
#endif

static int app_topics_subscribe(void)
{
	int err;
	static char custom_topic[75] = &amp;quot;$aws/things/nrf-352656101080789/shadow/update&amp;quot;;
	static char custom_topic_2[75] = &amp;quot;$aws/things/nrf-352656101080789/shadow/delta&amp;quot;;

	const struct aws_iot_topic_data topics_list[APP_TOPICS_COUNT] = {
		[0].str = custom_topic,
		[0].len = strlen(custom_topic),
		[1].str = custom_topic_2,
		[1].len = strlen(custom_topic_2)
	};

	err = aws_iot_subscription_topics_add(topics_list,
					      ARRAY_SIZE(topics_list));
	if (err) {
		printk(&amp;quot;aws_iot_subscription_topics_add, error: %d\n&amp;quot;, err);
	}

	return err;
}

static void date_time_event_handler(const struct date_time_evt *evt)
{
	switch (evt-&amp;gt;type) {
	case DATE_TIME_OBTAINED_MODEM:
		printk(&amp;quot;DATE_TIME_OBTAINED_MODEM\n&amp;quot;);
		break;
	case DATE_TIME_OBTAINED_NTP:
		printk(&amp;quot;DATE_TIME_OBTAINED_NTP\n&amp;quot;);
		break;
	case DATE_TIME_OBTAINED_EXT:
		printk(&amp;quot;DATE_TIME_OBTAINED_EXT\n&amp;quot;);
		break;
	case DATE_TIME_NOT_OBTAINED:
		printk(&amp;quot;DATE_TIME_NOT_OBTAINED\n&amp;quot;);
		break;
	default:
		break;
	}

	/** Do not depend on obtained time, continue upon any event from the
	 *  date time library.
	 */
	k_sem_give(&amp;amp;date_time_obtained);
}

void aws_iot1(void)
{
	int err;
       
	printk(&amp;quot;The AWS IoT sample started, version: %s\n&amp;quot;, CONFIG_APP_VERSION);

	cJSON_Init();

#if defined(CONFIG_BSD_LIBRARY)
	bsd_lib_modem_dfu_handler();
#endif

	err = aws_iot_init(NULL, aws_iot_event_handler);
	if (err) {
		printk(&amp;quot;AWS IoT library could not be initialized, error: %d\n&amp;quot;,
		       err);
	}

	/** Subscribe to customizable non-shadow specific topics
	 *  to AWS IoT backend.
	 */
	err = app_topics_subscribe();
	if (err) {
		printk(&amp;quot;Adding application specific topics failed, error: %d\n&amp;quot;,
			err);
	}

	work_init();
	
#if defined(CONFIG_BSD_LIBRARY)
	modem_configure();

	err = modem_info_init();
	if (err) {
		printk(&amp;quot;Failed initializing modem info module, error: %d\n&amp;quot;,
			err);
	}

	k_sem_take(&amp;amp;lte_connected, K_FOREVER);
#endif


	date_time_update_async(date_time_event_handler);

	err = k_sem_take(&amp;amp;date_time_obtained, K_SECONDS(DATE_TIME_TIMEOUT_S));
	if (err) {
		printk(&amp;quot;Date time, no callback event within %d seconds\n&amp;quot;,
			DATE_TIME_TIMEOUT_S);
	}

	k_delayed_work_submit(&amp;amp;connect_work, K_NO_WAIT);
}

int main(void)
{
	aws_iot1();
	k_sleep(K_MSEC(10000));
	
	nrf_gnss_data_frame_t gps_data;
	uint8_t		      cnt = 0;

#ifdef CONFIG_SUPL_CLIENT_LIB
	static struct supl_api supl_api = {
		.read       = supl_read,
		.write      = supl_write,
		.handler    = inject_agps_type,
		.logger     = supl_logger,
		.counter_ms = k_uptime_get
	};
#endif

	printk(&amp;quot;Starting GPS application\n&amp;quot;);

	if (init_app() != 0) {
		return -1;
	}
	
	modem_configure();

	err = modem_info_init();
	if (err) {
		printk(&amp;quot;Failed initializing modem info module, error: %d\n&amp;quot;,
			err);
	}

	k_sem_take(&amp;amp;lte_connected, K_FOREVER);
	
	
#ifdef CONFIG_SUPL_CLIENT_LIB
	int rc = supl_init(&amp;amp;supl_api);

	if (rc != 0) {
		return rc;
	}
#endif

	printk(&amp;quot;Getting GPS data...\n&amp;quot;);

	while (1) {

		do {
			/* Loop until we don&amp;#39;t have more
			 * data to read
			 */
		} while (process_gps_data(&amp;amp;gps_data) &amp;gt; 0);

		if (IS_ENABLED(CONFIG_GPS_SAMPLE_NMEA_ONLY)) {
			print_nmea_data();
			nmea_string_cnt = 0;
		} else {
			printk(&amp;quot;\033[1;1H&amp;quot;);
			printk(&amp;quot;\033[2J&amp;quot;);
			print_satellite_stats(&amp;amp;last_pvt);
			print_gnss_stats(&amp;amp;last_pvt);
			printk(&amp;quot;---------------------------------\n&amp;quot;);

			if (!got_fix) {
				printk(&amp;quot;Seconds since last fix: %lld\n&amp;quot;,
				       (k_uptime_get() - fix_timestamp) / 1000);
				cnt++;
				printk(&amp;quot;Searching [%c]\n&amp;quot;,
				       update_indicator[cnt%4]);
			} else {
				print_fix_data(&amp;amp;last_pvt);
				
			}

			printk(&amp;quot;\nNMEA strings:\n\n&amp;quot;);
			print_nmea_data();
			printk(&amp;quot;---------------------------------&amp;quot;);
			
			
		}

		k_sleep(K_MSEC(500));
	}

	return 0;
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;and this is prg.config&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#GPS
# Copyright (c) 2019 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#
CONFIG_BSD_LIBRARY=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
CONFIG_AT_CMD=y
CONFIG_AT_NOTIF=y

# Enable SUPL client support
CONFIG_SUPL_CLIENT_LIB=n

# Networking
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y

# Disable native network stack to save some memory
CONFIG_NET_NATIVE=n

# Main thread
CONFIG_HEAP_MEM_POOL_SIZE=4096
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

# Application
CONFIG_GPS_SAMPLE_NMEA_ONLY=n

# General config
CONFIG_NCS_SAMPLES_DEFAULTS=y
CONFIG_REBOOT=y

# LTE link control
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_NETWORK_MODE_LTE_M_GPS=y
CONFIG_LTE_AUTO_INIT_AND_CONNECT=n
CONFIG_LTE_PSM_REQ_RPTAU=&amp;quot;00011111&amp;quot;
CONFIG_LTE_PSM_REQ_RAT=&amp;quot;00000010&amp;quot;
CONFIG_LTE_POWER_SAVING_MODE=y

# Download client (needed by AWS FOTA)
CONFIG_DOWNLOAD_CLIENT=y
CONFIG_DOWNLOAD_CLIENT_STACK_SIZE=4096

# MCUBOOT
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_MCUBOOT_IMG_MANAGER=y

# Image manager
CONFIG_IMG_MANAGER=y
CONFIG_FLASH=y
CONFIG_IMG_ERASE_PROGRESSIVELY=y

# AWS FOTA
CONFIG_AWS_FOTA=y
CONFIG_FOTA_DOWNLOAD=y
CONFIG_DFU_TARGET=y

# CJSON
CONFIG_CJSON_LIB=y

# Date Time library
CONFIG_DATE_TIME=y

# Modem information
CONFIG_MODEM_INFO=y


# BSD library
CONFIG_BSD_LIBRARY_SYS_INIT=y

# AT Host
CONFIG_AT_HOST_LIBRARY=y

# AWS IoT library
CONFIG_AWS_IOT=y
CONFIG_AWS_IOT_CLIENT_ID_STATIC=&amp;quot;nrf-352656101080789&amp;quot;
CONFIG_AWS_IOT_BROKER_HOST_NAME=&amp;quot;a6i4ulevbqzm-ats.iot.us-east-2.amazonaws.com&amp;quot;
CONFIG_AWS_IOT_SEC_TAG=201
CONFIG_AWS_IOT_APP_SUBSCRIPTION_LIST_COUNT=2
CONFIG_AWS_IOT_TOPIC_UPDATE_DELTA_SUBSCRIBE=y
CONFIG_AWS_IOT_CONNECTION_POLL_THREAD=y
CONFIG_AWS_IOT_LAST_WILL=y
CONFIG_AWS_IOT_TOPIC_GET_ACCEPTED_SUBSCRIBE=y
CONFIG_AWS_IOT_TOPIC_GET_REJECTED_SUBSCRIBE=y&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;Thanks in Advance for your time&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send data to own AWS server using Cloud Client sample ?</title><link>https://devzone.nordicsemi.com/thread/286856?ContentTypeID=1</link><pubDate>Tue, 29 Dec 2020 13:53:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c855cab2-33d8-49a0-95b9-aa84b04568b4</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hi Jaydip,&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Yes, you should be able to combine the AGPS and AWS_IOT sample. The AGPS sample uses a cloud back end which currently points to nRF Cloud. You will need to change this to AWS. &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/69558/can-we-send-the-agps-data-to-io-adafruit/285329"&gt;Please see this ticket&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send data to own AWS server using Cloud Client sample ?</title><link>https://devzone.nordicsemi.com/thread/286817?ContentTypeID=1</link><pubDate>Tue, 29 Dec 2020 10:27:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bf1d11a5-cf7c-4404-a390-a30bcb5366e7</guid><dc:creator>jaydip kavaiya</dc:creator><description>&lt;p&gt;HI Oyvind&lt;/p&gt;
&lt;p&gt;Thanks you for your reply&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="77062" url="~/f/nordic-q-a/69840/how-to-send-data-to-own-aws-server-using-cloud-client-sample/286757#286757"]you able to solve last issue from the support case you linked to? [/quote]
&lt;p&gt;I am Using AWS_IOT sample code Yes I am able to connect AWS server and received data on Link monitor like this&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;2020-12-25T04:05:22.610Z DEBUG modem &amp;lt;&amp;lt; Next connection retry in 30 seconds
2020-12-25T04:05:22.614Z DEBUG modem &amp;lt;&amp;lt; AWS_IOT_EVT_CONNECTING
2020-12-25T04:05:22.755Z DEBUG modem &amp;lt;&amp;lt; RRC mode: Connected
2020-12-25T04:05:26.959Z DEBUG modem &amp;lt;&amp;lt; AWS_IOT_EVT_CONNECTED
2020-12-25T04:05:27.091Z DEBUG modem &amp;lt;&amp;lt; Publishing: {
2020-12-25T04:05:27.094Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;state&amp;quot;:{
2020-12-25T04:05:27.095Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;reported&amp;quot;:{
2020-12-25T04:05:27.195Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;app_version&amp;quot;:&amp;quot;v1.0.0&amp;quot;,
2020-12-25T04:05:27.198Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;batv&amp;quot;:4410,
2020-12-25T04:05:27.199Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;ts&amp;quot;:943920514411
2020-12-25T04:05:27.201Z DEBUG modem &amp;lt;&amp;lt; }
2020-12-25T04:05:27.202Z DEBUG modem &amp;lt;&amp;lt; }
2020-12-25T04:05:27.203Z DEBUG modem &amp;lt;&amp;lt; } to AWS IoT broker
2020-12-25T04:05:27.547Z DEBUG modem &amp;lt;&amp;lt; AWS_IOT_EVT_READY
2020-12-25T04:05:27.957Z DEBUG modem &amp;lt;&amp;lt; AWS_IOT_EVT_DATA_RECEIVED
2020-12-25T04:05:28.091Z DEBUG modem &amp;lt;&amp;lt; Data received from AWS IoT console:
2020-12-25T04:05:28.094Z DEBUG modem &amp;lt;&amp;lt; Topic: $aws/things/nrf-352656101080789/shadow/get/accepted
2020-12-25T04:05:28.096Z DEBUG modem &amp;lt;&amp;lt; Message: {
2020-12-25T04:05:28.098Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;state&amp;quot;:{
2020-12-25T04:05:28.101Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;desired&amp;quot;:{
2020-12-25T04:05:28.103Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;welcome&amp;quot;:&amp;quot;aws-iot&amp;quot;
2020-12-25T04:05:28.105Z DEBUG modem &amp;lt;&amp;lt; },
2020-12-25T04:05:28.107Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;reported&amp;quot;:{
2020-12-25T04:05:28.109Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;welcome&amp;quot;:&amp;quot;aws-iot&amp;quot;,
2020-12-25T04:05:28.112Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;app_version&amp;quot;:&amp;quot;v1.0.0&amp;quot;,
2020-12-25T04:05:28.115Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;batv&amp;quot;:4410,
2020-12-25T04:05:28.117Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;ts&amp;quot;:943920514411
2020-12-25T04:05:28.119Z DEBUG modem &amp;lt;&amp;lt; }
2020-12-25T04:05:28.121Z DEBUG modem &amp;lt;&amp;lt; },
2020-12-25T04:05:28.123Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;metadata&amp;quot;:{
2020-12-25T04:05:28.125Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;desired&amp;quot;:{
2020-12-25T04:05:28.127Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;welcome&amp;quot;:{
2020-12-25T04:05:28.129Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;timestamp&amp;quot;:1608782408
2020-12-25T04:05:28.131Z DEBUG modem &amp;lt;&amp;lt; }
2020-12-25T04:05:28.133Z DEBUG modem &amp;lt;&amp;lt; },
2020-12-25T04:05:28.135Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;reported&amp;quot;:{
2020-12-25T04:05:28.137Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;welcome&amp;quot;:{
2020-12-25T04:05:28.139Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;timestamp&amp;quot;:1608782408
2020-12-25T04:05:28.142Z DEBUG modem &amp;lt;&amp;lt; },
2020-12-25T04:05:28.144Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;app_version&amp;quot;:{
2020-12-25T04:05:28.146Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;timestamp&amp;quot;:1608869128
2020-12-25T04:05:28.148Z DEBUG modem &amp;lt;&amp;lt; },
2020-12-25T04:05:28.150Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;batv&amp;quot;:{
2020-12-25T04:05:28.152Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;timestamp&amp;quot;:1608869128
2020-12-25T04:05:28.154Z DEBUG modem &amp;lt;&amp;lt; },
2020-12-25T04:05:28.156Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;ts&amp;quot;:{
2020-12-25T04:05:28.158Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;timestamp&amp;quot;:1608869128
2020-12-25T04:05:28.161Z DEBUG modem &amp;lt;&amp;lt; }
2020-12-25T04:05:28.163Z DEBUG modem &amp;lt;&amp;lt; }
2020-12-25T04:05:28.165Z DEBUG modem &amp;lt;&amp;lt; },
2020-12-25T04:05:28.167Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;version&amp;quot;:8,
2020-12-25T04:05:28.169Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;timestamp&amp;quot;:1608869128
2020-12-25T04:05:28.171Z DEBUG modem &amp;lt;&amp;lt; }
2020-12-25T04:05:34.359Z DEBUG modem &amp;lt;&amp;lt; RRC mode: Idle
2020-12-25T04:06:06.537Z DEBUG modem &amp;lt;&amp;lt; LTE cell changed: Cell ID: 33905667, Tracking area: 33794
2020-12-25T04:06:26.977Z DEBUG modem &amp;lt;&amp;lt; Publishing: {
2020-12-25T04:06:26.982Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;state&amp;quot;:{
2020-12-25T04:06:26.986Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;reported&amp;quot;:{
2020-12-25T04:06:26.990Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;batv&amp;quot;:4406,
2020-12-25T04:06:27.154Z DEBUG modem &amp;lt;&amp;lt; &amp;quot;ts&amp;quot;:943920574411
2020-12-25T04:06:27.158Z DEBUG modem &amp;lt;&amp;lt; }
2020-12-25T04:06:27.160Z DEBUG modem &amp;lt;&amp;lt; }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Now I want to send GPS data to my AWS server so there are 2 ways&lt;/p&gt;
&lt;p&gt;1) Is need to change in AGPS sample So question is where i need to changes in endpoint for AWS and certificate.&lt;/p&gt;
&lt;p&gt;2) Or Need to change in AWS_IOT sample who already connected to my AWS server So&amp;nbsp;&lt;span&gt;question&lt;/span&gt;&amp;nbsp;is where can I put my GPS(Latitude, Longitude, Altitude) data for publish to AWS&amp;nbsp;server.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And again Thank you for your valuable time.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards&lt;br /&gt;Jaydip&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send data to own AWS server using Cloud Client sample ?</title><link>https://devzone.nordicsemi.com/thread/286757?ContentTypeID=1</link><pubDate>Mon, 28 Dec 2020 15:28:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7d12a595-2658-46d6-bb1d-ca5b4e51616f</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I&amp;#39;m sorry, but were you able to solve last issue from the support case you linked to? (Case #&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/69490/change-destination-server-for-agps-code"&gt;261504&lt;/a&gt;) Are you getting the same error as that case? Please provide the output from when you are connecting to the cloud solution.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Thank you.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>