-
Notifications
You must be signed in to change notification settings - Fork 1
/
FlowMeter_Final_script.txt
103 lines (87 loc) · 1.28 KB
/
FlowMeter_Final_script.txt
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
>D
blinkpin=2
blink=0
blinkt=4
blinkc=0
p:total=0
p:liter=0
highflow=450
midflow=420
lowflow=390
highflowTC=150
midflowTC=80
lowflowTC=30
resetb=0
fastblink=2
midblink=4
slowblink=8
delta=0
flow=0
tmp=0
cflow="none"
lastval=0
>F
if blinkc>blinkt
then
if blink==0
then
blink=1
else
blink=0
endif
spinm(blinkpin blink)
blinkc=0
endif
if cflow!="none"
then
blinkc=blinkc+1
endif
>B
total=pc[1]
>S
if resetb==1
then
resetb=0
total=0
liter=0
=>Counter1 0
endif
delta=pc[1]-total
total=pc[1]
if delta>highflowTC
then
cflow="high"
blinkt=fastblink
tmp=(delta/highflow)
endif
if delta>midflowTC
and delta<highflowTC
then
cflow="mid"
blinkt=midblink
tmp=(delta/midflow)
endif
if delta<midflowTC
then
cflow="low"
blinkt=slowblink
tmp=(delta/lowflow)
endif
if delta==0
then
cflow="none"
blinkt=100000
spinm(blinkpin 0)
tmp=0
endif
liter=(liter+tmp)
flow=tmp*60
print total:%total% delta:%delta% liter:%liter% flowrate:%flow%
svars
=>publish stat/%topic%/Flow {"FlowRate":%flow%,"PulseRate":%delta%,"WaterFlow":"%cflow%","Total":%liter%,"Counter":%total%}
>W
Total{m}%liter% Liter
FlowRate{m}%flow% Liter/min
PulseRate{m}%delta% Pulse/sec
WaterFlow{m}%cflow%
bu(resetb "Resetting" "Reset Total")