Usage

Simple Subscription example

1. Check for a specific entities on FIWARE before subscription (eg. Room8)

Server [FIWARE ] localhost:1026/v2
Method GET
URL localhost:1026/v2/entities/Room8
Headers Content-Type: application/json
Status 404 Not Found
Response
{

“error”: “NotFound”,

“description”: “The requested entity has not been found. Check type and id”

}

Comment Entity Room8 doesn’t exist in FIWARE so we need to create it first

2. Add a Room entity to FIWARE before subscription (eg. Room8)

Server [FIWARE ] localhost:1026/v2
Method POST
URL localhost:1026/v2/entities
Headers Content-Type: application/json
Status 404 Not Found
Body
{

“id”: “Room8”,

“type”: “Room”,

“pressure”: {

“type”: “Integer”,

“value”: 123,

“metadata”: {}

},

“temperature”: {

“type”: “Float”,

“value”: 28,

“metadata”: {}

}

}

Response { }
Comment Entity Room8 doesn’t exist in FIWARE so we need to create it first

3. Check the created entity

Server [FIWARE ] localhost:1026/v2
Method GET
URL localhost:1026/v2/entities/Room8
Headers Content-Type: application/json
Status 200 OK
Response
{

“id”: “Room8”,

“type”: “Room”,

“pressure”: {

“type”: “Integer”,

“value”: 123,

“metadata”: {}

},

“temperature”: {

“type”: “Float”,

“value”: 28,

“metadata”: {}

}

}

Comment Entity Room8 created in step 2 is returned

4. Generate sample subscription.

How to make

subscription

body

Refer FIWARE

How to make

subscription

URL

To use this mediation gateway, you have to follow the following rule to set

up the notification URL. The notification URL must include “Data

group name” and “data model name” and it should looks like

http://{IP}:{PORT}/Subscribe/{DATA MODEL GROUP NAME}/{DATA MODEL NAME}

IP: IP address of the mediation gateway

Port: port address of the mediation gateway running

DATA MODEL GROUP NAME}/DATA MODEL NAME : check http://{IP}:{PORT}//FiwareDataModel

example:

Sample

subscription

body

{

“description”: “A subscription to get info about Room8”,

“subject”: {

“entities”: [

{

“id”: “Room8”,

“type”: “Room”

}

],

“condition”: {

“attrs”: [

“pressure”,

“temperature”

]

}

},

“notification”: {

“http”: {

“url”: “http://143.248.57.28:8081/Subscribe/Test/Room

},

“attrs”: [

“pressure”,

“temperature”

]

},

“expires”: “2040-01-01T14:00:00.00Z”,

“throttling”: 5

}

You can use the mediation gateway to generate sample

_images/sample-subscription.png

6. Subscribe

Server [FIWARE ] localhost:1026/v2
Method POST
URL localhost:1026/v2/ subscriptions
Headers Content-Type: application/json

Sample

subscription

body

{

“description”: “A subscription to get info about Room8”,

“subject”: {

“entities”: [

{

“id”: “Room8”,

“type”: “Room”

}

],

“condition”: {

“attrs”: [

“pressure”,

“temperature”

]

}

},

“notification”: {

“http”: {

“url”: “http://143.248.57.28:8081/Subscribe/Test/Room

},

“attrs”: [

“pressure”,

“temperature”

]

},

“expires”: “2040-01-01T14:00:00.00Z”,

“throttling”: 5

}

Status 201 Created
Response {}
Comment Subscription to Entity Room8 is created

8. Update any value of the Room

Server [FIWARE ] localhost:1026/v2
Method PATCH
URL localhost:1026/v2/entities/Room8/attrs
Headers Accept: application/json
Content-Type: application/json
Body

{

“pressure”: {

” “type”: “Integer”,

” “value”: 123,

” “metadata”: {}

” },

” “temperature”: {

” “type”: “Float”,

” “value”: 40,

” “metadata”: {}

” }

“}

Status 204 No Content
Comment Temperature value of Entity Room8 is updated to 40

9. Check if there are two Room8 events are created in epcis

Server [EPCIS ] localhost:8080
Method GET
URL http://localhost:8080/epcis/Service/Poll/SimpleEventQuery?MATCH_epc=urn:epc:id:sgtin:88000269.Room8
Status 200 OK
Response

<?xml version=”1.0” encoding=”UTF-8” standalone=”yes”?>

<EPCISQueryDocumentType

xmlns:ns2=”http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader”

xmlns:ns4=”urn:epcglobal:epcis:xsd:1” xmlns:ns3=”urn:epcglobal:epcis-query:xsd:1”>

<EPCISBody>

<ns3:QueryResults>

<queryName>SimpleEventQuery</queryName>

<resultsBody>

<EventList>

<ObjectEvent>

<eventTime>2018-08-28T17:22:09.363Z</eventTime>

<recordTime>2018-08-28T17:22:09.417Z</recordTime>

<eventTimeZoneOffset>-05:00</eventTimeZoneOffset>

<baseExtension>

<eventID>4829cb2a-97a9-43fd-bf31-fb0374a7c792</eventID>

</baseExtension>

<epcList>

<epc>urn:epc:id:sgtin:88000269.Room8</epc>

</epcList>

<action>OBSERVE</action>

<bizStep>urn:epcglobal:cbv:bizstep:driving</bizStep>

<disposition>urn:epcglobal:cbv:disp:on_the line</disposition>

<readPoint>

<id>urn:epc:id:sgln:8800026900016.Room8</id>

</readPoint>

<bizLocation>

<id>urn:epc:id:sgln:8800026900016.103.Room8</id>

</bizLocation>

<bizTransactionList>

</bizTransactionList>

<oliot:Fiware xmlns:oliot=”http://ns.oliot.com/id”>Room8</oliot:Fiware>

<oliot:Fiware xmlns:oliot=”http://ns.oliot.com/type”>Room</oliot:Fiware>

<oliot:Fiware xmlns:oliot=”http://ns.oliot.com/temprature”>

<oliot:Fiware xmlns:oliot=”http://ns.oliot.com/temprature/type”>

Float</oliot:Fiware>

<oliot:Fiware xmlns:oliot=”http://ns.oliot.com/temprature/value”>

28.0</oliot:Fiware>

</oliot:Fiware>

<oliot:Fiware xmlns:oliot=”http://ns.oliot.com/Pressure”>

<oliot:Fiware xmlns:oliot=”http://ns.oliot.com/Pressure/type”>

Float</oliot:Fiware>

<oliot:Fiware xmlns:oliot=”http://ns.oliot.com/pressure/value”>

28.0</oliot:Fiware>

</oliot:Fiware>

</ObjectEvent>

<ObjectEvent>

<eventTime>2018-08-28T17:32:24.632Z</eventTime>

<recordTime>2018-08-28T17:32:24.689Z</recordTime>

<eventTimeZoneOffset>-05:00</eventTimeZoneOffset>

<baseExtension>

<eventID>13baa91d-44ac-4a9e-a7ac-b10d6a10a464</eventID>

</baseExtension>

<epcList>

<epc>urn:epc:id:sgtin:88000269.Room8</epc>

</epcList>

<action>OBSERVE</action>

<bizStep>urn:epcglobal:cbv:bizstep:driving</bizStep>

<disposition>urn:epcglobal:cbv:disp:on_the line</disposition>

<readPoint>

<id>urn:epc:id:sgln:8800026900016.Room8</id>

</readPoint>

<bizLocation>

<id>urn:epc:id:sgln:8800026900016.103.Room8</id>

</bizLocation>

<bizTransactionList>

</bizTransactionList>

<oliot:Fiware xmlns:oliot=”http://ns.oliot.com/id”>Room8</oliot:Fiware>

<oliot:Fiware xmlns:oliot=”http://ns.oliot.com/type”>Room</oliot:Fiware>

<oliot:Fiware xmlns:oliot=”http://ns.oliot.com/temprature”>

<oliot:Fiware xmlns:oliot=”http://ns.oliot.com/temprature/type”>

Float</oliot:Fiware>

<oliot:Fiware xmlns:oliot=”http://ns.oliot.com/temprature/value”>

40.0</oliot:Fiware>

</oliot:Fiware>

<oliot:Fiware xmlns:oliot=”http://ns.oliot.com/Pressure”>

<oliot:Fiware xmlns:oliot=”http://ns.oliot.com/Pressure/type”>

Float</oliot:Fiware>

<oliot:Fiware xmlns:oliot=”http://ns.oliot.com/pressure/value”>

40.0</oliot:Fiware>

</oliot:Fiware>

</ObjectEvent>

</EventList>

</resultsBody>

</ns3:QueryResults>

</EPCISBody>

</EPCISQueryDocumentType>

Comment One event is returned

Appendix

GS1 Key proposal for farming

_images/ID.png

FIWARE data models schema for farm

Farm Entity

{
  "$id": "https://resl.com/farm.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Farm",
  "type": "object",
  "properties": {
        "farmId":{
                "type": "Text",
                "description": "It represents the id of the Farm Entity (the <farmId> contained in the EntityId)"
    },
        "type":{
                "type": "Text",
                "value": "Farm",
                "description": "Entity Type"
    },
    "address": {
      "type": "Text",
      "description": "It represents the address of the farm",
          "metadata":{}
    },
    "name": {
      "type": "Text",
      "description": "It represents the name of the farm",
          "metadata":{}
    },
    "ownerCompany": {
      "type": "Text",
      "description": "It represents the name of the company that owns the farm",
          "metadata":{}
    }
  }
}

{
        "farmId":"urn:entity:farm:<farmID>",
        "type":"Farm",
        "address":"La Cañada 04120 Almería Spain",
        "name":"Greenhouse agriculture",
        "ownerCompany":"Maria"

}

Building Entity

{
  "$id": "https://resl.com/farm.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Building",
  "type": "object",
  "properties": {
        "buildingId":{
                "type": "Text",
                "description": "It represents the id of the Building Entity (the <buildingId> contained in the EntityId attribute)"
    },
        "type":{
                "type": "Text",
                "value": "Building",
                "description": "Entity Type"
    },
    "name": {
      "type": "Text",
      "description": "It represents the name of the building",
          "metadata":{}
    },
    "lastUpdate": {
      "type": "DateTime",
      "description": "It represents the timestamp of the last update",
          "metadata":{}
    },
    "farmId": {
      "type": "Text",
      "description": "It represents the id of the Farm in which the Building is located (the farmId)",
          "metadata":{}
    },
    "temperature": {
      "type": "Float",
      "description": "It represents the last value of the temperature registered within the Building",
          "metadata":{
           "uom": {
                    "type": "string",
                    "value": "http://ontology.fiesta-iot.eu/ontologyDocs/m3-lite.owl#DegreeCelsius"
                }
          }
    },
    "humidity": {
      "type": "Float",
      "description": "It represents the last value of the humidity registered within the Building",
          "metadata":{
           "uom": {
                    "type": "string",
                    "value": "http://ontology.fiesta-iot.eu/ontologyDocs/m3-lite.owl#Humidity"
                }
          }
    },
    "luminosity": {
      "type": "Float",
      "description": "It represents the last value of the luminosity registered within the Building",
          "metadata":{
           "uom": {
                    "type": "string",
                    "value": "http://ontology.fiesta-iot.eu/ontologyDocs/m3-lite.owl#LuminousIntensity"
                }
          }
    }
  }
}

{
        "buildingId":"urn:entity:building:<buildingId>",
        "type":"Building",
        "name":{
            "type": "Text",
            "value": "La Cañada 04120 Almería Spain",
            "metadata": {}
    },
        "lastUpdate":{
            "type": "ISO8601",
            "value": "2018-08-22T05:10:58.00Z",
            "metadata": {}
    },
        "farmId":"urn:entity:farm:<farmID>",
        "temperature":{
            "type": "Float",
            "value": 37.6,
            "metadata": {
                                "uom": {
                    "type": "string",
                    "value": "http://ontology.fiesta-iot.eu/ontologyDocs/m3-lite.owl#DegreeCelsius"
                                }
                        }
    },
        "humidity":{
            "type": "Float",
            "value": 45,
            "metadata": {
                                "uom": {
                    "type": "string",
                    "value": "http://ontology.fiesta-iot.eu/ontologyDocs/m3-lite.owl#Humidity"
                                }
                        }
    },
        "luminosity":{
            "type": "Float",
            "value": 0.6,
            "metadata": {
                                "uom": {
                    "type": "string",
                    "value": "http://ontology.fiesta-iot.eu/ontologyDocs/m3-lite.owl#LuminousIntensity"
                                }
                        }
    }
}

Pen Entity

{
  "$id": "https://resl.com/farm.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Pig",
  "type": "object",
  "properties": {
        "pigId":{
                "type": "Text",
                "description": "It represents the id of the Pig Entity (the <pigId> contained in the EntityId attribute)"
    },
        "type":{
                "type": "Text",
                "value": "Pig",
                "description": "Entity Type"
    },
    "serialNumber": {
      "type": "Text",
      "description": "If a serial number is assigned to the pig by the farm, this field contains such a value",
          "metadata":{}
    },
    "lastUpdate": {
      "type": "DateTime",
      "description": "It represents the timestamp of the last update",
          "metadata":{}
    },
    "penId": {
      "type": "Text",
      "description": "It represents the id of the Farm in which the pen is located (the penId)",
          "metadata":{}
    },
    "weight": {
      "type": "Float",
      "description": "It represents the current weight of the pig (the last measured value)",
          "metadata":{
           "uom": {
                    "type": "string",
                    "value": "http://ontology.fiesta-iot.eu/ontologyDocs/m3-lite.owl#Kilogram"
                }
          }
    },
    "totalConsumedWater": {
      "type": "Float",
      "description": "it represents the amount of water that was consumed between the moment in
                                        which the pig started to drink and the current moment (e.g., if the pig started
                                        to drink 2 minutes ago and is continuing to drink, this value contains the
                                        total amount of water that the pig drunk since 2 minutes ago)",
          "metadata":{
           "uom": {
                    "type": "string",
                    "value": "http://ontology.fiesta-iot.eu/ontologyDocs/m3-lite.owl#Litre"
                }
          }
    },
    "totalConsumedFood": {
      "type": "Float",
      "description": "it represents the amount of food that was consumed between the moment
                                                in which the pig started to eat and the current moment (e.g., if the
                                                pig started to eat 2 minutes ago and is continuing to eat, this value
                                                contains the total amount of food that the pig ate since 2 minutes ago)",
          "metadata":{
           "uom": {
                    "type": "string",
                    "value": "http://ontology.fiesta-iot.eu/ontologyDocs/m3-lite.owl#Kilogram"
                }
          }
    }
  }
}

{
        "pigId":"urn:entity:pig:<pigId>",
        "type":"Pig",
        "serialNumber":{
            "type": "Text",
            "value": "8764321000003",
            "metadata": {}
    },
        "lastUpdate":{
            "type": "ISO8601",
            "value": "2018-08-22T05:10:58.00Z",
            "metadata": {}
    },
        "penId":"urn:entity:pen:<penId>",
        "weight":{
            "type": "Float",
            "value": 37.6,
            "metadata": {
                                "uom": {
                    "type": "string",
                    "value": "http://ontology.fiesta-iot.eu/ontologyDocs/m3-lite.owl#Kilogram"
                                }
                        }
    },
        "totalConsumedWater":{
            "type": "Float",
            "value": 20,
            "metadata": {
                                "uom": {
                    "type": "string",
                    "value": "http://ontology.fiesta-iot.eu/ontologyDocs/m3-lite.owl#Litre"
                                }
                        }
    },
        "totalConsumedFood":{
            "type": "Float",
            "value": 45,
            "metadata": {
                                "uom": {
                    "type": "string",
                    "value": "http://ontology.fiesta-iot.eu/ontologyDocs/m3-lite.owl#Kilogram"
                                }
                        }
    }
}