我在物联网代理中认可了我的设备:
curl -X POST http://192.168.1.110:80/iot/devices \
-i \
-H "Content-Type: application/json" \
-H "Fiware-Service: egmsmartcity" \
-H "Fiware-ServicePath: /egmsmartcitypath" \
-d ' { "devices": [ { "device_id": "test",
"entity_name": "sensors:test",
"entity_type": "sensors",
"protocol": "PDI-IoTA-MQTT-UltraLight",
"timezone": "Europe/Paris",
"endpoint": "notUsed",
"commands": [{ "name": "ping", "type": "command", "value": ""}] } ] }'
在上下文Broker中注册成功:
获取:http://192.168.1.77:1026/v1/contextEntities/sensors:test
带标题的:
Accept: application/json
Fiware-Service: egmsmartcity
Fiware-ServicePath: /egmsmartcitypath
我收到了以下回复:
{
contextElement: {
type: "sensors"
isPattern: "false"
id: "sensors:test"
attributes: [1]
0: {
name: "TimeInstant"
type: "ISO8601"
value: "2015-11-30T16:53:45.556269Z"
}-
-
}-
statusCode: {
code: "200"
reasonPhrase: "OK"
}-
}
然后当我尝试像这样更新命令时:
curl -X POST http://192.168.1.77:1026/v1/updateContext \
-i \
-H "Content-Type: application/json" \
-H "Fiware-Service: egmsmartcity" \
-H "Fiware-ServicePath: /egmsmartcitypath" \
-d ' {"updateAction":"UPDATE","contextElements":[{"id":"sensors:test","type":"sensors","isPattern":"false","attributes":[{"name":"ping","type":"command","value":"22" } ]} ]}'
我收到了这个回复:
HTTP/1.1 200 OK
Content-Length: 157
Content-Type: application/xml
Date: Mon, 30 Nov 2015 17:05:11 GMT
<updateContextResponse>
<errorCode>
<code>404</code>
<reasonPhrase>No context element found</reasonPhrase>
</errorCode>
</updateContextResponse>
为什么返回“没有找到上下文元素”?我错过了什么? 在此先感谢您的帮助!
[更新] 我试过一个简单的上传“/ iot / devices” 这是Iot Agent lg文件中的日志:
如果操作成功,则从localhost
HTTP Version: 1.1
Resource requested: /iot/devices
Resource delivered: /iot/devices
Query string
Content length: 0
Headers: Fiware-ServicePath: /egmsmartcitypath
Fiware-Service: egmsmartcity
User-Agent: curl/7.29.0
Host: localhost
Content-Type: application/json
Accept: */*
time=2015-12-02T10:41:41,516.800CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=operator() | file=[140373934458624:rest_handle.cc:396] | msg=Processing request /iot-754c76a3-b95a-4aac-976a-08ab37119c05-34
time=2015-12-02T10:41:41,516.813CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=execute_filters | file=[140373934458624:rest_handle.cc:410] | msg=Processing request /iot-754c76a3-b95a-4aac-976a-08ab37119c05-34
time=2015-12-02T10:41:41,516.820CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=execute_filters | file=[140373934458624:rest_handle.cc:411] | msg=execute_filters status: 200
time=2015-12-02T10:41:41,516.953CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=handle_request | file=[140374294497024:media_filter.cc:56] | msg=MediaFilter handle_request /iot-754c76a3-b95a-4aac-976a-08ab37119c05-34/iot/devices
time=2015-12-02T10:41:41,516.982CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=handle_request | file=[140374294497024:media_filter.cc:95] | msg=Accept: */*
time=2015-12-02T10:41:41,517.035CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=handle_end_filters | file=[140373934458624:rest_handle.cc:446] | msg=Processing request /iot-754c76a3-b95a-4aac-976a-08ab37119c05-34
time=2015-12-02T10:41:41,517.046CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=handle_end_filters | file=[140373934458624:rest_handle.cc:447] | msg=End filters status 200
time=2015-12-02T10:41:41,517.056CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=handle_request | file=[140373934458624:rest_handle.cc:492] | msg=Processing request /iot-754c76a3-b95a-4aac-976a-08ab37119c05-34
time=2015-12-02T10:41:41,517.062CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=handle_request | file=[140373934458624:rest_handle.cc:493] | msg=Proccessing in handle /iot
time=2015-12-02T10:41:41,517.180CET | lvl= INFO | comp=iota:IoTAgent-MQTT-UL20 | op=devices | file=[140373934458624:admin_service.cc:586] | msg=iota::AdminService::devices method:GET trace_message:/iot-754c76a3-b95a-4aac-976a-08ab37119c05-34
time=2015-12-02T10:41:41,517.215CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=get_all_devices_json | file=[140373934458624:admin_service.cc:1748] | msg=get_all_devices_json service=egmsmartcity service_path=/egmsmartcitypath detailed=
time=2015-12-02T10:41:41,517.234CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=conn | file=[140373934458624:mongo_connection.cc:261] | msg=MongoConnection::conn returns 0x20ba8f0
time=2015-12-02T10:41:41,517.262CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=count | file=[140373934458624:collection.cc:833] | msg=Collection:count bbdd=iot.DEVICE options= query={ service: "egmsmartcity", service_path: "/egmsmartcitypath" }
time=2015-12-02T10:41:41,517.524CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=find | file=[140373934458624:collection.cc:704] | msg=Collection:find bbdd=iot.DEVICE query={ service: "egmsmartcity", service_path: "/egmsmartcitypath" } limit=20 offset=0 options=-2147483648
time=2015-12-02T10:41:41,517.546CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=find | file=[140373934458624:collection.cc:718] | msg=before getConnection
time=2015-12-02T10:41:41,517.553CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=find | file=[140373934458624:collection.cc:723] | msg=before query
time=2015-12-02T10:41:41,517.737CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=create_response | file=[140373934458624:admin_service.cc:1309] | msg=create_response: 200 { "count": 2,"devices": [{ "device_id" : "sensorTmp" },{ "device_id" : "test" }]}
time=2015-12-02T10:41:41,517.766CET | lvl= INFO | comp=iota:IoTAgent-MQTT-UL20 | op=devices | file=[140373934458624:admin_service.cc:718] | msg=iota::AdminService::devices method:GET trace_message:/iot-754c76a3-b95a-4aac-976a-08ab37119c05-34 code: 200 response:{ "count": 2,"devices": [{ "device_id" : "sensorTmp" },{ "device_id" : "test" }]}
time=2015-12-02T10:41:41,517.902CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=finish | file=[140373934458624:rest_handle.cc:567] | msg=finish connection 2
如果操作不成功,请从Rest客户端
HTTP Version: 1.1
Resource requested: /iot/devices/
Resource delivered: /iot/devices/
Query string
Content length: 0
Headers: Fiware-ServicePath: /egmsmartcitypath
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36
Fiware-Service: egmsmartcity
Connection: keep-alive
Host: 192.168.1.110
Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Encoding: gzip, deflate, sdch
Accept: */*
Content-Type: application/json
time=2015-12-02T10:39:55,246.079CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=operator() | file=[140373942851328:rest_handle.cc:396] | msg=Processing request /iot-c7a1ab03-73e6-4f9b-82de-d8f569927296-33
time=2015-12-02T10:39:55,246.079CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=execute_filters | file=[140373942851328:rest_handle.cc:410] | msg=Processing request /iot-c7a1ab03-73e6-4f9b-82de-d8f569927296-33
time=2015-12-02T10:39:55,246.079CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=execute_filters | file=[140373942851328:rest_handle.cc:411] | msg=execute_filters status: 200
time=2015-12-02T10:39:55,246.156CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=handle_request | file=[140374294497024:media_filter.cc:56] | msg=MediaFilter handle_request /iot-c7a1ab03-73e6-4f9b-82de-d8f569927296-33/iot/devices/
time=2015-12-02T10:39:55,246.191CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=handle_request | file=[140374294497024:media_filter.cc:95] | msg=Accept: */*
time=2015-12-02T10:39:55,246.338CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=handle_end_filters | file=[140373942851328:rest_handle.cc:446] | msg=Processing request /iot-c7a1ab03-73e6-4f9b-82de-d8f569927296-33
time=2015-12-02T10:39:55,246.350CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=handle_end_filters | file=[140373942851328:rest_handle.cc:447] | msg=End filters status 200
time=2015-12-02T10:39:55,246.360CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=handle_request | file=[140373942851328:rest_handle.cc:492] | msg=Processing request /iot-c7a1ab03-73e6-4f9b-82de-d8f569927296-33
time=2015-12-02T10:39:55,246.366CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=handle_request | file=[140373942851328:rest_handle.cc:493] | msg=Proccessing in handle /iot
time=2015-12-02T10:39:55,246.586CET | lvl=DEBUG | comp=iota:IoTAgent-MQTT-UL20 | op=finish | file=[140373942851328:rest_handle.cc:567] | msg=finish connection 2
似乎iot代理在终止请求处理之前完成操作
答案 0 :(得分:1)
似乎IoT代理无法回答updateContext请求。将属性声明为命令时,IoT代理会将自身注册为Context Broker中Device实体的该属性的Context Provider。如果UPDATE请求到达CB的该属性,该请求将被转发到IoTA。如果IoTA无法应答或未找到,则请求将失败。
此问题的可能原因是公共IP的配置错误。如果Context Broker无法找到您要更新的属性的提供程序,则会返回404错误。您是否在IoT代理中配置了公共IP?