summaryrefslogtreecommitdiff
path: root/nrfdemo/src
diff options
context:
space:
mode:
authorMichal Hanus <mikehanus@protonmail.com>2025-04-21 19:30:57 +0200
committerMichal Hanus <mikehanus@protonmail.com>2025-04-21 19:30:57 +0200
commitd0cb33ee5f84bc5dd4358df040b1b21dde7aed42 (patch)
tree59f45f64a0f835e10f16ca3db64f79d12e04cc88 /nrfdemo/src
parent9078b7ec09b135f091cb951ed234bf013c9c838e (diff)
bck
Diffstat (limited to 'nrfdemo/src')
-rw-r--r--nrfdemo/src/main.c81
1 files changed, 36 insertions, 45 deletions
diff --git a/nrfdemo/src/main.c b/nrfdemo/src/main.c
index 431e8cf..770b178 100644
--- a/nrfdemo/src/main.c
+++ b/nrfdemo/src/main.c
@@ -42,9 +42,8 @@ LOG_MODULE_REGISTER(mqtt_app, LOG_LEVEL_INF);
static void lte_handler(const struct lte_lc_evt *const evt)
{
- LOG_INF("LTE handler");
- switch (evt->type) {
- case LTE_LC_EVT_NW_REG_STATUS:
+ 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;
@@ -74,15 +73,6 @@ static int modem_configure(void)
return err;
}
- /* lte_lc_init deprecated in >= v2.6.0 */
- #if NCS_VERSION_NUMBER < 0x20600
- err = lte_lc_init();
- if (err) {
- LOG_ERR("Failed to initialize LTE link control library, error: %d", err);
- return err;
- }
- #endif
-
LOG_INF("Connecting to LTE network");
err = lte_lc_connect_async(lte_handler);
if (err) {
@@ -93,39 +83,6 @@ static int modem_configure(void)
k_sem_take(&lte_connected, K_FOREVER);
LOG_INF("Connected to LTE network");
- #if 1
-
- /* Activate only the GNSS stack * /
- if (lte_lc_func_mode_set(LTE_LC_FUNC_MODE_ACTIVATE_GNSS) != 0) {
- LOG_ERR("Failed to activate GNSS functional mode");
- return 0;
- } */
-
- /* Register the GNSS event handler */
- if (nrf_modem_gnss_event_handler_set(gnss_event_handler) != 0) {
- LOG_ERR("Failed to set GNSS event handler");
- return 0;
- }
-
- /* Set the GNSS fix interval and GNSS fix retry period */
- //if (nrf_modem_gnss_fix_interval_set(CONFIG_GNSS_PERIODIC_INTERVAL) != 0) {
- // LOG_ERR("Failed to set GNSS fix interval");
- // return 0;
- //}
-
- //if (nrf_modem_gnss_fix_retry_set(CONFIG_GNSS_PERIODIC_TIMEOUT) != 0) {
- // LOG_ERR("Failed to set GNSS fix retry");
- // return 0;
- //}
-
- /* Start the GNSS receiver */
- LOG_INF("Starting GNSS");
- if (nrf_modem_gnss_start() != 0) {
- LOG_ERR("Failed to start GNSS");
- return 0;
- }
- #endif
-
// Blink LED to indicate we connected to MQTT broker
dk_set_led_on(DK_LED1);
@@ -234,12 +191,46 @@ int main(void)
LOG_ERR("Failed to initialize the buttons library");
}
+
+ /* Activate only the GNSS stack */
+ if (lte_lc_func_mode_set(LTE_LC_FUNC_MODE_ACTIVATE_GNSS) != 0) {
+ LOG_ERR("Failed to activate GNSS functional mode");
+ return 0;
+ }
+
+ /* Register the GNSS event handler */
+ if (nrf_modem_gnss_event_handler_set(gnss_event_handler) != 0) {
+ LOG_ERR("Failed to set GNSS event handler");
+ return 0;
+ }
+
+ /* Set the GNSS fix interval and GNSS fix retry period */
+ if (nrf_modem_gnss_fix_interval_set(1) != 0) {
+ LOG_ERR("Failed to set GNSS fix interval");
+ return 0;
+ }
+
+ if (nrf_modem_gnss_fix_retry_set(60) != 0) {
+ LOG_ERR("Failed to set GNSS fix retry");
+ return 0;
+ }
+
+ /* Start the GNSS receiver */
+ LOG_INF("Starting GNSS");
+ if (nrf_modem_gnss_start() != 0) {
+ LOG_ERR("Failed to start GNSS");
+ return 0;
+ }
+
err = client_init(&client);
if (err) {
LOG_ERR("Failed to initialize MQTT client: %d", err);
return 0;
}
+ /* Log the current system uptime */
+ gnss_start_time = k_uptime_get();
+
do_connect:
if (connect_attempt++ > 0) {
LOG_INF("Reconnecting in %d seconds...",