Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/wakaama: add on off switch #21109

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
25 changes: 22 additions & 3 deletions examples/lwm2m/lwm2m_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,17 @@ void lwm2m_cli_init(void)
}
}

static void _print_usage_lwm2m_light_cmd(const char *cmd)
{
assert(cmd);
printf("usage: %s light <on|off> <dimmer> [color]\n", cmd);
}

static int _parse_lwm2m_light_cmd(int argc, char **argv)
{
if (argc < 4) {
printf("usage: %s light <on|off> <dimmer> [color]\n", argv[0]);
if (argc < 4 || argc > 5) {
printf("Error: invalid number of arguments\n");
_print_usage_lwm2m_light_cmd(argv[0]);
return 1;
}

Expand All @@ -156,7 +163,19 @@ static int _parse_lwm2m_light_cmd(int argc, char **argv)
return 1;
}

bool status = !strcmp(argv[2], "on");
bool status;
if (!strcmp(argv[2], "on")) {
mguetschow marked this conversation as resolved.
Show resolved Hide resolved
status = true;
}
else if (!strcmp(argv[2], "off")) {
status = false;
}
else {
printf("Error: light status can only be 'on' or 'off'\n");
_print_usage_lwm2m_light_cmd(argv[0]);
return 1;
}

uint8_t dimmer = atoi(argv[3]);

if (argc > 4) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/wakaama/contrib/objects/on_off_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "ztimer.h"
#include "ztimer/stopwatch.h"

#define ENABLE_DEBUG 1
#define ENABLE_DEBUG 0
#include "debug.h"

#define _USED_INSTANCES(_obj) (_obj.wakaama_object.instanceList)
Expand Down Expand Up @@ -72,7 +72,7 @@
* @return COAP_500_INTERNAL_SERVER_ERROR otherwise
*/
static uint8_t _write_cb(lwm2m_context_t * context, uint16_t instance_id, int num_data,
lwm2m_data_t * data_array, lwm2m_object_t * object, lwm2m_write_type_t write_type);

Check warning on line 75 in pkg/wakaama/contrib/objects/on_off_switch.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters

/**
* @brief Gets the current value of a resource from a given On/off switch object @p instance.
Expand Down Expand Up @@ -109,7 +109,7 @@
lwm2m_object_t wakaama_object; /**< Wakaama internal object */
mutex_t lock; /**< mutex for the instances access */
lwm2m_obj_on_off_switch_inst_t *free_instances; /**< list of free instances */
lwm2m_obj_on_off_switch_inst_t instances[CONFIG_LWM2M_ON_OFF_SWITCH_INSTANCES_MAX]; /**< instances */

Check warning on line 112 in pkg/wakaama/contrib/objects/on_off_switch.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
};

struct lwm2m_on_off_switch_object _on_off_switch_object = {
Expand Down Expand Up @@ -330,7 +330,7 @@
}

static uint8_t _write_cb(lwm2m_context_t * context, uint16_t instance_id, int num_data,
lwm2m_data_t * data_array, lwm2m_object_t * object, lwm2m_write_type_t write_type)

Check warning on line 333 in pkg/wakaama/contrib/objects/on_off_switch.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
{
(void)context;
(void)write_type;
Expand Down Expand Up @@ -377,7 +377,6 @@
lwm2m_resource_value_changed(client_data->lwm2m_ctx, &uri);
}


lwm2m_object_t *lwm2m_object_on_off_switch_init(lwm2m_client_data_t *client_data)
{
assert(client_data);
Expand Down
Loading