-
Notifications
You must be signed in to change notification settings - Fork 2k
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
leandrolanzieri
wants to merge
4
commits into
RIOT-OS:master
Choose a base branch
from
leandrolanzieri:pkg/wakaama/add_on_off_switch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+795
−3
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8b0a86f
pkg/wakaama/objects: add IPSO on/off switch
leandrolanzieri 2254a35
examples/lwm2m: add on/off switch object
leandrolanzieri 9c15ffa
fixup! pkg/wakaama/objects: add IPSO on/off switch
leandrolanzieri db3088d
fixup! examples/lwm2m: add on/off switch object
leandrolanzieri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,12 +26,13 @@ | |
#include "objects/device.h" | ||
#include "objects/security.h" | ||
#include "objects/light_control.h" | ||
#include "objects/on_off_switch.h" | ||
|
||
#include "credentials.h" | ||
|
||
#define LED_COLOR "FFFFFF" | ||
#define LED_APP_TYPE "LED 0" | ||
# define OBJ_COUNT (4) | ||
# define OBJ_COUNT (5) | ||
|
||
uint8_t connected = 0; | ||
lwm2m_object_t *obj_list[OBJ_COUNT]; | ||
|
@@ -67,6 +68,7 @@ | |
obj_list[1] = lwm2m_client_get_server_object(&client_data, CONFIG_LWM2M_SERVER_SHORT_ID); | ||
obj_list[2] = lwm2m_object_device_init(&client_data); | ||
obj_list[3] = lwm2m_object_light_control_init(&client_data); | ||
obj_list[4] = lwm2m_object_on_off_switch_init(&client_data); | ||
|
||
/* create light control object instance */ | ||
lwm2m_obj_light_control_args_t light_args = { | ||
|
@@ -83,6 +85,17 @@ | |
puts("Error instantiating light control"); | ||
} | ||
|
||
/* create on/off switch object instance */ | ||
lwm2m_obj_on_off_switch_args_t switch_args = { | ||
.app_type = "Switch 0", | ||
.app_type_len = sizeof("Switch 0") - 1 | ||
}; | ||
|
||
res = lwm2m_object_on_off_switch_instance_create(&switch_args, 0); | ||
if (res < 0) { | ||
puts("Error instantiating on/off switch"); | ||
} | ||
|
||
/* create security object instance */ | ||
lwm2m_obj_security_args_t security_args = { | ||
.server_id = CONFIG_LWM2M_SERVER_SHORT_ID, | ||
|
@@ -159,6 +172,25 @@ | |
return 0; | ||
} | ||
|
||
static int _parse_lwm2m_switch_cmd(int argc, char **argv) | ||
{ | ||
if (argc < 3) { | ||
printf("usage: %s switch <on|off>\n", argv[0]); | ||
return 1; | ||
} | ||
|
||
if (!connected) { | ||
puts("LwM2M client not connected"); | ||
return 1; | ||
} | ||
|
||
bool status = !strcmp(argv[2], "on"); | ||
lwm2m_object_on_off_switch_update_status(0, status); | ||
|
||
return 0; | ||
} | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: whitespace There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
int lwm2m_cli_cmd(int argc, char **argv) | ||
{ | ||
if (argc == 1) { | ||
|
@@ -182,12 +214,16 @@ | |
return _parse_lwm2m_light_cmd(argc, argv); | ||
} | ||
|
||
if (!strcmp(argv[1], "switch")) { | ||
return _parse_lwm2m_switch_cmd(argc, argv); | ||
} | ||
|
||
help_error: | ||
if (IS_ACTIVE(DEVELHELP)) { | ||
printf("usage: %s <start|mem|light>\n", argv[0]); | ||
printf("usage: %s <start|mem|light|switch>\n", argv[0]); | ||
} | ||
else { | ||
printf("usage: %s <start|light>\n", argv[0]); | ||
printf("usage: %s <start|light|switch>\n", argv[0]); | ||
} | ||
|
||
return 1; | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, if the <on|off> is optional (in which case the follow up printf should be changed to
[on|off]
imo)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed