Compare commits
No commits in common. "f60e3a3f89549b4ce88df20888c08a01062d086a" and "519c68c455961042b282db94a94f0fad0fa2e965" have entirely different histories.
f60e3a3f89
...
519c68c455
@ -21,8 +21,6 @@ Content type is considered too:
|
|||||||
curl -X POST -d '{"key": "value"}' -H 'Content-Type: application/json' http://iot-data.clerie.de/ingress/asdf1234/
|
curl -X POST -d '{"key": "value"}' -H 'Content-Type: application/json' http://iot-data.clerie.de/ingress/asdf1234/
|
||||||
```
|
```
|
||||||
|
|
||||||
Check for the last data input with the `Last-Modified` header.
|
|
||||||
|
|
||||||
## Deployment
|
## Deployment
|
||||||
Init codebase
|
Init codebase
|
||||||
```
|
```
|
||||||
@ -40,15 +38,12 @@ Create `config.json` with the following contents and edit values for your needs:
|
|||||||
"key": "asdf1234"
|
"key": "asdf1234"
|
||||||
},
|
},
|
||||||
"sensor2": {
|
"sensor2": {
|
||||||
"key": "supersecret",
|
"key": "supersecret"
|
||||||
"delete-after": 60
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
`delete-after`: Specifies the seconds after which the data gets discarded and no data is returned.
|
|
||||||
|
|
||||||
Starten und updaten lässt sich die Flask-App folgendermaßen:
|
Starten und updaten lässt sich die Flask-App folgendermaßen:
|
||||||
```
|
```
|
||||||
cd iot-data/
|
cd iot-data/
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
from flask import Flask, abort, request, make_response
|
from flask import Flask, abort, request, make_response
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import time
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@ -33,26 +32,22 @@ def ingress(key):
|
|||||||
values[keys[key]] = {
|
values[keys[key]] = {
|
||||||
"payload": request.data,
|
"payload": request.data,
|
||||||
"content-type": content_type,
|
"content-type": content_type,
|
||||||
"last-modified": time.time(),
|
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
return make_response("", 404)
|
abort(401)
|
||||||
|
|
||||||
return make_response("", 201)
|
resp = make_response("", 201)
|
||||||
|
return resp
|
||||||
|
|
||||||
@app.route("/data/<string:name>/")
|
@app.route("/data/<string:name>/")
|
||||||
def data(name):
|
def data(name):
|
||||||
if not name in config:
|
if not name in config:
|
||||||
return make_response("", 404)
|
abort(404)
|
||||||
if name in values:
|
|
||||||
if "delete-after" in config[name]:
|
|
||||||
if (values[name]["last-modified"] + config[name]["delete-after"]) < time.time():
|
|
||||||
values.pop(name)
|
|
||||||
if not name in values:
|
if not name in values:
|
||||||
return make_response("", 404)
|
resp = make_response("", 204)
|
||||||
|
return resp
|
||||||
resp = make_response(values[name]["payload"], 200)
|
resp = make_response(values[name]["payload"], 200)
|
||||||
resp.headers['Content-Type'] = values[name]["content-type"]
|
resp.headers['content-type'] = values[name]["content-type"]
|
||||||
resp.headers['Last-Modified'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(values[name]["last-modified"]))
|
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user