Fiware orion订阅发送空正文

Fiware orion订阅发送空正文,fiware,fiware-orion,Fiware,Fiware Orion,我的设置: docker compose: 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

我的设置: docker compose:

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: ~
背景:

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"}
     ]
   }
 ]
}'
订阅:

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"
    }
  }
}'
我的用例类似于:

有一个办公室,为员工准备了水瓶。有一个 “传感器”,可对水瓶进行计数。当员工在 水瓶传感器将更新fiware中的值。当 号码低于3时,固件应通知订户。订户 现在可以订购新的水瓶了

我有几个问题:


  • 根据我记忆中的条件
    numberoflabels,IOTA默认配置为使用NGSIv1向CB发送更新。NGSIv1 API(已弃用:)的限制之一是数字总是作为字符串进行解析。因此,
    numberofblottle是有意义的。请您编辑您的问题帖子,提供更多关于您用例背景的信息?我的意思是,我看到了一系列请求(其中一些是猎户座请求,一些是物联网请求),但我并不完全理解它们是如何“协调”的。一个特别重要的问题是如何更新订阅所涵盖的实体(BottleCounter)。您是否直接在Context Brokker使用NGSIv2 API进行更新?还是通过IoAgent发送度量?嘿,实际上没有“用例”。我只是想玩玩它。我通过IoAgent更新值。我会更新问题!关于奖金问题:-这完全取决于你如何构建你的实体。您可以在
    瓶子计数器
    中有一个重复的
    地址
    静态属性,并发送该属性,或者,您可以在响应中发送
    REOFFICE
    ,并从接收端点发出后续NGSI请求以获取附加数据。您现有的实体正确地引用了经典链接数据结构中的其他实体。理想情况下,您应该避免以与关系数据库结构相同的方式考虑实体-提出后续请求是正确的方式(例如,在您的情况下,如果道路名称发生了变化怎么办?)关于问题2:“空体”是什么意思?完全没有正文(即
    内容长度:0
    )?或者一个有
    {}
    有效载荷的主体或者其他方式为空?NumberOfBaggles仍然会变成字符串,并且订阅不会触发。我已经编辑了我的答案,添加了有关问题可能原因的额外信息。
    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'
    
    - IOTA_CB_NGSI_VERSION=v2
    
    - IOTA_AUTOCAST=true