Documentation

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 Device Management Connect 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);