Cannot register commands in IoT Agent Fiware - fiware

I'm using IoT Agent with Ultralight run directly (not as a dockerized component). I'm able to register new device, which is mapped in Orion Context Broker. However I have an issue with registering Actuators which require commands within configuration data. I use:
curl -iX POST \
'http://MYIP:4061/iot/devices' \
-H 'Content-Type: application/json' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-d '{
"devices": [
{
"device_id": "lamp003",
"entity_name": "urn:ngsi-ld:Lamp:003",
"entity_type": "Lamp",
"protocol": "PDI-IoTA-UltraLight",
"transport": "MQTT",
"commands": [
{"name": "on","type": "command"},
{"name": "off","type": "command"}
]}
]
}
And in response I'm hit with:
op=IoTAgentNGSI.DeviceProvisioning | from=n/a | srv=n/a | subsrv=n/a |
msg=Device provisioning failed due to the following error: |
comp=IoTAgent Request error connecting to the Context Broker:
{"code":"400","reasonPhrase":"Bad Request","details":"missing isDomain
value for registration attribute"}
I tried adding "isDomain": "false" to elements of command table, but no luck. It used to work before and furthermore similar solution is presented on official guide.

isDomain part of the deprecated NGSI-v1 syntax. It is not used in NGSI-v2 or NGSI-LD
I think you may be running the IoT Agent as NGSI-v1. You'll need to set contextBroker.ngsiVersion in your config.js or set the following Env variable in Docker or Docker-compose.
IOTA_CB_NGSI_VERSION=v2
config.js
{
host: '192.168.56.101',
port: '1026',
ngsiVersion: 'v2'
}

Related

Modify attribute on device by IOT-Agent Json

I am using IOT-agent JSON with MQTT binding
I have a sensor-actuator registered in orion using iot-agent and I created the subscription.
If a third party application modifies a sensor value, orion must send iot-agent information and iot-agent to the device.
for example, if I have 3 attributes inside the sensor and one of them controls a valve.
In orion that attribute is true or false.
if the attribute is modified in orion must be sent to iot-agent and iot-agent to the device to close or open the valve.
extra information:
The software is two component of Fiware Generic Enable.
iot-agent JSON: https://github.com/telefonicaid/iotagent-json
Fiware-orionCB: https://github.com/telefonicaid/fiware-orion
Is it possible?
There is no official tutorial connecting the JSON IoT Agent to a device over MQTT, but a very similar one exists for the Ultralight IoT Agent
IoT Devices are either:
sensors - reading measurements from the real world
actuators - altering the state of the world
or both
Your issue here is that you cannot get Orion to update the attribute/state of a sensor directly. The attributes of the entity in the Context Broker represent the incoming state of the sensor - i.e. the measurements from that sensor.
For example for the sensor reading the state of a valve it could be "open: "true"
In order to update an actuator, you will need to send a command, rather than alter the value.
You should set up the command when provisioning the device (it is assumed you have a service already):
curl -iX POST \
'http://localhost:4041/iot/devices' \
-H 'Content-Type: application/json' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-d '{
"devices": [
{
"device_id": "bell001",
"entity_name": "urn:ngsi-ld:Bell:001",
"entity_type": "Bell",
"protocol": "PDI-IoTA-UltraLight",
"transport": "MQTT",
"commands": [
{ "name": "ring", "type": "command" }
],
"static_attributes": [
{"name":"refStore", "type": "Relationship","value": "urn:ngsi-ld:Store:001"}
]
}
]
}
'
You can then send the command to do something (like ring a bell, open a valve etc.) by altering the state of the command attribute.
curl -iX PATCH \
'http://localhost:1026/v2/entities/urn:ngsi-ld:Bell:001/attrs' \
-H 'Content-Type: application/json' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-d '{
"ring": {
"type" : "command",
"value" : ""
}
}'
Depending upon how you have provisioned devices, you may also need to register the command - though this may not be necessary.

'fiware-servicepath' header value does not match the number of notified context responses

Working on setting Cygnus as a sink to CKAN, and I get this error, what part of Cygnus setup is responsible for this( subscription, configuration ...)
cygnus_1 | time=2018-10-01T12:40:04.517Z | lvl=DEBUG | corr=1ea858dc-c577-
11e8-b0fd-0242ac140003 | trans=5c553916-f5e6-4bbc-b98a-bcaba61a306c |
srv=waste4think | subsrv=/room/test | comp=cygnus-ngsi | op=getEvents |
msg=com.telefonica.iot.cygnus.handlers.NGSIRestHandler[320] :
[NGSIRestHandler] Parsed NotifyContextRequest:{"
subscriptionId":"5bb2153fd1bde90f8813b236","originator":"null","contextResponse
s":[]}
I assume the error is connected to this contextResponses because it is empty, but I found no additional info what is causing this where I should look. And the error is not helping.
This is the more general question that issue since I cannot call this issue because I have no idea if it is me who is causing this or Cygnus to have indeed some problems.
Thanks.
When setting up the subscription, Cygnus currently only accepts notifications in the older NGSI v1 format- the attrsFormat=legacy is therefore needed.
e.g.
curl -iX POST \
'http://localhost:1026/v2/subscriptions' \
-H 'Content-Type: application/json' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-d '{
"description": "Notify Cygnus of all context changes",
"subject": {
"entities": [
{
"idPattern": ".*"
}
]
},
"notification": {
"http": {
"url": "http://cygnus:5050/notify"
},
"attrsFormat": "legacy"
},
"throttling": 5
}'
Further information about setting up subscriptions in Cygnus can be found in the Cygnus Tutorial

Send commands to Context Broker using iotagent-ul

I'm trying to send commands to the Orion Context Broker using iotagent-ul with HTTP protcol.
Context Broker and IoT Agent are in different servers (actually IoTA is in running in my laptop).
I've configured the necessary parameters in config.js file.
My request is as follows:
curl -L POST -H "Fiware-Service: myHome" -H "Fiware-ServicePath: /environment" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
"devices": [
{
"device_id": "sensor01",
"entity_name": "LivingRoomSensor",
"entity_type": "multiSensor",
"attributes": [
{ "object_id": "t", "name": "Temperature", "type": "celsius" },
{ "object_id": "l", "name": "Luminosity", "type": "lumens" }
]
}
]
}
' 'http://localhost:4061/iot/devices'
It shows the following erros:
In IoTA terminal:
time=2017-02-14T15:06:14.832Z | lvl=ERROR | corr=88ed3729-6682-44ce-9b0a-28098e54c94e | trans=88ed3729-6682-44ce-9b0a-28098e54c94e | op=IoTAgentNGSI.DomainControl | srv=myHome | subsrv=/environment | msg=TypeError: Cannot read property 'findOne' of undefined | comp=IoTAgent
In "cURL terminal":
curl: (52) Empty reply from server
Please can you tell us what's the IoT Agent UL version you are using?
On the other hand, it seems you are missing the 'protocol' field in the payload, please check
http://fiwaretourguide.readthedocs.io/en/latest/connection-to-the-internet-of-things/how-to-read-measures-captured-from-iot-devices/
best

FIWARE-IoT Agent: send command to device via MQTT

I am using the FIWARE IoT agent [1] to communicate with my devices using MQTT protocol, I create a command to be able to update my device value, Here is my request to create a device:
curl -X POST http://193.48.247.247:80/iot/devices \
-i \
-H "Content-Type: application/json" \
-H "Fiware-Service: egmsmartcity" \
-H "Fiware-ServicePath: /egmsmartcitypath" \
-d ' { "devices": [ { "device_id": "streetlight1",
"entity_name": "sensors:streetlight1",
"entity_type": "sensors",
"protocol": "PDI-IoTA-MQTT-UltraLight",
"timezone": "Europe/Paris",
"endpoint": "notUsed",
"commands": [{ "name": "streetlight1", "type": "command", "value": ""}] } ] }'
Since I am using MQTT, the filed endpoint is not used on my case but if I delete it the MQTT does not notify my device.
This request is working but is it the correct way to create a device to be able to send a command to my device via MQTT?
Thanks in advance for your help!
[1]https://github.com/telefonicaid/fiware-IoTAgent-Cplusplus
This field ("endpoint": "notUsed") comes from a previous functionality that is no longer implemented (it did not make sense in MQTT). Thus since recent versions onwards it is ignored and can be deleted. Perhaps you are using a previous version of the IoT Agent and this is why it is mandatory although not functional.
Thanks for using IDAS!

cygnus instance not reached from orion context broker

I have installed cygnus 0.8.2 on fiware image CentOS-7-x64, I subscribed to orion context broker using:
(curl 193.48.247.246:1026/v1/subscribeContext -s -S --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Fiware-Service: egmmqtt' --header 'Fiware-ServicePath: /egmmqttpath' -d #- | python -mjson.tool) <<EOF
{
"entities": [
{
"type": "sensors",
"isPattern": "false",
"id": "sensors:switch2A"
}
],
"attributes": [
"switch2A"
],
"reference": "http://193.48.247.223:5050/notify",
"duration": "P1M",
"notifyConditions": [
{
"type": "ONCHANGE",
"condValues": [
"switch2A"
]
}
],
"throttling": "PT1S"
}
EOF
No notification has reached cygnus and I got this error on orionContextBroker logs:
time=2015-10-06T17:43:37.898CEST | lvl=WARNING | trans=1443447780-161-00000000423 | function=sendHttpSocket | comp=Orion | msg=clientSocketHttp.cpp[358]: Notification failure for 193.48.247.223:5050 (curl_easy_perform failed: Couldn't connect to server)
I dont know why the cygnus instance is not reached under the associated public IP adress. In fact I can't ping cygnus machine instance from Orion instance. Any ideas of what I have missed? thanks!
In the security rules of cygnus instance the port on which cygnus is listenning (in my case 5050) has to be open so orion can reach cygnus instance.