首页 文章

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

提问于
浏览
1

所以I'm having some problems connection virtual devices to the contextBroker和我想要使用OpenIoT(即使没有设法找到任何有关服务创建的文档,也许我创建错了 . )

我做了 Python CreateService bus_auto 4jggokgpepnvsb2uv4s40d59ov 和i 'm not sure it returns me 201. I updated the config.ini file to work on MY service but when i send the observations it doesn'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))

2 回答

  • 0

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

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

    后来,我在ContextBroker中检查了这个实体:“thing:bus_auto_2”,我看到了我发送的最新观察结果 .

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

    干杯,

  • 1

    查看您的脚本,您似乎没有在queryContext请求中包含Fiware-Service标头 . 因此,查询在“默认服务”中解决,而不是在bus_auto服务中解析 .

    可能以下列方式更改HEADERS Map 可以解决问题:

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

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

    BASE_URL = 'http://130.206.80.40:1026'
    

相关问题