Refactor server folder
This commit is contained in:
parent
3653e3d12b
commit
1b904a7c95
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -46,3 +46,4 @@
|
|||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
Server/env
|
||||
|
|
BIN
Server/__pycache__/Rssi.cpython-35.pyc
Normal file
BIN
Server/__pycache__/Rssi.cpython-35.pyc
Normal file
Binary file not shown.
BIN
Server/__pycache__/fingerprint.cpython-35.pyc
Normal file
BIN
Server/__pycache__/fingerprint.cpython-35.pyc
Normal file
Binary file not shown.
BIN
Server/__pycache__/location.cpython-35.pyc
Normal file
BIN
Server/__pycache__/location.cpython-35.pyc
Normal file
Binary file not shown.
BIN
Server/__pycache__/models.cpython-35.pyc
Normal file
BIN
Server/__pycache__/models.cpython-35.pyc
Normal file
Binary file not shown.
|
@ -1,5 +1,6 @@
|
|||
from location import location
|
||||
from Rssi import RssiSample
|
||||
|
||||
class fingerprint:
|
||||
def __init__(self):
|
||||
self.location = location()
|
||||
|
@ -10,4 +11,4 @@ class fingerprint:
|
|||
def get_rssi(self):
|
||||
return self.rssi
|
||||
def get_loc(self):
|
||||
return self.location
|
||||
return self.location
|
59
Server/loc.py
Normal file → Executable file
59
Server/loc.py
Normal file → Executable file
|
@ -1,24 +1,43 @@
|
|||
#!flask/bin/python
|
||||
from flask import Flask
|
||||
from flask import abort
|
||||
from fingerprint import fingerprint
|
||||
from location import location
|
||||
from Rssi import RssiSample
|
||||
from models import Fingerprint, Location, RSSISample
|
||||
|
||||
# WARNING!
|
||||
# This file is beeing slit up between setup_server.py and loc_server.py, it shouldn't be used anymore (except for
|
||||
# testing, if needed)
|
||||
|
||||
app = Flask(__name__)
|
||||
add_mac=""
|
||||
cord_x=0
|
||||
cord_y=0
|
||||
|
||||
locat = location ()
|
||||
fingerprint = fingerprint()
|
||||
seuil = 60
|
||||
array_fingerprint = [fingerprint]
|
||||
min_dist = 1111111111111
|
||||
|
||||
@app.route('/')
|
||||
def root():
|
||||
return "User localisation server application"
|
||||
|
||||
@app.route('/coord/<c_x>/<c_y>', methods=['GET'])
|
||||
def storage_location(c_x,c_y):
|
||||
cord_x = c_x
|
||||
cord_y = c_y
|
||||
print("a")
|
||||
return "ok"
|
||||
|
||||
@app.route('/send_mac/<mac>', methods=['GET'])
|
||||
def get_mac(mac):
|
||||
add_mac = mac
|
||||
print(mac)
|
||||
return ""
|
||||
|
||||
|
||||
@app.route('/cnx/<code>', methods=['GET'])
|
||||
def cnx(code):
|
||||
if code == "please":
|
||||
|
@ -27,11 +46,45 @@ def cnx(code):
|
|||
abort(404)
|
||||
return "U're forbiden to be connected"
|
||||
|
||||
@app.route('/receive/<value>/<mac>')
|
||||
def add_to_finger_print(value,mac):
|
||||
rssi = RssiSample()
|
||||
rssi.setvalue(mac,value)
|
||||
locat.set_xy(cord_x,cord_y)
|
||||
################################################
|
||||
fingerprint.set(locat,rssi)
|
||||
array_fingerprint.append(fingerprint)
|
||||
#print("rssi.getvalue()")
|
||||
################################################
|
||||
return "added"
|
||||
|
||||
@app.route('/compute/<value>')
|
||||
def compute_location():
|
||||
rssi = RssiSample()
|
||||
rssi.affc(array_fingerprint[0].get_rssi())
|
||||
#remplir l'array_fingerprint depuis la bd
|
||||
for f in array_fingerprint :
|
||||
if min_dist>rssi_distance(rssi,f.get_rssi,seuil):
|
||||
min_dist = rssi_distance(rssi,f.get_rssi,seuil)
|
||||
locat = f.get_loc()
|
||||
return locat
|
||||
|
||||
|
||||
|
||||
def rssi_distance(s1,s2,seuil):
|
||||
distance = 0
|
||||
for (mac_adress,value) in s1 :
|
||||
if mac_adress in s2.keys() :
|
||||
distance += math.pow(value - s2.find(mac_adress).getvalue(),2)
|
||||
else:
|
||||
distance += math.pow(value+seuil,2)
|
||||
for (mac_adress,value) in s2:
|
||||
if mac_adress not in s1.keys() :
|
||||
distance += math.pow(value+seuil,2)
|
||||
return math.sqrt(distance)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# app.run(debug=True,host='172.17.9.60')
|
||||
app.run(debug=True,host='192.168.43.214')
|
||||
app.run(debug=True,host='127.0.0.1')
|
||||
#app.run(debug=True,host='192.168.43.214')
|
||||
|
|
54
Server/loc_server.py
Normal file
54
Server/loc_server.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
|
||||
from flask import Flask, url_for
|
||||
from flask import abort
|
||||
|
||||
from models import Fingerprint, Location, RSSISample
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/')
|
||||
def root():
|
||||
return "User localisation server application"
|
||||
|
||||
@app.route('/init')
|
||||
def init():
|
||||
"""
|
||||
Ask the device to send its MAC address for location
|
||||
"""
|
||||
# TODO: check if the DB is ready or not (if it contains some values)
|
||||
return "Ready for locating, give me your MAC address, please"
|
||||
# OR
|
||||
return "Database not ready yet, please use setup application"
|
||||
|
||||
@app.route('/send_mac', methods=['POST'])
|
||||
def send_mac():
|
||||
"""
|
||||
Get the MAC address of the device that wants to be located
|
||||
It would be wonderful if we could use many devices at the same time!
|
||||
|
||||
Send a POST request with the following parameter:
|
||||
mac=<your mac address>
|
||||
"""
|
||||
# mac = request.form.get("mac")
|
||||
# TODO: save the MAC into the session
|
||||
return "ACK, go to the following URL to get your location: " + url_for('get_loc', mac=mac)
|
||||
|
||||
@app.route('/get_loc', methods=['GET'])
|
||||
def get_loc():
|
||||
"""
|
||||
Get the location of the device
|
||||
"""
|
||||
# Process: ask the AP for the RSSI Samples for the saved MAC address (in session) and compute the found RSSI Sample,
|
||||
# then compare it to the ones in the DB to get the nearest location
|
||||
return "Located! You are here: x, y"
|
||||
|
||||
# No need for additionnal routes: as soon as we have some values in the DB, we can start locating clients with the
|
||||
# other server app.
|
||||
# The more we have values (fingerprints), the more accurate the location will be!
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True,host='127.0.0.1')
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
class location:
|
||||
def __init__(self):
|
||||
self.x=0
|
||||
|
@ -5,4 +6,4 @@ class location:
|
|||
def set_xy(self,cord_x,cord_y):
|
||||
self.x = cord_x
|
||||
self.y = cord_y
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ class Fingerprint(Base):
|
|||
__tablename__ = "fingerprint"
|
||||
id = Column(Integer, primary_key=True, nullable=False)
|
||||
location = relationship("Location", cascade="all, delete-orphan", backref="fingerprint")
|
||||
rssisample = relationship("RSSISample", cascade="all, delete-orphan", backref="fingerprint")
|
||||
rssi_sample = relationship("RSSISample", cascade="all, delete-orphan", backref="fingerprint")
|
||||
|
||||
|
||||
def main():
|
||||
|
|
56
Server/setup_server.py
Normal file
56
Server/setup_server.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
|
||||
from flask import Flask
|
||||
from flask import abort
|
||||
|
||||
from models import Fingerprint, Location, RSSISample
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/')
|
||||
def root():
|
||||
return "Set up server application"
|
||||
|
||||
@app.route('/init')
|
||||
def init():
|
||||
"""
|
||||
Set up the database before the mapping of the building
|
||||
"""
|
||||
# TODO: Create an empty database
|
||||
# a good idea would be to backup an eventual existing DB, to ensure not sadly loosing some precious data
|
||||
return "Setting up fingerprint database"
|
||||
|
||||
@app.route('/send_mac', methods=['POST'])
|
||||
def send_mac():
|
||||
"""
|
||||
Get the MAC address of the device that does the mapping
|
||||
It would be wonderful if we could use many devices at the same time!
|
||||
|
||||
Send a POST request with the following parameter:
|
||||
mac=<your mac address>
|
||||
"""
|
||||
# mac = request.form.get("mac")
|
||||
return "ACK, you can send me some locations"
|
||||
|
||||
@app.route('/send_loc', methods=['POST'])
|
||||
def send_loc():
|
||||
"""
|
||||
Get the location of the device
|
||||
|
||||
Send a POST request with the following parameters:
|
||||
x=<your x coordinate>
|
||||
y=<your y coordinate>
|
||||
"""
|
||||
# x = request.form.get("x")
|
||||
# y = request.form.get("y")
|
||||
# Process: ask the AP for the RSSI Samples to compute the fingerprint and save it with the location
|
||||
return "Located and saved, thank you! You can now move"
|
||||
|
||||
# No need for additionnal routes: as soon as we have some values in the DB, we can start locating clients with the
|
||||
# other server app.
|
||||
# The more we have values (fingerprints), the more accurate the location will be!
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True,host='127.0.0.1')
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,78 +0,0 @@
|
|||
#!flask/bin/python
|
||||
from flask import Flask
|
||||
from flask import abort
|
||||
from fingerprint import fingerprint
|
||||
from location import location
|
||||
from Rssi import RssiSample
|
||||
|
||||
app = Flask(__name__)
|
||||
add_mac=""
|
||||
cord_x=0
|
||||
cord_y=0
|
||||
|
||||
locat = location ()
|
||||
fingerprint = fingerprint()
|
||||
seuil = 60
|
||||
array_fingerprint = [fingerprint]
|
||||
min_dist = 1111111111111
|
||||
@app.route('/coord/<c_x>/<c_y>', methods=['GET'])
|
||||
def storage_location(c_x,c_y):
|
||||
cord_x = c_x
|
||||
cord_y = c_y
|
||||
print("a")
|
||||
return "ok"
|
||||
@app.route('/send_mac/<mac>', methods=['GET'])
|
||||
def get_mac(mac):
|
||||
add_mac = mac
|
||||
print(mac)
|
||||
return ""
|
||||
|
||||
|
||||
@app.route('/cnx/<code>', methods=['GET'])
|
||||
def cnx(code):
|
||||
if code == "please":
|
||||
return "u're connected"
|
||||
else:
|
||||
abort(404)
|
||||
return "U're forbiden to be connected"
|
||||
@app.route('/receive/<value>/<mac>')
|
||||
def add_to_finger_print(value,mac):
|
||||
rssi = RssiSample()
|
||||
rssi.setvalue(mac,value)
|
||||
locat.set_xy(cord_x,cord_y)
|
||||
################################################
|
||||
fingerprint.set(locat,rssi)
|
||||
array_fingerprint.append(fingerprint)
|
||||
#print("rssi.getvalue()")
|
||||
################################################
|
||||
return "added"
|
||||
@app.route('/compute/<value>')
|
||||
def compute_location():
|
||||
rssi = RssiSample()
|
||||
rssi.affc(array_fingerprint[0].get_rssi())
|
||||
#remplir l'array_fingerprint depuis la bd
|
||||
for f in array_fingerprint :
|
||||
if min_dist>rssi_distance(rssi,f.get_rssi,seuil):
|
||||
min_dist = rssi_distance(rssi,f.get_rssi,seuil)
|
||||
locat = f.get_loc()
|
||||
return locat
|
||||
|
||||
|
||||
|
||||
def rssi_distance(s1,s2,seuil):
|
||||
distance = 0
|
||||
for (mac_adress,value) in s1 :
|
||||
if mac_adress in s2.keys() :
|
||||
distance += math.pow(value - s2.find(mac_adress).getvalue(),2)
|
||||
else:
|
||||
distance += math.pow(value+seuil,2)
|
||||
for (mac_adress,value) in s2:
|
||||
if mac_adress not in s1.keys() :
|
||||
distance += math.pow(value+seuil,2)
|
||||
return math.sqrt(distance)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True,host='172.17.7.33')
|
||||
#app.run(debug=True,host='192.168.43.214')
|
Loading…
Reference in a new issue