Skip to content

Commit

Permalink
examples/wakaama: use light control object when LED0 is present
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrolanzieri committed Mar 18, 2021
1 parent cbf1226 commit 544daf4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/wakaama/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ SERVER_URI ?= '"coap://[fd00:dead:beef::1]"'

# NOTE: Add the package for wakaama
USEPKG += wakaama
USEMODULE += wakaama_objects_light_control
# Uncomment to enable Wakaama debug log
#CFLAGS += -DCONFIG_LWM2M_WITH_LOGS=1

Expand Down
47 changes: 45 additions & 2 deletions examples/wakaama/lwm2m_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,38 @@
#include "lwm2m_client.h"
#include "lwm2m_client_objects.h"
#include "lwm2m_platform.h"
#include "objects/light_control.h"

#define OBJ_COUNT (3)
#ifdef LED0_ON
#define LED_COLOR "Unknown"
#define LED_APP_TYPE "LED 0"
# define OBJ_COUNT (4)
#else
# define OBJ_COUNT (3)
#endif

uint8_t connected = 0;
lwm2m_object_t *obj_list[OBJ_COUNT];
lwm2m_client_data_t client_data;

#ifdef LED0_ON
void _led_cb(lwm2m_object_t *object, uint16_t instance_id, bool status, uint8_t dimmer, void *arg)
{
(void)object;
(void)instance_id;
(void)arg;

printf("Current dimmer value: %d%%\n", dimmer);

if (status) {
LED0_ON;
}
else {
LED0_OFF;
}
}
#endif

void lwm2m_cli_init(void)
{
/* this call is needed before creating any objects */
Expand All @@ -38,6 +63,24 @@ void lwm2m_cli_init(void)
obj_list[1] = lwm2m_client_get_server_object(&client_data);
obj_list[2] = lwm2m_client_get_device_object(&client_data);

#ifdef LED0_ON
obj_list[3] = lwm2m_object_light_control_get();
lwm2m_obj_light_control_args_t args = {
.cb = _led_cb,
.cb_arg = NULL,
.color = LED_COLOR,
.color_len = sizeof(LED_COLOR) - 1,
.app_type = LED_APP_TYPE,
.app_type_len = sizeof(LED_APP_TYPE) - 1
};

int res = lwm2m_object_light_control_instance_create(obj_list[3], 0, &args);

if (res < 0) {
puts("Error instantiating light control");
}
#endif

if (!obj_list[0] || !obj_list[1] || !obj_list[2]) {
puts("Could not create mandatory objects");
}
Expand All @@ -57,7 +100,7 @@ int lwm2m_cli_cmd(int argc, char **argv)
return 0;
}

if (IS_ACTIVE(DEVELHELP) && !strcmp(argv[1],"mem")) {
if (IS_ACTIVE(DEVELHELP) && !strcmp(argv[1], "mem")) {
lwm2m_tlsf_status();
return 0;
}
Expand Down

0 comments on commit 544daf4

Please sign in to comment.