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__)"Starting to collect..")
COLLECTION_DIR = os.getenv('COLLECTION_DIR', default='.')
......@@ -12,19 +18,62 @@ def healthcheck():
return 'This service is up and running!'
def _dump_raw_data_to_filesystem():
filepath = os.path.join(COLLECTION_DIR, '{}.json'.format(int(time.time())))
with open(filepath, encoding='utf-8', mode='w') as f:
except Exception as e:
return 'error'
return 'ok'
def _dummy_post_hanlder():
if"Request data: %s" %
if request.json:"Request json: %s" % request.json)
if request.form:"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: %s" %
if request.form:"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__":"", 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