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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
| | ###
int pSwitch = 2;
void setup() {
Serial.begin(9600);
Serial.println("WatchDog");
}
int InitCount = 60; // s
int count = InitCount;
void loop() {
if (Serial.available()) {
int c = Serial.read();
switch(c) {
default:
Serial.print("Invalid input: ");
Serial.println(c);
break;
case '\r':
case '\n':
;
break;
case '0':
Serial.println("Manual Reset");
count = 0;
break;
case '1':
Serial.println("Alive");
count = 1000;
break;
}
}
Serial.println(count);
if (count) {
count--;
digitalWrite(pSwitch, HIGH);
}
else {
Serial.println("Power Off");
digitalWrite(pSwitch, LOW);
delay(3000);
Serial.println("Power On");
digitalWrite(pSwitch, HIGH);
count = InitCount;
delay(60000);
}
delay(1000);
}
###
###
#need pyserial:
# $> pip install pyserial
import sys
import serial
import time
import datetime
args = sys.argv
if len(args) < 2:
print("Format: BarkDog port cmd")
quit()
port = args[1]
seri = serial.Serial(port, 9600, timeout=1000)
print("Open [{}]".format(seri))
one = bytes("1",'utf-8')
try:
line = seri.readline().strip()
print(line)
while True:
seri.write(one);
time.sleep(1);
print(datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S"))
except Exception as x:
print("Error Stop!! " + x.args)
finally:
seri.close()
###
|
|