Commit d8f963f0 authored by Federico Sismondi's avatar Federico Sismondi

Merge branch 'watering_fixes' into 'master'

Watering fixes

See merge request !20
parents 86d6d499 d17093f2
......@@ -307,7 +307,7 @@ def get_model_device(deveui,
body = {}
app.logger.info('Creating/Updating devices in CTX broker for deveui {}'.format(deveui))
app.logger.info('Generating data model for {}{}'.format(URN_BASE_DEVICE_ENTITY, deveui[-4:]))
# static values
body.update({'id': '{}{}'.format(URN_BASE_DEVICE_ENTITY, deveui[-4:])})
......@@ -539,7 +539,7 @@ def _create_device_entity(deveui, comment, longitude, latitude, last_reception,
dataFrame_rssi,
dataFrame_timestamp)
app.logger.debug('Sending data to CTX broker: {}'.format(body))
app.logger.debug('CREATING entity in CTX broker: {}'.format(body))
url = "{}/v2/entities/".format(URL_BASE)
r = client_request.post(
......@@ -559,9 +559,15 @@ def _create_device_entity(deveui, comment, longitude, latitude, last_reception,
return "ok"
def _patch_device_entity(deveui, comment, longitude, latitude, last_reception, dataFrame, dataFrame_rssi,
dataFrame_timestamp):
"""Updates LoRa devs into ctx broker
def _rewrite_device_attributes(deveui,
comment=None,
longitude=None,
latitude=None,
last_reception=None,
dataFrame=None,
dataFrame_rssi=None,
dataFrame_timestamp=None):
"""Updates Devices into ctx broker
"""
assert deveui
......@@ -580,8 +586,8 @@ def _patch_device_entity(deveui, comment, longitude, latitude, last_reception, d
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('Sending data to CTX broker: {}'.format(body))
url = "{}/v2/entities/{}/attrs?options=append".format(URL_BASE, entity_id)
app.logger.debug('PATCHING data in CTX broker: {}'.format(body))
url = "{}/v2/entities/{}/attrs".format(URL_BASE, entity_id)
r = client_request.post(
url=url,
headers=http_header_post,
......@@ -656,12 +662,8 @@ def post_dca_carouge_watering_sensed_data_payload():
soil_humidity,
sensor_eui
)})
resp.update({"update_device_entities": _patch_device_entity(
resp.update({"update_device_entities": _rewrite_device_attributes(
deveui=request.json['deveui'],
comment=None,
longitude=None,
latitude=None,
last_reception=None,
dataFrame=request.json['dataFrame'],
dataFrame_rssi=request.json['rssi'],
dataFrame_timestamp=request.json['timestamp']
......@@ -695,10 +697,9 @@ def init():
# push data to CTX broker
for i in lora_nodes_info:
# delete first so we start from scratch (no one besides us touches these entities)
client_request.delete(
url='{}/v2/entities/{}{}'.format(URL_BASE, URN_BASE_DEVICE_ENTITY,i['deveui'][-4:]),
url='{}/v2/entities/{}{}'.format(URL_BASE, URN_BASE_DEVICE_ENTITY, i['deveui'][-4:]),
headers=http_header_get
)
......
Markdown is supported
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