Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

location: add cellular support with extended location example #729

Merged
merged 10 commits into from
Jan 22, 2025
Merged
2 changes: 2 additions & 0 deletions examples/zephyr/common/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ endif # DNS_RESOLVER
configdefault ZVFS_EVENTFD_MAX
int
default 14 if GOLIOTH_OTA
default 13 if GOLIOTH_LOCATION_CELLULAR && GOLIOTH_LOCATION_WIFI
default 7

if LOG_BACKEND_GOLIOTH
Expand Down Expand Up @@ -117,6 +118,7 @@ config MAIN_STACK_SIZE
configdefault ZVFS_OPEN_MAX
int
default 23 if GOLIOTH_OTA
default 20 if GOLIOTH_LOCATION_CELLULAR && GOLIOTH_LOCATION_WIFI
default 16

config REBOOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(location_wifi)
project(location)

target_sources(app PRIVATE src/main.c)
target_sources_ifdef(CONFIG_GOLIOTH_CELLULAR_PLAYBACK app PRIVATE src/cellular_playback.c)
target_sources_ifdef(CONFIG_GOLIOTH_WIFI_PLAYBACK app PRIVATE src/wifi_playback.c)
target_sources_ifdef(CONFIG_SOC_SERIES_NRF91X app PRIVATE src/cellular_nrf91.c)
47 changes: 47 additions & 0 deletions examples/zephyr/location/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright (c) 2021-2025 Golioth, Inc.
# SPDX-License-Identifier: Apache-2.0

configdefault GOLIOTH_LOCATION_CELLULAR
default y if SOC_SERIES_NRF91X
default y if GOLIOTH_CELLULAR_PLAYBACK

configdefault GOLIOTH_LOCATION_WIFI
default y if WIFI

configdefault WIFI
default y if GOLIOTH_WIFI_PLAYBACK

source "${ZEPHYR_GOLIOTH_FIRMWARE_SDK_MODULE_DIR}/examples/zephyr/common/Kconfig.defconfig"

config APP_LOCATION_GET_INTERVAL
int "Interval (msec)"
default 0 if GOLIOTH_CELLULAR_PLAYBACK || GOLIOTH_WIFI_PLAYBACK
default 5000
help
Interval (msec) between requests of location information.

config GOLIOTH_CELLULAR_PLAYBACK
bool "Cellular playback"
default y
depends on DT_HAS_GOLIOTH_CELLULAR_PLAYBACK_ENABLED

config GOLIOTH_WIFI_PLAYBACK
bool "WiFi playback"
default y
depends on DT_HAS_GOLIOTH_WIFI_PLAYBACK_ENABLED

if GOLIOTH_CELLULAR_PLAYBACK || GOLIOTH_WIFI_PLAYBACK

config GOLIOTH_PLAYBACK_SPEED_FACTOR
int "Speed factor"
default 1000
help
Speed of playback.

1000 means 1x (normal) speed.
3000 means 3x speed.
500 means 0.5x speed.

endif # GOLIOTH_CELLULAR_PLAYBACK || GOLIOTH_WIFI_PLAYBACK

source "Kconfig.zephyr"
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Golioth WiFi location demo
# Golioth location demo

## Overview

This sample demonstrates how to connect to Golioth and get location
using scanned WiFi networks.
using cellular network cell towers information and/or scanned WiFi
networks.

## Requirements

Expand Down Expand Up @@ -93,11 +94,11 @@ This application has been built and tested with Native Simulator
(native_sim).

On your Linux host computer, open a terminal window, locate the source
code of this sample application (i.e., `examples/zephyr/location/wifi`)
code of this sample application (i.e., `examples/zephyr/location`)
and type:

```console
$ west build -b native_sim examples/zephyr/location/wifi
$ west build -b native_sim examples/zephyr/location
$ west build -t run
```

Expand All @@ -117,10 +118,10 @@ CONFIG_GOLIOTH_SAMPLE_WIFI_PSK="my-psk"
```

On your host computer open a terminal window, locate the source code of
this sample application (i.e., `examples/zephyr/location/wifi`) and type:
this sample application (i.e., `examples/zephyr/location`) and type:

```console
$ west build -b esp32_devkitc_wrover/esp32/procpu examples/zephyr/location/wifi
$ west build -b esp32_devkitc_wrover/esp32/procpu examples/zephyr/location
$ west flash
```

Expand Down Expand Up @@ -164,10 +165,20 @@ CONFIG_GOLIOTH_SAMPLE_WIFI_PSK="my-psk"
```

On your host computer open a terminal window, locate the source code of
this sample application (i.e., `examples/zephyr/location/wifi`) and type:
this sample application (i.e., `examples/zephyr/location`) and type:

```console
$ west build -b nrf52840dk/nrf52840 examples/zephyr/location/wifi
$ west build -b nrf52840dk/nrf52840 examples/zephyr/location
$ west flash
```

#### nRF9160 DK

On your host computer open a terminal window, locate the source code of
this sample application (i.e., `examples/zephyr/location`) and type:

```console
$ west build -b nrf9160dk/nrf9160/ns examples/zephyr/location
$ west flash
```

Expand All @@ -179,32 +190,32 @@ This is the output from the serial console:
*** Booting Zephyr OS build v4.0.0-1-gb39d67f51986 ***
[00:00:00.000,000] <inf> net_config: Initializing network
[00:00:00.000,000] <inf> net_config: IPv4 address: 192.0.2.1
[00:00:00.000,000] <dbg> location_wifi_main: main: Start WiFi location sample
[00:00:00.000,000] <dbg> location_main: main: Start location sample
[00:00:00.000,000] <inf> golioth_mbox: Mbox created, bufsize: 1848, num_items: 10, item_size: 168
[00:00:00.400,003] <inf> golioth_coap_client_zephyr: Golioth CoAP client connected
[00:00:00.400,003] <inf> location_wifi_main: Golioth client connected
[00:00:00.400,003] <inf> location_main: Golioth client connected
[00:00:00.400,003] <inf> golioth_coap_client_zephyr: Entering CoAP I/O loop
[00:00:00.580,002] <inf> location_wifi_main: 50.663974800 17.942322850 (32)
[00:00:00.760,001] <inf> location_wifi_main: 50.664181170 17.942337360 (23)
[00:00:01.170,001] <inf> location_wifi_main: 50.664464180 17.942332180 (22)
[00:00:01.700,001] <inf> location_wifi_main: 50.665216090 17.942386110 (26)
[00:00:02.190,001] <inf> location_wifi_main: 50.665924320 17.942342850 (17)
[00:00:02.690,001] <inf> location_wifi_main: 50.666588620 17.942297690 (21)
[00:00:03.180,001] <inf> location_wifi_main: 50.667436140 17.942253480 (25)
[00:00:03.680,001] <inf> location_wifi_main: 50.667930110 17.942142910 (27)
[00:00:04.170,001] <inf> location_wifi_main: 50.668083230 17.942170380 (33)
[00:00:04.670,001] <inf> location_wifi_main: 50.669921000 17.948761000 (569)
[00:00:05.170,001] <inf> location_wifi_main: 50.667979840 17.942204310 (36)
[00:00:05.660,001] <inf> location_wifi_main: 50.665045000 17.947862000 (604)
[00:00:06.170,001] <inf> location_wifi_main: 50.668312550 17.942551440 (31)
[00:00:06.670,001] <inf> location_wifi_main: 50.668242700 17.942328220 (52)
[00:00:07.170,001] <inf> location_wifi_main: 50.668386960 17.942680660 (46)
[00:00:07.670,001] <inf> location_wifi_main: 50.668344030 17.943467020 (37)
[00:00:08.180,001] <inf> location_wifi_main: 50.668361530 17.943982820 (50)
[00:00:08.680,001] <inf> location_wifi_main: 50.668426910 17.945390790 (58)
[00:00:09.170,001] <inf> location_wifi_main: 50.668490680 17.947672650 (43)
[00:00:09.780,001] <inf> location_wifi_main: 50.668505260 17.947435020 (34)
[00:00:10.160,001] <inf> location_wifi_main: 50.668612950 17.948811810 (71)
[00:00:10.670,001] <inf> location_wifi_main: 50.668666040 17.948747050 (107)
[00:00:11.270,001] <inf> location_wifi_main: 50.664927000 17.947822000 (593)
[00:00:00.580,002] <inf> location_main: 50.663974800 17.942322850 (32)
[00:00:00.760,001] <inf> location_main: 50.664181170 17.942337360 (23)
[00:00:01.170,001] <inf> location_main: 50.664464180 17.942332180 (22)
[00:00:01.700,001] <inf> location_main: 50.665216090 17.942386110 (26)
[00:00:02.190,001] <inf> location_main: 50.665924320 17.942342850 (17)
[00:00:02.690,001] <inf> location_main: 50.666588620 17.942297690 (21)
[00:00:03.180,001] <inf> location_main: 50.667436140 17.942253480 (25)
[00:00:03.680,001] <inf> location_main: 50.667930110 17.942142910 (27)
[00:00:04.170,001] <inf> location_main: 50.668083230 17.942170380 (33)
[00:00:04.670,001] <inf> location_main: 50.669921000 17.948761000 (569)
[00:00:05.170,001] <inf> location_main: 50.667979840 17.942204310 (36)
[00:00:05.660,001] <inf> location_main: 50.665045000 17.947862000 (604)
[00:00:06.170,001] <inf> location_main: 50.668312550 17.942551440 (31)
[00:00:06.670,001] <inf> location_main: 50.668242700 17.942328220 (52)
[00:00:07.170,001] <inf> location_main: 50.668386960 17.942680660 (46)
[00:00:07.670,001] <inf> location_main: 50.668344030 17.943467020 (37)
[00:00:08.180,001] <inf> location_main: 50.668361530 17.943982820 (50)
[00:00:08.680,001] <inf> location_main: 50.668426910 17.945390790 (58)
[00:00:09.170,001] <inf> location_main: 50.668490680 17.947672650 (43)
[00:00:09.780,001] <inf> location_main: 50.668505260 17.947435020 (34)
[00:00:10.160,001] <inf> location_main: 50.668612950 17.948811810 (71)
[00:00:10.670,001] <inf> location_main: 50.668666040 17.948747050 (107)
[00:00:11.270,001] <inf> location_main: 50.664927000 17.947822000 (593)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2025 Golioth, Inc.
# SPDX-License-Identifier: Apache-2.0

description: Cellular driver with playback of scanned cellular networks

compatible: "golioth,cellular-playback"

include: base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ CONFIG_GOLIOTH_SAMPLE_HARDCODED_CREDENTIALS=y
CONFIG_GOLIOTH_FIRMWARE_SDK=y

CONFIG_GOLIOTH_LOCATION=y
CONFIG_GOLIOTH_LOCATION_WIFI=y
CONFIG_WIFI=y
30 changes: 30 additions & 0 deletions examples/zephyr/location/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
sample:
description: Location example
name: location
common:
build_only: true
tags:
- golioth
- location
- socket
tests:
sample.golioth.location:
platform_allow:
- esp32_devkitc_wrover/esp32/procpu
- native_sim
- native_sim/native/64
- nrf52840dk/nrf52840
- nrf9151dk/nrf9151/ns
- nrf9160dk/nrf9160/ns
sample.golioth.location.wifi_only:
extra_configs:
- CONFIG_GOLIOTH_CELLULAR_PLAYBACK=n
platform_allow:
- native_sim
- native_sim/native/64
sample.golioth.location.cellular_only:
extra_configs:
- CONFIG_GOLIOTH_WIFI_PLAYBACK=n
platform_allow:
- native_sim
- native_sim/native/64
11 changes: 11 additions & 0 deletions examples/zephyr/location/socs/native.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/ {
cellular-playback {
compatible = "golioth,cellular-playback";
status = "okay";
};

wifi-playback {
compatible = "golioth,wifi-playback";
status = "okay";
};
};
41 changes: 41 additions & 0 deletions examples/zephyr/location/socs/nrf9151_ns.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# General config
CONFIG_HEAP_MEM_POOL_SIZE=4096
CONFIG_NEWLIB_LIBC=y

# Networking
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_IPV6=y
CONFIG_NET_IPV6_NBR_CACHE=n
CONFIG_NET_IPV6_MLD=n

# Increase native TLS socket implementation, so that it is chosen instead of
# offloaded nRF91 sockets
CONFIG_NET_SOCKETS_TLS_PRIORITY=35

# Modem library
CONFIG_NRF_MODEM_LIB=y

# LTE connectivity with network connection manager
CONFIG_NRF_MODEM_LIB_NET_IF=y
CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_START=y
CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_CONNECT=y
CONFIG_NET_CONNECTION_MANAGER=y
CONFIG_NET_CONNECTION_MANAGER_MONITOR_STACK_SIZE=1024

# Increased sysworkq size, due to LTE connectivity
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

# Disable options y-selected by NCS for no good reason
CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED=n
CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED=n

# MbedTLS configuration to support p-384 curve. These options
# enable using the MbedTLS built-in support for operations not
# supported by the default nRF Oberon crypto backend
CONFIG_NORDIC_SECURITY_BACKEND=n
CONFIG_MBEDTLS_LEGACY_CRYPTO_C=y

# Generate MCUboot compatible images
CONFIG_BOOTLOADER_MCUBOOT=y

CONFIG_LTE_LC_NEIGHBOR_CELL_MEAS_MODULE=y
38 changes: 38 additions & 0 deletions examples/zephyr/location/socs/nrf9160_ns.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# General config
CONFIG_HEAP_MEM_POOL_SIZE=4096
CONFIG_NEWLIB_LIBC=y

# Networking
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_IPV6=y
CONFIG_NET_IPV6_NBR_CACHE=n
CONFIG_NET_IPV6_MLD=n

# Increase native TLS socket implementation, so that it is chosen instead of
# offloaded nRF91 sockets
CONFIG_NET_SOCKETS_TLS_PRIORITY=35

# Modem library
CONFIG_NRF_MODEM_LIB=y

# LTE connectivity with network connection manager
CONFIG_NRF_MODEM_LIB_NET_IF=y
CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_START=y
CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_CONNECT=y
CONFIG_NET_CONNECTION_MANAGER=y
CONFIG_NET_CONNECTION_MANAGER_MONITOR_STACK_SIZE=1024

# Increased sysworkq size, due to LTE connectivity
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

# Disable options y-selected by NCS for no good reason
CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED=n
CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED=n

# MbedTLS configuration to support p-384 curve. These options
# enable using the MbedTLS built-in support for operations not
# supported by the default nRF Oberon crypto backend
CONFIG_NORDIC_SECURITY_BACKEND=n
CONFIG_MBEDTLS_LEGACY_CRYPTO_C=y

CONFIG_LTE_LC_NEIGHBOR_CELL_MEAS_MODULE=y
13 changes: 13 additions & 0 deletions examples/zephyr/location/src/cellular.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2025 Golioth, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <golioth/location/cellular.h>

int cellular_info_get(struct golioth_cellular_info *infos,
size_t num_max_infos,
size_t *num_returned_infos);
Loading