-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
receive information from submitted payload
- Loading branch information
1 parent
cd3ba85
commit a793b5c
Showing
6 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env python3 | ||
from flask import Flask, request | ||
from helper.location import Location | ||
import json | ||
|
||
# debug | ||
debug = True | ||
from datetime import datetime | ||
from debug.randomGeoCoordinates import GeoCoor | ||
|
||
application = Flask(__name__) | ||
|
||
# this is called if a device submits a new position | ||
# stores new position in database and delivers the last reported position of all friends of this device | ||
@application.route('/pub', methods = ['POST']) | ||
def addNewDatapoint(): | ||
datapoint = request.data | ||
if debug: | ||
f = open("locations.txt","a+") | ||
f.write(str(datapoint) + "\n") | ||
parsedDatapoint = json.loads(datapoint.decode("utf-8")) | ||
if parsedDatapoint["_type"] == 'location': | ||
# store information from given datapoint | ||
location = Location() | ||
location.accuracy = parsedDatapoint["acc"] | ||
location.altitude = parsedDatapoint["alt"] | ||
location.battery = parsedDatapoint["batt"] | ||
location.connection = parsedDatapoint["conn"] | ||
location.latitude = parsedDatapoint["lat"] | ||
location.longitude = parsedDatapoint["lon"] | ||
# catch if trigger is transmitted (Move mode) | ||
try: | ||
location.trigger = parsedDatapoint["t"] | ||
except KeyError as e: | ||
location.trigger = "UNDEFINED" | ||
location.trackerID = parsedDatapoint["tid"] | ||
location.timestamp = parsedDatapoint["tst"] | ||
location.velocity = parsedDatapoint["vel"] | ||
|
||
if debug: | ||
f = open("locations.txt","a+") | ||
f.write("Acc: " + str(location.accuracy) + | ||
" Alt: " + str(location.altitude) + | ||
" Batt: " + str(location.battery) + | ||
" Conn: " + str(location.connection) + | ||
" Lat: " + str(location.latitude) + | ||
" Lon: " + str(location.longitude) + | ||
" T: " + str(location.trigger) + | ||
" TID: " + str(location.trackerID) + | ||
" Tst: " + str(location.timestamp) + | ||
" Vel: " + str(location.velocity) + "\n") | ||
|
||
return '{"_type":"location","acc":16,"alt":0,"batt":4,"conn":"w","lat":' + GeoCoor.randomCoordsLat() + ',"lon":' + GeoCoor.randomCoordsLon() + ',"t":"u","tid":"wo","tst":' + str(int(datetime.timestamp(datetime.now())) - 300) + ',"vac":0,"vel":0}' | ||
else: | ||
f = open("locations.txt","a+") | ||
f.write(json.dumps(datapoint.decode("utf-8")) + "\n") | ||
return '' | ||
|
||
if __name__ == '__main__': | ||
application.run(debug = True, host='0.0.0.0') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import os, sys, sqlite3 | ||
|
||
class Database(): | ||
def addPosition(payload): | ||
create_database() | ||
connection = sqlite3.connect("./tempdata.db") | ||
|
||
def create_database(): | ||
if not os.path.exists("./database.db"): | ||
connection = sqlite3.connect("./tempdata.db") | ||
cursor = connection.cursor() | ||
# Tabelle erzeugen | ||
sql = "CREATE TABLE tempWerte("\ | ||
"id FLOAT, maxTempSensor FLOAT, minTempUser FLOAT, \ | ||
maxTempUser FLOAT) " | ||
cursor.execute(sql) | ||
connection.commit() | ||
connection.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from random import uniform | ||
|
||
class GeoCoor(): | ||
def randomCoordsLat(): | ||
x = uniform(50, 53) | ||
return str(x) | ||
|
||
def randomCoordsLon(): | ||
y = uniform(7,10) | ||
return str(y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Location(): | ||
# accuracy - Genauigkeit | ||
# altitude - Höhe | ||
# battery - Akkustand | ||
# connection - w -> phone is connected to a WiFi connection (iOS,Android); | ||
# o -> phone is offline (iOS,Android), m -> mobile data (iOS,Android) | ||
# latitude - Breitengrad | ||
# longitude - Längengrad | ||
# trigger - p -> ping issued randomly by background task (iOS,Android) | ||
# c -> circular region enter/leave event (iOS,Android) | ||
# b -> beacon region enter/leave event (iOS) | ||
# r -> response to a reportLocation cmd message (iOS,Android) | ||
# u -> manual publish requested by the user (iOS,Android) | ||
# t -> timer based publish in move move (iOS) | ||
# v -> updated by Settings/Privacy/Locations Services/System Services/Frequent Locations monitoring (iOS) | ||
# trackerID - Tracker Identifiaction | ||
# timestamp - Publish Timestamp | ||
# velocity - Geschwindigkeit | ||
__slots__ = ['accuracy', 'altitude', 'battery', 'connection', 'latitude', 'longitude', 'trigger', 'trackerID', 'timestamp', 'velocity'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|