iotagent-node-lib icon indicating copy to clipboard operation
iotagent-node-lib copied to clipboard

use of object_id for commands

Open SBlechmann opened this issue 1 year ago • 1 comments

Hey there,

"object_ids" and "name" are used as a translation layer between how things are called in field layer and in FIWARE, respectively. That works well for attributes (measurement values coming from the field layer). Nevertheless, this does not work for commands. When you register a device in the IoTA - let's say JSON - that has a command, this command get's posted as a registration in orion. This way, a PATCH on that command will trigger a request from orion to the IoTA. In my case, all communication between FIWARE and the field layer is done via MQTT. So the IoTA forwards this command to the corresponding topic (which works fine) but the payload looks like {"<attr_name>":}. Since the API documentation (or at least the given examples) states that commands can have object_ids, I was expecting the payload to be {"<object_id>":}. Am I missing something or is this just not implemented? I'm seeking to use this feature since the system in use gets more and more complex using data models in FIWARE but different naming schemas on the field layer.

Thanks for clearing things up :)

SBlechmann avatar Mar 22 '23 14:03 SBlechmann

If you provision a device with a command like this:

  "commands":[
      {
         "name":"expression",
         "type":"Number",
         "expression":"'hi'"
      }

And then, you send the command, you will obtain, as message payload (No matter what you put on expression command attribute)

"hi"

Note that you have the quotes. This can be change through the command option parameters payloadType and contentType

More info for IOTA-JSON here

So, through the usage of an expression, you can define a custom payload simulating whatever you want, for example, the typical behaviour:

{"cmdName":{"paramName":"paramValue"}}

mapedraza avatar Apr 28 '23 08:04 mapedraza