Commit 9e7e85e3 authored by Cédric Crettaz's avatar Cédric Crettaz 🖥

Update app.py for Carouge fountain.

parent aaba37e2
......@@ -308,12 +308,12 @@ def get_values_from_raw_reading(message_data):
@app.route('/dca-carouge-fountain-sensed-data/rest/callback/payloads/ul', methods=['POST'])
def post_dca_carouge_fountain_sensed_data_payload():
if request.json['deveui'] == '70b3d5078000066e':
if request.json['hardware_serial'] == '70B3D5FFFEBF6952' or request.json['hardware_serial'] == '70B3D5FFFEBF6A44':
app.logger.info('Got message from probe LoRa device, hence sensors have LoRa coverage')
return {'status': 'ok'}
# return {'status': 'ok'}
if not request.json['dataFrame'] or request.json['dataFrame'] == '':
app.logger.error('Message with empty <data frame> field from sensor {}'.format(request.json['deveui']))
if not request.json['payload_raw'] or request.json['payload_raw'] == '':
app.logger.error('Message with empty <payload raw> field from sensor {}'.format(request.json['hardware_serial']))
raise InvalidUsage(message='Empty data frame field received', payload=request.json)
app.logger.info("Got message from FOUNTAIN devices: {}".format(request.json))
......@@ -322,8 +322,8 @@ def post_dca_carouge_fountain_sensed_data_payload():
resp = {}
resp.update({"fs_dump": _dump_raw_data_to_filesystem()})
resp.update({"update_entities": _update_fountain_entity(
request.json['dataFrame'],
request.json['timestamp'])
request.json['payload_raw'],
request.json['metadata']['time'])
})
return resp
......@@ -391,21 +391,21 @@ def _update_historical_db_from_local_raw_files():
with open(json_file, "r") as f:
json_data = json.load(f)
if not json_data['dataFrame'] or json_data['dataFrame'] == '':
print("(!) Warning found emtpy data frame from device {}".format(json_data['deveui']))
if not json_data['payload_raw'] or json_data['payload_raw'] == '':
print("(!) Warning found emtpy data frame from device {}".format(json_data['hardware_serial']))
try:
values = get_values_from_raw_reading(json_data['dataFrame'])
values = get_values_from_raw_reading(json_data['payload_raw'])
except ValueError as e:
print("(!) Failed trying to parse file {}".format(json_file))
print("(!) Got as frame data {}".format(json_data['dataFrame']))
print("(!) Got as frame data {}".format(json_data['payload_raw']))
continue # jump to next file
if len(values) == 1: # this is LoRa Device w/ the turbidity sensor
entity = get_model_water_quality_observed(
turbidity=values[0],
dateObserved=json_data['timestamp'],
meta_datetime=json_data['timestamp'], # only needed for historical data collected offline
dateObserved=json_data['metadata']['time'],
meta_datetime=json_data['metadata']['time'], # only needed for historical data collected offline
)
elif len(values) == 5: # this is the device with 5 water quality sensors
......@@ -415,8 +415,8 @@ def _update_historical_db_from_local_raw_files():
freeChlorine=values[2] / 100 if values[2] else None, # in mg/L
totalChlorine=values[3] / 100 if values[3] else None, # in mg/L
redox=values[4] / 1000 if values[4] else None, # in volts
dateObserved=json_data['timestamp'],
meta_datetime=json_data['timestamp'],
dateObserved=json_data['metadata']['time'],
meta_datetime=json_data['metadata']['time'],
)
else:
......
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