Skip to content

Commit

Permalink
zephyr: lwm2m_client: Update to most recent Zephyr sample
Browse files Browse the repository at this point in the history
Update to most recent zephyr sample.

Add resource 5/0/1 in order to test sending an URL where a firmware
update can be downloaded. This is the first step to test OTA updates.

Signed-off-by: Jonas Remmert <jremmert@gmx.net>
  • Loading branch information
jonas-rem authored and Kappuccino111 committed Jun 4, 2024
1 parent 72230cc commit 02199ff
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 67 deletions.
3 changes: 2 additions & 1 deletion fw_test/lwm2m_client/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ endif

config LWM2M_APP_SERVER
string "LwM2M server address"
default "coaps://192.0.2.2:5684" if LWM2M_DTLS_SUPPORT
default "coap://192.0.2.2:5683" if !LWM2M_DTLS_SUPPORT
default "coaps://192.0.2.2:5684" if (LWM2M_DTLS_SUPPORT && !LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP)
default "coaps://192.0.2.2:5784" if (LWM2M_DTLS_SUPPORT && LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP)
help
LwM2M server address. Write as a full URI including optional port number.
Only accepted protocols are "coap://" and "coaps://"
Expand Down
29 changes: 0 additions & 29 deletions fw_test/lwm2m_client/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ samples/net/lwm2m_client directory:
* - :file:`overlay-dtls.conf`
- This overlay config can be added for DTLS support via MBEDTLS.

* - :file:`overlay-bt.conf`
- This overlay config can be added to enable Bluetooth networking support.

* - :file:`overlay-queue.conf`
- This overlay config can be added to enable LWM2M Queue Mode support.

Expand Down Expand Up @@ -179,32 +176,6 @@ the overlay file for Bootstrap over DTLS (5784 in case of Leshan Demo Bootstrap
Server) and to configure correct security mode in the ``LWM2M Bootstrap Server``
tab in the web UI (Pre-shared Key).

Bluetooth Support
=================

To build the lwm2m-client sample for hardware requiring Bluetooth for
networking (IPSP node connected via 6lowpan) do the following:

.. zephyr-app-commands::
:zephyr-app: samples/net/lwm2m_client
:host-os: unix
:board: <board to use>
:conf: "prj.conf overlay-bt.conf"
:goals: build
:compact:

The overlay-\*.conf files can also be combined. For example, you could build a
DTLS-enabled LwM2M client sample for BLENano2 hardware by using the following
commands (requires Bluetooth for networking):

.. zephyr-app-commands::
:zephyr-app: samples/net/lwm2m_client
:host-os: unix
:board: nrf52_blenano2
:conf: "prj.conf overlay-bt.conf overlay-dtls.conf"
:goals: build
:compact:

OpenThread Support
==================

Expand Down
1 change: 0 additions & 1 deletion fw_test/lwm2m_client/overlay-bootstrap.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
CONFIG_LWM2M_PEER_PORT=5783
CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP=y
13 changes: 0 additions & 13 deletions fw_test/lwm2m_client/overlay-bt.conf

This file was deleted.

9 changes: 8 additions & 1 deletion fw_test/lwm2m_client/overlay-queue.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
CONFIG_LWM2M_QUEUE_MODE_ENABLED=y
CONFIG_LWM2M_QUEUE_MODE_UPTIME=20

# Listen for incoming CoAP messages for 30 seconds after last TX.
# This is a common NAT timeout for cellular networks.
CONFIG_LWM2M_QUEUE_MODE_UPTIME=30

# When DTLS Connection Identifier is used, we can keep socket open
# and just stop polling while in idle state (QUEUE_RX_OFF).
# If the server does not support DTLS-CID, use
CONFIG_LWM2M_RD_CLIENT_STOP_POLLING_AT_IDLE=y

# Default lifetime is 1 day
Expand Down
13 changes: 1 addition & 12 deletions fw_test/lwm2m_client/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,6 @@ tests:
tags:
- net
- lwm2m
sample.net.lwm2m_client.bt:
harness: net
extra_args: OVERLAY_CONFIG=overlay-bt.conf
platform_allow:
- nrf52840dk_nrf52840
- disco_l475_iot1
tags:
- net
- lwm2m
integration_platforms:
- disco_l475_iot1
sample.net.lwm2m_client.queue_mode:
harness: net
depends_on: netif
Expand All @@ -80,7 +69,7 @@ tests:
extra_args: SHIELD=wnc_m14a2a
platform_allow:
- frdm_k64f
- nrf52840dk_nrf52840
- nrf52840dk/nrf52840
integration_platforms:
- frdm_k64f
tags:
Expand Down
23 changes: 17 additions & 6 deletions fw_test/lwm2m_client/src/firmware_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,23 @@ static void *firmware_get_buf(uint16_t obj_inst_id, uint16_t res_id,
return firmware_buf;
}

static int firmware_block_received_cb(uint16_t obj_inst_id,
uint16_t res_id, uint16_t res_inst_id,
uint8_t *data, uint16_t data_len,
bool last_block, size_t total_size)
static int firmware_download_cb(uint16_t obj_inst_id,
uint16_t res_id, uint16_t res_inst_id,
uint8_t *data, uint16_t data_len,
bool last_block, size_t total_size, size_t offset)
{
LOG_INF("FIRMWARE: BLOCK RECEIVED: len:%u last_block:%d",
data_len, last_block);
LOG_INF("FIRMWARE: DOWNLOAD");
LOG_INF("Download Link: %s", data);
return 0;
}

static int firmware_block_received_cb(uint16_t obj_inst_id, uint16_t res_id,
uint16_t res_inst_id, uint8_t *data,
uint16_t data_len, bool last_block,
size_t total_size, size_t offset)
{
LOG_INF("FIRMWARE: BLOCK RECEIVED: offset:%zd len:%u last_block:%d",
offset, data_len, last_block);
return 0;
}

Expand All @@ -58,6 +68,7 @@ void init_firmware_update(void)
{
/* setup data buffer for block-wise transfer */
lwm2m_register_pre_write_callback(&LWM2M_OBJ(5, 0, 0), firmware_get_buf);
lwm2m_register_post_write_callback(&LWM2M_OBJ(5, 0, 1), firmware_download_cb);
lwm2m_firmware_set_write_cb(firmware_block_received_cb);

/* register cancel callback */
Expand Down
2 changes: 1 addition & 1 deletion fw_test/lwm2m_client/src/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static uint32_t led_state;

/* TODO: Move to a pre write hook that can handle ret codes once available */
static int led_on_off_cb(uint16_t obj_inst_id, uint16_t res_id, uint16_t res_inst_id, uint8_t *data,
uint16_t data_len, bool last_block, size_t total_size)
uint16_t data_len, bool last_block, size_t total_size, size_t offset)
{
int ret = 0;
uint32_t led_val;
Expand Down
22 changes: 21 additions & 1 deletion fw_test/lwm2m_client/src/lwm2m-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
#include <zephyr/net/conn_mgr_monitor.h>
#include <zephyr/net/conn_mgr_connectivity.h>
#include "modules.h"
#include "lwm2m_resource_ids.h"

#define APP_BANNER "Run LWM2M client"

Expand All @@ -30,6 +31,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
#define CLIENT_SERIAL_NUMBER "345000123"
#define CLIENT_FIRMWARE_VER "1.0"
#define CLIENT_HW_VER "1.0.1"
#define TEMP_SENSOR_UNITS "Celcius"

/* Macros used to subscribe to specific Zephyr NET management events. */
#define L4_EVENT_MASK (NET_EVENT_L4_CONNECTED | NET_EVENT_L4_DISCONNECTED)
Expand All @@ -45,6 +47,8 @@ static uint8_t bat_level = 95;
static uint8_t bat_status = LWM2M_DEVICE_BATTERY_STATUS_CHARGING;
static int mem_free = 15;
static int mem_total = 25;
static double min_range = 0.0;
static double max_range = 100;

static struct lwm2m_ctx client_ctx;

Expand Down Expand Up @@ -88,9 +92,17 @@ static int device_factory_default_cb(uint16_t obj_inst_id,
return 0;
}


static int lwm2m_setup(void)
{
struct lwm2m_res_item temp_sensor_items[] = {
{&LWM2M_OBJ(IPSO_OBJECT_TEMP_SENSOR_ID, 0, MIN_RANGE_VALUE_RID), &min_range,
sizeof(min_range)},
{&LWM2M_OBJ(IPSO_OBJECT_TEMP_SENSOR_ID, 0, MAX_RANGE_VALUE_RID), &max_range,
sizeof(max_range)},
{&LWM2M_OBJ(IPSO_OBJECT_TEMP_SENSOR_ID, 0, SENSOR_UNITS_RID), TEMP_SENSOR_UNITS,
sizeof(TEMP_SENSOR_UNITS)}
};

/* setup SECURITY object */

/* Server URL */
Expand Down Expand Up @@ -173,6 +185,14 @@ static int lwm2m_setup(void)
/* setup TEMP SENSOR object */
init_temp_sensor();

/* Set multiple TEMP SENSOR resource values in one function call. */
int err = lwm2m_set_bulk(temp_sensor_items, ARRAY_SIZE(temp_sensor_items));

if (err) {
LOG_ERR("Failed to set TEMP SENSOR resources");
return err;
}

/* IPSO: Light Control object */
init_led_device();

Expand Down
4 changes: 2 additions & 2 deletions fw_test/lwm2m_client/src/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
/* An example data validation callback. */
static int timer_on_off_validate_cb(uint16_t obj_inst_id, uint16_t res_id, uint16_t res_inst_id,
uint8_t *data, uint16_t data_len, bool last_block,
size_t total_size)
size_t total_size, size_t offset)
{
LOG_INF("Validating On/Off data");

Expand All @@ -34,7 +34,7 @@ static int timer_on_off_validate_cb(uint16_t obj_inst_id, uint16_t res_id, uint1

static int timer_digital_state_cb(uint16_t obj_inst_id, uint16_t res_id, uint16_t res_inst_id,
uint8_t *data, uint16_t data_len, bool last_block,
size_t total_size)
size_t total_size, size_t offset)
{
bool *digital_state = (bool *)data;

Expand Down

0 comments on commit 02199ff

Please sign in to comment.