-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
215 lines (207 loc) · 5.33 KB
/
index.html
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Intellidwell Sprinkler Controller</title>
<style>
body {
background-color: #333;
color: white;
font-family: Arial, sans-serif;
padding: 20px;
position: relative;
}
h1 {
color: #FFD700;
}
.switch {
position: relative;
display: inline-block;
width: 60px; /* Retain original fixed width */
height: 34px;
margin: 10px;
vertical-align: middle; /* Ensure vertical alignment with text */
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: .4s;
border-radius: 34px;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
transition: .4s;
border-radius: 50%;
}
input:checked + .slider {
background-color: #2196F3;
}
input:checked + .slider:before {
transform: translateX(26px);
}
button {
background-color: #2196F3;
border: none;
color: white;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
border-radius: 12px;
}
button_red {
background-color: #FF0000;
border: none;
color: white;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
border-radius: 12px;
}
}
.logs-button {
position: absolute;
top: 20px;
right: 20px;
background-color: #2196F3;
border: none;
color: white;
padding: 10px;
cursor: pointer;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
}
.logs-button svg {
width: 24px;
height: 24px;
fill: white;
}
@media (max-width: 600px) {
body {
padding: 5px;
}
.switch {
margin: 5px 0; /* Adjust margins for mobile */
}
button {
width: 100%;
padding: 12px;
}
.logs-button {
top: 10px;
right: 10px;
font-size: 20px;
}
</style>
</head>
<body>
<h1>Intellidwell Sprinkler Controller</h1>
<div>
<label class="switch">
<input type="checkbox" onchange="toggleRelay(this, 0)" data-index="0">
<span class="slider"></span>
</label> Zone 1<br>
<label class="switch">
<input type="checkbox" onchange="toggleRelay(this, 1)" data-index="1">
<span class="slider"></span>
</label> Zone 2<br>
<label class="switch">
<input type="checkbox" onchange="toggleRelay(this, 2)" data-index="2">
<span class="slider"></span>
</label> Zone 3<br>
<label class="switch">
<input type="checkbox" onchange="toggleRelay(this, 3)" data-index="3">
<span class="slider"></span>
</label> Zone 4<br>
<label class="switch">
<input type="checkbox" onchange="toggleRelay(this, 4)" data-index="4">
<span class="slider"></span>
</label> Zone 5<br>
<label class="switch">
<input type="checkbox" onchange="toggleRelay(this, 5)" data-index="5">
<span class="slider"></span>
</label> Zone 6<br>
<label class="switch">
<input type="checkbox" onchange="toggleRelay(this, 6)" data-index="6">
<span class="slider"></span>
</label> Zone 7<br>
<label class="switch">
<input type="checkbox" onchange="toggleRelay(this, 7)" data-index="7">
<span class="slider"></span>
</label> Zone 8<br>
<label class="switch">
<input type="checkbox" onchange="toggleRelay(this, 8)" data-index="8">
<span class="slider"></span>
</label> Zone 9<br>
<label class="switch">
<input type="checkbox" onchange="toggleRelay(this, 9)" data-index="9">
<span class="slider"></span>
</label> Zone 10<br>
</div>
<button type="button" onclick="window.location.href='/scheduler'">Scheduler</button>
<div>
<button class="logs-button" onclick="window.location.href='/logs-page'">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 2h14a2 2 0 012 2v16a2 2 0 01-2 2H3a2 2 0 01-2-2V4a2 2 0 012-2zm0 2v16h14V4H3zm2 2h2v12H5V6zm4 0h2v12H9V6zm4 0h2v12h-2V6z"/></svg>
</button>
<button type="button" onclick="window.location.href='/settings'">Settings</button>
<button_red type="button_red" onclick="restartDevice()">Restart Device</button_red>
</div>
<script>
function updateSwitches() {
fetch('/get-relay-states')
.then(response => response.json())
.then(states => {
states.forEach((state, index) => {
const switchElement = document.querySelector(`input[type="checkbox"][data-index="${index}"]`);
if (switchElement) {
const currentState = (state === 1);
if (switchElement.checked !== currentState) {
switchElement.checked = currentState;
}
}
});
})
.catch(error => console.error('Error fetching relay states:', error));
}
// Call updateSwitches every 500 milliseconds
setInterval(updateSwitches, 2000);
function toggleRelay(element, pin) {
const state = element.checked ? 'on' : 'off';
fetch(`/relay/${pin}/${state}`)
.then(response => response.text())
.then(data => console.log(data));
}
function restartDevice() {
fetch('/restart', { method: 'POST' })
.then(response => response.text())
.then(data => console.log(data))
.catch(error => console.error('Error restarting device:', error));
}
</script>
</body>
</html>