Loading...
Searching...
No Matches

Illuminance Sensor object implementation for LwM2M client using Wakaama. More...

Detailed Description

Illuminance Sensor object implementation for LwM2M client using Wakaama.

Warning
This feature is experimental!
This implements the LwM2M Illuminance Sensor object (ID 3301) as specified in the LwM2M registry.

The sensor value can be updated by the application using the lwm2m_object_illuminance_update_value function, or polled when required if a callback is registered upon object instantiation via lwm2m_obj_illuminance_args_t::read_cb.

To use this object add USEMODULE += wakaama_objects_illuminance to the application Makefile.

Resources

For an XML description of the object see https://raw.githubusercontent.com/OpenMobileAlliance/lwm2m-registry/prod/version_history/3301-1_0.xml

This object is based on the IPSO Sensor base object, therefore it shares the same resources.

Usage

  1. Initialize the LwM2M object with an initialized client pointer.
lwm2m_object_t *obj = lwm2m_object_illuminance_init(&client_data);
lwm2m_object_t * lwm2m_object_illuminance_init(lwm2m_client_data_t *client_data)
Initialize the Illuminance Sensor object handle.
  1. Create a new instance of the object with a given configuration (lwm2m_obj_illuminance_args_t). Here, you can decide the way of updating the sensor values: polling or pushing. In this case, we register a callback function that is called whenever the sensor value is read.
// callback function to read the sensor value
int _read_cb(void *arg, int16_t *value)
{
(void)arg;
// generate new value
*value = 100;
return 0;
}
// initialize an instance of illuminance sensor object
const lwm2m_obj_illuminance_args_t illuminance_args = {
.max_range_value = 4000.0,
.units = "lx",
.units_len = sizeof("lx") - 1,
.instance_id = 0,
.read_cb = _read_cb,
.read_cb_arg = NULL
};
int32_t res = lwm2m_object_illuminance_instance_create(&illuminance_args);
if (res < 0) {
puts("Could not create illuminance object instance");
}
int32_t lwm2m_object_illuminance_instance_create(const lwm2m_obj_illuminance_args_t *args)
Create a new Illuminance Sensor instance.
Arguments for the creation of an object based on the IPSO Sensor Base object instance.
int16_t min_range_value
Minimum value that can be measured by the sensor.
  1. You can now update the sensor values using the lwm2m_object_illuminance_update_value function.
uint16_t instance_id = (uint16_t)res;
lwm2m_object_illuminance_update_value(&client_data, instance_id, new_value);
void lwm2m_object_illuminance_update_value(const lwm2m_client_data_t *client_data, uint16_t instance_id, int16_t value)
Update the value of the illuminance sensor and trigger a notification to the observing servers,...

Modules

 LwM2M Illuminance Sensor object compile configurations
 

Files

file  illuminance.h
 

Macros

#define LWM2M_ILLUMINANCE_OBJECT_ID   3301
 LwM2M Illuminance Sensor object ID.
 

Typedefs

typedef lwm2m_obj_ipso_base_sensor_args_t lwm2m_obj_illuminance_args_t
 Arguments for the creation of a Illuminance Sensor object instance.
 

Functions

lwm2m_object_t * lwm2m_object_illuminance_init (lwm2m_client_data_t *client_data)
 Initialize the Illuminance Sensor object handle.
 
int32_t lwm2m_object_illuminance_instance_create (const lwm2m_obj_illuminance_args_t *args)
 Create a new Illuminance Sensor instance.
 
void lwm2m_object_illuminance_update_value (const lwm2m_client_data_t *client_data, uint16_t instance_id, int16_t value)
 Update the value of the illuminance sensor and trigger a notification to the observing servers, if any.
 

Macro Definition Documentation

◆ LWM2M_ILLUMINANCE_OBJECT_ID

#define LWM2M_ILLUMINANCE_OBJECT_ID   3301

LwM2M Illuminance Sensor object ID.

Definition at line 115 of file illuminance.h.

Typedef Documentation

◆ lwm2m_obj_illuminance_args_t

Arguments for the creation of a Illuminance Sensor object instance.

Definition at line 120 of file illuminance.h.

Function Documentation

◆ lwm2m_object_illuminance_init()

lwm2m_object_t * lwm2m_object_illuminance_init ( lwm2m_client_data_t client_data)

Initialize the Illuminance Sensor object handle.

Parameters
[in]client_dataPointer to the LwM2M client data.
Returns
Pointer to the global handle of the Illuminance Sensor object.

◆ lwm2m_object_illuminance_instance_create()

int32_t lwm2m_object_illuminance_instance_create ( const lwm2m_obj_illuminance_args_t args)

Create a new Illuminance Sensor instance.

Parameters
[in]argsInitialize structure with the parameter for the instance. Must not be NULL.
Returns
> 0 value representing the instance ID if the instance was created successfully.
<0 otherwise

◆ lwm2m_object_illuminance_update_value()

void lwm2m_object_illuminance_update_value ( const lwm2m_client_data_t client_data,
uint16_t  instance_id,
int16_t  value 
)

Update the value of the illuminance sensor and trigger a notification to the observing servers, if any.

Parameters
[in]client_dataPointer to the LwM2M client.
[in]instance_idID of the instance to update.
[in]valueNew value for the sensor.