mesh_ping.py
· 681 B · Python
原始檔案
import sys
import time
import meshtastic
import meshtastic.tcp_interface
interval = 10
if len(sys.argv) > 1:
interval = int(sys.argv[1])
while True:
try:
with meshtastic.tcp_interface.TCPInterface("meshtastic.local") as iface:
if iface != None:
print("connected to tcp")
for i in range(10):
fmt_time = time.strftime("%H:%M:%S", time.localtime())
iface.sendText(f"ping {fmt_time}", wantAck=True, channelIndex=1)
print("sent", fmt_time)
time.sleep(interval)
except KeyboardInterrupt:
print("bye")
exit(1)
except:
print("AAA!")
1 | import sys |
2 | import time |
3 | |
4 | import meshtastic |
5 | import meshtastic.tcp_interface |
6 | |
7 | interval = 10 |
8 | if len(sys.argv) > 1: |
9 | interval = int(sys.argv[1]) |
10 | |
11 | while True: |
12 | try: |
13 | with meshtastic.tcp_interface.TCPInterface("meshtastic.local") as iface: |
14 | if iface != None: |
15 | print("connected to tcp") |
16 | |
17 | for i in range(10): |
18 | fmt_time = time.strftime("%H:%M:%S", time.localtime()) |
19 | iface.sendText(f"ping {fmt_time}", wantAck=True, channelIndex=1) |
20 | print("sent", fmt_time) |
21 | time.sleep(interval) |
22 | except KeyboardInterrupt: |
23 | print("bye") |
24 | exit(1) |
25 | except: |
26 | print("AAA!") |
27 |