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 2 commits into
base: master
Choose a base branch
from

Conversation

leandrolanzieri
Copy link
Contributor

Contribution description

This adds a simple on/off switch object to the supported LwM2M objects: Object 3342. From the specs:

This IPSO object should be used with an On/Off switch to report the state of the switch.

switch

Testing procedure

Use the lwm2m example, the 'switch' can be controlled via shell.

Issues/PRs references

None

@github-actions github-actions bot added Area: pkg Area: External package ports Area: examples Area: Example Applications labels Dec 25, 2024
@leandrolanzieri leandrolanzieri changed the title Pkg/wakaama/add on off switch pkg/wakaama: add on off switch Dec 25, 2024
@leandrolanzieri leandrolanzieri added the Type: new feature The issue requests / The PR implemements a new feature for RIOT label Dec 25, 2024
@leandrolanzieri leandrolanzieri added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Dec 25, 2024
@leandrolanzieri leandrolanzieri force-pushed the pkg/wakaama/add_on_off_switch branch from 3621c59 to 2254a35 Compare December 25, 2024 10:48
@riot-ci
Copy link

riot-ci commented Dec 25, 2024

Murdock results

✔️ PASSED

2254a35 examples/lwm2m: add on/off switch object

Success Failures Total Runtime
10249 0 10249 17m:57s

Artifacts

Copy link
Contributor

@Teufelchen1 Teufelchen1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👁️ 👁️

@@ -159,6 +172,25 @@ static int _parse_lwm2m_light_cmd(int argc, char **argv)
return 0;
}

static int _parse_lwm2m_switch_cmd(int argc, char **argv)
{
if (argc < 3) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (argc < 3) {
if (argc != 3) {

Or, if the <on|off> is optional (in which case the follow up printf should be changed to [on|off] imo)

Suggested change
if (argc < 3) {
if ((argc != 3) && (argc != 2)) {

return 0;
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: whitespace

Comment on lines +38 to +41
bool status; /**< digital input status */
uint32_t counter; /**< counter for the digital input */
ztimer_stopwatch_t stopwatch; /**< stopwatch for time periods */
char app_type[CONFIG_LWM2M_ON_OFF_SWITCH_APP_TYPE_MAX_SIZE]; /**< application type */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool status; /**< digital input status */
uint32_t counter; /**< counter for the digital input */
ztimer_stopwatch_t stopwatch; /**< stopwatch for time periods */
char app_type[CONFIG_LWM2M_ON_OFF_SWITCH_APP_TYPE_MAX_SIZE]; /**< application type */
bool status; /**< wether the switch is on or off */
uint32_t counter; /**< how often the switch was flipped */
ztimer_stopwatch_t stopwatch; /**< ??? How long the switch was on ? */
char app_type[CONFIG_LWM2M_ON_OFF_SWITCH_APP_TYPE_MAX_SIZE]; /**< application type */

* @return COAP_404_NOT_FOUND if the instance was not found
* @return COAP_500_INTERNAL_SERVER_ERROR otherwise
*/
static uint8_t _read_cb(lwm2m_context_t * context, uint16_t instance_id, int * num_data,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It bugs me that the return type is uint8_t instead of e.g. lwm2m_cb_result_t. But I don't think it is up to you to change?

Comment on lines +158 to +159
static uint8_t _read_cb(lwm2m_context_t * context, uint16_t instance_id, int * num_data,
lwm2m_data_t ** data_array, lwm2m_object_t * object)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How sure are you that the pointer, in this cb and the write_cb, can not be NULL? If you have doubt, please add asserts or additional checks.

break;
}

case LWM2M_ON_OFF_SWITCH_APP_TYPE_ID:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clarify to me why we have this functionality here and lower in the lwm2m_object_on_off_switch_update_app_type()? It's not a drop-in replacement due to the mutex tho.

}

for (int i = 0; i < num_data && result == COAP_204_CHANGED; i++) {
switch (data_array[i].id) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no default case. Does it matter?

Comment on lines +323 to +324
client_data = (lwm2m_client_data_t *)_on_off_switch_object.wakaama_object.userData;
lwm2m_resource_value_changed(client_data->lwm2m_ctx, &uri);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client_data might be NULL!

Comment on lines +328 to +330
lwm2m_object_t *lwm2m_object_on_off_switch_init(lwm2m_client_data_t *client_data)
{
/* initialize the instances */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lwm2m_object_t *lwm2m_object_on_off_switch_init(lwm2m_client_data_t *client_data)
{
/* initialize the instances */
lwm2m_object_t *lwm2m_object_on_off_switch_init(lwm2m_client_data_t *client_data)
{
assert(client_data);
/* initialize the instances */

Alternatively, ensure all code can handle NULL in the field.

/* if app is specified, copy locally */
if (args->app_type) {
if (args->app_type_len > CONFIG_LWM2M_ON_OFF_SWITCH_APP_TYPE_MAX_SIZE) {
DEBUG("[lwm2m:on_off_switch]: not enough space for app_type string\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DEBUG("[lwm2m:on_off_switch]: not enough space for app_type string\n");
DEBUG("[lwm2m:on_off_switch]: not enough space for app_type string, got %d but max is %d\n", args->app_type_len, CONFIG_LWM2M_ON_OFF_SWITCH_APP_TYPE_MAX_SIZE -1);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: examples Area: Example Applications Area: pkg Area: External package ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants