Some last fixes in server

This commit is contained in:
Skia 2016-06-17 14:52:22 +02:00
parent fab57efdb6
commit 01b13ec007
2 changed files with 21 additions and 12 deletions

View file

@ -69,7 +69,12 @@ def get_loc():
"""
Get the location of the device
"""
rssi_sample = get_rssi_sample(websession["mac_address"])
print("Locating...")
if "mac_address" in websession.keys():
mac = websession["mac_address"]
else:
mac = request.args.get('mac')
rssi_sample = get_rssi_sample(mac)
location = compute_location(rssi_sample)
# Process: ask the AP for the RSSI Samples for the saved MAC address (in websession) and compute the found RSSI Sample,

View file

@ -70,21 +70,25 @@ def get_rssi_element(ip, mac, elem_dict):
mac = mac.replace(':', '')
macbytes = binascii.unhexlify(mac)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((str(ip), PORT))
sent = 0
while sent == 0:
sent = s.send(macbytes)
s.settimeout(3)
try:
s.connect((str(ip), PORT))
sent = 0
while sent == 0:
sent = s.send(macbytes)
chunk = b''
while chunk == b'':
chunk = s.recv(4)
chunk = b''
while chunk == b'':
chunk = s.recv(4)
s.shutdown(socket.SHUT_RDWR)
s.close()
s.shutdown(socket.SHUT_RDWR)
s.close()
print("%s: %s" % (str(ip), struct.unpack('!i', chunk)))
print("%s: %s" % (str(ip), struct.unpack('!i', chunk)))
rssi = struct.unpack('!i', chunk)[0]
except:
rssi = -100
rssi = struct.unpack('!i', chunk)[0]
elem_dict[ip] = rssi