首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Fiware orion订阅发送空体

Fiware orion订阅发送空体
EN

Stack Overflow用户
提问于 2019-02-20 03:01:30
回答 1查看 204关注 0票数 1

我的设置:码头-撰写:

代码语言:javascript
复制
version: "3.1"
services:
  mongo-db:
    image: mongo:3.6
    hostname: mongo-db
    container_name: db-mongo
    expose:
      - "27017"
    ports:
      - "27017:27017"
    networks:
      - default
    command: --bind_ip_all --smallfiles
    volumes:
      - mongo-db:/data

  orion:
    image: fiware/orion:2.1.0
    hostname: orion
    container_name: fiware-orion
    depends_on:
      - mongo-db
    networks:
      - default
    expose:
      - "1026"
    ports:
      - "1026:1026"
    command: -dbhost mongo-db -logLevel DEBUG
    logging:
      driver: none
    healthcheck:
      test: curl --fail -s http://localhost:1026/version || exit 1

  iot-agent:
    image: fiware/iotagent-ul:latest
    hostname: iot-agent
    container_name: fiware-iot-agent
    depends_on:
        - mongo-db
    networks:
        - default
    expose:
        - "4041"
        - "7896"
    ports:
        - "4041:4041"
        - "7896:7896"
    logging:
      driver: none
    environment:
        - "IOTA_CB_HOST=orion"
        - "IOTA_CB_PORT=1026"
        - "IOTA_NORTH_PORT=4041"
        - "IOTA_REGISTRY_TYPE=mongodb"
        - "IOTA_LOG_LEVEL=DEBUG"
        - "IOTA_TIMESTAMP=true"
        - "IOTA_MONGO_HOST=mongo-db"
        - "IOTA_MONGO_PORT=27017"
        - "IOTA_CB_NGSI_VERSION=v2"
        - "IOTA_MONGO_DB=iotagentul"
        - "IOTA_HTTP_PORT=7896"
        - "IOTA_PROVIDER_URL=http://iot-agent:4041"


networks:
  default:
    ipam:
      config:
        - subnet: 172.18.1.0/24

volumes:
  mongo-db: ~

背景:

代码语言:javascript
复制
curl -iX POST \
  'http://localhost:1026/v2/op/update' \
  -H 'Content-Type: application/json' \
  -H 'fiware-service: didi' \
  -H 'fiware-servicepath: /' \
  -d '{
  "actionType":"APPEND",
  "entities":[
    {
      "id":"urn:ngsi-ld:Furniture:unit001", "type":"Furniture",
      "name":{
        "type":"Text", "value":"Bürostuhl"
      },
      "price":{
        "type":"Integer", "value":404.40
      }
    },
    {
      "id":"urn:ngsi-ld:Furniture:unit002", "type":"Furniture",
      "name":{
        "type":"Text", "value":"Bürotisch"
      },
      "price":{
        "type":"Integer", "value":203.40
      }
    },
    {
      "id":"urn:ngsi-ld:DeliverService:unit001", "type":"ServiceProvider",
      "name":{
        "type":"Text", "value":"trinkajo"
      },
       "address":{
            "type":"PostalAddress",
            "value":{
               "telephoneNumber":"43q4q53",
               "internetAdresse":"https://www.345345.de/"
            }
         }
    },
    {
      "id":"urn:ngsi-ld:BottleCounter:001", "type":"BottleCounter",
      "name":{
        "type":"Text", "value":"Wasserflaschenzähler"
      },
      "numberOfBottles": {"type":"Integer", "value":645}
    }
  ]
}'




curl -iX POST \
  'http://localhost:1026/v2/op/update' \
  -H 'Content-Type: application/json' \
  -H 'fiware-service: didi' \
  -H 'fiware-servicepath: /' \
  -d '{
  "actionType":"APPEND",
  "entities":[
    {
      "id":"urn:ngsi-ld:Furniture:unit001", "type":"Furniture",
      "refOffice": {
        "type": "Relationship",
        "value": "urn:ngsi-ld:Office:001"
      }
    },
    {
      "id":"urn:ngsi-ld:Furniture:unit002", "type":"Furniture",
      "refOffice": {
        "type": "Relationship",
        "value": "urn:ngsi-ld:Office:001"

      }  
    },
    {
      "id":"urn:ngsi-ld:DeliverService:unit001", "type":"ServiceProvider",
      "refOffice": {
        "type": "Relationship",
        "value": "urn:ngsi-ld:Office:001"

      }  
    }
  ]
}'
curl -iX POST \
  'http://localhost:1026/v2/op/update' \
  -H 'Content-Type: application/json' \
  -H 'fiware-service: didi' \
  -H 'fiware-servicepath: /' \
  -d '{
   "actionType":"APPEND",
   "entities":[
      {
         "id":"urn:ngsi-ld:Office:001", "type" : "Office",
         "name":{
            "type":"Text",
            "value":"didi-Hamburg"
         },
         "sizeInM2":{
            "type":"Integer",
            "value":60
         },
         "address":{
            "type":"PostalAddress",
            "value":{
               "country":"Germany",
               "locality":"sdfg",
               "street":"sdfg",
               "houseNumber" : "34",
               "postalCode":"34533"
            }
         }
      }
   ]
}'


curl -iX POST \
  'http://localhost:4041/iot/services' \
  -H 'Content-Type: application/json' \
  -H 'fiware-service: didi' \
  -H 'fiware-servicepath: /' \
  -d '{
 "services": [
   {
     "apikey":      "4jggokgpepnvsb2uv4s40d59ov",
     "cbroker":     "http://orion:1026",
     "entity_type": "Thing",
     "resource":    "/iot/d"
   }
 ]
}'
curl -G -X GET \
  'http://localhost:1026/v2/entities/urn:ngsi-ld:Office:001' \
  -H 'fiware-service: didi' \
  -H 'fiware-servicepath: /' \
  -d 'type=Office' \
  -d 'options=keyValues' | json_pp

curl -iX POST \
  'http://localhost:4041/iot/devices' \
  -H 'Content-Type: application/json' \
  -H 'fiware-service: didi' \
  -H 'fiware-servicepath: /' \
  -d '{
 "devices": [
   {
     "device_id":   "bottleCounter001",
     "entity_name": "urn:ngsi-ld:BottleCounter:001",
     "entity_type": "BottleCounter",
     "timezone":    "Europe/Berlin",
     "attributes": [
       { "object_id": "c", "name": "numberOfBottles", "type": "Integer" }
     ],
     "static_attributes": [
       { "name":"refOffice", "type": "Relationship", "value": "urn:ngsi-ld:Office:001"}
     ]
   }
 ]
}'

订阅:

代码语言:javascript
复制
curl -iX POST \
  --url 'http://localhost:1026/v2/subscriptions' \
  --header 'Content-Type: application/json' \
  -H 'fiware-service: didi' \
  -H 'fiware-servicepath: /' \
  --data '{
  "description": "Notify me of low stock in Office 001",
  "subject": {
    "entities": [{"idPattern": ".*", "type" : "BottleCounter"}],
    "condition": {
      "attrs": ["numberOfBottles"],
      "expression": {"q": "numberOfBottles<10;refOffice==urn:ngsi-ld:Office:001"}
    }
  },
  "notification": {
    "http": {
      "url": "http://delivery:8080/subscription/office"
    }
  }
}'

如何成功地更新值numberOfBottles

代码语言:javascript
复制
curl -iX POST \
  'http://localhost:7896/iot/d?k=4jggokgpepnvsb2uv4s40d59ov&i=bottleCounter001' \
  -H 'fiware-service: didi' \
  -H 'fiware-servicepath: /' \
  -H 'Content-Type: text/plain' \
  -d 'c|2'

我的用法是:

有一个办公室,里面有给员工的水瓶。有一个可以计数水瓶的“传感器”。当员工拿着水瓶时,感应器会更新fiware中的值。当号码在3以下时,软件应通知订户。订阅者现在可以订购新的水瓶了。

我有几个问题:

  1. 使用条件numberOfBottles<10,订阅永远不会被触发。当我使用像numberOfBottles!=10这样的东西时,它是起作用的
  2. 只有一个空体被发送到url http://delivery:8080/subscription/office

一个额外的问题是:如果我能修复第一个问题:在触发订阅时,是否有一种方法可以将属性addressurn:ngsi-ld:DeliverService:unit001发送到url http://delivery:8080/subscription/office

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-21 11:16:58

据我所知,IOTA默认配置为使用NGSIv1向CB发送更新。NGSIv1 API的一个限制(被废弃的:)是数字总是被解析为字符串。因此,numberOfBottles<10过滤器不工作是有意义的。

为了克服这个问题,应该将IOTA配置为使用NGSIv2。将以下内容添加到对接者-Compose.yml中物联网代理的环境中,然后重新部署:

代码语言:javascript
复制
- IOTA_CB_NGSI_VERSION=v2

关于奖金问题,我认为@JasonFox已经在问题评论中回答了这个问题。

编辑:我意识到您正在使用UL代理。不同于JSON代理(它允许您在发送给代理的请求中指定JSON支持的值,例如数字),UL编码是基于文本的。因此,为了将数值提升到CB,您需要(除了上面描述的IOTA_CB_NGSI_VERSION设置):

  1. 将IOTA_AUTOCAST配置设置为true:
  • IOTA_AUTOCAST=true
  1. 在配置时使用"Number"作为属性类型(而不是"Integer")。

这在文件的这一节中有更详细的描述。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54778164

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档