Loading...
Searching...
No Matches

On/Off switch object implementation for LwM2M client using Wakaama. More...

Detailed Description

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

  1. Initialize the LwM2M client with lwm2m_object_on_off_switch_init, by passing a pointer to the LwM2M client data.
  2. 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;
lwm2m_client_data_t client_data;
lwm2m_client_init(&client_data);
on_off_switch = lwm2m_object_on_off_switch_init(&client_data);
.app_type = APP_TYPE,
.app_type_len = sizeof(APP_TYPE) - 1
};
void lwm2m_client_init(lwm2m_client_data_t *client_data)
Initializes a LwM2M client.
struct lwm2m_obj_on_off_switch_args lwm2m_obj_on_off_switch_args_t
Arguments for the creation of an on/off switch object instance.
lwm2m_object_t * lwm2m_object_on_off_switch_init(lwm2m_client_data_t *client_data)
Initialize the on/off switch object.
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 client descriptor.
  1. 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.

Topics

 LwM2M On/Off switch object compile configurations
 

Files

file  on_off_switch.h
 

Data Structures

struct  lwm2m_obj_on_off_switch_args
 Arguments for the creation of an on/off switch object instance. More...
 

Macros

#define LWM2M_ON_OFF_SWITCH_OBJECT_ID   3342
 On/Off switch object ID.
 

Typedefs

typedef struct lwm2m_obj_on_off_switch_args lwm2m_obj_on_off_switch_args_t
 Arguments for the creation of an on/off switch object instance.
 

Functions

lwm2m_object_t * lwm2m_object_on_off_switch_init (lwm2m_client_data_t *client_data)
 Initialize the on/off switch object.
 
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.
 
int lwm2m_object_on_off_switch_update_status (uint16_t instance_id, bool status)
 Update the status of a on/off switch instance.
 
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.
 

On/Off switch object resource's IDs.

#define LWM2M_ON_OFF_SWITCH_DIGITAL_INPUT_STATE_ID   5500
 Digital input state esource ID.
 
#define LWM2M_ON_OFF_SWITCH_DIGITAL_INPUT_COUNTER_ID   5501
 Digital Input Counter resource ID.
 
#define LWM2M_ON_OFF_SWITCH_ON_TIME_ID   5852
 On Time resource ID.
 
#define LWM2M_ON_OFF_SWITCH_OFF_TIME_ID   5854
 Off Time resource ID.
 
#define LWM2M_ON_OFF_SWITCH_APP_TYPE_ID   5750
 Application type resource ID.
 

Macro Definition Documentation

◆ LWM2M_ON_OFF_SWITCH_APP_TYPE_ID

#define LWM2M_ON_OFF_SWITCH_APP_TYPE_ID   5750

Application type resource ID.

Definition at line 138 of file on_off_switch.h.

◆ LWM2M_ON_OFF_SWITCH_DIGITAL_INPUT_COUNTER_ID

#define LWM2M_ON_OFF_SWITCH_DIGITAL_INPUT_COUNTER_ID   5501

Digital Input Counter resource ID.

Definition at line 126 of file on_off_switch.h.

◆ LWM2M_ON_OFF_SWITCH_DIGITAL_INPUT_STATE_ID

#define LWM2M_ON_OFF_SWITCH_DIGITAL_INPUT_STATE_ID   5500

Digital input state esource ID.

Definition at line 122 of file on_off_switch.h.

◆ LWM2M_ON_OFF_SWITCH_OBJECT_ID

#define LWM2M_ON_OFF_SWITCH_OBJECT_ID   3342

On/Off switch object ID.

Definition at line 113 of file on_off_switch.h.

◆ LWM2M_ON_OFF_SWITCH_OFF_TIME_ID

#define LWM2M_ON_OFF_SWITCH_OFF_TIME_ID   5854

Off Time resource ID.

Definition at line 134 of file on_off_switch.h.

◆ LWM2M_ON_OFF_SWITCH_ON_TIME_ID

#define LWM2M_ON_OFF_SWITCH_ON_TIME_ID   5852

On Time resource ID.

Definition at line 130 of file on_off_switch.h.

Function Documentation

◆ lwm2m_object_on_off_switch_init()

lwm2m_object_t * lwm2m_object_on_off_switch_init ( lwm2m_client_data_t * client_data)

Initialize the on/off switch object.

Parameters
[in]client_dataLwM2M client data.
Returns
Pointer to the On/Off switch object on success

◆ lwm2m_object_on_off_switch_instance_create()

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.

Parameters
[in]argsInitialize structure with the parameter for the instance. Must not be NULL.
[in]instance_idID 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_idID of the instance to update.
[in]app_typeString representing new application type. Must be NULL terminated, must not be NULL.
[in]lenLength 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_idID of the instance to update.
[in]statusNew status of the switch.
Returns
0 on success
-EINVAL if the instance does not exist