Commit 99e9633c authored by Cédric Crettaz's avatar Cédric Crettaz 🖥
Browse files

Update app.py for DMV integration for the watering.

parent 35955009
......@@ -130,6 +130,7 @@ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(message)s', date
# get config from environment
COLLECTION_DIR = os.getenv('COLLECTION_DIR', default='raw_data')
URL_BASE = 'http://{}:1026'.format(os.getenv('ORION_HOST', default='localhost'))
URL_BASE_DMV = 'http://{}:5002'.format(os.getenv('DATA_MODEL_VALIDATION', default='localhost'))
LORA_PLATFORM_URL = os.getenv('LORA_PLATFORM_URL')
LORA_PLATFORM_SECRET_FILE = os.getenv('LORA_PLATFORM_SECRET_FILE', 'secret_carouge_lora')
......@@ -210,7 +211,7 @@ def get_ngsiv2_typed_description(val, force_date_modified=None):
ret.update({'value': val}) # bypassed
elif isinstance(val, list):
ret.update({'value': val}) # bypassed
ret.update({'value': 'StructuredValue'}) # bypassed
elif isinstance(val, type(None)):
ret.update({'type': 'Text', 'value': None})
......@@ -592,7 +593,8 @@ def _update_flowerbed_entity(soil_moisture, sensor_eui):
body = {}
body.update({'soilMoisture': get_ngsiv2_typed_description(soil_moisture)})
body.update({'moistureUnit': get_ngsiv2_typed_description('cb')})
url = "{}/v2/entities/{}/attrs".format(URL_BASE, flowerbed_id)
#url = "{}/v2/entities/{}/attrs".format(URL_BASE, flowerbed_id)
url = "{}/validation/v2/entities/{}/attrs".format(URL_BASE_DMV, flowerbed_id)
r = client_request.patch(
url=url,
headers=http_header_post,
......@@ -635,7 +637,8 @@ def _update_flowerbed_entity_new(soil_moisture, soil_temperature, conductivity,
body.update({'soilTemperature': get_ngsiv2_typed_description(soil_temperature)})
body.update({'soilMoistureEc': get_ngsiv2_typed_description(conductivity)})
body.update({'moistureUnit' : get_ngsiv2_typed_description('percent')})
url = "{}/v2/entities/{}/attrs".format(URL_BASE, flowerbed_id)
#url = "{}/v2/entities/{}/attrs".format(URL_BASE, flowerbed_id)
url = "{}/validation/v2/entities/{}/attrs".format(URL_BASE_DMV, flowerbed_id)
r = client_request.patch(
url=url,
headers=http_header_post,
......@@ -845,16 +848,18 @@ def _rewrite_device_attributes(deveui,
last_reception,
dataFrame,
dataFrame_rssi,
dataFrame_timestamp)
dataFrame_timestamp,
dateFrame_timestamp)
entity_id = body['id']
entity_type = body['type']
body.pop('id') # we don't need this for a PATCH
body.pop('type') # we don't need this for a PATCH
#body.pop('id') # we don't need this for a PATCH
#body.pop('type') # we don't need this for a PATCH
app.logger.debug('PATCHING data in CTX broker: {}'.format(body))
url = "{}/v2/entities/{}/attrs".format(URL_BASE, entity_id)
#url = "{}/v2/entities/{}/attrs".format(URL_BASE, entity_id)
url = "{}/validation/v2/entities/{}/attrs".format(URL_BASE_DMV, entity_id)
r = client_request.post(
url=url,
headers=http_header_post,
......@@ -928,7 +933,8 @@ def post_dca_carouge_watering_sensed_data_payload():
resp.update({"fs_dump": _dump_raw_data_to_filesystem()})
resp.update({"update_flowerbed_entities": _update_flowerbed_entity(
soil_humidity,
sensor_eui
sensor_eui,
request.json['timestamp']
)})
resp.update({"update_device_entities": _rewrite_device_attributes(
deveui=request.json['deveui'],
......@@ -955,7 +961,8 @@ def post_dca_carouge_watering_sensed_data_payload():
soil_humidity,
soil_temperature,
conductivity,
sensor_eui
sensor_eui,
request.json['timestamp']
)})
resp.update({"update_device_entities": _rewrite_device_attributes(
deveui=request.json['deveui'],
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment