使用 IDAS 和 ContextBroker 在服务中创建实体

Create entity in a service using IDAS and ContextBroker

所以 I'm having some problems connection virtual devices to the contextBroker 我认为这是因为 Fiware 服务。我不想使用 OpenIoT(即使这对我也不起作用)。我没有设法找到任何关于服务创建的文档,也许我创建错了。

我做了 Python CreateService bus_auto 4jggokgpepnvsb2uv4s40d59ov但我不确定 returns 我 201。我更新了 config.ini 文件以在我的服务上工作但是当我发送观察结果时它没有' t 改变contextBroker上实体的值

我现在 运行 它在

我的 config.ini 文件:

[user]
# Please, configure here your username at FIWARE Cloud and a valid Oauth2.0 TOKEN for your user (you can use get_token.py to obtain a valid TOKEN).
username=
token=NULL

[contextbroker]
host=127.0.0.1
port=1026
OAuth=no
# Here you need to specify the ContextBroker database you are querying.
# Leave it blank if you want the general database or the IDAS service if you are looking for IoT devices connected by you.
fiware_service=bus_auto

[idas]
host=130.206.80.40
adminport=5371
ul20port=5371
OAuth=no
# Here you need to configure the IDAS service your devices will be sending data to.
# By default the OpenIoT service is provided.
fiware-service=bus_auto
fiware-service-path=/
apikey=4jggokgpepnvsb2uv4s40d59ov

[local]
#Choose here your System type. Examples: RaspberryPI, MACOSX, Linux, ...
host_type=CentOS
# Here please add a unique identifier for you. Suggestion: the 3 lower hexa bytes of your Ethernet MAC. E.g. 79:ed:af
# Also you may use your e-mail address.
host_id=db:00:ff

我正在使用 python 脚本 GetEntity.py:

python2.7 GetEntity.py bus_auto_2 

我还尝试使用我创建的 python 脚本:

import json
import urllib
import urllib2

BASE_URL = 'http://127.0.0.1:1026'
QUERY_URL = BASE_URL+'/v1/queryContext'

HEADERS = {
    'Content-Type': 'application/json',
    'Accept': 'application/json'
}

QUERY_EXAMPLE = {
    "entities": [
        {
            "type": "bus_auto_2",
            "isPattern": "false",
            "id": "Room1"
        }
    ]
}


def post(url, data):
    """"""
    req = urllib2.Request(url, data, HEADERS)
    f = urllib2.urlopen(req)
    result = json.loads(f.read())
    f.close()
    return result

if __name__ == "__main__":
    print post(UPDATE_URL, json.dumps(UPDATE_EXAMPLE))
    print post(QUERY_URL, json.dumps(QUERY_EXAMPLE))

我看到服务创建得很好,实际上我看到其中定义了一个设备。

我什至成功发送了一个观察 (t|23) bus_auto_2 设备

稍后,我检查了 ContextBroker 这个实体:"thing:bus_auto_2" 并且我看到了我发送的最新观察结果。

您是否在 config.ini 文件中更新了 ContextBroker 和 IDAS 部分的 FIWARE_SERVICE?

干杯,

查看您的脚本,您似乎没有在 queryContext 请求中包含 Fiware-Service header。因此,查询在 "default service" 中解析,而不是在 bus_auto 服务中解析。

按以下方式更改 HEADERS 地图可能会解决问题:

HEADERS = {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'Fiware-Service: 'bus_auto' 
}

编辑:除了上述更改外,请注意 BASE_URL 指向本地 Orion 实例,而不是与 IDAS 连接的实例(运行 在与 IDAS 相同的机器上)。因此,我认为您还需要按以下方式修改 BASE_URL:

BASE_URL = 'http://130.206.80.40:1026'