ソースを参照

Added project for python server that will receive gps tracker positions

tags/v1.2.0
Bertrand Lemasle 7年前
コミット
b8aed99418
2個のファイルの変更112行の追加0行の削除
  1. +77
    -0
      GpsTrackerServer/GpsTrackerServer.pyproj
  2. +35
    -0
      GpsTrackerServer/main.py

+ 77
- 0
GpsTrackerServer/GpsTrackerServer.pyproj ファイルの表示

@@ -0,0 +1,77 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>38a5dbf7-8f3d-4c79-b589-ab52837ba180</ProjectGuid>
<ProjectHome>.</ProjectHome>
<ProjectTypeGuids>{1b580a1a-fdb3-4b32-83e1-6407eb2722e6};{349c5851-65df-11da-9384-00065b846f21};{888888a0-9f3d-457c-b088-3a5042f75d52}</ProjectTypeGuids>
<StartupFile>main.py</StartupFile>
<SearchPath>
</SearchPath>
<WorkingDirectory>.</WorkingDirectory>
<LaunchProvider>Web launcher</LaunchProvider>
<WebBrowserUrl>http://localhost</WebBrowserUrl>
<OutputPath>.</OutputPath>
<SuppressCollectPythonCloudServiceFiles>true</SuppressCollectPythonCloudServiceFiles>
<Name>GpsTrackerServer</Name>
<RootNamespace>GpsTrackerServer</RootNamespace>
<InterpreterId>Global|PythonCore|3.6</InterpreterId>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<ItemGroup>
<Compile Include="main.py">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<InterpreterReference Include="Global|PythonCore|3.6" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.Web.targets" />
<!-- Specify pre- and post-build commands in the BeforeBuild and
AfterBuild targets below. -->
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<AutoAssignPort>True</AutoAssignPort>
<UseCustomServer>True</UseCustomServer>
<CustomServerUrl>http://localhost</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}" User="">
<WebProjectProperties>
<StartPageUrl>
</StartPageUrl>
<StartAction>CurrentPage</StartAction>
<AspNetDebugging>True</AspNetDebugging>
<SilverlightDebugging>False</SilverlightDebugging>
<NativeDebugging>False</NativeDebugging>
<SQLDebugging>False</SQLDebugging>
<ExternalProgram>
</ExternalProgram>
<StartExternalURL>
</StartExternalURL>
<StartCmdLineArguments>
</StartCmdLineArguments>
<StartWorkingDirectory>
</StartWorkingDirectory>
<EnableENC>False</EnableENC>
<AlwaysStartWebServerOnDebug>False</AlwaysStartWebServerOnDebug>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
</Project>

+ 35
- 0
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()

読み込み中…
キャンセル
保存