From b8aed994184ba1ba4bd936ae695cdff92d8acf61 Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Wed, 21 Mar 2018 15:17:16 +1300 Subject: [PATCH] Added project for python server that will receive gps tracker positions --- GpsTrackerServer/GpsTrackerServer.pyproj | 77 ++++++++++++++++++++++++ GpsTrackerServer/main.py | 35 +++++++++++ 2 files changed, 112 insertions(+) create mode 100644 GpsTrackerServer/GpsTrackerServer.pyproj create mode 100644 GpsTrackerServer/main.py diff --git a/GpsTrackerServer/GpsTrackerServer.pyproj b/GpsTrackerServer/GpsTrackerServer.pyproj new file mode 100644 index 0000000..d12a86b --- /dev/null +++ b/GpsTrackerServer/GpsTrackerServer.pyproj @@ -0,0 +1,77 @@ + + + 10.0 + Debug + 2.0 + 38a5dbf7-8f3d-4c79-b589-ab52837ba180 + . + {1b580a1a-fdb3-4b32-83e1-6407eb2722e6};{349c5851-65df-11da-9384-00065b846f21};{888888a0-9f3d-457c-b088-3a5042f75d52} + main.py + + + . + Web launcher + http://localhost + . + true + GpsTrackerServer + GpsTrackerServer + Global|PythonCore|3.6 + + + true + false + + + true + false + + + + Code + + + + + + + + + + + + + + + + True + True + http://localhost + False + + + + + + + CurrentPage + True + False + False + False + + + + + + + + + False + False + + + + + \ No newline at end of file diff --git a/GpsTrackerServer/main.py b/GpsTrackerServer/main.py new file mode 100644 index 0000000..3258d82 --- /dev/null +++ b/GpsTrackerServer/main.py @@ -0,0 +1,35 @@ +""" +Basic HTTP server to receive and save gps positions sent by Arduino GPS Tracker +""" + +import falcon + +class RequireCSV: + + def process_request(self, req, resp): + if req.method in ('POST', 'PUT'): + if 'text/csv' not in req.content_type: + raise falcon.HTTPUnsupportedMediaType('Only CSV is supported') + +class PositionsResource: + + def on_post(self, req, resp): + data = req.bounded_stream.read() + resp.body = data + resp.status = falcon.HTTP_201 + +positions = PositionsResource() + +api = falcon.API(middleware=[ + RequireCSV() +]) + +api.add_route('/positions', positions) + +if __name__ == "__main__": + # Use python built-in WSGI reference implemention to run a web server + from wsgiref.simple_server import make_server + + print('Starting web server...') + srv = make_server('localhost', 8080, api) + srv.serve_forever() \ No newline at end of file