Skip to content

Commit f9737e0

Browse files
SeppoTakalokartben
authored andcommitted
samples: net: lwm2m: Add support for nRF52840 on nRF9160DK
Add support for running LwM2M client on nRF52840 chip using nRF9160 as a modem through serial port. nRF9160 should run Serial LTE Modem application build from nRF Connect SDK. nRF9160DK board has two MCU, nRF9160 and nRF52840. Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
1 parent d4e8724 commit f9737e0

File tree

4 files changed

+67
-4
lines changed

4 files changed

+67
-4
lines changed

samples/net/lwm2m_client/Kconfig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ config LWM2M_APP_TLS_TAG
2727
TLS security tag to use when connecting.
2828
endif
2929

30+
config HAS_INTERNET
31+
bool
32+
default y if (WIFI || MODEM)
33+
3034
config LWM2M_APP_SERVER
3135
string "LwM2M server address"
32-
default "coap://leshan.eclipseprojects.io:5683" if (WIFI && !LWM2M_DTLS_SUPPORT)
33-
default "coaps://leshan.eclipseprojects.io:5684" if (WIFI && LWM2M_DTLS_SUPPORT)
36+
default "coap://leshan.eclipseprojects.io:5683" if (HAS_INTERNET && !LWM2M_DTLS_SUPPORT)
37+
default "coaps://leshan.eclipseprojects.io:5684" if (HAS_INTERNET && LWM2M_DTLS_SUPPORT)
3438
default "coap://192.0.2.2:5683" if !LWM2M_DTLS_SUPPORT
3539
default "coaps://192.0.2.2:5684" if (LWM2M_DTLS_SUPPORT && !LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP)
3640
default "coaps://192.0.2.2:5784" if (LWM2M_DTLS_SUPPORT && LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
CONFIG_UART_ASYNC_API=y
2+
CONFIG_UART_1_ASYNC=y
3+
CONFIG_UART_1_INTERRUPT_DRIVEN=n
4+
5+
# Align with the Serial LTE Modem (SLM) application.
6+
CONFIG_MODEM_CELLULAR_UART_BUFFER_SIZES=6000
7+
8+
# Networking
9+
CONFIG_NETWORKING=y
10+
CONFIG_NET_NATIVE=y
11+
CONFIG_NET_L2_PPP=y
12+
CONFIG_NET_IPV4=y
13+
CONFIG_NET_UDP=y
14+
CONFIG_NET_SOCKETS=y
15+
CONFIG_NET_CONTEXT_RCVTIMEO=y
16+
17+
# DNS
18+
CONFIG_DNS_RESOLVER=y
19+
CONFIG_NET_L2_PPP_OPTION_DNS_USE=y
20+
CONFIG_DNS_SERVER_IP_ADDRESSES=y
21+
CONFIG_DNS_SERVER1="8.8.8.8"
22+
CONFIG_LWM2M_DNS_SUPPORT=y
23+
24+
# Network management
25+
CONFIG_NET_MGMT=y
26+
CONFIG_NET_MGMT_EVENT=y
27+
CONFIG_NET_CONNECTION_MANAGER=y
28+
29+
# Modem driver
30+
CONFIG_MODEM=y
31+
CONFIG_MODEM_CELLULAR=y
32+
33+
# LwM2M client does not use power management
34+
CONFIG_PM_DEVICE=n
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <nrf52840/nrf9160dk_uart1_on_if0_3.dtsi>
2+
3+
/ {
4+
aliases {
5+
modem = &modem;
6+
};
7+
};
8+
9+
&uart1 {
10+
current-speed = <115200>;
11+
hw-flow-control;
12+
13+
modem: modem {
14+
compatible = "nordic,nrf91-slm";
15+
status = "okay";
16+
mdm-power-gpios = <&interface_to_nrf9160 4 GPIO_ACTIVE_LOW>;
17+
};
18+
};

samples/net/lwm2m_client/src/lwm2m-client.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,13 @@ int main(void)
376376
k_sem_init(&quit_lock, 0, K_SEM_MAX_LIMIT);
377377

378378
if (IS_ENABLED(CONFIG_NET_CONNECTION_MANAGER)) {
379+
struct net_if *iface = net_if_get_default();
380+
381+
if (!iface) {
382+
LOG_ERR("No network interface found!");
383+
return -ENODEV;
384+
}
385+
379386
/* Setup handler for Zephyr NET Connection Manager events. */
380387
net_mgmt_init_event_callback(&l4_cb, l4_event_handler, L4_EVENT_MASK);
381388
net_mgmt_add_event_callback(&l4_cb);
@@ -385,14 +392,14 @@ int main(void)
385392
CONN_LAYER_EVENT_MASK);
386393
net_mgmt_add_event_callback(&conn_cb);
387394

388-
ret = net_if_up(net_if_get_default());
395+
ret = net_if_up(iface);
389396

390397
if (ret < 0 && ret != -EALREADY) {
391398
LOG_ERR("net_if_up, error: %d", ret);
392399
return ret;
393400
}
394401

395-
(void)conn_mgr_if_connect(net_if_get_default());
402+
(void)conn_mgr_if_connect(iface);
396403

397404
LOG_INF("Waiting for network connection...");
398405
k_sem_take(&network_connected_sem, K_FOREVER);

0 commit comments

Comments
 (0)