Skip to main content
Jump to: navigation, search

OM2M/one/MQTT Binding

< OM2M‎ | one

The Eclipse OM2M MQTT Binding implements the TS-0010 MQTT Protocol Binding defined by the oneM2M consortium. The document is available on the oneM2M website. The Eclipse Paho library has been used as a MQTT Client for the Eclipse OM2M MQTT Binding.

Configuration

Broker

The OM2M MQTT Binding does NOT include the MQTT Broker. The use of the MQTT binding requires to use an external MQTT Broker. For instance, the Eclipse Mosquitto broker can be used (available at: Mosquitto Website).

Constants

The following constants can be specified in the OM2M product (org.eclipse.om2m.site.*-cse projects) or directly in the config.ini file in the compiled product (under the configuration folder).

Constant value Usage Default value
org.eclipse.om2m.mqtt.ip Broker Host name or IP localhost
org.eclipse.om2m.mqtt.port Broker Port 1883
org.eclipse.om2m.mqtt.username Broker username (optional) null
org.eclipse.om2m.mqtt.password Broker password (optional) null
org.eclipse.om2m.mqtt.timeout Binding request timeout for the client (second) 20

Start the binding

At first, the binding is not started in the org.eclipse.om2m.site.in-cse product. To start it, one must retrieve the bundleId of the MQTT binding plugin using the ss mqtt and then start it using the command start <bundleId>. Otherwise, it can be set as auto-start into the OM2M product.

oneM2M Requests

oneM2M defines a request/response paradigm to interact with the CSE Entities. Since the MQTT protocol uses a different paradigm (publish/subscribe), an adaptation has to be done.

To achieve this communication via the MQTT Protocol, a request topic has been defined where the client will be able to send the serialized request. Then the response will be posted on a predefined topic where the client will retrieve the serialized response. All information concerning the authentification, the operation, the response status and other parameters will be held into the serialized request/response.

MQTT Topic

The oneM2M technical specification provides the topics that has to be used for MQTT communication. The serialized request has to be pushed on a specific request topic and the response will be given to a different predefined topic.

Request topic

The request topic is formulated as the following:

/oneM2M/req/<originator>/<target-id>/<serialization-format>

The <target-id> shall be the CSE-ID that is listening on the broker (for instance in-cse) and the <originator> correspond to the originator provided into the X-M2M-Origin header.

Then the last information of the topic is serialization format of the request. The <serialization-format> parameter can have 2 values:

  • xml for XML format
  • json for JSON format

Response topic

The response topic is constructed based on the request topic.

/oneM2M/resp/<target-id>/<originator>/<serialization-format>

MQTT Payload

The payload published into the topic is the serialized RequestPrimitive or ResponsePrimitive. The RequestPrimitive correspond to all information needed to formulate a oneM2M request and receive the response into the ResponsePrimitive.

The main parameters are:

Parameter short name Parameter name Usage
fr From Originator of the request
to To Destination of the request
op Operation The operation to perform (CREATE, RETRIEVE, ...)
rqi Request Identifier Correlation ID for the request and response
pc Primitive Content Content of the request (e.g., ressource to be created)
ty Type The type of the resource to be created
rsc Response Status Code  The oneM2M response status code


The Operation values are:

Operation Value
CREATE  1
RETRIEVE  2
UPDATE 3
DELETE 4
NOTIFY 5
DISCOVERY 6

Retrieve the CSE Base

The aim of this request is to retrieve the CSE Base resource of the in-cse. The request topic is: /oneM2M/req/AE_123/in-cse/json.

{
   "m2m:rqp": {
      "fr": "AE_123",
      "to": "/in-cse",
      "op": 2,
      "rqi": 123456
   }
}

The response will be published on the topic: /oneM2M/resp/in-cse/AE_123/json. Response payload is:

{
   "m2m:rsp" : {
      "rsc" : 2000,
      "rqi" : "1234",
      "pc" : {
         "m2m:cb" : [ {
            "rn" : "in-name",
            "ty" : 5,
            "ri" : "/in-cse",
            "ct" : "20161116T111621",
            "lt" : "20161116T111621",
            "acpi" : [ "/in-cse/acp-95896161" ],
            "cst" : 1,
            "csi" : "in-cse",
            "srt" : [ 1, 2, 3, 4, 5, 9, 14, 15, 16, 17, 23 ],
            "poa" : [ "http://127.0.0.1:8080/" ]
         } ]
      },
      "to" : "AE_123",
      "fr" : "/in-cse"
   }
}

Create container

The aim of the request is to create a container named cntName. The Request topic is: /oneM2M/req/AE_123/in-cse/json.

Payload:

{
    "m2m:rqp" : {
        "fr" : "AE_123",
        "to" : "/in-cse/in-name/AE_123",
        "op" : 1,
        "rqi": 123456,
        "pc": {
            "m2m:cnt" : {
                "rn": "cntName"
            }
        },
        "ty": 3
    }
}

The response will be pushed on the topic: /oneM2M/resp/in-cse/AE_123/json. The payload would be:

{
   "m2m:rsp" : {
      "rsc" : 2001,
      "rqi" : "123456",
      "pc" : {
         "m2m:cnt" : [ {
            "rn" : "cntName",
            "ty" : 3,
            "ri" : "/in-cse/cnt-114901069",
            "pi" : "/in-cse",
            "ct" : "20161116T111750",
            "lt" : "20161116T111750",
            "acpi" : [ "/in-cse/acp-95896161" ],
            "et" : "20171116T111750",
            "st" : 0,
            "mni" : 10,
            "mbs" : 10000,
            "mia" : 0,
            "cni" : 0,
            "cbs" : 0,
            "ol" : "/in-cse/in-name/AE_123/cntName/ol",
            "la" : "/in-cse/in-name/AE_123/cntName/la"
         } ]
      },
      "to" : "AE_1234",
      "fr" : "/in-cse"
}

Create contentInstance

Once, you created a container, you can store data by creating a contentInstance under it. The request is to create a contenInstance under a container named cntName. The Request topic is: /oneM2M/req/AE_123/in-cse/json.

Payload:

{
    "m2m:rqp" : {
        "fr" : "AE_123",
        "to" : "/in-cse/in-name/AE_123/cntName",
        "op" : 1,
        "rqi": 123456,
        "pc": {
            "m2m:cin" : {
            "cnf": "message",
            "con": "<obj><int name=\"data\" val=\"30.5\"/><int name=\"unit\" val=\"celsius\"/></obj>"
            }
        },
        "ty": 4
    }
}

The response will be pushed on the topic: /oneM2M/resp/in-cse/AE_123/json.

Copyright © Eclipse Foundation, Inc. All Rights Reserved.