Skip to content

Commit df14c00

Browse files
committed
Add notifications
1 parent 634a040 commit df14c00

1 file changed

Lines changed: 164 additions & 0 deletions

File tree

README.md

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ The tutorial uses [cUrl](https://ec.haxx.se/) commands throughout, but is also a
5050
- [Overwrite Multiple Attributes of a Data Entity](#overwrite-multiple-attributes-of-a-data-entity)
5151
- [Batch Update Attributes of Multiple Data Entities](#batch-update-attributes-of-multiple-data-entities)
5252
- [Batch Replace Entity Data](#batch-replace-entity-data)
53+
- [Setting up concise Subscriptions](#setting-up-concise-subscriptions)
54+
- [Concise Notification](#concise-notification)
55+
- [Concise GeoJSON Notification](#concise-geojson-notification)
5356

5457
</details>
5558

@@ -1087,6 +1090,167 @@ Batch processing uses the `/ngsi-ld/v1/entityOperations/update` endpoint with a
10871090
parameter, this means we will overwrite existing entities. `/ngsi-ld/v1/entityOperations/upsert` could also be used if
10881091
new entities are also to be created.
10891092

1093+
## Setting up concise Subscriptions
1094+
1095+
### Concise Notification
1096+
1097+
The concise format can also be used when generating a notification from a subscription. Simply set the
1098+
`format": "concise"` within the `notification` element as shown
1099+
1100+
#### :one::nine: Request:
1101+
1102+
```console
1103+
curl -X POST 'http://{{orion}}/ngsi-ld/v1/subscriptions/' \
1104+
-H 'Content-Type: application/ld+json' \
1105+
-H 'NGSILD-Tenant: openiot' \
1106+
--data-raw '{
1107+
"description": "Notify me of low feedstock on Farm:001",
1108+
"type": "Subscription",
1109+
"entities": [{"id": "urn:ngsi-ld:Animal:pig003", "type": "Animal"}],
1110+
"notification": {
1111+
"format": "concise",
1112+
"endpoint": {
1113+
"uri": "http://tutorial:3000/subscription/low-stock-farm001-ngsild",
1114+
"accept": "application/geo+json"
1115+
}
1116+
},
1117+
"@context": "http://context/ngsi-context.jsonld"
1118+
}'
1119+
```
1120+
1121+
Then go to the Device Monitor `http://localhost:3000/app/farm/urn:ngsi-ld:Building:farm001` and remove some hay from the
1122+
barn. Eventually a request is sent to `subscription/low-stock-farm001` as shown:
1123+
1124+
#### `http://localhost:3000/app/monitor`
1125+
1126+
#### Subscription Payload:
1127+
1128+
```json
1129+
{
1130+
"id": "urn:ngsi-ld:Notification:6220b4e464f3729a8527f8a0",
1131+
"type": "Notification",
1132+
"subscriptionId": "urn:ngsi-ld:Subscription:6220b4a964f3729a8527f88c",
1133+
"@context": "http://context/ngsi-context.jsonld",
1134+
"notifiedAt": "2022-03-03T12:30:28.237Z",
1135+
"data": [
1136+
{
1137+
"id": "urn:ngsi-ld:Animal:pig003",
1138+
"type": "Animal",
1139+
"heartRate": {
1140+
"value": 67,
1141+
"unitCode": "5K",
1142+
"observedAt": "2022-03-03T12:30:27.000Z",
1143+
"providedBy": {
1144+
"object": "urn:ngsi-ld:Device:pig003"
1145+
}
1146+
},
1147+
"phenologicalCondition": "maleAdult",
1148+
"reproductiveCondition": "active",
1149+
"name": "Flamingo",
1150+
"legalID": "M-boar003-Flamingo",
1151+
"sex": "male",
1152+
"species": "pig",
1153+
"location": {
1154+
"value": {
1155+
"type": "Point",
1156+
"coordinates": [13.357, 52.513]
1157+
},
1158+
"observedAt": "2022-03-03T12:30:27.000Z",
1159+
"providedBy": {
1160+
"object": "urn:ngsi-ld:Device:pig003"
1161+
}
1162+
}
1163+
}
1164+
]
1165+
}
1166+
```
1167+
1168+
### Concise GeoJSON Notification
1169+
1170+
#### :two::zero: Request:
1171+
1172+
It is also possible to send GeoJSON notifications if the `"accept": "application/geo+json"` attribute is set. Combining
1173+
this with `"format": "concise"` results in a `FeatureCollection` with properties in concise format.
1174+
1175+
```console
1176+
curl -X POST 'http://{{orion}}/ngsi-ld/v1/subscriptions/' \
1177+
-H 'Content-Type: application/ld+json' \
1178+
-H 'NGSILD-Tenant: openiot' \
1179+
--data-raw '{
1180+
"description": "Notify me of low feedstock on Farm:001",
1181+
"type": "Subscription",
1182+
"entities": [{"id": "urn:ngsi-ld:Animal:pig003", "type": "Animal"}],
1183+
"notification": {
1184+
"format": "concise",
1185+
"endpoint": {
1186+
"uri": "http://tutorial:3000/subscription/low-stock-farm001-ngsild",
1187+
"accept": "application/geo+json"
1188+
}
1189+
},
1190+
"@context": "http://context/ngsi-context.jsonld"
1191+
}'
1192+
```
1193+
1194+
#### Subscription Payload:
1195+
1196+
The result of a concise GeoJSON notification can be seen below.
1197+
1198+
```json
1199+
{
1200+
"id": "urn:ngsi-ld:Notification:6220b50264f3729a8527f8ab",
1201+
"type": "Notification",
1202+
"subscriptionId": "urn:ngsi-ld:Subscription:6220b47764f3729a8527f886",
1203+
"notifiedAt": "2022-03-03T12:30:58.294Z",
1204+
"data": {
1205+
"type": "FeatureCollection",
1206+
"features": [
1207+
{
1208+
"id": "urn:ngsi-ld:Animal:pig003",
1209+
"type": "Feature",
1210+
"properties": {
1211+
"type": "Animal",
1212+
"heartRate": {
1213+
"value": 63,
1214+
"unitCode": "5K",
1215+
"observedAt": "2022-03-03T12:30:58.000Z",
1216+
"providedBy": {
1217+
"object": "urn:ngsi-ld:Device:pig003"
1218+
}
1219+
},
1220+
"phenologicalCondition": "maleAdult",
1221+
"reproductiveCondition": "active",
1222+
"name": "Flamingo",
1223+
"legalID": "M-boar003-Flamingo",
1224+
"sex": "male",
1225+
"species": "pig",
1226+
"location": {
1227+
"value": {
1228+
"type": "Point",
1229+
"coordinates": [13.357, 52.513]
1230+
},
1231+
"observedAt": "2022-03-03T12:30:58.000Z",
1232+
"providedBy": {
1233+
"object": "urn:ngsi-ld:Device:pig003"
1234+
}
1235+
}
1236+
},
1237+
"@context": "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld",
1238+
"geometry": {
1239+
"value": {
1240+
"type": "Point",
1241+
"coordinates": [13.357, 52.513]
1242+
},
1243+
"observedAt": "2022-03-03T12:30:58.000Z",
1244+
"providedBy": {
1245+
"object": "urn:ngsi-ld:Device:pig003"
1246+
}
1247+
}
1248+
}
1249+
]
1250+
}
1251+
}
1252+
```
1253+
10901254
# Next Steps
10911255

10921256
Want to learn how to add more complexity to your application by adding advanced features? You can find out by reading

0 commit comments

Comments
 (0)