sirnino
sirnino

Reputation: 427

Command doesn't forward from FIWARE JSON Agent toward the Broker MQTT

I've deployed the iot stack with docker. These are the used containers:

I've registered the following device on the agent:

{
     "device_id": "t3",
     "service": "lmobile",
     "service_path": "/lmobile_Industry",
     "entity_name": "t3",
     "entity_type": "Device",
     "endpoint": "tcp://<mqttborker_publicip>:<port>",
     "transport": "MQTT",
     "attributes": [{
                "object_id": "led",
                "name": "led",
                "type": "text"
     }],
     "lazy": [],
     "commands": [{
                "object_id": "c",
                "name": "c",
                "type": "Command"
     }],
     "static_attributes": [
                      ....
     ],
     "protocol": "JSON"
}

and the corresponding entity has been properly created on the OCB and when I publish a new measure on the mqttbroker, under the topic /<apikey>/t3/attrs the measure is properly forward toward the OCB.

In order to send the command c to the device I send the following updateContext on OCB:

curl -s -X POST http://<orionhost>:1026/v1/updateContext
       -H 'accept: application/json'
       -H 'cache-control: no-cache' 
       -H 'content-type: application/json'
       -H 'fiware-service: lmobile'
       -H 'fiware-servicepath: /lmobile_Industry'
       -d '{
             "contextElements": [
                 {
                    "type": "Device",
                     "isPattern": "false",
                     "id": "t3",
                     "attributes": [
                       {
                         "name":"c",
                         "type":"Command",
                         "value":100
                       }
                     ]
                 }
             ],
             "updateAction": "UPDATE"
         }'

and I receive the following error response:

{
     "errorCode": {
         "code": "404",
         "reasonPhrase": "No context element found",
         "details": "invalid context provider response"
     }
}

In the OCB Log I can see the following WARNING Message: time=Thursday 18 Oct 08:55:54 2018.431Z | lvl=WARN | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=postQueryContext.cpp[169]:queryForward | msg=Other Error (context provider response to QueryContext is empty). Anyway, the updateContext is properly forwarded to the Agent.

In the Agent Log (in DEBUG) I can see the followings:

iotstack_agent-json.1.xyz@xerus-1    | time=2018-10-18T09:02:33.975Z | lvl=DEBUG | corr=8d2864ec-d2b4-11e8-b445-02420aff0161 | trans=de5680e7-0727-4577-ac44-ddeb59df1f31 | op=IoTAgentNGSI.GenericMiddlewares | srv=lmobile | subsrv=/lmobile_Industry | msg=Request for path [/updateContext] from [<agent_publicip>:<port>] | comp=IoTAgent
iotstack_agent-json.1.xyz@xerus-1    | time=2018-10-18T09:02:33.976Z | lvl=DEBUG | corr=8d2864ec-d2b4-11e8-b445-02420aff0161 | trans=de5680e7-0727-4577-ac44-ddeb59df1f31 | op=IoTAgentNGSI.GenericMiddlewares | srv=lmobile | subsrv=/lmobile_Industry | msg=Body:
iotstack_agent-json.1.xyz@xerus-1    |
iotstack_agent-json.1.xyz@xerus-1    | {
iotstack_agent-json.1.xyz@xerus-1    |     "contextElements": [
iotstack_agent-json.1.xyz@xerus-1    |         {
iotstack_agent-json.1.xyz@xerus-1    |             "type": "Device",
iotstack_agent-json.1.xyz@xerus-1    |             "isPattern": "false",
iotstack_agent-json.1.xyz@xerus-1    |             "id": "t3",
iotstack_agent-json.1.xyz@xerus-1    |             "attributes": [
iotstack_agent-json.1.xyz@xerus-1    |                 {
iotstack_agent-json.1.xyz@xerus-1    |                     "name": "c",
iotstack_agent-json.1.xyz@xerus-1    |                     "type": "Command",
iotstack_agent-json.1.xyz@xerus-1    |                     "value": "100"
iotstack_agent-json.1.xyz@xerus-1    |                 }
iotstack_agent-json.1.xyz@xerus-1    |             ]
iotstack_agent-json.1.xyz@xerus-1    |         }
iotstack_agent-json.1.xyz@xerus-1    |     ],
iotstack_agent-json.1.xyz@xerus-1    |     "updateAction": "UPDATE"
iotstack_agent-json.1.xyz@xerus-1    | }
iotstack_agent-json.1.xyz@xerus-1    |
iotstack_agent-json.1.xyz@xerus-1    |  | comp=IoTAgent
iotstack_agent-json.1.xyz@xerus-1    | time=2018-10-18T09:02:33.978Z | lvl=DEBUG | corr=8d2864ec-d2b4-11e8-b445-02420aff0161 | trans=de5680e7-0727-4577-ac44-ddeb59df1f31 | op=IoTAgentNGSI.DomainControl | srv=lmobile | subsrv=/lmobile_Industry | msg=response-time: 6 | comp=IoTAgent

Here I don't see warnings or errors but no commands are forwarded to the MQTT Broker on any topic (I'm subscribed both to the specific topic for commands /<apikey>/t3/cmd and to all topics by using the wildcard #).

Upvotes: 2

Views: 281

Answers (2)

Jason Fox
Jason Fox

Reputation: 5300

@fgalan is correct - you do not need the endpoint field when provisioning a service group for MQTT

curl -iX POST \
  'http://localhost:4041/iot/services' \
  -H 'Content-Type: application/json' \
  -H 'fiware-service: openiot' \
  -H 'fiware-servicepath: /' \
  -d '{
 "services": [
   {
     "apikey":      "4jggokgpepnvsb2uv4s40d59ov",
     "cbroker":     "http://orion:1026",
     "entity_type": "Thing",
     "resource":    ""
   }
 ]
}'

However it is essential that config.json file is configured correctly to talk to the MQTT Broker.

Personally I'd use docker-compose and assign the values using Docker environment variables, but it is also possible to edit the config.json file directly:

 environment:
     - "IOTA_MQTT_HOST=mosquitto" # The host name of the MQTT Broker
     - "IOTA_MQTT_PORT=1883" # The port the MQTT Broker is listening on to receive topics

Here is the mapping between ENV variables and config.json settings:

  • IOTA_MQTT_HOST - mqtt.host
  • IOTA_MQTT_PORT - mqtt.port
  • IOTA_MQTT_USERNAME - mqtt.username
  • IOTA_MQTT_PASSWORD - mqtt.password
  • IOTA_MQTT_QOS - mqtt.qos

Note that cbroker is also an optional attribute - if it is not provided, the IoT Agent uses the default context broker URL as defined in the configuration file

The Tutorial for provisioning a device over MQTT uses the Ultralight IoT Agent, but the JSON IoT Agent should work in the same fashion.

Upvotes: 1

fgalan
fgalan

Reputation: 12322

Not fully sure, but maybe is a problem at provisioning stage. The endpoint starting with tcp:// is a bit weird to me...

More in detail, looking to ths piece of documentation I read:

The example shows there are two differences comparing [MQTT provision] with provisioning for HTTP:

  • The absence of an "endpoint" field
  • The presence of "transport" field, which value has to be "MQTT".

So I understant that you shouldn't use endpoint field at all at provisioning time.

Upvotes: 0

Related Questions