Fiware orion subscription sending empty body

SamuelTJackson

My setup: 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: ~

context:

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

The subscription:

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"
    }
  }
}'

How I successfully update the value numberOfBottles:

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'

My usecase is something like:

There is an office with water bottles for the employee. There is a 'sensor' which can count the water bottles. When an employee is taking a water bottle the sensor will update the value in fiware. When the number is below 3 fiware should notify the subscriber. The subscriber can now order new water bottles.

I have several problems:

  1. With the condition numberOfBottles<10 the subscription never get triggered. When I use something like numberOfBottles!=10 it is working
  2. There is only an empty body sent to the url http://delivery:8080/subscription/office

A bonus question: if I can fix the first issues: Is there a way to send the attribute address from urn:ngsi-ld:DeliverService:unit001 to the url http://delivery:8080/subscription/office when the subscription get triggered?

fgalan

As far as I remember, IOTAs are configured by default to use NGSIv1 to send updates to CB. One of the limitations of the NGSIv1 API (deprecated :) is that numbers are parsed always as strings. Thus it makes sense the numberOfBottles<10 filter doesn't work.

In order to overcome this problem IOTA should be configured to use NGSIv2. Add the following to the envrironment of the iot-agent in your docker-compose.yml and redeploy:

- IOTA_CB_NGSI_VERSION=v2

With regards to bonus question, I think @JasonFox has already answered it in the question comments.

EDIT: I have realized you are using UL agent. Different from JSON agent (which allows you to specify JSON supported values, such as numbers, in the request sent to the agent) UL encoding is based on text. Thus, in order to progress numeric values to CB you need (in addition to the IOTA_CB_NGSI_VERSION setting described above):

  1. Set the IOTA_AUTOCAST configuration to true:

    - IOTA_AUTOCAST=true
    
  2. Use "Number" as attribute type at provisioning time (instead of "Integer").

This is described in more detail in this section of the documentation.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

FIWARE:Orion ContextBrokerとCKAN

分類Dev

FIWARE Orion:通知応答

分類Dev

FIWARE Orion string query and dates

分類Dev

Camel body empty after sending to HTTP

分類Dev

Sendgrid Inbound Webhook Sending Empty Body

分類Dev

Sending an error to the subscription RXJS

分類Dev

What is wrong with my GEs subscription to Orion CB?

分類Dev

fiware orion:環境ごとに構成

分類Dev

Fiware Orion Context Broker-Send notifications after a period of time

分類Dev

Fiware Orion:Orion内部mongoDBを使用して他の情報を保存する

分類Dev

FIWARE Orion: orion からの通知に CreDate と modDate を追加する方法は?

分類Dev

Fiware: How to restrict user access to specific entity for Orion Context Broker API using keystone & keypass

分類Dev

Fiware Orion:httpCustom通知で属性を検出する

分類Dev

Fiware-Orion:ジオロケーション

分類Dev

FIWARE Orion:エンティティタイプの変更

分類Dev

Fiware:OrionとCygnus間の通信を保護する方法は?

分類Dev

Sending GET request parameters in body

分類Dev

Empty body with express and nodejs

分類Dev

Rectangular post body empty

分類Dev

FIWARE Orion:マルチテナンシーとフェデレーション

分類Dev

FIWARE Orion:サブスクリプションのフィルター

分類Dev

特定のmongodbセットアップでfiware-orionをデプロイする

分類Dev

FIWARE Orion Dockerコンテナ:通知サブスクリプションの問題

分類Dev

FIWARE Orionおよびpepプロキシソリューション?

分類Dev

Fiware-Orion ContextBrokerサブスクリプションの有効期限

分類Dev

Error While sending a mail from Email subscription in SSRS

分類Dev

Sending HTTP Post Request to site with array in Body

分類Dev

Empty Request body on express app

分類Dev

Spotify API returns empty body

Related 関連記事

  1. 1

    FIWARE:Orion ContextBrokerとCKAN

  2. 2

    FIWARE Orion:通知応答

  3. 3

    FIWARE Orion string query and dates

  4. 4

    Camel body empty after sending to HTTP

  5. 5

    Sendgrid Inbound Webhook Sending Empty Body

  6. 6

    Sending an error to the subscription RXJS

  7. 7

    What is wrong with my GEs subscription to Orion CB?

  8. 8

    fiware orion:環境ごとに構成

  9. 9

    Fiware Orion Context Broker-Send notifications after a period of time

  10. 10

    Fiware Orion:Orion内部mongoDBを使用して他の情報を保存する

  11. 11

    FIWARE Orion: orion からの通知に CreDate と modDate を追加する方法は?

  12. 12

    Fiware: How to restrict user access to specific entity for Orion Context Broker API using keystone & keypass

  13. 13

    Fiware Orion:httpCustom通知で属性を検出する

  14. 14

    Fiware-Orion:ジオロケーション

  15. 15

    FIWARE Orion:エンティティタイプの変更

  16. 16

    Fiware:OrionとCygnus間の通信を保護する方法は?

  17. 17

    Sending GET request parameters in body

  18. 18

    Empty body with express and nodejs

  19. 19

    Rectangular post body empty

  20. 20

    FIWARE Orion:マルチテナンシーとフェデレーション

  21. 21

    FIWARE Orion:サブスクリプションのフィルター

  22. 22

    特定のmongodbセットアップでfiware-orionをデプロイする

  23. 23

    FIWARE Orion Dockerコンテナ:通知サブスクリプションの問題

  24. 24

    FIWARE Orionおよびpepプロキシソリューション?

  25. 25

    Fiware-Orion ContextBrokerサブスクリプションの有効期限

  26. 26

    Error While sending a mail from Email subscription in SSRS

  27. 27

    Sending HTTP Post Request to site with array in Body

  28. 28

    Empty Request body on express app

  29. 29

    Spotify API returns empty body

ホットタグ

アーカイブ