Code Monkey home page Code Monkey logo

tutorials.ngsi-ld's Introduction

Smart Farm Tutorials

Documentation License: MIT Support badge Docker badge
Documentation CI

This is a collection of tutorials for the FIWARE ecosystem designed for NGSI-LD developers. Each tutorial consists of a series of exercises to demonstrate the correct use of individual FIWARE components and shows the flow of context data within a simple Smart Solution either by connecting to a series of dummy IoT devices or manipulating the context directly or programmatically.

📚
NGSI-LD
Documentation

Postman
Collections
Docker Hub
Quay.io
Artifact Hub

developer.​fiware.org

Note

Should I use NGSI-LD or NGSI-v2?

FIWARE offers two flavours of the NGSI interfaces:

  • NGSI-v2 offers JSON based interoperability used in individual Smart Systems
  • NGSI-LD offers JSON-LD based interoperability used for Federations and Data Spaces

Of the two, NGSI-LD is more complex and relies on the introduction of a JSON-LD @context. A full understanding of JSON-LD (Linked Data) is required to obtain the benefits of NGSI-LD , which allows for interoperability across apps and organisations.

In general, you should use NGSI-LD when creating a data space or introducing a system of systems aproach.

Use NGSI-v2 for simpler isolated systems. More information about NGSI-v2 can be found here

Data models

The tutorials define a series of data-models to be used within the @context. More information about the classes and attributes used can be found in the following:

Install

To download the full set of tutorials, simply clone this repository:

git clone https://github.com/FIWARE/tutorials.NGSI-LD.git
cd tutorials.NGSI-LD/
git submodule update --init --recursive

Swagger

The OpenAPI Specification (commonly known as Swagger) is an API description format for REST APIs. A Swagger spec allows you to describe an entire API (such as NGSI-LD itself) however in this tutorial we shall be concentrating on using Swagger to define data models.

API specifications can be written in YAML or JSON. The format is easy to learn and readable to both humans and machines. The complete OpenAPI Specification can be found on GitHub: OpenAPI 3.0 Specification. This is important since we will need a well-defined structure to be able to generate @context files.

Docker and Docker Compose

The NGSI-LD tutorials are designed to run under any Unix environment, the tested configuration and GitPod environment is currently based on Ubuntu 22.04.2 LTS. However, there may be some minor issues when running the tutorials directly on Windows machines or Apple M1 Silicon amd64 systems, and the following Virtual Box set-up or WSL set-up can be used when facing issues.

Each tutorial runs all components using Docker. Docker is a container technology which allows to different components isolated into their respective environments.

  • To install Docker on Windows follow the instructions here.
  • To install Docker on Mac follow the instructions here.
  • To install Docker on Linux follow the instructions here.

Docker Compose is a tool for defining and running multi-container Docker applications. A series of *.yaml files are used configure the required services for the application. This means all container services can be brought up in a single command. Docker Compose is installed by default as part of Docker for Windows and Docker for Mac, however Linux users will need to follow the instructions found here.

You can check your current Docker and Docker Compose versions using the following commands:

docker-compose -v
docker version

Please ensure that you are using Docker version 24.0.x or higher and Docker Compose 2.24.x or higher and upgrade if necessary.

Although not officially supported, older versions of docker without an integrated docker-compose can be run by adding legacy to all bash script commands:

./services start legacy

Postman

The tutorials which use HTTP requests supply a collection for use with the Postman utility. Postman is a testing framework for REST APIs. The tool can be downloaded from www.postman.com. All the FIWARE Postman collections can be downloaded directly from the Postman API network.

GitPod

Gitpod is an open-source Kubernetes application for ready-to-code cloud development environments that spins up an automated dev environment for each task, in the cloud. It enables you to run the tutorials in a cloud development environment directly from your browser or your Desktop IDE.

Windows Subsystem for Linux

We will start up our services using a simple bash script. Windows users should download the Windows Subsystem for Linux to provide a command-line functionality similar to a Linux distribution on Windows.

Tutorials List

Core Context Management: NGSI-LD Fundamentals

  101. Understanding @context
  102. Working with @context
  103. CRUD Operations
  104. Concise Payloads
  105. Merge-Patch and Put
  106. Entity Relationships
  107. Subscriptions
  108. Temporal Operations
109. Extended Properties

Internet of Things, Robots and third-party systems

  201. Introduction to IoT Sensors
  202. Provisioning the Ultralight IoT Agent
  203. Provisioning the JSON IoT Agent

Core Context Management: Manipulating Context Data and Persisting Historic Data

  304. Querying Time Series Data (QuantumLeap)
  305. Big Data Analysis (Flink)
  306. Big Data Analysis (Spark)

Security: Identity Management

  401. Managing Users and Organizations
  402. Roles and Permissions

Processing, Analysis and Visualization

  507. Cloud-Edge Computing

Usage

Most tutorials supply a services script to start the containers:

cd <tutorial-name>
git checkout NGSI-LD
./services start

Following the tutorial exercises via Postman

Each tutorial submodule contains one or more docker-compose.yml files, along with a Postman collection containing the necessary HTTP requests: import the collection into Postman and follow the instructions.

Following the tutorial exercises from the command-line

Each submodule contains full instructions in README which details the appropriate bash commands (cUrl and Docker Compose) to run.

Full instructions can be found within the documentation


License

MIT © 2020-2024 FIWARE Foundation e.V.

tutorials.ngsi-ld's People

Contributors

actions-user avatar asmataamallah1 avatar dependabot[bot] avatar elcid-chawa avatar fisuda avatar flopezag avatar imgbotapp avatar jason-fox avatar jmcanterafonseca-iota avatar kilicbaran avatar pradumnnec avatar skorpinakos avatar tarswars avatar tobixdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tutorials.ngsi-ld's Issues

Use of payload with HTTP GET

In many examples, a payload is used with GET requests, for example

curl -G -iX GET 'http://localhost:1026/ngsi-ld/v1/entities/urn:ngsi-ld:TemperatureSensor:001' \
-H 'Link: <http://context/ngsi-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
-d 'attrs=temperature'

I think this should be avoided and all data should included as query parameters. Note that according to HTTP 1.1 RFC

A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request

include "verified" property data-models/ngsi-context.jsonld

Tutorial examples use the verified property of property (e.g., the request in this example) However, this term is not included in the context file

As a matter of fact, if you replace the context url in that request with

https://raw.githubusercontent.com/FIWARE/tutorials.Getting-Started/NGSI-LD/data-models/ngsi-context.jsonld

and then put the output in json-ld playground, you will observe that "verified" property is ignored.

Proof of concept

Integration of NGSILD broker with orion broker

I was integrating IoT Agent with orion-ld , by using [https://ngsi-ld-tutorials.readthedocs.io/en/latest/iot-agent.html]. i was trying request no 14 by using upsert API for sending the command to the device. please help me to do this.

Use of undefined attributes in "Understanding @context" section

The tutorial says:

Many types of device reading (i.e. context data attributes) have been predefined within the SAREF ontology - so it is reasonable to use the URIs defining these attributes as a basis of extending our model.

However fillingLevel is not defined in https://ontology.tno.nl/saref/. Similarly, at some other point it uses:

"airPollution": "https://w3id.org/saref#airPollution",
"atmosphericPressure": "https://w3id.org/saref#atmosphericPressure",

But both airPollution and atmosphericPressure are not defined in https://ontology.tno.nl/saref/

As side note, as far as I could search bot airPollution and fillingLevel are not event defined in ETSI's SAREF ontology.

Entity ID uniqueness concern

First, thank you for writing these tutorials, they are a great help in getting started with NGSI-LD.

I think the uniqueness of the full entity IDs is in question when following the tutorial.

Reading section "Creating Several Entities at Once" there is a paragraph that says:

In both cases we have encoded each entity id according to the NGSI-LD specification - the proposal is that each id is a URN
follows a standard format: urn:ngsi-ld::. This will mean that every id in the system will be unique.

Also important: probably better to name this 'service-id' or 'device-id' as the term entity-id can easily be confused with the entity's id itself.

The concern is that this does not make an entity's full id unique. There seems to be an assumption that there is a single creator of entities that can guarantee that 'entitiy-id' is unique for an entity-type. This is an incorrect assumption. In an IoT environment there can be multiple agents that publish a temperature for example, each agent will use its own entity-id but without central coordination there is a chance of duplication. Another example, in my test setup I have two zwave controllers. These controllers generate device-id's starting numbering at 1. Using various temperature sensors on both controllers show there are two sensors with device ID 2 simply because that is how the numbering per controller works out.

What seems to be missing is to include the unique ID of the publisher/agent that is responsible the entity creation.
The entity ID format would look like this:

urn:ngsi-ld:<entity-type>:<agent-id>:<device-id>[:...]

As long as agent-id's are unique the entity will be unique.
There are other ways to solve this problem but way leaves a nice breadcrumb of ownership in the entity's full id.

I've seen this issue in various documents including the ETSI specs so this concern is wider spread. The tutorials however seems like a good place to start.

I hope this helps somebody.
(updated to fix the entity ID presentation)

integration issue

Hi ,

I am integrating IOT agent from FogFlow using orion broker . In this scenario IOT agent send the data to the Orion broker and FogFlow have subscribe to the Orion broker to get the data . FogFlow is getting the following data in the notification .

{
	"@context": "https://fiware.github.io/data-models/context.jsonld",
	"id": "urn:ngsi-ld:Device:water001",
	"type": "Device",
	"heartRate": {
		"type": "Property",
		"value": {
			"@type": "Intangible",
			"@value": null
		},
		"unitCode": "5K"
	},
	"status": {
		"type": "Property",
		"value": {
			"@type": "Intangible",
			"@value": null
		}
	},
	"location": {
		"type": "GeoProperty",
		"value": {
			"type": "Point",
			"coordinates": [0, 0]
		}
	},
	"controlledAsset": {
		"type": "Relationship",
		"object": "urn:ngsi-ld:Building:barn001"
	},
	"category": {
		"type": "Property",
		"value": "sensor"
	},
	"supportedProtocol": {
		"type": "Property",
		"value": "ul20"
	},
	"on_status": {
		"type": "Property",
		"value": {
			"@type": "commandStatus",
			"@value": "UNKNOWN"
		}
	},
	"on_info": {
		"type": "Property",
		"value": {
			"@type": "commandResult",
			"@value": " "
		}
	},
	"off_status": {
		"type": "Property",
		"value": {
			"@type": "commandStatus",
			"@value": "UNKNOWN"
		}
	},
	"off_info": {
		"type": "Property",
		"value": {
			"@type": "commandResult",
			"@value": " "
		}
	},
	"on": {
		"type": "command",
		"value": ""
	},
	"off": {
		"type": "command",
		"value": ""
	}
}

This data has @type and @value at some places. I am confused whether this data is correct or not , because if we use same data to create entity i am getting error of "NOT A VALID JSON" Scorpio broker .

Git clone command correction

https://ngsi-ld-tutorials.readthedocs.io/en/latest/iot-agent-json.html shows:
git clone https://github.com/FIWARE/tutorials.IoT-Agent.git
should be changed to
git clone https://github.com/FIWARE/tutorials.IoT-Agent-JSON.git

But for the tutorials.IoT-Agent-JSON repository the issue was already fixed (see also FIWARE/tutorials.IoT-Agent-JSON#3).

Given that tutorials.IoT-Agent-JSON is a submodule of tutorials.NGSI-LD, perhaps it's missing a submodule update? (i.e. point tutorials.IoT-Agent-JSON to latest version)

Tutorial sequence is unclear

The Temporal Operations page states: "The tutorial activates the IoT collars for connected animals in the previous tutorial and links to the IoT-Agent tutorials page, which is inconsistent when you come from the subscriptions tutorial and have clicked on the 'Next' button at the bottom of the page.

In addition, I followed the IoT-Agent tutorial but didn't see anything that corresponded to collar activation.

installation issue

Hi ,

I am getting the following issue while installing setup with Scorpio broker .

Template parsing error: template: :1:8: executing "" at <.State.Health.Status>: map has no entry for key "Health"
./services: line 90: [: ==: unary operator expected
Template parsing error: template: :1:8: executing "" at <.State.Health.Status>: map has no entry for key "Health"
./services: line 90: [: ==: unary operator expected
Template parsing error: template: :1:8: executing "" at <.State.Health.Status>: map has no entry for key "Health"
./services: line 90: [: ==: unary operator expected
Template parsing error: template: :1:8: executing "" at <.State.Health.Status>: map has no entry for key "Health"
./services: line 90: [: ==: unary operator expected
Template parsing error: template: :1:8: executing "" at <.State.Health.Status>: map has no entry for key "Health"
./services: line 90: [: ==: unary operator expected
Template parsing error: template: :1:8: executing "" at <.State.Health.Status>: map has no entry for key "Health"
./services: line 90: [: ==: unary operator expected
Template parsing error: template: :1:8: executing "" at <.State.Health.Status>: map has no entry for key "Health"
./services: line 90: [: ==: unary operator expected
Template parsing error: template: :1:8: executing "" at <.State.Health.Status>: map has no entry for key "Health"
./services: line 90: [: ==: unary operator expected
Template parsing error: template: :1:8: executing "" at <.State.Health.Status>: map has no entry for key "Health"
./services: line 90: [: ==: unary operator expected
Template parsing error: template: :1:8: executing "" at <.State.Health.Status>: map has no entry for key "Health"
./services: line 90: [: ==: unary operator expected
Template parsing error: template: :1:8: executing "" at <.State.Health.Status>: map has no entry for key "Health"
./services: line 90: [: ==: unary operator expected
Template parsing error: template: :1:8: executing "" at <.State.Health.Status>: map has no entry for key "Health"
./services: line 90: [: ==: unary operator expected
Template parsing error: template: :1:8: executing "" at <.State.Health.Status>: map has no entry for key "Health"
./services: line 90: [: ==: unary operator expected
Template parsing error: template: :1:8: executing "" at <.State.Health.Status>: map has no entry for key "Health"
./services: line 90: [: ==: unary operator expected
Template parsing error: template: :1:8: executing "" at <.State.Health.Status>: map has no entry for key "Health"
./services: line 90: [: ==: unary operator expected
Template parsing error: template: :1:8: executing "" at <.State.Health.Status>: map has no entry for key "Health"
./services: line 90: [: ==: unary operator expected
Template parsing error: template: :1:8: executing "" at <.State.Health.Status>: map has no entry for key "Health"
./services: line 90: [: ==: unary operator expected
Template parsing error: template: :1:8: executing "" at <.State.Health.Status>: map has no entry for key "Health"
./services: line 90: [: ==: unary operator expected
Template parsing error: template: :1:8: executing "" at <.State.Health.Status>: map has no entry for key "Health"
./services: line 90: [: ==: unary operator expected

my docker-compose version is 1.29.2

Please help to resolve this issue

relationships of properties are ambiguous

In section "Entity Relationships", at subsection "RELATIONSHIPS OF PROPERTIES", the document showed how to retrieve the temperature of a barn (the data has been duplicated from the TemperatureSensor to the Building), but didn't provide information about how the data was duplicated or whether the data has been duplicated automatically or has been copied manually by users.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.