Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
naiades
naiades-platform-poc
Commits
3829b85f
Commit
3829b85f
authored
Jul 16, 2020
by
Federico Sismondi
Browse files
Update() flask routes to for LoRa server callbacks
parent
ea8a4507
Changes
1
Hide whitespace changes
Inline
Side-by-side
dca-carouge-watering/app.py
View file @
3829b85f
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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment