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

Parents
  • Hello, 

    I'm sorry, but were you able to solve last issue from the support case you linked to? (Case #261504) Are you getting the same error as that case? Please provide the output from when you are connecting to the cloud solution. 

    Thank you. 

    kind regards,
    Øyvind

  • HI Oyvind

    Thanks you for your reply

    you able to solve last issue from the support case you linked to?

    I am Using AWS_IOT sample code Yes I am able to connect AWS server and received data on Link monitor like this 

    2020-12-25T04:05:22.610Z DEBUG modem << Next connection retry in 30 seconds
    2020-12-25T04:05:22.614Z DEBUG modem << AWS_IOT_EVT_CONNECTING
    2020-12-25T04:05:22.755Z DEBUG modem << RRC mode: Connected
    2020-12-25T04:05:26.959Z DEBUG modem << AWS_IOT_EVT_CONNECTED
    2020-12-25T04:05:27.091Z DEBUG modem << Publishing: {
    2020-12-25T04:05:27.094Z DEBUG modem << "state":{
    2020-12-25T04:05:27.095Z DEBUG modem << "reported":{
    2020-12-25T04:05:27.195Z DEBUG modem << "app_version":"v1.0.0",
    2020-12-25T04:05:27.198Z DEBUG modem << "batv":4410,
    2020-12-25T04:05:27.199Z DEBUG modem << "ts":943920514411
    2020-12-25T04:05:27.201Z DEBUG modem << }
    2020-12-25T04:05:27.202Z DEBUG modem << }
    2020-12-25T04:05:27.203Z DEBUG modem << } to AWS IoT broker
    2020-12-25T04:05:27.547Z DEBUG modem << AWS_IOT_EVT_READY
    2020-12-25T04:05:27.957Z DEBUG modem << AWS_IOT_EVT_DATA_RECEIVED
    2020-12-25T04:05:28.091Z DEBUG modem << Data received from AWS IoT console:
    2020-12-25T04:05:28.094Z DEBUG modem << Topic: $aws/things/nrf-352656101080789/shadow/get/accepted
    2020-12-25T04:05:28.096Z DEBUG modem << Message: {
    2020-12-25T04:05:28.098Z DEBUG modem << "state":{
    2020-12-25T04:05:28.101Z DEBUG modem << "desired":{
    2020-12-25T04:05:28.103Z DEBUG modem << "welcome":"aws-iot"
    2020-12-25T04:05:28.105Z DEBUG modem << },
    2020-12-25T04:05:28.107Z DEBUG modem << "reported":{
    2020-12-25T04:05:28.109Z DEBUG modem << "welcome":"aws-iot",
    2020-12-25T04:05:28.112Z DEBUG modem << "app_version":"v1.0.0",
    2020-12-25T04:05:28.115Z DEBUG modem << "batv":4410,
    2020-12-25T04:05:28.117Z DEBUG modem << "ts":943920514411
    2020-12-25T04:05:28.119Z DEBUG modem << }
    2020-12-25T04:05:28.121Z DEBUG modem << },
    2020-12-25T04:05:28.123Z DEBUG modem << "metadata":{
    2020-12-25T04:05:28.125Z DEBUG modem << "desired":{
    2020-12-25T04:05:28.127Z DEBUG modem << "welcome":{
    2020-12-25T04:05:28.129Z DEBUG modem << "timestamp":1608782408
    2020-12-25T04:05:28.131Z DEBUG modem << }
    2020-12-25T04:05:28.133Z DEBUG modem << },
    2020-12-25T04:05:28.135Z DEBUG modem << "reported":{
    2020-12-25T04:05:28.137Z DEBUG modem << "welcome":{
    2020-12-25T04:05:28.139Z DEBUG modem << "timestamp":1608782408
    2020-12-25T04:05:28.142Z DEBUG modem << },
    2020-12-25T04:05:28.144Z DEBUG modem << "app_version":{
    2020-12-25T04:05:28.146Z DEBUG modem << "timestamp":1608869128
    2020-12-25T04:05:28.148Z DEBUG modem << },
    2020-12-25T04:05:28.150Z DEBUG modem << "batv":{
    2020-12-25T04:05:28.152Z DEBUG modem << "timestamp":1608869128
    2020-12-25T04:05:28.154Z DEBUG modem << },
    2020-12-25T04:05:28.156Z DEBUG modem << "ts":{
    2020-12-25T04:05:28.158Z DEBUG modem << "timestamp":1608869128
    2020-12-25T04:05:28.161Z DEBUG modem << }
    2020-12-25T04:05:28.163Z DEBUG modem << }
    2020-12-25T04:05:28.165Z DEBUG modem << },
    2020-12-25T04:05:28.167Z DEBUG modem << "version":8,
    2020-12-25T04:05:28.169Z DEBUG modem << "timestamp":1608869128
    2020-12-25T04:05:28.171Z DEBUG modem << }
    2020-12-25T04:05:34.359Z DEBUG modem << RRC mode: Idle
    2020-12-25T04:06:06.537Z DEBUG modem << LTE cell changed: Cell ID: 33905667, Tracking area: 33794
    2020-12-25T04:06:26.977Z DEBUG modem << Publishing: {
    2020-12-25T04:06:26.982Z DEBUG modem << "state":{
    2020-12-25T04:06:26.986Z DEBUG modem << "reported":{
    2020-12-25T04:06:26.990Z DEBUG modem << "batv":4406,
    2020-12-25T04:06:27.154Z DEBUG modem << "ts":943920574411
    2020-12-25T04:06:27.158Z DEBUG modem << }
    2020-12-25T04:06:27.160Z DEBUG modem << }

    Now I want to send GPS data to my AWS server so there are 2 ways

    1) Is need to change in AGPS sample So question is where i need to changes in endpoint for AWS and certificate.

    2) Or Need to change in AWS_IOT sample who already connected to my AWS server So question is where can I put my GPS(Latitude, Longitude, Altitude) data for publish to AWS server. 

    And again Thank you for your valuable time.

    Regards
    Jaydip

  • Hello, 

    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.

    Kind regards,
    Øyvind

  • I've talked to our R&D team. It's possible to 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 proper setup found in the documentation for aws_iot.

    The A-GPS sample states:
    "The A-GPS sample demonstrates how the nRF Cloud Assisted GPS (A-GPS) feature or an external SUPL client 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 CONFIG_AGPS_SRC_SUPL configurable option. By default, nRF Cloud is used for A-GPS and cloud communication"

    In terms of using SUPL you have to change the default AGPS source by setting CONFIG_AGPS_SRC_SUPL=y. You also need to import the SUPL library into their NCS tree. Please see the SUPL documentation.

    -Øyvind

  • Hi Oyvind 

    I Tried many way to send GPS data to AWS server but not get any data.

    I follow this step

    1] Run GPS sample and AWS_IOT sample seperatly work perfect for me.

    2] Merge both code with all file (like main.c file, config file, Prj.conf file sample yml file) successfully compile and build.

    3] The only problem with modem LTE configuration.

    4] As per your suggestion I use PSM mode so get GPS data and after send data to AWS 

    in Modem_configuration getting error.

    5] Can you please tell me how to config.

    its so greatful and thankful to me

    In This code got GPS data complete and when move to AWS modem is not configure.

    This is Kconfig

    #
    # 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 LTE_POWER_SAVING_MODE
    	bool "Request Power Saving Mode (PSM) from cellular network"
    
    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
    

    This is prj.conf

    #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="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-352656101076381"
    CONFIG_AWS_IOT_BROKER_HOST_NAME="a6i4ulevbqzm-ats.iot.us-east-2.amazonaws.com"
    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

    #define AT_Normal           "AT+CFUN=4"
    #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_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_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("Connecting to LTE network. This may take minutes.");
    
    #if defined(CONFIG_LTE_POWER_SAVING_MODE)
    		err = lte_lc_psm_req(true);
    		if (err) {
    			printk("PSM request failed, error: %d", err);
    			return err;
    		}
    
    		printk("PSM mode requested");
    #endif
    
    		err = lte_lc_init_and_connect();
    		if (err) {
    			printk("LTE link could not be established, error: %d",
    				err);
    			return err;
    		}
    
    		printk("Connected to LTE network");
    	}
    
    	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("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-352656101076381/shadow/GPS";
    	static char custom_topic_2[75] = "$aws/things/nrf-352656101076381/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 nrf_modem_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;
    }
    
    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) {
    
    				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:
    			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("Starting GPS application\n");
    
    	if (init_app() != 0) {
    		//return -1;
    	}
            while (set) {
    
    		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);
    				set = false;
    			}
    
    			printk("\nNMEA strings:\n\n");
    			print_nmea_data();
    			printk("---------------------------------");
    		}
    
    		k_msleep(500);
    	}
    	
    	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);
        get_gps();
            
    }
    

    Thanks & Regards

    Jaydip

  • Hello, 


    jaydip kavaiya said:
    The only problem with modem LTE configuration.

    What is the issue with the modem configuration?

    jaydip kavaiya said:

    As per your suggestion I use PSM mode so get GPS data and after send data to AWS 

    in Modem_configuration getting error.

    Can you please provide the error code you get?

    Kind regards,
    Øyvind

      

  • HI Oyvind

    Thanks you for your Support and all valuable answer

    problem is solved, Now I get the GPS data and also send to my AWS server

    for just now I am only doing basic not use PSM mode(for PSM mode definitely need your help),

    but from use of below step I did it successfully.

    Step 1: Init_app as it is use in GPS sample code

    Step 2: Get GPS data after some time (3 min)

    Step 3: Close the GPS socket

    Step 4:  send this command

                 (i) AT+CFUN=4

                 (ii) AT%XSYSTEMMODE=1,0,0,0 

                 (iii) AT+CFUN=1"

    Step 5: Modem confgi as it is in AWS sample code

    Thanks & Regards

    Jaydip Kavaiya

Reply
  • HI Oyvind

    Thanks you for your Support and all valuable answer

    problem is solved, Now I get the GPS data and also send to my AWS server

    for just now I am only doing basic not use PSM mode(for PSM mode definitely need your help),

    but from use of below step I did it successfully.

    Step 1: Init_app as it is use in GPS sample code

    Step 2: Get GPS data after some time (3 min)

    Step 3: Close the GPS socket

    Step 4:  send this command

                 (i) AT+CFUN=4

                 (ii) AT%XSYSTEMMODE=1,0,0,0 

                 (iii) AT+CFUN=1"

    Step 5: Modem confgi as it is in AWS sample code

    Thanks & Regards

    Jaydip Kavaiya

Children
No Data
Related