Skip to content
Browse files

samples: net: lwm2m_client: If hwinfo interface is enabled, use it

Previously we always used the board identifier (via CONFIG_BOARD) as
identifier, however this causes troubles in case of tests with multiple
boards of the same kind on the same server. The device_id addresses that
problem nicely if enabled and supported by the architecture.

Signed-off-by: Daniel Egger <>
  • Loading branch information...
therealprof authored and jukkar committed Mar 8, 2019
1 parent d596262 commit 08d10e1793fbfb237ad3902e25d2182249e1fde5
Showing with 26 additions and 0 deletions.
  1. +26 −0 samples/net/lwm2m_client/src/lwm2m-client.c
@@ -11,6 +11,7 @@
#include <logging/log.h>

#include <hwinfo.h>
#include <zephyr.h>
#include <drivers/gpio.h>
#include <drivers/sensor.h>
@@ -412,7 +413,32 @@ void main(void)
client.tls_tag = TLS_TAG;

#if defined(CONFIG_HWINFO)
u8_t dev_id[16];
char dev_str[33];
ssize_t length;
int i;

(void)memset(dev_id, 0x0, sizeof(dev_id));

/* Obtain the device id */
length = hwinfo_get_device_id(dev_id, sizeof(dev_id));

/* If this fails for some reason, use all zeros instead */
if (length <= 0) {
length = sizeof(dev_id);

/* Render the obtained serial number in hexadecimal representation */
for (i = 0 ; i < length ; i++) {
sprintf(&dev_str[i*2], "%02x", dev_id[i]);

lwm2m_rd_client_start(&client, dev_str, rd_client_event);
/* client.sec_obj_inst is 0 as a starting point */
lwm2m_rd_client_start(&client, CONFIG_BOARD, rd_client_event);

k_sem_take(&quit_lock, K_FOREVER);

0 comments on commit 08d10e1

Please sign in to comment.
You can’t perform that action at this time.