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

How to send data to own AWS server using Cloud Client sample ?

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 TAG.

3) Updated the modem certificates.

but get an error.

this my Kconfig 

#
# Copyright (c) 2020 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#

menu "Cloud Client Sample Settings"

config CLOUD_BACKEND
	string "Selects the cloud backend to be used"
	default "AWS_IOT"
	help
	  Possible values are "NRF_CLOUD", "AWS_IOT", "AZURE_IOT_HUB".

config AWS_IOT_BROKER_HOST_NAME
	string "AWS IoT MQTT broker hostname"
	default "a6i4ulevbqzm-ats.iot.us-east-2.amazonaws.com"
	help
	  Default is set to be the nRF Cloud MQTT broker.	  

config AWS_IOT_CLIENT_ID_STATIC
	string "Client ID"
	default "nrf-352656101080789"
	
config AWS_IOT_SEC_TAG
	int "Security tag for TLS credentials"
	default 111
	
config MQTT_BROKER_PORT
	int "AWS IoT MQTT broker port"
	default 8883
	  
config CLOUD_MESSAGE
	string "Sets the custom message published periodically to cloud"
	default "{\"state\":{\"reported\":{\"message\":\"Hello Internet of Things!\"}}}"

config CLOUD_MESSAGE_PUBLICATION_INTERVAL
	int "Sets how often the custom message should be published to cloud, in seconds"
	default 10

config CLOUD_CONNECTION_RETRY_TIMEOUT_SECONDS
	int "Sets the number of seconds between each cloud connection retry"
	default 30

choice
	prompt "Cloud Publication Trigger"
	default CLOUD_PUBLICATION_BUTTON_PRESS

config CLOUD_PUBLICATION_BUTTON_PRESS
	bool "Triggers publication to cloud upon a button press"

config CLOUD_PUBLICATION_SEQUENTIAL
	bool "Sets sequential publication to cloud set by the CONFIG_MESSAGE_PUBLICATION_INTERVAL option"

endchoice

config POWER_SAVING_MODE_ENABLE
	bool "Requests PSM from cellular network"

endmenu

module = CLOUD_CLIENT
module-str = Cloud client
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"

menu "Zephyr Kernel"
source "Kconfig.zephyr"
endmenu

this my prj.config

#
# Copyright (c) 2020 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#

# General config
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
CONFIG_RESET_ON_FATAL_ERROR=n
CONFIG_NCS_SAMPLES_DEFAULTS=y

# Log level
# For more verbose and detailed log output, set the log level to
# CONFIG_CLOUD_CLIENT_LOG_LEVEL_DBG=y instead.
CONFIG_CLOUD_CLIENT_LOG_LEVEL_INF=y

# Network
CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=n
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_OFFLOAD=y

# LTE link control
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_NETWORK_MODE_LTE_M=y
CONFIG_LTE_AUTO_INIT_AND_CONNECT=n

# BSD library
CONFIG_BSD_LIBRARY=y

# DK
CONFIG_DK_LIBRARY=y

# AT commands interface
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_AT_HOST_LIBRARY=y

# Generic cloud API
CONFIG_CLOUD_API=y

# Selected cloud backend
CONFIG_CLOUD_BACKEND="AWS_IOT"

# nRF Cloud
CONFIG_NRF_CLOUD=n
# CONFIG_NRF_CLOUD_CONNECTION_POLL_THREAD=y

# AWS IoT
CONFIG_AWS_IOT=y
CONFIG_AWS_IOT_CLIENT_ID_STATIC="nrf-352656101080789"
CONFIG_AWS_IOT_BROKER_HOST_NAME="a6i4ulevbqzm-ats.iot.us-east-2.amazonaws.com"
CONFIG_AWS_IOT_SEC_TAG=111
CONFIG_AWS_IOT_TOPIC_UPDATE_DELTA_SUBSCRIBE=y
CONFIG_AWS_IOT_CONNECTION_POLL_THREAD=y

# Azure IoT Hub
# CONFIG_AZURE_IOT_HUB=y
# CONFIG_AZURE_IOT_HUB_DEVICE_ID="my-device"
# CONFIG_AZURE_IOT_HUB_HOSTNAME="example.endpoint.com"
# CONFIG_AZURE_IOT_HUB_SEC_TAG=10

# Heap and stacks
# Extended memory heap size needed for encoding nRF Cloud messages to JSON
CONFIG_HEAP_MEM_POOL_SIZE=8192
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

is there any i need to change?

Thanks & Regards

Iand Prj.config file

  • I'm not able to compile. Can you please share full project?

  • I'm not able to compile. Can you please share full project?

    Sure, Thanks you for your fast reply I stuck at this point.

    1.main.c

    2.prj.conf

    3.Kconfig

    4 sample.yaml

    5 CMakeLists

    6. Logfile

    I use GPS sample so rest are as it is.

    /*
     * Copyright (c) 2019 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
     */
    
    #include <zephyr.h>
    #include <nrf_socket.h>
    #include <net/socket.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    #include <modem/lte_lc.h>
    #include <modem/bsdlib.h>
    #include <modem/at_cmd.h>
    #include <modem/at_notif.h>
    #include <modem/modem_info.h>
    #include <bsd.h>
    
    #include <net/aws_iot.h>
    #include <power/reboot.h>
    #include <date_time.h>
    #include <dfu/mcuboot.h>
    #include <cJSON.h>
    #include <cJSON_os.h>
    
    #ifdef CONFIG_SUPL_CLIENT_LIB
    #include <supl_os_client.h>
    #include <supl_session.h>
    #include "supl_support.h"
    #endif
    
    #define AT_XSYSTEMMODE      "AT\%XSYSTEMMODE=1,0,1,0"
    #define AT_ACTIVATE_GPS     "AT+CFUN=31"
    #define AT_ACTIVATE_LTE     "AT+CFUN=21"
    #define AT_DEACTIVATE_LTE   "AT+CFUN=20"
    
    #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      "AT\%XMAGPIO=1,0,0,1,1,1574,1577"
    #ifdef CONFIG_GPS_SAMPLE_ANTENNA_ONBOARD
    #define AT_COEX0       "AT\%XCOEX0=1,1,1565,1586"
    #elif CONFIG_GPS_SAMPLE_ANTENNA_EXTERNAL
    #define AT_COEX0       "AT\%XCOEX0"
    #endif
    #endif /* CONFIG_BOARD_NRF9160DK_NRF9160NS */
    
    #ifdef CONFIG_BOARD_THINGY91_NRF9160NS
    #define AT_MAGPIO      "AT\%XMAGPIO=1,1,1,7,1,746,803,2,698,748,2,1710,2200," \
    			"3,824,894,4,880,960,5,791,849,7,1565,1586"
    #ifdef CONFIG_GPS_SAMPLE_ANTENNA_ONBOARD
    #define AT_COEX0       "AT\%XCOEX0=1,1,1565,1586"
    #elif CONFIG_GPS_SAMPLE_ANTENNA_EXTERNAL
    #define AT_COEX0       "AT\%XCOEX0"
    #endif
    #endif /* CONFIG_BOARD_THINGY91_NRF9160NS */
    
    static const char update_indicator[] = {'\\', '|', '/', '-'};
    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),
    		"This sample does not support LTE auto-init and connect");
    
    #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("Err: %lu\n", (unsigned long)error);
    }
    
    static int setup_modem(void)
    {
    	for (int i = 0; i < 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[] = "+CEREG: 1";
    static const char status2[] = "+CEREG:1";
    static const char status3[] = "+CEREG: 5";
    static const char status4[] = "+CEREG:5";
    
    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(&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("AT+CEREG=2", NULL, 0, NULL) != 0) {
    			return -1;
    		}
    
    		k_sem_take(&lte_ready, K_FOREVER);
    
    		at_notif_deregister_handler(NULL, wait_for_lte);
    		if (at_cmd_write("AT+CEREG=0", 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 >= 0) {
    			printk("GPS Socket created\n");
    		} else {
    			printk("Could not init socket (err: %d)\n", gnss_fd);
    			return -1;
    		}
    
    		retval = nrf_setsockopt(gnss_fd,
    					NRF_SOL_GNSS,
    					NRF_SO_GNSS_FIX_RETRY,
    					&fix_retry,
    					sizeof(fix_retry));
    		if (retval != 0) {
    			printk("Failed to set fix retry value\n");
    			return -1;
    		}
    
    		retval = nrf_setsockopt(gnss_fd,
    					NRF_SOL_GNSS,
    					NRF_SO_GNSS_FIX_INTERVAL,
    					&fix_interval,
    					sizeof(fix_interval));
    		if (retval != 0) {
    			printk("Failed to set fix interval value\n");
    			return -1;
    		}
    
    		retval = nrf_setsockopt(gnss_fd,
    					NRF_SOL_GNSS,
    					NRF_SO_GNSS_NMEA_MASK,
    					&nmea_mask,
    					sizeof(nmea_mask));
    		if (retval != 0) {
    			printk("Failed to set nmea mask\n");
    			return -1;
    		}
    	}
    
    	if ((ctrl == GNSS_INIT_AND_START) ||
    	    (ctrl == GNSS_RESTART)) {
    		retval = nrf_setsockopt(gnss_fd,
    					NRF_SOL_GNSS,
    					NRF_SO_GNSS_START,
    					&delete_mask,
    					sizeof(delete_mask));
    		if (retval != 0) {
    			printk("Failed to start GPS\n");
    			return -1;
    		}
    	}
    
    	if (ctrl == GNSS_STOP) {
    		retval = nrf_setsockopt(gnss_fd,
    					NRF_SOL_GNSS,
    					NRF_SO_GNSS_STOP,
    					&delete_mask,
    					sizeof(delete_mask));
    		if (retval != 0) {
    			printk("Failed to stop GPS\n");
    			return -1;
    		}
    	}
    
    	return 0;
    }
    
    static int init_app(void)
    {
    	int retval;
    
    
    	if (setup_modem() != 0) {
    		printk("Failed to initialize modem\n");
    		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 < NRF_GNSS_MAX_SATELLITES; ++i) {
    
    		if ((pvt_data->pvt.sv[i].sv > 0) &&
    		    (pvt_data->pvt.sv[i].sv < 33)) {
    
    			tracked++;
    
    			if (pvt_data->pvt.sv[i].flags &
    					NRF_GNSS_SV_FLAG_USED_IN_FIX) {
    				in_fix++;
    			}
    
    			if (pvt_data->pvt.sv[i].flags &
    					NRF_GNSS_SV_FLAG_UNHEALTHY) {
    				unhealthy++;
    			}
    		}
    	}
    
    	printk("Tracking: %d Using: %d Unhealthy: %d\n", tracked,
    							 in_fix,
    							 unhealthy);
    }
    
    static void print_gnss_stats(nrf_gnss_data_frame_t *pvt_data)
    {
    	if (pvt_data->pvt.flags & NRF_GNSS_PVT_FLAG_DEADLINE_MISSED) {
    		printk("GNSS notification deadline missed\n");
    	}
    	if (pvt_data->pvt.flags & NRF_GNSS_PVT_FLAG_NOT_ENOUGH_WINDOW_TIME) {
    		printk("GNSS operation blocked by insufficient time windows\n");
    	}
    }
    
    static void print_fix_data(nrf_gnss_data_frame_t *pvt_data)
    {
    	printf("Longitude:  %f\n", pvt_data->pvt.longitude);
    	printf("Latitude:   %f\n", pvt_data->pvt.latitude);
    	printf("Altitude:   %f\n", pvt_data->pvt.altitude);
    	printf("Speed:      %f\n", pvt_data->pvt.speed);
    	printf("Heading:    %f\n", pvt_data->pvt.heading);
    	printk("Date:       %02u-%02u-%02u\n", pvt_data->pvt.datetime.year,
    					       pvt_data->pvt.datetime.month,
    					       pvt_data->pvt.datetime.day);
    	printk("Time (UTC): %02u:%02u:%02u\n", pvt_data->pvt.datetime.hour,
    					       pvt_data->pvt.datetime.minute,
    					      pvt_data->pvt.datetime.seconds);
    }
    
    static void print_nmea_data(void)
    {
    	for (int i = 0; i < nmea_string_cnt; ++i) {
    		printk("%s", 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 > 0) {
    
    		switch (gps_data->data_id) {
    		case NRF_GNSS_PVT_DATA_ID:
    			memcpy(&last_pvt,
    			       gps_data,
    			       sizeof(nrf_gnss_data_frame_t));
    			nmea_string_cnt = 0;
    			got_fix = false;
    
    			if ((gps_data->pvt.flags &
    				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 < 10) {
    				memcpy(nmea_strings[nmea_string_cnt++],
    				       gps_data->nmea,
    				       retval);
    			}
    			break;
    
    		case NRF_GNSS_AGPS_DATA_ID:
    #ifdef CONFIG_SUPL_CLIENT_LIB
    			printk("\033[1;1H");
    			printk("\033[2J");
    			printk("New AGPS data requested, contacting SUPL server, flags %d\n",
    			       gps_data->agps.data_flags);
    			gnss_ctrl(GNSS_STOP);
    			activate_lte(true);
    			printk("Established LTE link\n");
    			if (open_supl_socket() == 0) {
    				printf("Starting SUPL session\n");
    				supl_session(&gps_data->agps);
    				printk("Done\n");
    				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,
    				&type,
    				sizeof(type));
    
    	if (retval != 0) {
    		printk("Failed to send AGNSS data, type: %d (err: %d)\n",
    		       type,
    		       errno);
    		return -1;
    	}
    
    	printk("Injected AGPS data, flags: %d, size: %d\n", 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(&message_ts);
    	if (err) {
    		printk("date_time_now, error: %d\n", err);
    		return err;
    	}
    
    #if defined(CONFIG_BSD_LIBRARY)
    	/* Request battery voltage data from the modem. */
    	err = modem_info_short_get(MODEM_INFO_BATTERY, &bat_voltage);
    	if (err != sizeof(bat_voltage)) {
    		printk("modem_info_short_get, error: %d\n", 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, "app_version",
    				    CONFIG_APP_VERSION);
    	} else {
    		err = 0;
    	}
    
    	err += json_add_number(reported_obj, "batv", bat_voltage);
    	err += json_add_number(reported_obj, "ts", message_ts);
    	err += json_add_obj(state_obj, "reported", reported_obj);
    	err += json_add_obj(root_obj, "state", state_obj);
    
    	if (err) {
    		printk("json_add, error: %d\n", err);
    		goto cleanup;
    	}
    
    	message = cJSON_Print(root_obj);
    	if (message == NULL) {
    		printk("cJSON_Print, error: returned NULL\n");
    		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("Publishing: %s to AWS IoT broker\n", message);
    
    	err = aws_iot_send(&tx_data);
    	if (err) {
    		printk("aws_iot_send, error: %d\n", 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("aws_iot_connect, error: %d\n", err);
    	}
    
    	printk("Next connection retry in %d seconds\n",
    	       CONFIG_CONNECTION_RETRY_TIMEOUT_SECONDS);
    
    	k_delayed_work_submit(&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("shadow_update, error: %d\n", err);
    	}
    
    	printk("Next data publication in %d seconds\n",
    	       CONFIG_PUBLICATION_INTERVAL_SECONDS);
    
    	k_delayed_work_submit(&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("shadow_update, error: %d\n", 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("cJSON Parse failure");
    		return;
    	}
    
    	str = cJSON_Print(root_obj);
    	if (str == NULL) {
    		printk("Failed to print JSON object");
    		goto clean_exit;
    	}
    
    	printf("Data received from AWS IoT console:\nTopic: %.*s\nMessage: %s\n",
    	       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->type) {
    	case AWS_IOT_EVT_CONNECTING:
    		printk("AWS_IOT_EVT_CONNECTING\n");
    		break;
    	case AWS_IOT_EVT_CONNECTED:
    		printk("AWS_IOT_EVT_CONNECTED\n");
    
    		k_delayed_work_cancel(&connect_work);
    
    		if (evt->data.persistent_session) {
    			printk("Persistent session enabled\n");
    		}
    
    #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(&shadow_update_version_work, K_NO_WAIT);
    
    		/** Start sequential shadow data updates.
    		 */
    		k_delayed_work_submit(&shadow_update_work,
    				K_SECONDS(CONFIG_PUBLICATION_INTERVAL_SECONDS));
    
    #if defined(CONFIG_BSD_LIBRARY)
    		int err = lte_lc_psm_req(true);
    		if (err) {
    			printk("Requesting PSM failed, error: %d\n", err);
    		}
    #endif
    		break;
    	case AWS_IOT_EVT_READY:
    		printk("AWS_IOT_EVT_READY\n");
    		break;
    	case AWS_IOT_EVT_DISCONNECTED:
    		printk("AWS_IOT_EVT_DISCONNECTED\n");
    		k_delayed_work_cancel(&shadow_update_work);
    
    		if (k_delayed_work_pending(&connect_work)) {
    			break;
    		}
    
    		k_delayed_work_submit(&connect_work, K_NO_WAIT);
    		break;
    	case AWS_IOT_EVT_DATA_RECEIVED:
    		printk("AWS_IOT_EVT_DATA_RECEIVED\n");
    		print_received_data(evt->data.msg.ptr, evt->data.msg.topic.str,
    				    evt->data.msg.topic.len);
    		break;
    	case AWS_IOT_EVT_FOTA_START:
    		printk("AWS_IOT_EVT_FOTA_START\n");
    		break;
    	case AWS_IOT_EVT_FOTA_ERASE_PENDING:
    		printk("AWS_IOT_EVT_FOTA_ERASE_PENDING\n");
    		printk("Disconnect LTE link or reboot\n");
    #if defined(CONFIG_BSD_LIBRARY)
    		err = lte_lc_offline();
    		if (err) {
    			printk("Error disconnecting from LTE\n");
    		}
    #endif
    		break;
    	case AWS_IOT_EVT_FOTA_ERASE_DONE:
    		printk("AWS_FOTA_EVT_ERASE_DONE\n");
    		printk("Reconnecting the LTE link");
    #if defined(CONFIG_BSD_LIBRARY)
    		err = lte_lc_connect();
    		if (err) {
    			printk("Error connecting to LTE\n");
    		}
    #endif
    		break;
    	case AWS_IOT_EVT_FOTA_DONE:
    		printk("AWS_IOT_EVT_FOTA_DONE\n");
    		printk("FOTA done, rebooting device\n");
    		aws_iot_disconnect();
    		sys_reboot(0);
    		break;
    	case AWS_IOT_EVT_FOTA_DL_PROGRESS:
    		printk("AWS_IOT_EVT_FOTA_DL_PROGRESS, (%d%%)",
    		       evt->data.fota_progress);
    	case AWS_IOT_EVT_ERROR:
    		printk("AWS_IOT_EVT_ERROR, %d\n", evt->data.err);
    		break;
    	default:
    		printk("Unknown AWS IoT event type: %d\n", evt->type);
    		break;
    	}
    }
    
    static void work_init(void)
    {
    	k_delayed_work_init(&shadow_update_work, shadow_update_work_fn);
    	k_delayed_work_init(&connect_work, connect_work_fn);
    	k_delayed_work_init(&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->type) {
    	case LTE_LC_EVT_NW_REG_STATUS:
    		if ((evt->nw_reg_status != LTE_LC_NW_REG_REGISTERED_HOME) &&
    		     (evt->nw_reg_status != LTE_LC_NW_REG_REGISTERED_ROAMING)) {
    			break;
    		}
    
    		printk("Network registration status: %s\n",
    			evt->nw_reg_status == LTE_LC_NW_REG_REGISTERED_HOME ?
    			"Connected - home network" : "Connected - roaming");
    
    		k_sem_give(&lte_connected);
    		break;
    	case LTE_LC_EVT_PSM_UPDATE:
    		printk("PSM parameter update: TAU: %d, Active time: %d\n",
    			evt->psm_cfg.tau, evt->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),
    			       "eDRX parameter update: eDRX: %f, PTW: %f",
    			       evt->edrx_cfg.edrx, evt->edrx_cfg.ptw);
    		if (len > 0) {
    			printk("%s\n", log_buf);
    		}
    		break;
    	}
    	case LTE_LC_EVT_RRC_UPDATE:
    		printk("RRC mode: %s\n",
    			evt->rrc_mode == LTE_LC_RRC_MODE_CONNECTED ?
    			"Connected" : "Idle");
    		break;
    	case LTE_LC_EVT_CELL_UPDATE:
    		printk("LTE cell changed: Cell ID: %d, Tracking area: %d\n",
    			evt->cell.id, evt->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("Modem could not be configured, error: %d\n",err);
    			return;
    		}
    	}
    }
    
    static void at_configure(void)
    {
    	int err;
    
    	err = at_notif_init();
    	__ASSERT(err == 0, "AT Notify could not be initialized.");
    	err = at_cmd_init();
    	__ASSERT(err == 0, "AT CMD could not be established.");
    }
    
    static void bsd_lib_modem_dfu_handler(void)
    {
    	int err;
    
    	err = bsdlib_init();
    
    	switch (err) {
    	case MODEM_DFU_RESULT_OK:
    		printk("Modem update suceeded, reboot\n");
    		sys_reboot(SYS_REBOOT_COLD);
    		break;
    	case MODEM_DFU_RESULT_UUID_ERROR:
    	case MODEM_DFU_RESULT_AUTH_ERROR:
    		printk("Modem update failed, error: %d\n", err);
    		printk("Modem will use old firmware\n");
    		sys_reboot(SYS_REBOOT_COLD);
    		break;
    	case MODEM_DFU_RESULT_HARDWARE_ERROR:
    	case MODEM_DFU_RESULT_INTERNAL_ERROR:
    		printk("Modem update malfunction, error: %d, reboot\n", 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] = "$aws/things/nrf-352656101080789/shadow/update";
    	static char custom_topic_2[75] = "$aws/things/nrf-352656101080789/shadow/delta";
    
    	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("aws_iot_subscription_topics_add, error: %d\n", err);
    	}
    
    	return err;
    }
    
    static void date_time_event_handler(const struct date_time_evt *evt)
    {
    	switch (evt->type) {
    	case DATE_TIME_OBTAINED_MODEM:
    		printk("DATE_TIME_OBTAINED_MODEM\n");
    		break;
    	case DATE_TIME_OBTAINED_NTP:
    		printk("DATE_TIME_OBTAINED_NTP\n");
    		break;
    	case DATE_TIME_OBTAINED_EXT:
    		printk("DATE_TIME_OBTAINED_EXT\n");
    		break;
    	case DATE_TIME_NOT_OBTAINED:
    		printk("DATE_TIME_NOT_OBTAINED\n");
    		break;
    	default:
    		break;
    	}
    
    	/** Do not depend on obtained time, continue upon any event from the
    	 *  date time library.
    	 */
    	k_sem_give(&date_time_obtained);
    }
    
    void aws_iot1(void)
    {
    	int err;
           
    	printk("The AWS IoT sample started, version: %s\n", 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("AWS IoT library could not be initialized, error: %d\n",
    		       err);
    	}
    
    	/** Subscribe to customizable non-shadow specific topics
    	 *  to AWS IoT backend.
    	 */
    	err = app_topics_subscribe();
    	if (err) {
    		printk("Adding application specific topics failed, error: %d\n",
    			err);
    	}
    
    	work_init();
    	
    // #if defined(CONFIG_BSD_LIBRARY)
    	// modem_configure();
    
    	// err = modem_info_init();
    	// if (err) {
    		// printk("Failed initializing modem info module, error: %d\n",
    			// err);
    	// }
    
    	// k_sem_take(&lte_connected, K_FOREVER);
    // #endif
    
    
    	date_time_update_async(date_time_event_handler);
    
    	err = k_sem_take(&date_time_obtained, K_SECONDS(DATE_TIME_TIMEOUT_S));
    	if (err) {
    		printk("Date time, no callback event within %d seconds\n",
    			DATE_TIME_TIMEOUT_S);
    	}
    
    	k_delayed_work_submit(&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("Starting GPS application\n");
    
    	if (init_app() != 0) {
    		return -1;
    	}
    	
    #if defined(CONFIG_BSD_LIBRARY)
    	modem_configure();
    
    	err = modem_info_init();
    	if (err) {
    		printk("Failed initializing modem info module, error: %d\n",
    			err);
    	}
    
    	k_sem_take(&lte_connected, K_FOREVER);
    #endif
    	
    	
    #ifdef CONFIG_SUPL_CLIENT_LIB
    	int rc = supl_init(&supl_api);
    
    	if (rc != 0) {
    		return rc;
    	}
    #endif
    
    	aws_iot1();
    
    	printk("Getting GPS data...\n");
    
    	while (1) {
    
    		do {
    			/* Loop until we don't have more
    			 * data to read
    			 */
    		} while (process_gps_data(&gps_data) > 0);
    
    		if (IS_ENABLED(CONFIG_GPS_SAMPLE_NMEA_ONLY)) {
    			print_nmea_data();
    			nmea_string_cnt = 0;
    		} else {
    			printk("\033[1;1H");
    			printk("\033[2J");
    			print_satellite_stats(&last_pvt);
    			print_gnss_stats(&last_pvt);
    			printk("---------------------------------\n");
    
    			if (!got_fix) {
    				printk("Seconds since last fix: %lld\n",
    				       (k_uptime_get() - fix_timestamp) / 1000);
    				cnt++;
    				printk("Searching [%c]\n",
    				       update_indicator[cnt%4]);
    			} else {
    				print_fix_data(&last_pvt);
    				
    			}
    
    			printk("\nNMEA strings:\n\n");
    			print_nmea_data();
    			printk("---------------------------------");
    			
    			
    		}
    
    		k_sleep(K_MSEC(500));
    	}
    
    	return 0;
    }

    #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="00011111"
    #CONFIG_LTE_PSM_REQ_RAT="00000010"
    #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="nrf-352656101080789"
    CONFIG_AWS_IOT_BROKER_HOST_NAME="a6i4ulevbqzm-ats.iot.us-east-2.amazonaws.com"
    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

    2021-01-07T09:34:57.690Z DEBUG modem << *** Booting Zephyr OS build v2.4.0-ncs1-1710-g5a7b4eb71047  ***
    2021-01-07T09:34:57.727Z DEBUG modem << Flash regionsDomainPermissions
    2021-01-07T09:34:57.732Z DEBUG modem << 00 02 0x00000 0x18000 Securerwxl
    2021-01-07T09:34:57.736Z DEBUG modem << 03 31 0x18000 0x100000 Non-Securerwxl
    2021-01-07T09:34:57.741Z DEBUG modem << Non-secure callable region 0 placed in flash region 2 with size 32.
    2021-01-07T09:34:57.984Z DEBUG modem << SRAM regionDomainPermissions
    2021-01-07T09:34:58.017Z DEBUG modem << 00 07 0x00000 0x10000 Securerwxl
    2021-01-07T09:34:58.024Z DEBUG modem << 08 31 0x10000 0x40000 Non-Securerwxl
    2021-01-07T09:34:58.031Z DEBUG modem << PeripheralDomainStatus
    2021-01-07T09:34:58.038Z DEBUG modem << 00 NRF_P0               Non-SecureOK
    2021-01-07T09:34:58.044Z DEBUG modem << 01 NRF_CLOCK            Non-SecureOK
    2021-01-07T09:34:58.049Z DEBUG modem << 02 NRF_RTC0             Non-SecureOK
    2021-01-07T09:34:58.053Z DEBUG modem << 03 NRF_RTC1             Non-SecureOK
    2021-01-07T09:34:58.059Z DEBUG modem << 04 NRF_NVMC             Non-SecureOK
    2021-01-07T09:34:58.064Z DEBUG modem << 05 NRF_UARTE1           Non-SecureOK
    2021-01-07T09:34:58.071Z DEBUG modem << 06 NRF_UARTE2           SecureSKIP
    2021-01-07T09:34:58.079Z DEBUG modem << 07 NRF_TWIM2            Non-SecureOK
    2021-01-07T09:34:58.091Z DEBUG modem << 08 NRF_SPIM3            Non-SecureOK
    2021-01-07T09:34:58.096Z DEBUG modem << 09 NRF_TIMER0           Non-SecureOK
    2021-01-07T09:34:58.102Z DEBUG modem << 10 NRF_TIMER1           Non-SecureOK
    2021-01-07T09:34:58.107Z DEBUG modem << 11 NRF_TIMER2           Non-SecureOK
    2021-01-07T09:34:58.118Z DEBUG modem << 12 NRF_SAADC            Non-SecureOK
    2021-01-07T09:34:58.126Z DEBUG modem << 13 NRF_PWM0             Non-SecureOK
    2021-01-07T09:34:58.139Z DEBUG modem << 14 NRF_PWM1             Non-SecureOK
    2021-01-07T09:34:58.141Z DEBUG modem << 15 NRF_PWM2             Non-SecureOK
    2021-01-07T09:34:58.142Z DEBUG modem << 16 NRF_PWM3             Non-SecureOK
    2021-01-07T09:34:58.143Z DEBUG modem << 17 NRF_WDT              Non-SecureOK
    2021-01-07T09:34:58.145Z DEBUG modem << 18 NRF_IPC              Non-SecureOK
    2021-01-07T09:34:58.146Z DEBUG modem << 19 NRF_VMC              Non-SecureOK
    2021-01-07T09:34:58.148Z DEBUG modem << 20 NRF_FPU              Non-SecureOK
    2021-01-07T09:34:58.149Z DEBUG modem << 21 NRF_EGU1             Non-SecureOK
    2021-01-07T09:34:58.150Z DEBUG modem << 22 NRF_EGU2             Non-SecureOK
    2021-01-07T09:34:58.152Z DEBUG modem << 23 NRF_DPPIC            Non-SecureOK
    2021-01-07T09:34:58.155Z DEBUG modem << 24 NRF_GPIOTE1          Non-SecureOK
    2021-01-07T09:34:58.156Z DEBUG modem << 25 NRF_REGULATORS       Non-SecureOK
    2021-01-07T09:34:58.161Z DEBUG modem << SPM: NS image at 0x18200
    2021-01-07T09:34:58.162Z DEBUG modem << SPM: NS MSP at 0x2002a4a0
    2021-01-07T09:34:58.164Z DEBUG modem << SPM: NS reset vector at 0x1e6e9
    2021-01-07T09:34:58.165Z DEBUG modem << SPM: prepare to jump to Non-Secure image.
    2021-01-07T09:34:58.196Z DEBUG modem << *** Booting Zephyr OS build v2.4.0-ncs1-1710-g5a7b4eb71047  ***
    2021-01-07T09:34:58.217Z DEBUG modem << Starting GPS application
    2021-01-07T09:34:58.234Z DEBUG modem << GPS Socket created
    2021-01-07T09:34:58.268Z DEBUG modem << E: Could not send AT command, error: -8
    2021-01-07T09:34:58.271Z DEBUG modem << Modem could not be configured, error: -8
    
    #
    # Copyright (c) 2020 Nordic Semiconductor ASA
    #
    # SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
    #
    
    menu "GPS sample"
    
    config APP_VERSION
    	string "Application version"
    	default "v1.0.0"
    
    config PUBLICATION_INTERVAL_SECONDS
    	int "Interval in seconds that the sample will publish data"
    	default 60
    
    config CONNECTION_RETRY_TIMEOUT_SECONDS
    	int "Number of seconds between each AWS IoT connection retry"
    	default 20
    
    config GPS_SAMPLE_NMEA_ONLY
    	bool "Output only NMEA strings"
    	help
    	  Outputs only NMEA strings from the GPS.
    
    choice GPS_SAMPLE_ANTENNA
    	default GPS_SAMPLE_ANTENNA_ONBOARD
    	prompt "Select which antenna to use for GPS"
    
    config GPS_SAMPLE_ANTENNA_ONBOARD
    	bool "Use onboard antenna"
    
    config GPS_SAMPLE_ANTENNA_EXTERNAL
    	bool "Use external antenna"
    
    endchoice
    
    endmenu
    
    menu "Zephyr Kernel"
    source "Kconfig.zephyr"
    endmenu
    

    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

    #
    # 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
    )
    

    At this point i was tried from last 3 days and stuck at this point, all this error are releted to modem configuration.

    Thanks again.

  • Looking at your output. You are aware that GPS and LTE do not work at the same time?

    2021-01-07T09:34:58.217Z DEBUG modem << Starting GPS application
    2021-01-07T09:34:58.234Z DEBUG modem << GPS Socket created
    2021-01-07T09:34:58.268Z DEBUG modem << E: Could not send AT command, error: -8
    2021-01-07T09:34:58.271Z DEBUG modem << Modem could not be configured, error: -8

    From the GPS Receiver chapter
    "The GPS receiver supports GPS L1 C/A reception. Operation is time multiplexed with LTE modem, and it is possible to obtain the GPS position either while the LTE is in RRC Idle mode or power saving mode (PSM), or when the LTE modem is completely deactivated."

    Kind regards,
    Øyvind

  • Thanks Oyvind,

    OK I read this so,Now can you pleas suggest me how can get and send GPS data to AWS server continuously.

    Regrads

    Jaydip

  • 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  deactivate GPS and exit RRC Idle mode or PSM, or activate the modem, in order to send data. Make sure that you wait for +CSCON: 1 indicating that you are connected. 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.

Related