Atos-Research-and-Innovation / IoTagent-LoRaWAN

FIWARE IoT Agent for LoRaWAN protocol (with CayenneLpp and CBOR data models)
https://fiware-lorawan.readthedocs.io/en/latest/
Other
34 stars 40 forks source link

Fiware Data model representation #8

Closed dherykw closed 5 years ago

dherykw commented 6 years ago

Hi all,

First of all, thank you for your great work, we started to miss this agent.

One question, is it possible to represent a Device Fiware data model (including the location attribute) inside an Orion using this agent. If it were possible it would be nice a quick example integrating all the components. Agent + OCB + Device Data model.

Thanks so much.

dcalvoalonso commented 5 years ago

Hi @dherykw,

Could you please elaborate a bit more on this issue?

For instance, it would be helpful to understand your requirement if you could include in the issue an example regarding how such the Orion entity would look like.

dherykw commented 5 years ago

Hello @dcalvoalonso

The json schema would be this

And the entity datamodel example:

{
  "id": "device-9845A",
  "type": "Device",
  "category": ["sensor"],
  "controlledProperty": ["fillingLevel","temperature"],
  "controlledAsset": ["wastecontainer-Osuna-100"],
  "mcc": "214",
  "mnc": "07",
  "batteryLevel": 0.75,
  "serialNumber": "9845A",
  "refDeviceModel": "myDevice-wastecontainer-sensor-345",
  "value": "l=0.22;t=21.2",
  "deviceState": "ok",
  "dateFirstUsed": "2014-09-11T11:00:00Z",
  "owner": ["http://person.org/leon"],
  "location": {
    "type": "Point",
    "coordinates": [-3.712247222222222, 40.423852777777775]
  }
}

Thanks in advance.

dcalvoalonso commented 5 years ago

Most of the fields within this data model could be wrapped or provisioned using static attributes since I understand that their values will not change, e.g., category, owner or even location. The only dynamic values are: batteryLevel, value, deviceState and dateFirstUsed.

In this sense, please find below an example of device provisioning:

{

  "devices": [

    {

      "protocol": "GENERIC_PROTO",

      "device_id": "device-9845A",

      "entity_name": "device-9845A",

      "entity_type": "Device",

      "timezone": "America/Santiago",

      "attributes": [

        {

          "name": "value",

          "type": "Number"

        },

        {

          "name": "deviceState",

          "type": "String"

        },

        {

          "name": "dateFirstUsed",

          "type": "Timestamp"

        },  

        {

          "name": "batteryLevel",

          "type": "Number"

        }

      ],

      "internal_attributes": {

        "lorawan": {

          "application_server": {

            "host": "eu.thethings.network",

            "username": "ari_ioe_app_demo1",

            "password": "ttn-account-v2.UitfM5cPazqW52_zbtgUS6wM5vp1MeLC9Yu-Cozjfp0",

            "provider": "TTN"

          },

          "dev_eui": "3339343752356A14",

          "app_eui": "70B3D57ED000985F",

          "application_id": "ari_ioe_app_demo1",

          "application_key": "9BE6B8EF16415B5F6ED4FBEAFE695C49"

        }

      },

      "static_attributes": 

        [

            {

                "name": "category",

                "type": "Array",

                "value": ["sensor"]

            },

            {

                "name": "controlledProperty",

                "type": "Array",

                "value": ["fillingLevel", "temperature"]

            },    

            {

                "name": "controlledAsset",

                "type": "Array",

                "value": ["wastecontainer-Osuna-100"]

            }, 

            {

                "name": "ipAddress",

                "type": "Array",

                "value": ["192.14.56.78"]

            },

            {

                "name": "mcc",

                "type": "Number",

                "value": "214"

            },

            {

                "name": "mnc",

                "type": "Number",

                "value": "07"

            },  

            {

                "name": "serialNumber",

                "type": "String",

                "value": "9845A"

            },     

            {

                "name": "refDeviceModel",

                "type": "String",

                "value": "myDevice-wastecontainer-sensor-345"

            },    

            {

                "name": "owner",

                "type": "Array",

                "value": ["http://person.org/leon"]

            },

            {

                "name": "location",

                "type": "geo:point",

                "value": "-3.712247222222222, 40.423852777777775"       

            }

        ]

    }

  ]

}

batteryLevel, value, deviceState and dateFirstUsed must be reported by the correponding IoT device. For that purpose, the IoT Agent supports two different LoRaWAN infrastructures (TTN and LoRaServer.io) and two different data models (CayenneLpp and CBOR).

dherykw commented 5 years ago

Hello Daniel,

Thanks so much for the support, in our use case batteryLevel, values (fill level and temperature) and GPS is provided by the IoT Device but using CayenneLpp or CBOR format, for that reason we think that data must be formated by the IoTAgent to match with the Device Data Model.

I am trying to find some documentation to know if the location format that you propose is compatible with geolocation queries.

Thanks again.

dcalvoalonso commented 5 years ago

From your last message, I understand that maybe we are talking about a waste management use case, correct? I ask this because there is a more appropriate data model: https://github.com/Fiware/dataModels/blob/master/specs/WasteManagement/WasteContainer/doc/spec.md

dherykw commented 5 years ago

It is a specific IoF use case for fumigating but we have used the device data model example adding location because it is very close to our use case. Indeed we have a proposal to improve the data model, but this is another business of another repo. :)

dcalvoalonso commented 5 years ago

You can use CayenneLpp and TTN LoRaWAN infrastructure. For instance, in order to provision the device:

{

  "devices": [

    {

      "protocol": "GENERIC_PROTO",

      "device_id": "lora-n-001",

      "entity_name": "lora-n-001",

      "entity_type": "Device",

      "timezone": "America/Santiago",

      "attributes": [

        {

          "name": "temperature_1",

          "type": "Number"

        },

        {

          "name": "analog_in_2",

          "type": "String"

        },

        {

          "name": "analog_in_3",

          "type": "Number"

        },

        {

          "name": "location",

          "type": "geo:point",

          "object_id": "gps_0"

        }

      ],

      "internal_attributes": {

        "lorawan": {

          "application_server": {

            "host": "eu.thethings.network",

            "username": "ari_ioe_app_demo1",

            "password": "********************************************",

            "provider": "TTN"

          },

          "dev_eui": "**********************************",

          "app_eui": "*************************",

          "application_id": "ari_ioe_app_demo1",

          "application_key": "*******************************"

        }

      },

      "static_attributes": 

        [

            {

                "name": "category",

                "type": "Array",

                "value": ["sensor"]

            },

            {

                "name": "controlledProperty",

                "type": "Array",

                "value": ["fillingLevel", "temperature"]

            },    

            {

                "name": "controlledAsset",

                "type": "Array",

                "value": ["wastecontainer-Osuna-100"]

            }, 

            {

                "name": "ipAddress",

                "type": "Array",

                "value": ["192.14.56.78"]

            },

            {

                "name": "mcc",

                "type": "Number",

                "value": "214"

            },

            {

                "name": "mnc",

                "type": "Number",

                "value": "07"

            },  

            {

                "name": "serialNumber",

                "type": "String",

                "value": "9845A"

            },     

            {

                "name": "refDeviceModel",

                "type": "String",

                "value": "myDevice-wastecontainer-sensor-lora-n-001"

            },    

            {

                "name": "owner",

                "type": "Array",

                "value": ["http://person.org/leon"]

            }

        ]

    }

  ]

}

This would result in the following representation at the Context Broker:

[
    {
        "id": "lora-n-001",
        "type": "Device",
        "TimeInstant": {
            "type": "DateTime",
            "value": "2018-09-13T14:32:04.00Z",
            "metadata": {}
        },
        "analog_in_2": {
            "type": "String",
            "value": 0.75,
            "metadata": {
                "TimeInstant": {
                    "type": "DateTime",
                    "value": "2018-09-13T14:32:04.00Z"
                }
            }
        },
        "analog_in_3": {
            "type": "Number",
            "value": 0.22,
            "metadata": {
                "TimeInstant": {
                    "type": "DateTime",
                    "value": "2018-09-13T14:32:04.00Z"
                }
            }
        },
        "category": {
            "type": "Array",
            "value": [
                "sensor"
            ],
            "metadata": {
                "TimeInstant": {
                    "type": "DateTime",
                    "value": "2018-09-13T14:32:04.00Z"
                }
            }
        },
        "controlledAsset": {
            "type": "Array",
            "value": [
                "wastecontainer-Osuna-100"
            ],
            "metadata": {
                "TimeInstant": {
                    "type": "DateTime",
                    "value": "2018-09-13T14:32:04.00Z"
                }
            }
        },
        "controlledProperty": {
            "type": "Array",
            "value": [
                "fillingLevel",
                "temperature"
            ],
            "metadata": {
                "TimeInstant": {
                    "type": "DateTime",
                    "value": "2018-09-13T14:32:04.00Z"
                }
            }
        },
        "ipAddress": {
            "type": "Array",
            "value": [
                "192.14.56.78"
            ],
            "metadata": {
                "TimeInstant": {
                    "type": "DateTime",
                    "value": "2018-09-13T14:32:04.00Z"
                }
            }
        },
        "location": {
            "type": "geo:point",
            "value": "0, 0",
            "metadata": {}
        },
        "mcc": {
            "type": "Number",
            "value": "214",
            "metadata": {
                "TimeInstant": {
                    "type": "DateTime",
                    "value": "2018-09-13T14:32:04.00Z"
                }
            }
        },
        "mnc": {
            "type": "Number",
            "value": "07",
            "metadata": {
                "TimeInstant": {
                    "type": "DateTime",
                    "value": "2018-09-13T14:32:04.00Z"
                }
            }
        },
        "owner": {
            "type": "Array",
            "value": [
                "http://person.org/leon"
            ],
            "metadata": {
                "TimeInstant": {
                    "type": "DateTime",
                    "value": "2018-09-13T14:32:04.00Z"
                }
            }
        },
        "refDeviceModel": {
            "type": "String",
            "value": "myDevice-wastecontainer-sensor-lora-n-001",
            "metadata": {
                "TimeInstant": {
                    "type": "DateTime",
                    "value": "2018-09-13T14:32:04.00Z"
                }
            }
        },
        "serialNumber": {
            "type": "String",
            "value": "9845A",
            "metadata": {
                "TimeInstant": {
                    "type": "DateTime",
                    "value": "2018-09-13T14:32:04.00Z"
                }
            }
        },
        "temperature_1": {
            "type": "Number",
            "value": 27.4,
            "metadata": {
                "TimeInstant": {
                    "type": "DateTime",
                    "value": "2018-09-13T14:32:04.00Z"
                }
            }
        }
    }
]

Note that analog_in_2, analog_in_3 correspond to batteryLevel and level measurements.

Examples of CayenneLpp payloads to report values for these fields are:

dherykw commented 5 years ago

Thanks so much Daniel, I only have two question:

  1. would be analog_in_2, analog_in_3, and temperature_1 compliant with the fiware data models?
  2. will this location attribute format allow Geographical Queries?

Best

dcalvoalonso commented 5 years ago
  1. As you pointed in https://github.com/Atos-Research-and-Innovation/IoTagent-LoRaWAN/issues/8#issuecomment-420627755, in https://github.com/Fiware/dataModels, there is not a model that fits exactly your use-case. Therefore, I feel that you cannot be compliant with anything. In this sense, you could open a new issue in https://github.com/Fiware/dataModels, explain that you have detected this lack and propose a new model with a Pull Request.
  2. Yes. In fact, there is an open PR in https://github.com/Fiware/dataModels/pull/254/files to improve the documentation of the current models for location fields. As you can see, one of the supported types is geo:point.
dherykw commented 5 years ago

We have planted a similar issue to fgalan in the FIWARE data model repository, we tried to propose a solution but he has suggested us that we should represent the value in the following format to compliant with the FIWARE data models.

"value": {
  "type": "StructuredValue",
  "value":   {
    "temperature": 28.5
    "humidity": 68
  },
  "metadata": {
    "units": {
      "type": "StructuredValue",
      "value": {
        "temperature": "ºC",
        "humidity": "%"
      }
    }
  }
}

Is that possible using this IoTAgent?

Thanks in advance

dcalvoalonso commented 5 years ago

I am afraid that using structured data is not possible nor with this IoT Agents or with any other. You can see that there is an open and unresolved issue in the base library that is used by all the agents: https://github.com/telefonicaid/iotagent-node-lib/issues/549. :(

dherykw commented 5 years ago

Ok Daniel, thank you very much for your support and patience.

I will request to fix the issue in the iotagent node lib issue that you have mentioned. telefonicaid/iotagent-node-lib#549 :+1: