Commit 3829b85f authored by Federico Sismondi's avatar Federico Sismondi
Browse files

Update() flask routes to for LoRa server callbacks

parent ea8a4507
from flask import Flask
from flask import request
import logging
import os
import json
import time
app = Flask(__name__)
logger = logging.getLogger(__name__)
logger.info("Starting to collect..")
COLLECTION_DIR = os.getenv('COLLECTION_DIR', default='.')
@app.route('/')
@app.route('/healthcheck')
......@@ -12,19 +18,62 @@ def healthcheck():
return 'This service is up and running!'
def _dump_raw_data_to_filesystem():
try:
filepath = os.path.join(COLLECTION_DIR, '{}.json'.format(int(time.time())))
with open(filepath, encoding='utf-8', mode='w') as f:
json.dump(
obj=request.json,
fp=f
)
except Exception as e:
app.logger.error(e)
return 'error'
return 'ok'
def _dummy_post_hanlder():
if request.data:
app.logger.info("Request data: %s" % request.data)
if request.json:
app.logger.info("Request json: %s" % request.json)
if request.form:
app.logger.info("Request form: %s" % request.form)
return 'Got POST with json %s' % request.json
@app.route('/dca-carouge-watering-sensed-data', methods=['POST'])
def post_dca_carouge_watering_sensed_data():
# if request.data:
# app.logger.info("Request data: %s" % request.data)
if request.form:
app.logger.info("Got data: %s" % request.json)
return _dummy_post_hanlder()
return 'Got POST for /callback_lora_sensor, with body %s' % request.json
@app.route('/dca-carouge-watering-sensed-data/test ', methods=['POST'])
def post_dca_carouge_watering_sensed_data_test():
return _dummy_post_hanlder()
@app.route('/dca-carouge-watering-sensed-data/rest/callback/payloads/ul', methods=['POST'])
def post_dca_carouge_watering_sensed_data_payload():
resp = {}
resp.update({"fs_dump": _dump_raw_data_to_filesystem()})
resp.update({'description': _dummy_post_hanlder()})
return resp
@app.route('/dca-carouge-watering-sensed-data', methods=['GET'])
def get_dca_carouge_watering_sensed_data():
return 'This is still not implemented '
@app.route('/dca-carouge-watering-sensed-data/rest/callback/payloads/ul', methods=['GET'])
def get_dca_carouge_watering_sensed_data_callback():
return 'This is still not implemented '
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True, port=80)
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