Mistake on this page? Email us

Objects

Types

There are three types of objects:

  • Device object.
  • Security object.
  • Custom object.

Creating objects

Use the M2MObject class to create and configure objects of all types.

Tip: The M2MObject class is derived from the M2MBase class, so you can use all the public methods from M2MBase and its derived classes.

  • To create a device object (there can be only one instance of M2MDevice):

    static M2MDevice* create_device();
    
  • To create a security object:

    static M2MSecurity* create_security(M2MSecurity::ServerType server_type);
    
  • You can create a Bootstrap or normal object by passing the appropriate enum value.

  • For a custom object, you need to pass the name of the object that you would like to create (for example, 3303):

    static M2MObject* create_object(const String &name);
    

Deleting objects

To delete a device object:

M2MDevice::delete_instance();

Creating object instances

Each object - device, security and custom - can have an object instance. Each device and security object can only have one instance associated with it, so creating an object automatically creates the object instance.

Use M2MObjectInstance to create an object Instance for a custom object.

Tip: The M2MObjectInstance class is derived from the M2MBase class, so you can use all the public methods from M2MObjectInstance and its derived classes.

Custom object instances need IDs. The object instance structure on Device Management Connect is Object/Object_Instance_ID, where the ID starts at 0 and increments. When you create an object instance, you need to pass the ID that you want to assign it. For example, if you pass 0 to an object called 3303, you get the Instance /3303/0 on Device Management Connect:

M2MObject::create_object_instance(uint16_t instance_id);

M2MObjectInstance* object_instance = _object->create_object_instance(0);
 if(object_instance) {
     object_instance->set_register_uri(true);  // The registration message explicitly sends this object instance path as registered resource such as /3303/0.
 }

Configuring an object or object instance

Once you have created an object or object instance (of any type), you can configure various parameters in it to control or modify communication with Device Management Connect:

M2MObject* _object = M2MInterfaceFactory::create_object("3303");
 if(_object) {
 _object->set_register_uri(true); // The registration message explicitly sends this object path as registered resource such as /3303.
 }

Object and object instances can have many parameters; we review only the most important ones, which you must configure properly to work with the objects or object instances.

Setting the operation mode

Setting the operation mode of an object or object instance determines which Device Management Connect requests it can handle: GET, PUT, POST and DELETE.

For an object:

virtual void set_operation(M2MBase::Operation operation);
_object->set_operation(M2MBase::GET_PUT_POST_ALLOWED); // This defines the REST operations that can be performed on this object. In this case, GET, PUT and POST are allowed; since DELETE is not listed, it is not allowed

For an object instance:

virtual void set_operation(M2MBase::Operation operation);
object_instance->set_operation(M2MBase::GET_PUT_DELETE_ALLOWED); // This defines the REST operations that can be performed on this object instance. In this case, GET, PUT and DELTE are allowed; since POST is not listed, it is not allowed

Setting the observable mode

By default, objects and object instances are not observable. You can set them to be observable, or change them back to not observable.

  • For an object:

    virtual void set_observable(bool observable);
    
    _object->set_observable(true); // The object can be observed from the server.
    _object->set_observable(false); // The object cannot be observed from the server.
    
  • For an object instance:

    virtual void set_observable(bool observable);
    
    _object_instance->set_observable(true); // The object instance can be observed from the server.
    _object_instance->set_observable(false); // The object instance cannot be observed from the server.
    

Setting the CoAP content type

Currently, the only available content type is the OMA TLV type. In future releases, we will introduce support for the JSON content types.

The OMA TLV type works only for objects and object instances with a numeric value. For example, if you are creating a custom object, it must be of a numeric type, such as 100.

  • For an object:

    M2MObject* _object = M2MInterfaceFactory::create_object("100");
    
  • For an object instance:

    M2MObject* _object = M2MInterfaceFactory::create_object("100");
    M2MObjectInstance * object_instance = _object->create_object_instance(0);
    

By default, Device Management Client assigns the CoAP content type of 11542 to all the numeric objects. If you want to assign any other CoAP content type, for example 120, you can set the object's CoAP content type:

  • For an object:

    virtual void set_coap_content_type(const uint8_t content_type);
    _object->set_coap_content_type(120);
    
  • For an object instance:

    virtual void set_coap_content_type(const uint8_t content_type);
    object_instance->set_coap_content_type(120);