IoT Agent for UltraLight 2.0

Sanity check for IoT Agent for UL

Once IoT Agent for UltraLight 2.0 is running, you can check the status by the following command:

Request:

ngsi version --host iotagent-ul.example.com --pretty

Response:

{
  "libVersion": "2.15.1",
  "port": "4041",
  "baseRoot": "/",
  "version": "1.16.2"
}

IoT Agent for UL over MQTT

Create service

Request:

ngsi services \
  --host iotagent-ul.example.com \
  create \
  --apikey 8f9z57ahxmtzx21oczr5vaabot \
  --type Thing \
  --resource /iot/ul \
   --cbroker http://orion:1026

List services

Request:

ngsi services \
  --host iotagent-ul.example.com \
  list \
  --pretty

Response:

{
  "count": 1,
  "services": [
    {
      "commands": [],
      "lazy": [],
      "attributes": [],
      "_id": "618cff6b36b21980226fffc2",
      "resource": "/iot/ul",
      "apikey": "8f9z57ahxmtzx21oczr5vaabot",
      "service": "openiot",
      "subservice": "/",
      "__v": 0,
      "static_attributes": [],
      "internal_attributes": [],
      "entity_type": "Thing"
    }
  ]
}

Create device

Request:

ngsi devices \
  --host iotagent-ul.example.com \
  create \
  --data '{ \
  "devices": [
    {
      "device_id":   "sensor001",
      "entity_name": "urn:ngsi-ld:WeatherObserved:sensor001",
      "entity_type": "Sensor",
      "timezone":    "Asia/Tokyo",
      "protocol":    "PDI-IoTA-UltraLight",
      "transport":   "MQTT",
      "attributes": [
        { "object_id": "d", "name": "dateObserved", "type": "DateTime" },
        { "object_id": "t", "name": "temperature", "type": "Number" },
        { "object_id": "h", "name": "relativeHumidity", "type": "Number" },
        { "object_id": "p", "name": "atmosphericPressure", "type": "Number" }
      ],
      "static_attributes": [
        { "name":"location", "type": "geo:json", "value" : { "type": "Point", "coordinates" : [ 139.7671, 35.68117 ] } }
      ]
    }
  ]
}'

List devices

Request:

ngsi devices \
  --host iotagent-ul.example.com \
  list \
  --pretty

Response:

{
  "count": 1,
  "devices": [
    {
      "device_id": "sensor001",
      "service": "openiot",
      "service_path": "/",
      "entity_name": "urn:ngsi-ld:WeatherObserved:sensor001",
      "entity_type": "Sensor",
      "transport": "MQTT",
      "attributes": [
        {
          "object_id": "d",
          "name": "dateObserved",
          "type": "DateTime"
        },
        {
          "object_id": "t",
          "name": "temperature",
          "type": "Number"
        },
        {
          "object_id": "h",
          "name": "relativeHumidity",
          "type": "Number"
        },
        {
          "object_id": "p",
          "name": "atmosphericPressure",
          "type": "Number"
        }
      ],
      "lazy": [],
      "commands": [],
      "static_attributes": [
        {
          "name": "location",
          "type": "geo:json",
          "value": {
            "type": "Point",
            "coordinates": [
              139.7671,
              35.68117
            ]
          }
        }
      ],
      "protocol": "PDI-IoTA-UltraLight",
      "explicitAttrs": false
    }
  ]
}

Send data

Request:

mosquitto_pub \
  --debug \
  --host mosquitto.example.com
  --port 8883 \
  --username fiware --pw ZSpi0wAz1e1ZImd8 \
  --topic "/8f9z57ahxmtzx21oczr5vaabot/sensor001/attrs" \
  --message "d|2021-11-11T11:36:49+0000|t|10465|h|27378|p|20617" \
  --cafile ./config/mosquitto/isrgrootx1.pem

Get entity

Request:

ngsi get \
  --host orion.example.com \
  --service openiot \
  --path / \
  entity \
  --id urn:ngsi-ld:WeatherObserved:sensor001 \
  --pretty

Response:

{
  "id": "urn:ngsi-ld:WeatherObserved:sensor001",
  "type": "Sensor",
  "TimeInstant": {
    "type": "DateTime",
    "value": "2021-11-11T11:36:49.576Z",
    "metadata": {}
  },
  "atmosphericPressure": {
    "type": "Number",
    "value": 20617,
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2021-11-11T11:36:49.576Z"
      }
    }
  },
  "dateObserved": {
    "type": "DateTime",
    "value": "2021-11-11T11:36:49.000Z",
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2021-11-11T11:36:49.576Z"
      }
    }
  },
  "location": {
    "type": "geo:json",
    "value": {
      "type": "Point",
      "coordinates": [
        139.7671,
        35.68117
      ]
    },
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2021-11-11T11:36:49.576Z"
      }
    }
  },
  "relativeHumidity": {
    "type": "Number",
    "value": 27378,
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2021-11-11T11:36:49.576Z"
      }
    }
  },
  "temperature": {
    "type": "Number",
    "value": 10465,
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2021-11-11T11:36:49.576Z"
      }
    }
  }
}

Examples

Look at examples here.

IoT Agent for UL over HTTP

Create service

Request:

ngsi services \
  --host iotagent-ul.example.com \
  create \
  --apikey Dk8A0vfwTkTiAY71QyyKzOv9CT \
  --type Thing \
  --resource /iot/ul \
  --cbroker http://orion:1026

List services

Request:

ngsi services \
  --host iotagent-ul.example.com \
  list \
  --pretty

Response:

{
  "count": 1,
  "services": [
    {
      "commands": [],
      "lazy": [],
      "attributes": [],
      "_id": "618d03230e779727e4443d1a",
      "resource": "/iot/ul",
      "apikey": "Dk8A0vfwTkTiAY71QyyKzOv9CT",
      "service": "openiot",
      "subservice": "/",
      "__v": 0,
      "static_attributes": [],
      "internal_attributes": [],
      "entity_type": "Thing"
    }
  ]
}

Create device

Request:

ngsi devices \
  --host iotagent-ul.example.com \
  create \
  --data '{
  "devices": [
    {
      "device_id":   "sensor003",
      "entity_name": "urn:ngsi-ld:WeatherObserved:sensor003",
      "entity_type": "Sensor",
      "timezone":    "Asia/Tokyo",
      "attributes": [
        { "object_id": "d", "name": "dateObserved", "type": "DateTime" },
        { "object_id": "t", "name": "temperature", "type": "Number" },
        { "object_id": "h", "name": "relativeHumidity", "type": "Number" },
        { "object_id": "p", "name": "atmosphericPressure", "type": "Number" }
      ],
      "static_attributes": [
        { "name":"location", "type": "geo:json", "value" : { "type": "Point", "coordinates" : [ 139.7671, 35.68117 ] } }
      ]
    }
  ]
}'

List devices

Request:

ngsi devices \
  --host iotagent-ul.example.com \
  list \
  --pretty

Response:

  "count": 1,
  "devices": [
    {
      "device_id": "sensor003",
      "service": "openiot",
      "service_path": "/",
      "entity_name": "urn:ngsi-ld:WeatherObserved:sensor003",
      "entity_type": "Sensor",
      "transport": "HTTP",
      "attributes": [
        {
          "object_id": "d",
          "name": "dateObserved",
          "type": "DateTime"
        },
        {
          "object_id": "t",
          "name": "temperature",
          "type": "Number"
        },
        {
          "object_id": "h",
          "name": "relativeHumidity",
          "type": "Number"
        },
        {
          "object_id": "p",
          "name": "atmosphericPressure",
          "type": "Number"
        }
      ],
      "lazy": [],
      "commands": [],
      "static_attributes": [
        {
          "name": "location",
          "type": "geo:json",
          "value": {
            "type": "Point",
            "coordinates": [
              139.7671,
              35.68117
            ]
          }
        }
      ],
      "explicitAttrs": false
    }
  ]
}

Send data

Request:

 curl -X POST "https://iotagent-http.example.com/iot/ul?k=Dk8A0vfwTkTiAY71QyyKzOv9CT&i=sensor003" \
   -u "fiware:AEAtp3JC6qxtPKah" \
   -H "Content-Type: text/plain" \
   -d "d|2021-11-11T11:59:14+0000|t|20641|h|8290|p|5371"

Get entity

Request:

ngsi get \
  --host orion.example.com \
  --service openiot \
  --path / \
  entity \
  --id urn:ngsi-ld:WeatherObserved:sensor003 \
  --pretty

Response:

{
  "id": "urn:ngsi-ld:WeatherObserved:sensor003",
  "type": "Sensor",
  "TimeInstant": {
    "type": "DateTime",
    "value": "2021-11-11T11:59:14.440Z",
    "metadata": {}
  },
  "atmosphericPressure": {
    "type": "Number",
    "value": 5371,
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2021-11-11T11:59:14.440Z"
      }
    }
  },
  "dateObserved": {
    "type": "DateTime",
    "value": "2021-11-11T11:59:14.000Z",
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2021-11-11T11:59:14.440Z"
      }
    }
  },
  "location": {
    "type": "geo:json",
    "value": {
      "type": "Point",
      "coordinates": [
        139.7671,
        35.68117
      ]
    },
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2021-11-11T11:59:14.440Z"
      }
    }
  },
  "relativeHumidity": {
    "type": "Number",
    "value": 8290,
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2021-11-11T11:59:14.440Z"
      }
    }
  },
  "temperature": {
    "type": "Number",
    "value": 20641,
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2021-11-11T11:59:14.440Z"
      }
    }
  }
}

Examples

Look at examples here.