-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckWiFi.py
29 lines (25 loc) · 1010 Bytes
/
checkWiFi.py
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
"""@package docstring
wait functions
"""
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import subprocess
from PyQt5.QtCore import QTimer, QObject, pyqtSignal
## @brief Periodically check wifi connection and alarm if disconnected
## @author Jeroen Veen
class CheckWiFi(QObject):
timer = QTimer()
postMessage = pyqtSignal(str)
def __init__(self, interval=100):
super().__init__()
self.interval = 1000*interval
self.timer.timeout.connect(self.update)
self.timer.start(self.interval)
def update(self):
ps = subprocess.Popen(['iwgetid'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
try:
output = subprocess.check_output(('grep', 'ESSID'), stdin=ps.stdout)
except subprocess.CalledProcessError:
# grep did not match any lines
self.postMessage.emit("{}: error; No wireless networks connected".format(self.__class__.__name__))
print("No wireless networks connected")