Skip to content

Commit

Permalink
Merge pull request #20652 from leandrolanzieri/dev/lwm2m/ipso_objects
Browse files Browse the repository at this point in the history
pkg/wakaama: implement IPSO sensor objects in LwM2M
  • Loading branch information
leandrolanzieri authored Jun 7, 2024
2 parents dd6051c + 3d96491 commit 7a2b08f
Show file tree
Hide file tree
Showing 18 changed files with 2,092 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/wakaama/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ config LWM2M_DTLS_PORT

endmenu # Remote server

rsource "contrib/objects/Kconfig"

config LWM2M_DEVICE_TTL
int "Lifetime of the device"
default 300
Expand Down Expand Up @@ -60,6 +62,4 @@ config LWM2M_BOOTSTRAP
help
Say y to support using a bootstrap server to get server information.

rsource "contrib/objects/Kconfig"

endmenu # Wakaama LwM2M
25 changes: 25 additions & 0 deletions pkg/wakaama/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,31 @@ USEMODULE += wakaama_objects
USEMODULE += wakaama_objects_device
USEMODULE += wakaama_objects_security


ifneq (,$(filter wakaama_objects_barometer,$(USEMODULE)))
USEMODULE += wakaama_objects_ipso_sensor_base
endif

ifneq (,$(filter wakaama_objects_current,$(USEMODULE)))
USEMODULE += wakaama_objects_ipso_sensor_base
endif

ifneq (,$(filter wakaama_objects_humidity,$(USEMODULE)))
USEMODULE += wakaama_objects_ipso_sensor_base
endif

ifneq (,$(filter wakaama_objects_illuminance,$(USEMODULE)))
USEMODULE += wakaama_objects_ipso_sensor_base
endif

ifneq (,$(filter wakaama_objects_temperature,$(USEMODULE)))
USEMODULE += wakaama_objects_ipso_sensor_base
endif

ifneq (,$(filter wakaama_objects_voltage,$(USEMODULE)))
USEMODULE += wakaama_objects_ipso_sensor_base
endif

USEMODULE += ztimer
USEMODULE += ztimer_sec
USEPKG += tlsf
Expand Down
5 changes: 5 additions & 0 deletions pkg/wakaama/contrib/objects/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
# directory for more details.
#

menu "LwM2M objects"

rsource "Kconfig.device"
rsource "Kconfig.security"
rsource "Kconfig.ipso"
rsource "Kconfig.light_control"

endmenu
62 changes: 62 additions & 0 deletions pkg/wakaama/contrib/objects/Kconfig.ipso
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
menu "IPSO sensor objects"
depends on USEMODULE_WAKAAMA_OBJECTS_IPSO_SENSOR_BASE

config LWM2M_IPSO_SENSOR_BASE_UNITS_MAX_SIZE
int "Maximum size of strings representing units"
default 4

menu "IPSO barometer object"
depends on USEMODULE_WAKAAMA_OBJECTS_BAROMETER

config LWM2M_BAROMETER_INSTANCES_MAX
int "Maximum number of barometer object instances"
default 1

endmenu

menu "IPSO current object"
depends on USEMODULE_WAKAAMA_OBJECTS_CURRENT

config LWM2M_CURRENT_INSTANCES_MAX
int "Maximum number of current object instances"
default 1

endmenu

menu "IPSO humidity object"
depends on USEMODULE_WAKAAMA_OBJECTS_HUMIDITY

config LWM2M_HUMIDITY_INSTANCES_MAX
int "Maximum number of humidity object instances"
default 1

endmenu

menu "IPSO illuminance object"
depends on USEMODULE_WAKAAMA_OBJECTS_ILLUMINANCE

config LWM2M_ILLUMINANCE_INSTANCES_MAX
int "Maximum number of illuminance object instances"
default 1

endmenu

menu "IPSO temperature object"
depends on USEMODULE_WAKAAMA_OBJECTS_TEMPERATURE

config LWM2M_TEMPERATURE_INSTANCES_MAX
int "Maximum number of temperature object instances"
default 1

endmenu

menu "IPSO voltage object"
depends on USEMODULE_WAKAAMA_OBJECTS_VOLTAGE

config LWM2M_VOLTAGE_INSTANCES_MAX
int "Maximum number of voltage object instances"
default 1

endmenu

endmenu # "IPSO objects"
68 changes: 68 additions & 0 deletions pkg/wakaama/contrib/objects/barometer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (C) 2024 HAW Hamburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @{
* @ingroup lwm2m_objects_barometer
*
* @file
* @brief Barometer object implementation for LwM2M client using Wakaama
*
* @author Leandro Lanzieri <[email protected]>
* @}
*/

#include "liblwm2m.h"
#include "lwm2m_client.h"
#include "objects/barometer.h"
#include "objects/ipso_sensor_base.h"

#define ENABLE_DEBUG 0
#include "debug.h"

/**
* @brief Barometer object implementation descriptor.
*/
static lwm2m_obj_ipso_sensor_base_t _barometer_object;

/**
* @brief Pool of object instances.
*/
static lwm2m_obj_ipso_sensor_base_inst_t _instances[CONFIG_LWM2M_BAROMETER_INSTANCES_MAX];

lwm2m_object_t *lwm2m_object_barometer_init(lwm2m_client_data_t *client_data)
{
assert(client_data);
int res = lwm2m_object_ipso_sensor_base_init_derived(client_data, &_barometer_object,
LWM2M_BAROMETER_OBJECT_ID,
_instances,
CONFIG_LWM2M_BAROMETER_INSTANCES_MAX);

if (res) {
DEBUG("[lwm2m:barometer]: failed to create object\n");
return NULL;
}

return &_barometer_object.object;
}

int32_t lwm2m_object_barometer_instance_create(const lwm2m_obj_barometer_args_t *args)
{
int32_t result = lwm2m_object_ipso_sensor_base_instance_create(&_barometer_object, args);

if (result) {
DEBUG("[lwm2m:barometer]: failed to create instance\n");
}

return result;
}

void lwm2m_object_barometer_update_value(const lwm2m_client_data_t *client_data,
uint16_t instance_id, int16_t value)
{
lwm2m_object_ipso_sensor_base_update_value(client_data, &_barometer_object, instance_id, value);
}
68 changes: 68 additions & 0 deletions pkg/wakaama/contrib/objects/current.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (C) 2024 HAW Hamburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @{
* @ingroup lwm2m_objects_current
*
* @file
* @brief Current sensor object implementation for LwM2M client using Wakaama
*
* @author Leandro Lanzieri <[email protected]>
* @}
*/

#include "liblwm2m.h"
#include "lwm2m_client.h"
#include "objects/current.h"
#include "objects/ipso_sensor_base.h"

#define ENABLE_DEBUG 0
#include "debug.h"

/**
* @brief Current Sensor object implementation descriptor.
*/
static lwm2m_obj_ipso_sensor_base_t _current_object;

/**
* @brief Pool of object instances.
*/
static lwm2m_obj_ipso_sensor_base_inst_t _instances[CONFIG_LWM2M_CURRENT_INSTANCES_MAX];

lwm2m_object_t *lwm2m_object_current_init(lwm2m_client_data_t *client_data)
{
assert(client_data);
int res = lwm2m_object_ipso_sensor_base_init_derived(client_data, &_current_object,
LWM2M_CURRENT_OBJECT_ID,
_instances,
CONFIG_LWM2M_CURRENT_INSTANCES_MAX);

if (res) {
DEBUG("[lwm2m:current]: failed to create object\n");
return NULL;
}

return &_current_object.object;
}

int32_t lwm2m_object_current_instance_create(const lwm2m_obj_current_args_t *args)
{
int32_t result = lwm2m_object_ipso_sensor_base_instance_create(&_current_object, args);

if (result) {
DEBUG("[lwm2m:current]: failed to create instance\n");
}

return result;
}

void lwm2m_object_current_update_value(const lwm2m_client_data_t *client_data, uint16_t instance_id,
int16_t value)
{
lwm2m_object_ipso_sensor_base_update_value(client_data, &_current_object, instance_id, value);
}
69 changes: 69 additions & 0 deletions pkg/wakaama/contrib/objects/humidity.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (C) 2024 HAW Hamburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @{
* @ingroup lwm2m_objects_humidity
*
* @file
* @brief Humidity Sensor object implementation for LwM2M client using Wakaama
*
* @author Leandro Lanzieri <[email protected]>
* @}
*/

#include "mutex.h"
#include "liblwm2m.h"
#include "lwm2m_client.h"
#include "objects/humidity.h"
#include "objects/ipso_sensor_base.h"

#define ENABLE_DEBUG 1
#include "debug.h"

/**
* @brief Humidity Sensor object implementation descriptor.
*/
static lwm2m_obj_ipso_sensor_base_t _humidity_object;

/**
* @brief Pool of object instances.
*/
static lwm2m_obj_ipso_sensor_base_inst_t _instances[CONFIG_LWM2M_HUMIDITY_INSTANCES_MAX];

lwm2m_object_t *lwm2m_object_humidity_init(lwm2m_client_data_t *client_data)
{
assert(client_data);
int res = lwm2m_object_ipso_sensor_base_init_derived(client_data, &_humidity_object,
LWM2M_HUMIDITY_OBJECT_ID,
_instances,
CONFIG_LWM2M_HUMIDITY_INSTANCES_MAX);

if (res) {
DEBUG("[lwm2m:humidity]: failed to create object\n");
return NULL;
}

return &_humidity_object.object;
}

int32_t lwm2m_object_humidity_instance_create(const lwm2m_obj_humidity_args_t *args)
{
int32_t result = lwm2m_object_ipso_sensor_base_instance_create(&_humidity_object, args);

if (result) {
DEBUG("[lwm2m:humidity]: failed to create instance\n");
}

return result;
}

void lwm2m_object_humidity_update_value(const lwm2m_client_data_t *client_data,
uint16_t instance_id, int16_t value)
{
lwm2m_object_ipso_sensor_base_update_value(client_data, &_humidity_object, instance_id, value);
}
Loading

0 comments on commit 7a2b08f

Please sign in to comment.