Browse Source

Some last fixes in server

master
Skia 3 years ago
parent
commit
01b13ec007
2 changed files with 21 additions and 12 deletions
  1. +6
    -1
      Server/loc_server.py
  2. +15
    -11
      Server/utils.py

+ 6
- 1
Server/loc_server.py 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,

+ 15
- 11
Server/utils.py 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



Loading…
Cancel
Save