|
1 | | -This is a simple Node.js express application which offers an NGSI proxy interface to four context providers. |
| 1 | +# FIWARE NGSI-LD Step-by-Step Tutorials Web App |
2 | 2 |
|
3 | | -# NGSI-LD `/ngsi-ld/v1/entities/` Endpoints |
| 3 | +[](https://fiware-tutorials.rtfd.io) |
| 4 | +[](https://hub.docker.com/r/fiware/tutorials.ngsi-ld/) |
| 5 | +[](https://stackoverflow.com/questions/tagged/fiware) |
| 6 | +[](https://cim.etsi.org/NGSI-LD/official/front-page.html) |
| 7 | +[](https://w3c.github.io/json-ld-syntax/) |
4 | 8 |
|
5 | | -Supported NGSI-LD context provider endpoints |
| 9 | +This is a Node.js Express application that serves as the main web interface for the FIWARE NGSI-LD Step-by-Step |
| 10 | +tutorials. It acts as a multi-purpose component, functioning as a Context Provider, a User Interface, and a secure proxy |
| 11 | +to other FIWARE components. |
6 | 12 |
|
7 | | -- `/random/temperature/ngsi-ld/v1/entities/` |
8 | | -- `/random/relativeHumidity/ngsi-ld/v1/entities/` |
9 | | -- `/random/tweets/ngsi-ld/v1/entities/` |
10 | | -- `/random/weatherConditions/ngsi-ld/v1/entities/` |
11 | | -- `/static/temperature/ngsi-ld/v1/entities/` |
12 | | -- `/static/relativeHumidity/ngsi-ld/v1/entities/` |
13 | | -- `/static/tweets/ngsi-ld/v1/entities/` |
14 | | -- `/static/weatherConditions/ngsi-ld/v1/entities/` |
15 | | -- `/catfacts/tweets/ngsi-ld/v1/entities/` |
16 | | -- `/twitter/tweets/ngsi-ld/v1/entities/` |
17 | | -- `/weather/temperature/ngsi-ld/v1/entities/` |
18 | | -- `/weather/relativeHumidity/ngsi-ld/v1/entities/` |
19 | | -- `/weather/weatherConditions/ngsi-ld/v1/entities/` |
| 13 | +## Features |
20 | 14 |
|
21 | | -The following dynamic NGSI-LD endpoints are supported |
| 15 | +* **Context Provider**: Exposes multiple NGSI-LD endpoints to provide context data (static, random, or proxied from external APIs like Twitter and OpenWeatherMap). |
| 16 | +* **Web Interface**: Renders web pages using Pug templates to visualize data and interact with the system. |
| 17 | +* **Data Persistence**: Connects to MongoDB for storing session data and application state. |
| 18 | +* **History Visualization**: Fetches and aggregates historical data for visualization. |
| 19 | +* **NGSI-LD Proxy**: Interactions with a Context Broker (e.g., Orion-LD, Scorpio Stellio). |
| 20 | +* **Device Control**: Provides an interface to send commands to dummy IoT devices via the Context Broker. |
22 | 21 |
|
23 | | -- `/random/<type>/<mapping>/ngsi-ld/v1/entities/:id`. returns random data values of `"type": "<type>"` - e.g. |
24 | | - `/random/text/quote/ngsi-ld/v1/entities/:id` will return random lorem ipsum |
| 22 | +## Endpoints |
25 | 23 |
|
26 | | -- `/static/<type>/<mapping>/ngsi-ld/v1/entities/:id` returns static data values of `"type": "<type>"` - e.g. |
27 | | - `/static/text/quote/ngsi-ld/v1/entities/:id` will return "I never could get the hang of thursdays" |
| 24 | +### NGSI-LD Context Provider Endpoints |
28 | 25 |
|
29 | | -- `/twitter/<type>/<mapping><queryString>/<attr>/ngsi-ld/v1/entities/:id` Work in progress |
| 26 | +The application provides context data under `/ngsi-ld/v1/entities/`: |
30 | 27 |
|
31 | | -- `/weather/<type>/<mapping>/<queryString>/<attr>/ngsi-ld/v1/entities/:id` Retrieves the Weather data for the |
32 | | - `queryString` location and maps the data from the given `attr` to the entity response. |
| 28 | +- **Random Data**: `/random/<type>/...` |
| 29 | +- **Static Data**: `/static/<type>/...` |
| 30 | +- **Twitter Data**: `/catfacts/...`, `/twitter/...` |
| 31 | +- **Weather Data**: `/weather/...` |
33 | 32 |
|
34 | | - For Example `/weather/number/berlin%2cde/wind_speed/ngsi-ld/v1/entities/:id` will read the `wind_speed` value from |
35 | | - Berlin. and `/weather/number/cairo%2ceg/temp/ngsi-ld/v1/entities/:id` will read the `temp` value from Cairo. |
| 33 | +### Health Checks |
36 | 34 |
|
37 | | -## Mappings |
| 35 | +- `/health`: General application health check. |
| 36 | +- `/random/health`, `/static/health`: Check availability of random/static context providers. |
| 37 | +- `/twitter/health`: Check connectivity to Twitter API. |
| 38 | +- `/weather/health`: Check connectivity to OpenWeatherMap API. |
38 | 39 |
|
39 | | -NGSI attribute names should follow Data Model Guidelines (e.g. `camelCasing`) Data returned from third-party APIs will |
40 | | -not enforce the same guidelines. It is therefore necessary to invoke a mapping to be able to know which values to |
41 | | -retieve. |
| 40 | +## Environment Variables |
42 | 41 |
|
43 | | -The mapping path element is assumes that mappings are defined in the path as follows: |
| 42 | +The application is configured using the following environment variables: |
44 | 43 |
|
45 | | -- `temperature` |
46 | | - - `temperature` NGSI attribute maps to `temperature` attribute on the API data |
47 | | -- `temperature:temp` |
48 | | - - `temperature` NGSI attribute maps to `temp` attribute on the API data |
49 | | -- `temperature:temp,windSpeed:wind_speed` |
50 | | - - `temperature` NGSI attribute maps to `temp` attribute on the API data |
51 | | - - `windSpeed` NGSI attribute maps to `wind_speed` attribute on the API data |
| 44 | +### Core Configuration |
52 | 45 |
|
53 | | -For the full guidelines see the |
54 | | -[FIWARE Data Models](https://fiware-datamodels.readthedocs.io/en/latest/guidelines/index.html) |
| 46 | +- `WEB_APP_PORT` - Port the application listens on. Default: `3000`. |
| 47 | +- `NODE_ENV` - Environment mode (e.g., `production`, `development`). |
| 48 | +- `DEBUG` - Debug logging namespace. Recommended: `tutorial:*`. |
| 49 | +- `SESSION_SECRET` - Secret used for signing session cookies. |
| 50 | +- `SESSION_OFF` - If set to `true`, disables session management. Default: `false`. |
55 | 51 |
|
56 | | -## Health Check Endpoints |
| 52 | +### Database Connectivity |
57 | 53 |
|
58 | | -The following health check endpoints are supported: |
| 54 | +- `MONGO_URL` - Connection string for MongoDB. Default: `mongodb://localhost:27017`. |
59 | 55 |
|
60 | | -- `/random/health` A non-error response shows that an NGSI proxy is available on the network and returning values. |
61 | | - Each Request will return some random dummy data. |
| 56 | +### FIWARE Component Connectivity |
62 | 57 |
|
63 | | -- `/static/health` A non-error response shows that an NGSI proxy is available on the network and returning values. |
64 | | - Each Request will return the same data. |
| 58 | +- `CONTEXT_BROKER` - URL of the Context Broker. Default: `http://localhost:1026/ngsi-ld/v1`. |
| 59 | +- `DEVICE_BROKER` - URL for device commands, usually same as Context Broker. Default: same as `CONTEXT_BROKER`. |
| 60 | +- `NGSI_LD_TENANT` - Tenant for NGSI-LD requests. Default: `openiot`. |
| 61 | +- `IOTA_JSON_LD_CONTEXT` - JSON-LD Context URL for device commands. Default: `http://localhost:3000/data-models/ngsi-context.jsonld`. |
65 | 62 |
|
66 | | -- `/catfacts/health` A non-error response shows that an NGSI proxy is available on the network and returning values. |
67 | | - Each Request will return the same data. |
| 63 | +### IoT Device Connectivity |
68 | 64 |
|
69 | | -- `/twitter/health` A non-error response shows that an NGSI proxy for the Twitter API is available on the network and |
70 | | - returning values. |
| 65 | +Variables to configure the connection to the Dummy IoT Devices service: |
71 | 66 |
|
72 | | - If the proxy is correctly configured to connect to the Twitter API, a series of Tweets will be returned. |
| 67 | +- `DUMMY_DEVICES_PORT` - Port where the Dummy Devices service is running. Default: `3001`. |
| 68 | +- `DUMMY_DEVICES` - Full URL of the Dummy Devices service. Default: `http://localhost:${DUMMY_DEVICES_PORT}`. |
| 69 | +- `MOVE_TRACTOR` - Interval (in ms) to auto-move tractors (simulation). Default: `10000`. |
| 70 | +- `DUMMY_OFF` - If `true`, disables dummy device updates/interaction from this app. Default: `false`. |
73 | 71 |
|
74 | | - The Twitter API uses OAuth2: |
75 | | - |
76 | | - - To get Consumer Key & Consumer Secret for the Twitter API, you have to create an app in Twitter via |
77 | | - [https://developer.twitter.com/](https://developer.twitter.com/). Then you'll be taken to a page containing |
78 | | - Consumer Key & Consumer Secret. |
79 | | - - For more information see: [https://developer.twitter.com/](https://developer.twitter.com/) |
80 | | - |
81 | | -- `/weather/health` A non-error response shows that an NGSI proxy for the Weather API is available on the network and |
82 | | - returning values. |
83 | | - |
84 | | - If the proxy is correctly configured to connect to the Open Weather Map API, the current weather in Berlin will be |
85 | | - returned. |
86 | | - |
87 | | - Most of the Weather API features require an API key. |
88 | | - |
89 | | - - Sign up for a key at [`https://openweathermap.org/api`](https://openweathermap.org/api) |
90 | | - - For more information see: [`https://openweathermap.org/appid`](https://openweathermap.org/appid) |
91 | | - |
92 | | -## Keys and Secrets |
93 | | - |
94 | | -All Keys and Secrets must be passed in using Environment variables. The following variables **must** be provided |
95 | | - |
96 | | -- `OPENWEATHERMAP_KEY_ID=<ADD_YOUR_KEY_ID>` |
97 | | -- `TWITTER_CONSUMER_KEY=<ADD_YOUR_CONSUMER_KEY>` |
98 | | -- `TWITTER_CONSUMER_SECRET=<ADD_YOUR_CONSUMER_SECRET>` |
99 | | - |
100 | | ---- |
101 | 72 |
|
102 | 73 | ## License |
103 | 74 |
|
104 | | -MIT © 2020-2026 FIWARE Foundation e.V. |
| 75 | +[MIT](LICENSE) © 2020-2026 FIWARE Foundation e.V. |
105 | 76 |
|
106 | 77 | See the LICENSE file in the root of this project for license details. |
107 | 78 |
|
108 | 79 | The Program includes additional icons downloaded from www.flaticon.com which were obtained under license: |
109 | 80 |
|
110 | 81 | - Smashicons - [https://www.flaticon.com/authors/smashicons](https://www.flaticon.com/authors/smashicons) - CC 3.0 BY |
111 | | -- Those Icons - [https://www.flaticon.com/authors/those-icons](https://www.flaticon.com/authors/those-icons) - CC 3.0 |
112 | | - BY |
| 82 | +- Those Icons - [https://www.flaticon.com/authors/those-icons](https://www.flaticon.com/authors/those-icons) - CC 3.0 BY |
113 | 83 | - Freepik - [http://www.freepik.com/](http://www.freepik.com/) - CC 3.0 BY |
114 | 84 | - Bootstrap - [https://github.com/twbs/icons](https://github.com/twbs/icons) - MIT |
0 commit comments