-
Notifications
You must be signed in to change notification settings - Fork 0
/
ping_script.py
executable file
·53 lines (45 loc) · 1.28 KB
/
ping_script.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
import rospy
from std_msgs.msg import String
from math import *
import tf
import os
import signal
import sys
import rospy
from serial.serialutil import SerialException as SerialException
# SIGINT Handler to escape loops. Use Ctrl-C to exit
def sigint_handler(signal, frame):
sys.exit(0)
def ping(hostname):
response = os.system("ping -c 1 -t 1 " + hostname)
if response != 0:
print(hostname + "'s connection is weak")
return False
else:
print(hostname + " is connected")
return True
if __name__ == "__main__":
signal.signal(signal.SIGINT, sigint_handler)
rospy.init_node("Ping_Node")
rospy.loginfo("Starting Ping Node")
iter_time = rospy.Rate(0.2)
while True:
os.system("clear")
if not (ping("192.168.69.21") and ping("192.168.69.9")):
ping("192.168.69.21")
ping("192.168.69.9")
ping("192.168.69.101")
ping("192.168.69.20")
ping("192.168.69.1")
ping("192.168.69.100")
# else:
# print("NUC and RPi Connected!!")
# print()
# ping("192.168.69.202")
# print()
# ping("192.168.69.203")
# print()
# ping("192.168.69.204")
# print()
iter_time.sleep()