-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_ping.py
More file actions
26 lines (22 loc) · 778 Bytes
/
basic_ping.py
File metadata and controls
26 lines (22 loc) · 778 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
# Simple ping script with EasyHTTP & context manager
import time
from easyhttp_python import EasyHTTP
def main():
# Async context manager whuch initializing EasyHTTP
with EasyHTTP(debug=True, port=5000) as easy:
try:
# Pinging device by ID once every 3 seconds
while True:
# Bool: True if device is online(sended PONG command)
if easy.ping("ABC123"):
print(f"Device ABC123 is online")
else:
print(f"Device ABC123 is offline")
time.sleep(3)
except KeyboardInterrupt:
# Stopping
easy.stop()
except Exception as e:
print(e)
if __name__ == '__main__':
main()