On/Off switch object implementation for LwM2M client using Wakaama.
More...
On/Off switch object implementation for LwM2M client using Wakaama.
- Warning
- This feature is experimental!
This API is considered experimental and may change in future releases without deprecation process.
This implements the LwM2M IPSO on/off switch object (ID 3342) as specified in the LwM2M registry.
This IPSO object should be used with an On/Off switch to report the state of the switch.
To use this object add USEMODULE += wakaama_objects_on_off_switch
to the application Makefile.
Resources
For an XML description of the object see https://raw.githubusercontent.com/OpenMobileAlliance/lwm2m-registry/prod/3342.xml
Name | ID | Mandatory | Type | Range | Units | Implemented |
Digital Input State | 5500 | Yes | Boolean | - | - | Yes |
Digital Input Counter | 5501 | No | Integer | - | - | Yes |
On time | 5852 | No | Integer | - | s | Yes |
Off Time | 5854 | No | Integer | - | s | Yes |
Application Type | 5750 | No | String | - | - | Yes |
Usage
- Initialize the LwM2M client with lwm2m_object_on_off_switch_init, by passing a pointer to the LwM2M client data.
- Now you can create instances of the on/off switch object with lwm2m_object_on_off_switch_instance_create.
#define APP_TYPE "BTN 0"
lwm2m_object_t *on_off_switch;
.app_type_len = sizeof(APP_TYPE) - 1
};
void lwm2m_client_init(lwm2m_client_data_t *client_data)
Initializes a LwM2M client.
int lwm2m_object_on_off_switch_instance_create(const lwm2m_obj_on_off_switch_args_t *args, int32_t instance_id)
Create a new on/off switch instance and add it to the object list.
lwm2m_object_t * lwm2m_object_on_off_switch_init(lwm2m_client_data_t *client_data)
Initialize the on/off switch object.
Arguments for the creation of an on/off switch object instance.
const char * app_type
Array of chars with the app type.
- You can update the status and app_type of the on/off switch instance with lwm2m_object_on_off_switch_update_status and lwm2m_object_on_off_switch_update_app_type respectively. As this will make sure to send notifications to servers that may be observing these resources, avoid calling them from interrupt contexts.
int lwm2m_object_on_off_switch_update_app_type(uint16_t instance_id, const char *app_type, size_t len)
Update the application type of a on/off switch instance.
◆ lwm2m_object_on_off_switch_init()
Initialize the on/off switch object.
- Parameters
-
[in] | client_data | LwM2M client data. |
- Returns
- Pointer to the On/Off switch object on success
◆ lwm2m_object_on_off_switch_instance_create()
Create a new on/off switch instance and add it to the object
list.
- Parameters
-
[in] | args | Initialize structure with the parameter for the instance. Must not be NULL. |
[in] | instance_id | ID for the new instance. It must be between 0 and (UINT16_MAX - 1), if -1 the next available ID will be used. |
- Returns
- 0 on success
-
-EINVAL if an invalid
instance_id
is given
-
-ENOMEM if no memory is available to create a new instance
◆ lwm2m_object_on_off_switch_update_app_type()
int lwm2m_object_on_off_switch_update_app_type |
( |
uint16_t |
instance_id, |
|
|
const char * |
app_type, |
|
|
size_t |
len |
|
) |
| |
Update the application type of a on/off switch instance.
- Parameters
-
[in] | instance_id | ID of the instance to update. |
[in] | app_type | String representing new application type. Must be NULL terminated, must not be NULL. |
[in] | len | Length of the app_type string. |
- Returns
- 0 on success
-
-EINVAL if the instance does not exist
-
-ENOBUFS if the app_type string is too long (size > CONFIG_LWM2M_ON_OFF_SWITCH_APP_TYPE_MAX_SIZE)
◆ lwm2m_object_on_off_switch_update_status()
int lwm2m_object_on_off_switch_update_status |
( |
uint16_t |
instance_id, |
|
|
bool |
status |
|
) |
| |
Update the status of a on/off switch instance.
- Parameters
-
[in] | instance_id | ID of the instance to update. |
[in] | status | New status of the switch. |
- Returns
- 0 on success
-
-EINVAL if the instance does not exist