-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhumanPiClient.py
More file actions
54 lines (45 loc) · 1.5 KB
/
humanPiClient.py
File metadata and controls
54 lines (45 loc) · 1.5 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import socket
import sys
import select
import subprocess
import argparse
import time
import re, uuid
parser = argparse.ArgumentParser(description='Display WLAN signal strength.')
parser.add_argument(dest='interface', nargs='?', default='wlan0',
help='wlan interface (default: wlan0)')
args = parser.parse_args()
client=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
client.connect(('192.168.43.95',12345))
time.sleep(0.1)
client.send("\n".encode('ascii'))
socket_list=[sys.stdin,client]
while True:
# ready,_,_=select.select(socket_list,[],[],0)
# for socket in ready:
# if socket is client:
# data=client.recv(1024)
# print(data.decode('ascii'))
# if not data :
# sys.exit()
macAd=':'.join(re.findall('..', '%012x' % uuid.getnode()))
cmd = subprocess.Popen('iwconfig %s' % args.interface, shell=True,
stdout=subprocess.PIPE)
b=-1
for line in cmd.stdout:
if 'Link Quality' in line:
a= line.lstrip(' ')[-10:-7]
a=abs(int(a))
if(a<50):
b='0'
if(a>50 and a<57):
b='1'
if(a>60):
b='2'
client.send(str(b).encode('ascii'))
client.send(macAd.encode('ascii'))
elif 'Not-Associated' in line:
b='No signal'
client.send(str(b).encode('ascii'))
# msg=sys.stdin.readline()
# client.send(str(msg).encode('ascii'))