-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrssiClient.py
More file actions
37 lines (29 loc) · 934 Bytes
/
rssiClient.py
File metadata and controls
37 lines (29 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
import socket
addr = 'E8:B1:FC:F5:16:02'
port = 4
btAddr = '34:43:0b:0b:bd:9b'
bufferSize = 1024
#cmd = 'hcitool rssi ' + btAddr # Use for bluetooth
#command = 'sudo iw wlan0 scan | grep "SSID: Nucleus" -B2' # Used to search wifi networks
command = 'iw wlan0 station dump | grep "signal" '# Use for a connected wifi network
server = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
server.connect((addr, port))
while True:
cmd = server.recv(bufferSize)
# process command
cmd = str(cmd, 'utf-8')
print(cmd)
res = cmd
if cmd == 'quit':
server.send(bytes(cmd, 'utf-8'))
break
elif cmd == 'u':
res = 'u'
#res += os.popen(command).read()[-3:-1]
res += os.popen(command).read()[8:14]
server.send(bytes(res, 'utf-8'))
else:
server.send(bytes(res,'utf-8'))
print('Closing server socket')
server.close()