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

How to turn on/off GPS while LTE is on?

I'm attempting t to turn on and off GPS function while LTE is on, but it doesn't work out. I merged mqtt_simple and gps example programs into a new project. What's wrong with the program?

In configure_gps_off_on function, buf stores "ERROR" in the line of bytes_received = recv(at_sock, buf, 2, 0),  which means that receiving data through socket does not work.

ncs version: 1.0.0

In version 1.0.0, is it possible to use LTE and GPS at the same time?

<prj.conf>
# General config
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y

# Networking
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=4

# LTE link control
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_AUTO_INIT_AND_CONNECT=n

# BSD library
CONFIG_BSD_LIBRARY=y

# AT Host
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_AT_HOST_LIBRARY=y

# MQTT
CONFIG_MQTT_LIB=y
CONFIG_MQTT_LIB_TLS=n

# Appliaction
CONFIG_MQTT_PUB_TOPIC="myPubTopic"
CONFIG_MQTT_SUB_TOPIC="mySubTopic"
CONFIG_MQTT_CLIENT_ID="myClientID"
CONFIG_MQTT_BROKER_HOSTNAME="xxxxxxxx.com"
CONFIG_MQTT_BROKER_PORT=xxxx

# Main thread
CONFIG_MAIN_THREAD_PRIORITY=7
CONFIG_MAIN_STACK_SIZE=4096

CONFIG_HEAP_MEM_POOL_SIZE=1024

# Disable native network stack to save some memory
CONFIG_NET_IPV4=n
CONFIG_NET_IPV6=n
CONFIG_NET_UDP=n
CONFIG_NET_TCP=n
CONFIG_NET_RX_STACK_SIZE=256
CONFIG_NET_TX_STACK_SIZE=256

<main.c>

/*
 * Copyright (c) 2018 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
 */

#include <zephyr.h>
#include <stdio.h>
#include <uart.h>
#include <string.h>

#include <net/mqtt.h>
#include <nrf_socket.h>
#include <net/socket.h>
#include <lte_lc.h>

#include <stdio.h>

#define MQTT_USERNAME "username"
#define MQTT_PASSWORD "password"

#define AT_XSYSTEMMODE_EN_M1_GPS "AT\%XSYSTEMMODE=1,0,1,0" // %XSYSTEMMODE=<M1_support>,<NB1_support>,<GNSS_support>,<LTE_preference>
#define AT_XSYSTEMMODE_EN_M1 "AT\%XSYSTEMMODE=1,0,0,0"
#define AT_CFUN_EN_MODEM "AT+CFUN=1"
/* Set the modem functional mode.
 * 0 – Power off
 * 1 – Normal mode
 * 4 – Offline mode
 * 44 – Offline mode without shutting down UICC */

#ifdef CONFIG_BOARD_NRF9160_PCA10090NS
#define AT_MAGPIO_EN_GPS "AT\%XMAGPIO=1,0,0,1,1,1574,1577" // %XMAGPIO=<MAGPIO0>,<MAGPIO1>,<MAGPIO2>,<The number of frequency ranges>,<state_0>,<flo_0>,<fhi_0><state_1>,<flo_1>,<fhi_1>,...
#define AT_MAGPIO_DIS  "AT\%XMAGPIO"
#endif

#define GPS_EN true
#define GPS_DIS false

static int            fd;

static char           nmea_strings[10][NRF_GNSS_NMEA_MAX_LEN];
static u32_t          nmea_string_cnt;

static bool           got_first_fix;
static bool           update_terminal;
static u64_t          fix_timestamp;
nrf_gnss_data_frame_t last_fix;

/* Buffers for MQTT client. */
static u8_t rx_buffer[CONFIG_MQTT_MESSAGE_BUFFER_SIZE];
static u8_t tx_buffer[CONFIG_MQTT_MESSAGE_BUFFER_SIZE];
static u8_t payload_buf[CONFIG_MQTT_PAYLOAD_BUFFER_SIZE];

/* The mqtt client struct */
static struct mqtt_client client;

/* MQTT Broker details. */
static struct sockaddr_storage broker;

/* Connected flag */
static bool connected;

/* File descriptor */
static struct pollfd fds;

#if defined(CONFIG_BSD_LIBRARY)

/**@brief Recoverable BSD library error. */
void bsd_recoverable_error_handler(uint32_t err)
{
	printk("bsdlib recoverable error: %u\n", err);
}

/**@brief Irrecoverable BSD library error. */
void bsd_irrecoverable_error_handler(uint32_t err)
{
	printk("bsdlib irrecoverable error: %u\n", err);

	__ASSERT_NO_MSG(false);
}

#endif /* defined(CONFIG_BSD_LIBRARY) */

/* GPS setting*/
static int configure_gps_off_on(bool status)
{
	int  at_sock;
	int  bytes_sent;
	int  bytes_received;
	char buf[2];
        char *at_commands[3];

        if(status == GPS_EN){
                at_commands[0] = AT_XSYSTEMMODE_EN_M1_GPS;
                at_commands[1] = AT_MAGPIO_EN_GPS;
        } else {
                at_commands[0] = AT_XSYSTEMMODE_EN_M1;
                at_commands[1] = AT_MAGPIO_DIS;
        }

        at_commands[2] = AT_CFUN_EN_MODEM;

        printf("at_commands[0] = %s\n", at_commands[0]);
        printf("at_commands[1] = %s\n", at_commands[1]);
        printf("at_commands[2] = %s\n", at_commands[2]);

	at_sock = socket(AF_LTE, 0, NPROTO_AT); // retunr 4
        printk("at_sock = %u\n", at_sock);
	if (at_sock < 0) {
                printk("Error1\n");
		return -1;
	}

	for (int i = 0; i < ARRAY_SIZE(at_commands); i++) {
		bytes_sent = send(at_sock, at_commands[i], strlen(at_commands[i]), 0); 
                printk("at_commands[i] = %s\n", at_commands[i]);
                printk("strlen(at_commands[i]) = %u\n", strlen(at_commands[i]));

		if (bytes_sent < 0) {
			close(at_sock);
                        printk("Error2\n");
			return -1;
		}

		do {
			bytes_received = recv(at_sock, buf, 2, 0); // this is not successful
		} while (bytes_received == 0);

                printk("buf = %s\n", buf); // "ER"

		if (memcmp(buf, "OK", 2) != 0) {
			close(at_sock);
                        printk("Error3\n"); // reach here
			return -1;
		}
	}

	close(at_sock);

	return 0;
}

static int init_gps(void)
{
	u16_t fix_retry     = 0;
	u16_t fix_interval  = 1;
	u16_t nmea_mask     = NRF_CONFIG_NMEA_GSV_MASK |
			      NRF_CONFIG_NMEA_GSA_MASK |
			      NRF_CONFIG_NMEA_GLL_MASK |
			      NRF_CONFIG_NMEA_GGA_MASK |
			      NRF_CONFIG_NMEA_RMC_MASK;
	int   retval;

	if (configure_gps_off_on(GPS_EN) != 0) {
		printk("Failed to enable GPS\n");
		return -1;
	}

	fd = nrf_socket(NRF_AF_LOCAL, NRF_SOCK_DGRAM, NRF_PROTO_GNSS);

	if (fd >= 0) {
		printk("Socket created\n");
	} else {
		printk("Could not init socket (err: %d)\n", fd);
		return -1;
	}

	retval = nrf_setsockopt(fd,
				NRF_SOL_GNSS,
				NRF_SO_GNSS_FIX_RETRY,
				&fix_retry,
				sizeof(uint16_t));

	if (retval != 0) {
		printk("Failed to set fix retry value\n");
		return -1;
	}

	retval = nrf_setsockopt(fd,
				NRF_SOL_GNSS,
				NRF_SO_GNSS_FIX_INTERVAL,
				&fix_interval,
				sizeof(uint16_t));

	if (retval != 0) {
		printk("Failed to set fix interval value\n");
		return -1;
	}

	retval = nrf_setsockopt(fd,
				NRF_SOL_GNSS,
				NRF_SO_GNSS_NMEA_MASK,
				&nmea_mask,
				sizeof(uint16_t));

	if (retval != 0) {
		printk("Failed to set nmea mask\n");
		return -1;
	}

	retval = nrf_setsockopt(fd,
				NRF_SOL_GNSS,
				NRF_SO_GNSS_START,
				NULL,
				0);

	if (retval != 0) {
		printk("Failed to start GPS\n");
		return -1;
	}

	return 0;
}

int process_gps_data(nrf_gnss_data_frame_t *gps_data)
{
	int retval;

	retval = nrf_recv(fd, gps_data, sizeof(nrf_gnss_data_frame_t), NRF_MSG_DONTWAIT);

	if (retval > 0) {

		switch (gps_data->data_id) {
		case NRF_GNSS_PVT_DATA_ID:

			if ((gps_data->pvt.flags &
				NRF_GNSS_PVT_FLAG_FIX_VALID_BIT)
				== NRF_GNSS_PVT_FLAG_FIX_VALID_BIT) {

				if (!got_first_fix) {
					got_first_fix = true;
				}

				fix_timestamp = k_uptime_get();
				memcpy(&last_fix, gps_data, sizeof(nrf_gnss_data_frame_t));

				nmea_string_cnt = 0;
				update_terminal = true;
			}
			break;

		case NRF_GNSS_NMEA_DATA_ID:
			if (nmea_string_cnt < 10) {
				memcpy(nmea_strings[nmea_string_cnt++],
				       gps_data->nmea,
				       retval);
			}
			break;

		default:
			break;
		}
	}

	return retval;
}

static void print_pvt_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.day,
					       pvt_data->pvt.datetime.month,
					       pvt_data->pvt.datetime.year);
	printk("Time (UTC): %02u:%02u:%02u\n", pvt_data->pvt.datetime.hour,
					       pvt_data->pvt.datetime.minute,
					      pvt_data->pvt.datetime.seconds);
}


/**@brief Function to print strings without null-termination
 */
static void data_print(u8_t *prefix, u8_t *data, size_t len)
{
	char buf[len + 1];

	memcpy(buf, data, len);
	buf[len] = 0;
	printk("%s%s\n", prefix, buf);
}

/**@brief Function to publish data on the configured topic
 */
static int data_publish(struct mqtt_client *c, enum mqtt_qos qos,
	u8_t *data, size_t len)
{
	struct mqtt_publish_param param;

	param.message.topic.qos = qos;
	param.message.topic.topic.utf8 = CONFIG_MQTT_PUB_TOPIC;
	param.message.topic.topic.size = strlen(CONFIG_MQTT_PUB_TOPIC);
	param.message.payload.data = data;
	param.message.payload.len = len;
	param.message_id = sys_rand32_get();
	param.dup_flag = 0;
	param.retain_flag = 0;

	data_print("Publishing: ", data, len);
	printk("to topic: %s len: %u\n",
		CONFIG_MQTT_PUB_TOPIC,
		(unsigned int)strlen(CONFIG_MQTT_PUB_TOPIC));

	return mqtt_publish(c, &param);
}

/**@brief Function to subscribe to the configured topic
 */
static int subscribe(void)
{
	struct mqtt_topic subscribe_topic = {
		.topic = {
			.utf8 = CONFIG_MQTT_SUB_TOPIC,
			.size = strlen(CONFIG_MQTT_SUB_TOPIC)
		},
		.qos = MQTT_QOS_1_AT_LEAST_ONCE
	};

	const struct mqtt_subscription_list subscription_list = {
		.list = &subscribe_topic,
		.list_count = 1,
		.message_id = 1234
	};

	printk("Subscribing to: %s len %u\n", CONFIG_MQTT_SUB_TOPIC,
		(unsigned int)strlen(CONFIG_MQTT_SUB_TOPIC));

	return mqtt_subscribe(&client, &subscription_list);
}

/**@brief Function to read the published payload.
 */
static int publish_get_payload(struct mqtt_client *c, size_t length)
{
	u8_t *buf = payload_buf;
	u8_t *end = buf + length;

	if (length > sizeof(payload_buf)) {
		return -EMSGSIZE;
	}

	while (buf < end) {
		int ret = mqtt_read_publish_payload(c, buf, end - buf);

		if (ret < 0) {
			int err;

			if (ret != -EAGAIN) {
				return ret;
			}

			printk("mqtt_read_publish_payload: EAGAIN\n");

			err = poll(&fds, 1, K_SECONDS(CONFIG_MQTT_KEEPALIVE));
			if (err > 0 && (fds.revents & POLLIN) == POLLIN) {
				continue;
			} else {
				return -EIO;
			}
		}

		if (ret == 0) {
			return -EIO;
		}

		buf += ret;
	}

	return 0;
}

/**@brief MQTT client event handler
 */
void mqtt_evt_handler(struct mqtt_client *const c,
		      const struct mqtt_evt *evt)
{
	int err;

	switch (evt->type) {
	case MQTT_EVT_CONNACK:
		if (evt->result != 0) {
			printk("MQTT connect failed %d\n", evt->result);
			break;
		}

		connected = true;
		printk("[%s:%d] MQTT client connected!\n", __func__, __LINE__);
		subscribe();
		break;

	case MQTT_EVT_DISCONNECT:
		printk("[%s:%d] MQTT client disconnected %d\n", __func__,
		       __LINE__, evt->result);

		connected = false;
		break;

	case MQTT_EVT_PUBLISH: {
		const struct mqtt_publish_param *p = &evt->param.publish;

		printk("[%s:%d] MQTT PUBLISH result=%d len=%d\n", __func__,
		       __LINE__, evt->result, p->message.payload.len);
		err = publish_get_payload(c, p->message.payload.len);
		if (err >= 0) {
			data_print("Received: ", payload_buf,
				p->message.payload.len);
			/* Echo back received data */
			data_publish(&client, MQTT_QOS_1_AT_LEAST_ONCE,
				payload_buf, p->message.payload.len);
		} else {
			printk("mqtt_read_publish_payload: Failed! %d\n", err);
			printk("Disconnecting MQTT client...\n");

			err = mqtt_disconnect(c);
			if (err) {
				printk("Could not disconnect: %d\n", err);
			}
		}
	} break;

	case MQTT_EVT_PUBACK:
		if (evt->result != 0) {
			printk("MQTT PUBACK error %d\n", evt->result);
			break;
		}

		printk("[%s:%d] PUBACK packet id: %u\n", __func__, __LINE__,
				evt->param.puback.message_id);
		break;

	case MQTT_EVT_SUBACK:
		if (evt->result != 0) {
			printk("MQTT SUBACK error %d\n", evt->result);
			break;
		}

		printk("[%s:%d] SUBACK packet id: %u\n", __func__, __LINE__,
				evt->param.suback.message_id);
		break;

	default:
		printk("[%s:%d] default: %d\n", __func__, __LINE__,
				evt->type);
		break;
	}
}

/**@brief Resolves the configured hostname and
 * initializes the MQTT broker structure
 */
static void broker_init(void)
{
	int err;
	struct addrinfo *result;
	struct addrinfo *addr;
	struct addrinfo hints = {
		.ai_family = AF_INET,
		.ai_socktype = SOCK_STREAM
	};

	err = getaddrinfo(CONFIG_MQTT_BROKER_HOSTNAME, NULL, &hints, &result);
	if (err) {
		printk("ERROR: getaddrinfo failed %d\n", err);

		return;
	}

	addr = result;
	err = -ENOENT;

	/* Look for address of the broker. */
	while (addr != NULL) {
		/* IPv4 Address. */
		if (addr->ai_addrlen == sizeof(struct sockaddr_in)) {
			struct sockaddr_in *broker4 =
				((struct sockaddr_in *)&broker);
			char ipv4_addr[NET_IPV4_ADDR_LEN];

			broker4->sin_addr.s_addr =
				((struct sockaddr_in *)addr->ai_addr)
				->sin_addr.s_addr;
			broker4->sin_family = AF_INET;
			broker4->sin_port = htons(CONFIG_MQTT_BROKER_PORT);

			inet_ntop(AF_INET, &broker4->sin_addr.s_addr,
				  ipv4_addr, sizeof(ipv4_addr));
			printk("IPv4 Address found %s\n", ipv4_addr);

			break;
		} else {
			printk("ai_addrlen = %u should be %u or %u\n",
				(unsigned int)addr->ai_addrlen,
				(unsigned int)sizeof(struct sockaddr_in),
				(unsigned int)sizeof(struct sockaddr_in6));
		}

		addr = addr->ai_next;
		break;
	}

	/* Free the address. */
	freeaddrinfo(result);
}

/**@brief Initialize the MQTT client structure
 */
static void client_init(struct mqtt_client *client)
{
	mqtt_client_init(client);

	broker_init();

        static struct mqtt_utf8 password;
	static struct mqtt_utf8 user_name;

	password.utf8 = (u8_t*)MQTT_PASSWORD;
	password.size = strlen(MQTT_PASSWORD);
	user_name.utf8 = (u8_t*)MQTT_USERNAME;
	user_name.size = strlen(MQTT_USERNAME);

	/* MQTT client configuration */
	client->broker = &broker;
	client->evt_cb = mqtt_evt_handler;
	client->client_id.utf8 = (u8_t *)CONFIG_MQTT_CLIENT_ID;
	client->client_id.size = strlen(CONFIG_MQTT_CLIENT_ID);
	client->password = &password;
	client->user_name = &user_name;
	client->protocol_version = MQTT_VERSION_3_1_1;

	/* MQTT buffers configuration */
	client->rx_buf = rx_buffer;
	client->rx_buf_size = sizeof(rx_buffer);
	client->tx_buf = tx_buffer;
	client->tx_buf_size = sizeof(tx_buffer);

	/* MQTT transport configuration */
	client->transport.type = MQTT_TRANSPORT_NON_SECURE;
}

/**@brief Initialize the file descriptor structure used by poll.
 */
static int fds_init(struct mqtt_client *c)
{
	if (c->transport.type == MQTT_TRANSPORT_NON_SECURE) {
		fds.fd = c->transport.tcp.sock;
	} else {
#if defined(CONFIG_MQTT_LIB_TLS)
		fds.fd = c->transport.tls.sock;
#else
		return -ENOTSUP;
#endif
	}

	fds.events = POLLIN;

	return 0;
}

/**@brief Configures modem to provide LTE link. Blocks until link is
 * successfully established.
 */
static void modem_configure(void)
{
#if defined(CONFIG_LTE_LINK_CONTROL)
	if (IS_ENABLED(CONFIG_LTE_AUTO_INIT_AND_CONNECT)) {
		/* Do nothing, modem is already turned on
		 * and connected.
		 */
	} else {
		int err;

		printk("LTE Link Connecting ...\n");
		err = lte_lc_init_and_connect();
		__ASSERT(err == 0, "LTE link could not be established.");
		printk("LTE Link Connected!\n");
	}
#endif
}

int8_t poll_and_check_rcv_data(u32_t interval_msec){
        int err = poll(&fds, 1, interval_msec); // Check if any data comes through LTE-M. When it is waiting for an incoming data, it sleeps
        int8_t ret = 0;
        if (err < 0) {
              printk("ERROR: poll %d\n", errno);
              return -1;
        }

        /* Check if data is received through LTE-M */
        /* Caution!! These are mandatory */
        if ((fds.revents & POLLIN) == POLLIN) {
                err = mqtt_input(&client); // if a publish event comes, mqtt_evt_handler is called here
                if (err != 0) {
                        printk("ERROR: mqtt_input %d\n", err);
                        return -1;
                }
        }

        if ((fds.revents & POLLERR) == POLLERR) {
                printk("POLLERR\n");
                return -1;
        }

        if ((fds.revents & POLLNVAL) == POLLNVAL) {
                printk("POLLNVAL\n");
                return -1;
        }

        return ret;
}


void main(void)
{
	int err;

	printk("The MQTT simple sample started\n");

	modem_configure();

	client_init(&client);

	err = mqtt_connect(&client);
	if (err != 0) {
		printk("ERROR: mqtt_connect %d\n", err);
		return;
	}

	err = fds_init(&client);
	if (err != 0) {
		printk("ERROR: fds_init %d\n", err);
		return;
	}

        poll_and_check_rcv_data(K_SECONDS(5)); 

        /* GPS variables */
        nrf_gnss_data_frame_t gps_data;

	while (1) {

                printk("Staring GPS application\n");

                if (init_gps() != 0) {
                        printk("init_app fail\n");
                }

                printk("Getting GPS data...\n");

		do {
			/* Loop until we don't have more
			 * data to read
			 */
		} while (process_gps_data(&gps_data) > 0);

                printk("---------------------------------\n");
                print_pvt_data(&last_fix);
                /* If gps data is broken, get it again */
                printk("---------------------------------\n");

                configure_gps_off_on(GPS_DIS);

                k_sleep(K_SECONDS(20));
	}
}

<result>
***** Booting Zephyr OS v1.14.99-ncs2-rc3 *****
The MQTT simple sample started
LTE Link Connecting ...
LTE Link Connected!
IPv4 Address found xxx.xx.xx.xxx
[mqtt_evt_handler:389] MQTT client connected!
Subscribing to: my/subscribe/topic len 18
Staring GPS application
at_commands[0] = AT%XSYSTEMMODE=1,0,1,0
at_commands[1] = AT%XMAGPIO=1,0,0,1,1,1574,1577
at_commands[2] = AT+CFUN=1
at_sock = 4
at_commands[i] = AT%XSYSTEMMODE=1,0,1,0
strlen(at_commands[i]) = 22
buf = ER
Error3
Failed to enable GPS
init_app fail
Getting GPS data...
---------------------------------
Longitude:  0.000000
Latitude:   0.000000
Altitude:   0.000000
Speed:      0.000000
Heading:    0.000000
Date:       00-00-00
Time (UTC): 00:00:00
---------------------------------
at_commands[0] = AT%XSYSTEMMODE=1,0,0,0
at_commands[1] = AT%XMAGPIO
at_commands[2] = AT+CFUN=1
at_sock = 4
at_commands[i] = AT%XSYSTEMMODE=1,0,0,0
strlen(at_commands[i]) = 22
buf = ER
Error3

Parents
  • hi

    the tag "v1.0.0 " and "this pull request,"

    is only for latest revision HW(so not work for    0.8.5

    This patch removes support for early prototype hardware and
    moves to only support latest revision. This simplifies the
    device tree file sctructure


  • But the error happens when the project is built. That's not related to support for hardware.

  • lHi!

    Maybe a silly question, but have you long-pressed button 1 to start the GPS?

    My experience is as follows (sorry for the rather lengthy comment):

    1. I have used both Windows 10 x64 and on MacOS Mojave.

    2. I can build joakim's asset_tracker and program the DK v0.8.5 on both platforms. I had problems getting west to work properly on the Mac, but succeeded eventually by using the west and nrf folder from ncs on Windows. Strange, but...

    3. Building in Mojave is about 2-3 times faster than in Windows (same PC that can boot either of the platforms). Also, in Mojave programming the DK 8i.e., download Zephyr/Merged hex) works every time whereas it fails every secobnd time in Windows (resulting in an error message about a "Generic error").

    4. I have had the same results using Cat-M1 or NB-IoT (have access to both where I am), but when "switching" between the two in either direction always requires a more elaborate procedure rebooting the DK twice before an LTE connection can be established. With switching I mean building the app with a new setting for CONFIG_LTE_NETWORK_MODE_NBIOT and reprogramming the board.

    5. Independent of platform, I must set CONFIG_NRF_CLOUD_PROVISION_CERTIFICATES=y and provide a certificates file. mI f not, I get a socket error and the DK reboots:

    Connecting to LTE network. This may take several minutes.
    [00:00:06.437,164] .[0m<dbg> lte_lc.at_handler: recv: +CEREG: 2,"0485","018A7412",9
    .[0m
    [00:00:07.029,296] .[0m<dbg> lte_lc.at_handler: recv: +CEREG: 1,"0485","018A7412",9
    .[0m
    Connected to LTE network
    [00:00:07.296,142] .[0m<dbg> nrf_cloud_transport.nct_connect: IPv4 Address 0xfc8dcb34.[0m
    Socket error: POLLHUP
    LTE link disconnect
    Shutdown modem

    6. Apart from the setting for CONFIG_LTE_NETWORK_MODE_NBIOT and the provisioning, I use the proj.conf as provided.

    7. After starting the app, I get similar console output as above, and then simulated environment data appears on the nrfcloud.com web page while the GPS map shows "Waiting for GPS data...".

    8. a. After long-pressing button 1 (5 sec), the console shows 

    Starting GPS
    Enabling PSM
    PSM enabled
    [00:12:03.735,137] .[0m<dbg> nrf9160_gps.enable_gps: GPS mode is enabled.[0m
    [00:12:03.742,492] .[0m<dbg> nrf9160_gps.enable_gps: Functional mode: 1.[0m
    [00:12:03.749,572] .[0m<dbg> nrf9160_gps.start: GPS socket created.[0m
    [00:12:03.760,162] .[0m<dbg> nrf9160_gps.start: GPS operational.[0m
    GPS started successfully.
    Searching for satellites to get position fix. This may take several minutes.
    The device will attempt to get a fix for 360 seconds, before the GPS is stopped.
    GPS operation started

    8.b. After some additional about 15 seconds

    [00:12:23.344,726] .[0m<dbg> nrf9160_gps.print_satellite_stats: Tracking: 0 Using: 0 Unhealthy: 0.[0m
    [00:12:23.353,973] .[0m<dbg> nrf9160_gps.print_satellite_stats: Seconds since last fix 743.[0m
    [00:12:23.362,487] .[0m<dbg> nrf9160_gps.print_satellite_stats: Tracking: 0 Using: 0 Unhealthy: 0.[0m
    [00:12:23.371,582] .[0m<dbg> nrf9160_gps.print_satellite_stats: Seconds since last fix 743.[0m
    ...

    8.c. If the GPS gets a fix (for me this requires a quite "open" location with very few surrounding "obstacles" like buildings), the console indicates that GPS and PSM are stopped/disabled and the GPS position and the simulated environment data is updated on the web page.

    If the GPS doesn't get a fix, the consoleindicates that GPS and PSM are stopped/disabled and only the simulated environment data is updated on the web page.

    8.d After a 30 sec delay the GPS starts again and the above is repeated

    I wish there was more info from Nordic about how things should be done. My aim is similar to yours: Get rid of the simulated sensor and nRF Cloud stuff and switch between LTE and GPS and send GPS data to our own AWS using MQTT.

    Best regards, Per 

  • Hi Per. You are awesome!

    > 8. a. After long-pressing button 1 (5 sec), the console shows
    I got the same result.

    >Maybe a silly question, but have you long-pressed button 1 to start the GPS?
    Where is this described?

    > 8.b. After some additional about 15 seconds
    I can't get the same result. There is no output and rebooted after several minutes.

    This is my output. I don't see any GPS data on nRF Connect while other simulated data is updated.
    Can you tell me the setting of SW1 and SW2? 

    Do you use #943 commit?

    Starting GPS
    gps_work_handler starts
    Enabling PSM
    PSM enabled
    [00:00:31.946,197] <dbg> nrf9160_gps.enable_gps: GPS mode is enabled
    [00:00:31.953,613] <dbg> nrf9160_gps.enable_gps: Functional mode: 1
    [00:00:31.960,937] <dbg> nrf9160_gps.start: GPS socket created
    [00:00:31.971,588] <dbg> nrf9160_gps.start: GPS operational
    GPS started successfully.
    Searching for satellites to get position fix. This may take several minutes.
    The device will attempt to get a fix for 360 seconds, before the GPS is stopped.
    GPS operation started
    
    <no output for several minutes>
    
    [00:06:32.002,258] <dbg> nrf9160_gps.stop: Stopping GPS
    GPS operation was stopped
    The device will try to get fix again in 30 seconds
    Socket error: POLLHUP
    Reboot
    ***** Booting Zephyr OS build v1.14.99-ncs2-495-ga8933a2ead01 *****
    [00:00:00.005,706] <inf> mcuboot: Starting bootloader
    [00:00:00.012,176] <inf> mcuboot: Primary image: magic=unset, copy_done=0x3, image_ok=0x3
    [00:00:00.020,935] <inf> mcuboot: Scratch: magic=unset, copy_done=0x50, image_ok=0x3
    [00:00:00.029,235] <inf> mcuboot: Boot source: primary slot

  • Hi Yusuke,

    Yes I use commit #943.

    8.a. Well, maybe there is some easy to find info about the need to start the GPS by long-pressing button 1, but I found out by looking at Kconfig in src\gps_controller, which contains the config GPS_CONTROL_ON_LONG_PRESS. This parameter can then be found in ui_evt_handler where you can see that you need to press UI_BUTTON_1 for at least 5 sec...

    8.b. This actually has happened for me as well on ccasion. It has even happened that the first fix works, but that the GPS doesn't start the second time. I also tend to loose the cloud connection regulalrly. I then reboot the DK and then it works. quite annoying, but I haven't figured out why these things happen.

    I assume you have kept CONFIG_NRF9160_GPS_LOG_LEVEL_DBG=y, which is necessary for the togging of the GPS activity.

    Also, I think you must set SW2 to N.C. (see gps_trigger_handler() which checks UI_SWITCH_2). I have SW1 set to GND, but I don't think this matters for anything else than pairing.

    One thing you get is the POLLHUP socket error when the GPS is stopped. This I have never seen.

    For me, debugging is complicated by the fact that I cannot be indoors when testing the GPS. I must be outdoors to get good enough signals, but it's raining quite a lot...

  • > This parameter can then be found in ui_evt_handler where you can see that you need to press UI_BUTTON_1 for at least 5 sec...

    I got it.

    > 8.b. This actually has happened for me as well on ccasion. It has even happened that the first fix works, but that the GPS doesn't start the second time. I also tend to loose the cloud connection regulalrly. I then reboot the DK and then it works. quite annoying, but I haven't figured out why these things happen.

    I set SW2 to N.C. and SW1 to GND, but I don’t get GPS data.

    Starting GPS
    gps_work_handler starts
    Enabling PSM
    PSM enabled
    [00:00:31.946,197] <dbg> nrf9160_gps.enable_gps: GPS mode is enabled
    [00:00:31.953,613] <dbg> nrf9160_gps.enable_gps: Functional mode: 1
    [00:00:31.960,937] <dbg> nrf9160_gps.start: GPS socket created
    [00:00:31.971,588] <dbg> nrf9160_gps.start: GPS operational
    GPS started successfully.
    Searching for satellites to get position fix. This may take several minutes.
    The device will attempt to get a fix for 360 seconds, before the GPS is stopped.
    GPS operation started
    
    <no output for several minutes>
    
    [00:06:31.703,186] <dbg> nrf9160_gps.stop: Stopping GPS
    GPS operation was stopped
    The device will try to get fix again in 30 seconds
    Enabling PSM
    PSM enabled
    [00:07:02.727,264] <dbg> nrf9160_gps.enable_gps: GPS mode is enabled
    [00:07:02.734,863] <dbg> nrf9160_gps.enable_gps: Functional mode: 1
    [00:07:02.746,124] <dbg> nrf9160_gps.start: GPS operational
    GPS started successfully.
    Searching for satellites to get position fix. This may take several minutes.
    The device will attempt to get a fix for 360 seconds, before the GPS is stopped.
    GPS operation started

    > One thing you get is the POLLHUP socket error when the GPS is stopped. This I have never seen.

    I solved this issue. iBass SIM seems to cut the connection every 5 minutes in the place where I live.. I knew this issue from before. I replaced it with a LTE-M SIM of another carrier and this issue disappeared. You said “I also tend to loose the cloud connection regulalrly.” I recommend you to try another SIM.

    > For me, debugging is complicated by the fact that I cannot be indoors when testing the GPS.

    The real-GPS asset_tracker is not officially released and so it might have some bugs. I will wait for its official release because it’s a hard job to debug unofficial program for my skill level....

Reply Children
No Data
Related