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

GPS and accelerometer data to own AWS server

Hi,

I am a little confused between GPS and AGPS sample code provided by nordic. can you help me to understand it?

I just want to send GPS and accelerometer data of thingy91 to my own AWS IOT server. which one would be the easiest way to use to satisfy requirements.

Parents
  • Hello,

     

    which one would be the easiest way to use to satisfy requirements.

     The easiest solution would be to just use regular GPS, if you don't care about performance. A-GPS is used for performance reasons, not necessarily because it is easy to use. A-GPS requires additional data to be downloaded from a server before the GPS can be used.

Reply
  • Hello,

     

    which one would be the easiest way to use to satisfy requirements.

     The easiest solution would be to just use regular GPS, if you don't care about performance. A-GPS is used for performance reasons, not necessarily because it is easy to use. A-GPS requires additional data to be downloaded from a server before the GPS can be used.

Children
  • Hi,

    I understood.

    SO I tried to merge the AWS_IOT sample and GPS code. In both the code they have initialized the modem. Shown below:

    From GPS sample

    	if (init_app() != 0) {
    		return -1;
    	}

    From AWS_IOT sample

    #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

    While I am calling both in the main function getting a "failed to initialize modem" error.

     

    Can you help me out to solve the above error

    With regards,
    Rahul Kidecha
  • Do you have CONFIG_LTE_AUTO_INIT_AND_CONNECT enabled in prj.conf? It looks like the modem initializes automatically.

  • Do you have CONFIG_LTE_AUTO_INIT_AND_CONNECT enabled in prj.conf? It looks like the modem initializes automatically.

    No. It is disabled. If you want can share prj and main.c file

  • Hi Hakon,

    Thank you for your reply.

    I want to send the GPS data to my AWS_IOT server. I made changes in the AWS_IOT code and got connected to the server successfully. Then run GPS code both are working fine when run individually.

    As I want to send the GPS data tried to merge the code. As per my understanding, both have different modem configuration settings which not allowed to work properly.

    I have tried to arrange the modem configuration function in a different position. Sometimes AWS_IOT works fine but GPS not and vice-versa.

    If you help to configure the modem will solve the whole problem. It is kind of difficult to play with LTE and GPS as both works concurrently. 

    #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
    
    # 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="*************"
    CONFIG_AWS_IOT_BROKER_HOST_NAME="*************"
    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

    /*
     * 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;
    	
    #if defined(CONFIG_BSD_LIBRARY)
    
    	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("Modem could not be configured, error: %d\n",
    				err);
    			return;
    		}
    	}
    		err = modem_info_init();
    	if (err) {
    		printk("Failed initializing modem info module, error: %d\n",
    			err);
    	}
    	k_sem_take(&lte_connected, K_FOREVER);
    #endif	
    }
    
    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);
    }
    
    // int main(void)
    // {
    	// 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("Starting GPS application\n");
    
    	// if (init_app() != 0) {
    		// return -1;
    	// }
    
    // #ifdef CONFIG_SUPL_CLIENT_LIB
    	// int rc = supl_init(&supl_api);
    
    	// if (rc != 0) {
    		// return rc;
    	// }
    // #endif
    
    	// 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;
    // }
    
    
    int main(void)
    {
    	nrf_gnss_data_frame_t gps_data;
    	uint8_t		      cnt = 0;
    	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
    	
    #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
    
    	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();
    		
    	printk("Starting GPS application\n");
    	
    	modem_configure();
    		
    	if (init_app() != 0) {
    		//return -1;
    		printk("error in init app\n");
    	}
    
    	
    #ifdef CONFIG_SUPL_CLIENT_LIB
    	int rc = supl_init(&supl_api);
    
    	if (rc != 0) {
    		return rc;
    	}
    #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);
    	
    	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;
    }
    

    2021-01-07T10:28:09.398Z INFO Application data folder: C:\Users\rahul\AppData\Roaming\nrfconnect\pc-nrfconnect-linkmonitor
    2021-01-07T10:28:09.421Z DEBUG App pc-nrfconnect-linkmonitor v1.1.10 official
    2021-01-07T10:28:09.421Z DEBUG App path: C:\Users\rahul\.nrfconnect-apps\node_modules\pc-nrfconnect-linkmonitor
    2021-01-07T10:28:09.421Z DEBUG nRFConnect 3.6.1 is supported by the app (^3.6.0)
    2021-01-07T10:28:09.421Z DEBUG nRFConnect path: C:\Users\rahul\AppData\Local\Programs\nrfconnect\resources\app.asar
    2021-01-07T10:28:09.421Z DEBUG HomeDir: C:\Users\rahul
    2021-01-07T10:28:09.421Z DEBUG TmpDir: C:\Users\rahul\AppData\Local\Temp
    2021-01-07T10:28:12.670Z INFO Modem port is opened
    2021-01-07T10:28:12.676Z DEBUG modem >> AT+CFUN?
    2021-01-07T10:28:12.873Z DEBUG modem << *** Booting Zephyr OS build v2.4.0-ncs1-1710-g5a7b4eb71047  ***
    2021-01-07T10:28:12.887Z DEBUG modem << 
    2021-01-07T10:28:12.889Z DEBUG modem << I: UART check failed: 1. Dropping buffer and retrying.
    2021-01-07T10:28:12.918Z DEBUG modem << The AWS IoT sample started, version: v1.0.0
    2021-01-07T10:28:12.920Z DEBUG modem << W: Already initialized. Nothing to do
    2021-01-07T10:28:12.921Z DEBUG modem << Starting GPS application
    2021-01-07T10:28:14.542Z DEBUG modem << +CEREG: 2,"8402","02055C03",7,0,0,"11100000","11100000"
    2021-01-07T10:28:14.546Z DEBUG modem << LTE cell changed: Cell ID: 33905667, Tracking area: 33794
    2021-01-07T10:28:14.547Z DEBUG modem << PSM parameter update: TAU: -1, Active time: -1
    2021-01-07T10:28:14.695Z DEBUG modem << +CSCON: 1
    2021-01-07T10:28:14.698Z DEBUG modem << RRC mode: Connected
    2021-01-07T10:28:15.837Z DEBUG modem << +CEREG: 5,"8402","02055C03",7,,,"11100000","11100000"
    2021-01-07T10:28:15.841Z DEBUG modem << Network registration status: Connected - roaming
    2021-01-07T10:28:15.843Z DEBUG modem << Failed to initialize modem
    2021-01-07T10:28:15.844Z DEBUG modem << error in init app
    2021-01-07T10:28:16.720Z DEBUG modem << DATE_TIME_OBTAINED_NTP
    2021-01-07T10:28:16.721Z DEBUG modem << Next connection retry in 20 seconds
    2021-01-07T10:28:16.725Z DEBUG modem << Getting GPS data...
    2021-01-07T10:28:16.727Z DEBUG modem << [1;1H[2JTracking: 0 Using: 0 Unhealthy: 0
    2021-01-07T10:28:16.728Z DEBUG modem << ---------------------------------
    2021-01-07T10:28:16.729Z DEBUG modem << Seconds since last fix: 4
    2021-01-07T10:28:16.729Z DEBUG modem << Searching [|]
    2021-01-07T10:28:16.731Z DEBUG modem << NMEA strings:
    2021-01-07T10:28:16.732Z DEBUG modem << ---------------------------------AWS_IOT_EVT_CONNECTING
    2021-01-07T10:28:17.233Z DEBUG modem << [1;1H[2JTracking: 0 Using: 0 Unhealthy: 0
    2021-01-07T10:28:17.237Z DEBUG modem << ---------------------------------
    2021-01-07T10:28:17.238Z DEBUG modem << Seconds since last fix: 4
    2021-01-07T10:28:17.239Z DEBUG modem << Searching [/]
    2021-01-07T10:28:17.240Z DEBUG modem << NMEA strings:
    2021-01-07T10:28:17.748Z DEBUG modem << ---------------------------------[1;1H[2JTracking: 0 Using: 0 Unhealthy: 0
    2021-01-07T10:28:17.750Z DEBUG modem << ---------------------------------
    2021-01-07T10:28:17.751Z DEBUG modem << Seconds since last fix: 5
    2021-01-07T10:28:17.752Z DEBUG modem << Searching [-]
    2021-01-07T10:28:17.753Z DEBUG modem << NMEA strings:
    2021-01-07T10:28:18.263Z DEBUG modem << ---------------------------------[1;1H[2JTracking: 0 Using: 0 Unhealthy: 0
    2021-01-07T10:28:18.265Z DEBUG modem << ---------------------------------
    2021-01-07T10:28:18.268Z DEBUG modem << Seconds since last fix: 5
    2021-01-07T10:28:18.269Z DEBUG modem << Searching [\]
    2021-01-07T10:28:18.270Z DEBUG modem << NMEA strings:
    2021-01-07T10:28:18.777Z DEBUG modem << ---------------------------------[1;1H[2JTracking: 0 Using: 0 Unhealthy: 0
    2021-01-07T10:28:18.779Z DEBUG modem << ---------------------------------
    2021-01-07T10:28:18.780Z DEBUG modem << Seconds since last fix: 6
    2021-01-07T10:28:18.781Z DEBUG modem << Searching [|]
    2021-01-07T10:28:18.782Z DEBUG modem << NMEA strings:
    2021-01-07T10:28:19.293Z DEBUG modem << ---------------------------------[1;1H[2JTracking: 0 Using: 0 Unhealthy: 0
    2021-01-07T10:28:19.298Z DEBUG modem << ---------------------------------
    2021-01-07T10:28:19.299Z DEBUG modem << Seconds since last fix: 6
    2021-01-07T10:28:19.300Z DEBUG modem << Searching [/]
    2021-01-07T10:28:19.301Z DEBUG modem << NMEA strings:
    2021-01-07T10:28:19.808Z DEBUG modem << ---------------------------------[1;1H[2JTracking: 0 Using: 0 Unhealthy: 0
    2021-01-07T10:28:19.814Z DEBUG modem << ---------------------------------
    2021-01-07T10:28:19.815Z DEBUG modem << Seconds since last fix: 7
    2021-01-07T10:28:19.816Z DEBUG modem << Searching [-]
    2021-01-07T10:28:19.817Z DEBUG modem << NMEA strings:
    2021-01-07T10:28:20.319Z DEBUG modem << ---------------------------------[1;1H[2JTracking: 0 Using: 0 Unhealthy: 0
    2021-01-07T10:28:20.320Z DEBUG modem << ---------------------------------
    2021-01-07T10:28:20.321Z DEBUG modem << Seconds since last fix: 7
    2021-01-07T10:28:20.321Z DEBUG modem << Searching [\]
    2021-01-07T10:28:20.322Z DEBUG modem << NMEA strings:
    2021-01-07T10:28:20.837Z DEBUG modem << ---------------------------------[1;1H[2JTracking: 0 Using: 0 Unhealthy: 0
    2021-01-07T10:28:20.842Z DEBUG modem << ---------------------------------
    2021-01-07T10:28:20.843Z DEBUG modem << Seconds since last fix: 8
    2021-01-07T10:28:20.843Z DEBUG modem << Searching [|]
    2021-01-07T10:28:20.844Z DEBUG modem << NMEA strings:
    2021-01-07T10:28:21.353Z DEBUG modem << ---------------------------------[1;1H[2JTracking: 0 Using: 0 Unhealthy: 0
    2021-01-07T10:28:21.357Z DEBUG modem << ---------------------------------
    2021-01-07T10:28:21.358Z DEBUG modem << Seconds since last fix: 8
    2021-01-07T10:28:21.358Z DEBUG modem << Searching [/]
    2021-01-07T10:28:21.359Z DEBUG modem << NMEA strings:
    2021-01-07T10:28:21.868Z DEBUG modem << ---------------------------------[1;1H[2JTracking: 0 Using: 0 Unhealthy: 0
    2021-01-07T10:28:21.869Z DEBUG modem << ---------------------------------
    2021-01-07T10:28:21.870Z DEBUG modem << Seconds since last fix: 9
    2021-01-07T10:28:21.871Z DEBUG modem << Searching [-]
    2021-01-07T10:28:21.871Z DEBUG modem << NMEA strings:
    2021-01-07T10:28:22.382Z DEBUG modem << ---------------------------------[1;1H[2JTracking: 0 Using: 0 Unhealthy: 0
    2021-01-07T10:28:22.388Z DEBUG modem << ---------------------------------
    2021-01-07T10:28:22.389Z DEBUG modem << Seconds since last fix: 9
    2021-01-07T10:28:22.390Z DEBUG modem << Searching [\]
    2021-01-07T10:28:22.391Z DEBUG modem << NMEA strings:
    2021-01-07T10:28:22.898Z DEBUG modem << ---------------------------------[1;1H[2JTracking: 0 Using: 0 Unhealthy: 0
    2021-01-07T10:28:22.915Z DEBUG modem << ---------------------------------
    2021-01-07T10:28:22.918Z DEBUG modem << Seconds since last fix: 10
    2021-01-07T10:28:22.921Z DEBUG modem << Searching [|]
    2021-01-07T10:28:22.925Z DEBUG modem << NMEA strings:
    2021-01-07T10:28:23.412Z DEBUG modem << ---------------------------------[1;1H[2JTracking: 0 Using: 0 Unhealthy: 0
    2021-01-07T10:28:23.418Z DEBUG modem << ---------------------------------
    2021-01-07T10:28:23.419Z DEBUG modem << Seconds since last fix: 10
    2021-01-07T10:28:23.420Z DEBUG modem << Searching [/]
    2021-01-07T10:28:23.421Z DEBUG modem << NMEA strings:
    2021-01-07T10:28:23.929Z DEBUG modem << ---------------------------------[1;1H[2JTracking: 0 Using: 0 Unhealthy: 0
    2021-01-07T10:28:23.940Z DEBUG modem << ---------------------------------
    2021-01-07T10:28:23.941Z DEBUG modem << Seconds since last fix: 11
    2021-01-07T10:28:23.941Z DEBUG modem << Searching [-]
    2021-01-07T10:28:23.942Z DEBUG modem << NMEA strings:
    2021-01-07T10:28:24.443Z DEBUG modem << ---------------------------------[1;1H[2JTracking: 0 Using: 0 Unhealthy: 0
    2021-01-07T10:28:24.454Z DEBUG modem << ---------------------------------
    2021-01-07T10:28:24.455Z DEBUG modem << Seconds since last fix: 11
    2021-01-07T10:28:24.456Z DEBUG modem << Searching [\]
    2021-01-07T10:28:24.457Z DEBUG modem << NMEA strings:
    2021-01-07T10:28:24.959Z DEBUG modem << ---------------------------------[1;1H[2JTracking: 0 Using: 0 Unhealthy: 0
    2021-01-07T10:28:24.970Z DEBUG modem << ---------------------------------
    2021-01-07T10:28:24.971Z DEBUG modem << Seconds since last fix: 12
    2021-01-07T10:28:24.972Z DEBUG modem << Searching [|]
    2021-01-07T10:28:24.973Z DEBUG modem << NMEA strings:
    2021-01-07T10:28:25.239Z DEBUG modem << ---------------------------------AWS_IOT_EVT_CONNECTED
    2021-01-07T10:28:25.242Z DEBUG modem << Persistent session enabled
    2021-01-07T10:28:25.253Z DEBUG modem << Publishing: {
    2021-01-07T10:28:25.255Z DEBUG modem << "state":{
    2021-01-07T10:28:25.257Z DEBUG modem << "reported":{
    2021-01-07T10:28:25.265Z DEBUG modem << "app_version":"v1.0.0",
    2021-01-07T10:28:25.267Z DEBUG modem << "batv":4406,
    2021-01-07T10:28:25.268Z DEBUG modem << "ts":1610015304543
    2021-01-07T10:28:25.269Z DEBUG modem << }
    2021-01-07T10:28:25.270Z DEBUG modem << }
    2021-01-07T10:28:25.271Z DEBUG modem << } to AWS IoT broker
    2021-01-07T10:28:25.272Z DEBUG modem << AWS_IOT_EVT_READY
    2021-01-07T10:28:25.473Z DEBUG modem << [1;1H[2JTracking: 0 Using: 0 Unhealthy: 0
    2021-01-07T10:28:25.478Z DEBUG modem << ---------------------------------
    2021-01-07T10:28:25.479Z DEBUG modem << Seconds since last fix: 12
    2021-01-07T10:28:25.480Z DEBUG modem << Searching [/]
    2021-01-07T10:28:25.483Z DEBUG modem << NMEA strings:
    2021-01-07T10:28:25.722Z DEBUG modem << ---------------------------------AWS_IOT_EVT_DATA_RECEIVED
    2021-01-07T10:28:25.740Z DEBUG modem << Data received from AWS IoT console:
    2021-01-07T10:28:25.741Z DEBUG modem << Topic: $aws/things/nrf-352656101080789/shadow/update
    2021-01-07T10:28:25.746Z DEBUG modem << Message: {
    2021-01-07T10:28:25.747Z DEBUG modem << "state":{
    2021-01-07T10:28:25.747Z DEBUG modem << "reported":{
    2021-01-07T10:28:25.748Z DEBUG modem << "app_version":"v1.0.0",
    2021-01-07T10:28:25.748Z DEBUG modem << "batv":4406,
    2021-01-07T10:28:25.749Z DEBUG modem << "ts":1610015304543
    2021-01-07T10:28:25.749Z DEBUG modem << }
    2021-01-07T10:28:25.750Z DEBUG modem << }
    2021-01-07T10:28:25.750Z DEBUG modem << }
    2021-01-07T10:28:25.871Z DEBUG modem << AWS_IOT_EVT_DATA_RECEIVED
    2021-01-07T10:28:25.944Z DEBUG modem << Data received from AWS IoT console:
    2021-01-07T10:28:25.946Z DEBUG modem << Topic: $aws/things/nrf-352656101080789/shadow/get/accepted
    2021-01-07T10:28:25.947Z DEBUG modem << Message: {
    2021-01-07T10:28:25.947Z DEBUG modem << "state":{
    2021-01-07T10:28:25.948Z DEBUG modem << "desired":{
    2021-01-07T10:28:25.948Z DEBUG modem << "welcome":"Vikas"
    2021-01-07T10:28:25.949Z DEBUG modem << },
    2021-01-07T10:28:25.949Z DEBUG modem << "reported":{
    2021-01-07T10:28:25.949Z DEBUG modem << "welcome":"Dark Horse",
    2021-01-07T10:28:25.950Z DEBUG modem << "app_version":"v1.0.0",
    2021-01-07T10:28:25.951Z DEBUG modem << "batv":4406,
    2021-01-07T10:28:25.951Z DEBUG modem << "ts":943920003687
    2021-01-07T10:28:25.952Z DEBUG modem << },
    2021-01-07T10:28:25.952Z DEBUG modem << "delta":{
    2021-01-07T10:28:25.952Z DEBUG modem << "welcome":"Vikas"
    2021-01-07T10:28:25.953Z DEBUG modem << }
    2021-01-07T10:28:25.953Z DEBUG modem << },
    2021-01-07T10:28:25.954Z DEBUG modem << "metadata":{
    2021-01-07T10:28:25.961Z DEBUG modem << "desired":{
    2021-01-07T10:28:25.962Z DEBUG modem << "welcome":{
    2021-01-07T10:28:25.962Z DEBUG modem << "timestamp":1608869909
    2021-01-07T10:28:25.963Z DEBUG modem << }
    2021-01-07T10:28:25.963Z DEBUG modem << },
    2021-01-07T10:28:25.964Z DEBUG modem << "reported":{
    2021-01-07T10:28:25.964Z DEBUG modem << "welcome":{
    2021-01-07T10:28:25.964Z DEBUG modem << "timestamp":1608869909
    2021-01-07T10:28:25.965Z DEBUG modem << },
    2021-01-07T10:28:25.965Z DEBUG modem << "app_version":{
    2021-01-07T10:28:25.966Z DEBUG modem << "timestamp":1610013963
    2021-01-07T10:28:25.966Z DEBUG modem << },
    2021-01-07T10:28:25.966Z DEBUG modem << "batv":{
    2021-01-07T10:28:25.967Z DEBUG modem << "timestamp":1610013963
    2021-01-07T10:28:25.967Z DEBUG modem << },
    2021-01-07T10:28:25.968Z DEBUG modem << "ts":{
    2021-01-07T10:28:25.968Z DEBUG modem << "timestamp":1610013963
    2021-01-07T10:28:25.969Z DEBUG modem << }
    2021-01-07T10:28:25.969Z DEBUG modem << }
    2021-01-07T10:28:25.970Z DEBUG modem << },
    2021-01-07T10:28:25.971Z DEBUG modem << "version":3203,
    2021-01-07T10:28:25.971Z DEBUG modem << "timestamp":1610015305
    2021-01-07T10:28:25.972Z DEBUG modem << }
    2021-01-07T10:28:25.973Z DEBUG modem << AWS_IOT_EVT_DATA_RECEIVED
    2021-01-07T10:28:25.993Z DEBUG modem << Data received from AWS IoT console:
    2021-01-07T10:28:25.994Z DEBUG modem << Topic: $aws/things/nrf-352656101080789/shadow/update/delta
    2021-01-07T10:28:25.995Z DEBUG modem << Message: {
    2021-01-07T10:28:25.996Z DEBUG modem << "version":3204,
    2021-01-07T10:28:25.997Z DEBUG modem << "timestamp":1610015305,
    2021-01-07T10:28:25.998Z DEBUG modem << "state":{
    2021-01-07T10:28:25.999Z DEBUG modem << "welcome":"Vikas"
    2021-01-07T10:28:25.999Z DEBUG modem << },
    2021-01-07T10:28:25.999Z DEBUG modem << "metadata":{
    2021-01-07T10:28:26.006Z DEBUG modem << "w[1;1H[2JTracking: 0 Using: 0 Unhealthy: 0---------------------------------Seconds since last fix: 13Searching [-]NMEA strings:---------------------------------elcome":{
    2021-01-07T10:28:26.007Z DEBUG modem << "timestamp":1608869909
    2021-01-07T10:28:26.008Z DEBUG modem << }
    2021-01-07T10:28:26.008Z DEBUG modem << }
    2021-01-07T10:28:26.009Z DEBUG modem << }
    2021-01-07T10:28:26.504Z DEBUG modem << [1;1H[2JTracking: 0 Using: 0 Unhealthy: 0
    2021-01-07T10:28:26.517Z DEBUG modem << ---------------------------------
    2021-01-07T10:28:26.518Z DEBUG modem << Seconds since last fix: 13
    2021-01-07T10:28:26.518Z DEBUG modem << Searching [\]
    2021-01-07T10:28:26.519Z DEBUG modem << NMEA strings:
    2021-01-07T10:28:27.017Z DEBUG modem << ---------------------------------[1;1H[2JTracking: 0 Using: 0 Unhealthy: 0
    2021-01-07T10:28:27.019Z DEBUG modem << ---------------------------------
    2021-01-07T10:28:27.020Z DEBUG modem << Seconds since last fix: 14
    2021-01-07T10:28:27.020Z DEBUG modem << Searching [|]
    2021-01-07T10:28:27.020Z DEBUG modem << NMEA strings:
    2021-01-07T10:28:27.533Z DEBUG modem << ---------------------------------[1;1H[2JTracking: 0 Using: 0 Unhealthy: 0
    2021-01-07T10:28:27.551Z DEBUG modem << ---------------------------------
    2021-01-07T10:28:27.553Z DEBUG modem << Seconds since last fix: 14
    2021-01-07T10:28:27.554Z DEBUG modem << Searching [/]
    2021-01-07T10:28:27.556Z DEBUG modem << NMEA strings:
    2021-01-07T10:28:28.037Z DEBUG modem << ---------------------------------[1;1H[2JTracking: 0 Using: 0 Unhealthy: 0
    2021-01-07T10:28:28.048Z DEBUG modem << ---------------------------------
    2021-01-07T10:28:28.049Z DEBUG modem << Seconds since last fix: 15
    2021-01-07T10:28:28.049Z DEBUG modem << Searching [-]
    2021-01-07T10:28:28.054Z DEBUG modem << NMEA strings:
    

    Enclosing the prj, main, and Log files.

    If you see the Log file the way I initialized the modem only allowing to run AWS_IOT properly.

  • Rkidechaa said:
    both are working fine when run individually.

     For GPS and LTE to run concurrently, you need to enable PSM. As far as I can tell, from the CEREG return value PSM is not enabled. What SIM/operator are you using. What location do you try to connect from?

Related