... | ... | @@ -235,9 +235,10 @@ Querying context broker at: 10.81.6.109 |
|
|
Test subscription by sending an update into the entity and verifying if our webserver received http callback:
|
|
|
|
|
|
|
|
|
send update:
|
|
|
send a couple of entity updates:
|
|
|
```
|
|
|
>>> ./watering_06_update_specific_attrs.sh
|
|
|
>>> ./watering_06_update_specific_attrs.sh
|
|
|
Querying context broker at: 10.81.6.109
|
|
|
```
|
|
|
|
... | ... | @@ -248,3 +249,92 @@ callback: |
|
|
[2020-05-20 09:27:01,500] INFO in app: Got new soil moisture value from context broker: [{'id': 'urn:ngsi-ld:FlowerBed:FlowerBed-1', 'type': 'FlowerBed', 'soilMoistureVwc': 7}]
|
|
|
172.18.1.9 - - [20/May/2020 09:27:01] "POST /on_change_soilMoistureVwc HTTP/1.1" 200 -
|
|
|
```
|
|
|
|
|
|
Yay! we received the subscription updates! :)
|
|
|
|
|
|
## Historic API
|
|
|
|
|
|
The Historic API is implemented using QuantumLeap (FiWare enabler)
|
|
|
|
|
|
export env var for QuantumLeap host (same as Naiades IoT Platform)
|
|
|
|
|
|
```
|
|
|
export QUANTUM_HOST=10.81.6.109
|
|
|
```
|
|
|
|
|
|
Create subscription for subscribing quantum leap to orion, and hence to keep history of a certain entity/attr.
|
|
|
This is a suscription for keeping history of all Carouge FlowerBed's humidity measurements.
|
|
|
|
|
|
Check out the suscription and run it!
|
|
|
|
|
|
```
|
|
|
>>> cat historic_01_set_up.sh
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
[[ -z "$ORION_HOST" ]] && echo "Please set ORION_HOST env var. E.g. export ORION_HOST=127.0.0.1" && exit
|
|
|
echo "Querying context broker at: ${ORION_HOST}"
|
|
|
|
|
|
# API NOTES:
|
|
|
# "condition": { "attrs": [] } -> means monitor all the attributes in the entity
|
|
|
|
|
|
curl --location --request POST \
|
|
|
"http://$ORION_HOST:1026/v2/subscriptions/" \
|
|
|
--header "Fiware-Service: carouge" \
|
|
|
--header "Fiware-ServicePath: /Watering" \
|
|
|
--header "Content-Type: application/json" \
|
|
|
--header "Accept: application/json" \
|
|
|
--data '{
|
|
|
"description": "Notify QuantumLeap, the historic API, of all FlowerBed changes",
|
|
|
"subject": {
|
|
|
"entities": [
|
|
|
{
|
|
|
"idPattern": ".*",
|
|
|
"type": "FlowerBed"
|
|
|
}
|
|
|
],
|
|
|
"condition": {
|
|
|
"attrs": []
|
|
|
}
|
|
|
},
|
|
|
"notification": {
|
|
|
"http": {
|
|
|
"url": "http://172.18.1.7:8668/v2/notify"
|
|
|
},
|
|
|
"attrs": [],
|
|
|
"metadata": ["dateCreated", "dateModified"]
|
|
|
}
|
|
|
}'
|
|
|
|
|
|
>>> ./historic_01_set_up.sh
|
|
|
Querying context broker at: 10.81.6.109
|
|
|
```
|
|
|
|
|
|
send a couple of entity updates:
|
|
|
|
|
|
```
|
|
|
>>> ./watering_06_update_specific_attrs.sh
|
|
|
>>> ./watering_06_update_specific_attrs.sh
|
|
|
Querying context broker at: 10.81.6.109
|
|
|
```
|
|
|
|
|
|
check what the history looks like of the FloweBeds' humidty looks like:
|
|
|
|
|
|
```
|
|
|
>>> ./historic_02_api_query.sh
|
|
|
Querying QuantumLeap API at: 10.81.6.109
|
|
|
{
|
|
|
"index": [
|
|
|
"2017-03-31T08:00:00.000",
|
|
|
"2017-03-31T08:00:00.000",
|
|
|
"2017-03-31T08:00:00.000",
|
|
|
"2017-03-31T08:00:00.000"
|
|
|
],
|
|
|
"values": [
|
|
|
0.85,
|
|
|
4.0,
|
|
|
7.0,
|
|
|
9.0
|
|
|
]
|
|
|
}
|
|
|
```
|
|
|
|