Fiware Actuator/Sensor On Off pattern with status

162 Views Asked by At

My configuration includes orion, IoT Agent JSON, and mongoDB. I want to build a Fiware Lamp actuator and I want to have is on/off status (as sensor) as well.

At the moment I use a PATCH request with body (form ORION) : At First with on command:

{
  "on": {
      "type" : "command",
      "value" : ""
  }
}

And then with off command:

{
  "off": {
      "type" : "command",
      "value" : ""
  }
}

When I receive anything from the above, I respond from the dummy device with 200 OK.

The above in my configuration makes both the on and off tags as pending:

{
    "id": "urn:ngsi-ld:Lamp:001",
    "type": "Lamp",
    "TimeInstant": "2020-11-04T22:42:37.00Z",
    "category": [
        "actuator",
        "sensor"
    ],
    "controlledProperty": "lamp",
    "function": [
        "onOff",
        "sensing"
    ],
    "off_info": " ",
    "off_status": "PENDING",
    "on_info": " ",
    "on_status": "PENDING",
    "refStore": "urn:ngsi-ld:Store:001",
    "state": " ",
    "supportedProtocol": [
        "JSON"
    ],
    "supportedUnits": "My Unit 2",
    "on": "",
    "off": ""
}

I guess that I miss something in the way, so is there any response that I have to sent back to IoT Agent json to to make one of the two tags to stop be pending? Must I Update State or Info along the way?

P.S I expected to have a reply like this:

{
    "id": "urn:ngsi-ld:Lamp:001",
    "type": "Lamp",
    "TimeInstant": "2020-11-04T22:42:37.00Z",
    "category": [
        "actuator",
        "sensor"
    ],
    "controlledProperty": "lamp",
    "function": [
        "onOff",
        "sensing"
    ],
    "off_info": " ",
    "off_status": "PENDING",
    "on_info": " ",
    "on_status": "OFF",
    "refStore": "urn:ngsi-ld:Store:001",
    "state": " ",
    "supportedProtocol": [
        "JSON"
    ],
    "supportedUnits": "My Unit 2",
    "on": "",
    "off": ""
}
1

There are 1 best solutions below

2
Jason Fox On BEST ANSWER

The flow of a command can be seen below:

enter image description here

Assuming your command has reached the lamp and it has turned on, the result needs to be passed back into the IoT Agent. For the JSON IoT Agent, the payload looks something like this:

{"on" : "OK"}

Where the key is the name of the command, and the value is the status. My guess is that your device is just responding 200 OK without a payload, so the IoT Agent doesn't know which command has fired.

Note that in the case of a distributed network (e.g. MQTT or AMPQ) the response will be posted asynchronously on another topic so the command may be left in a PENDING state for some time.