-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbadetemp.html
More file actions
391 lines (337 loc) · 16 KB
/
Copy pathbadetemp.html
File metadata and controls
391 lines (337 loc) · 16 KB
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
<!DOCTYPE html>
<html lang="no">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Badetemperatur – Siljan kommune</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&family=DM+Mono:wght@400&display=swap" rel="stylesheet">
<!-- v0.4 Changelog:
v0.4 - Siljan kommune grønn fargeprofil (fra siljan.kommune.no)
- Offisiell logo fra siljan.kommune.no
- Supabase usynlig push ved BLE-avlesning
- iOS/Safari fallback: henter siste verdi fra Supabase
- Forbedret BLE-deteksjon og feilhåndtering
- QR-kode (placeholder) for utskrift
- Disclaimer i footer
v0.3 - Kommunevåpen SVG, temperaturring, QR-kode
v0.2 - BLE ESS UUID 0x181A, temperatur UUID 0x2A6E
v0.1 - Første prototype med Web Bluetooth
-->
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
--sk-green-dark: #1a4d2e;
--sk-green: #2d6a4f;
--sk-green-mid: #40916c;
--sk-green-light: #52b788;
--sk-green-pale: #95d5b2;
--sk-bg: #0f2b1a;
--sk-text: #e8f0ea;
--sk-text-dim: rgba(232,240,234,0.5);
--sk-text-faint: rgba(232,240,234,0.3);
--sk-surface: rgba(255,255,255,0.04);
--sk-border: rgba(255,255,255,0.08);
}
body {
font-family: 'DM Sans', sans-serif;
min-height: 100vh;
background: var(--sk-bg);
color: var(--sk-text);
display: flex; flex-direction: column;
align-items: center; justify-content: center;
padding: 24px; overflow-x: hidden;
}
body::before {
content: '';
position: fixed; top: -50%; left: -50%;
width: 200%; height: 200%;
background: radial-gradient(ellipse at 30% 20%, rgba(45,106,79,0.15) 0%, transparent 60%),
radial-gradient(ellipse at 70% 80%, rgba(82,183,136,0.06) 0%, transparent 50%);
z-index: 0;
}
.card {
position: relative; z-index: 1;
background: var(--sk-surface);
border: 1px solid var(--sk-border);
border-radius: 20px;
padding: 36px 32px 28px;
max-width: 380px; width: 100%;
text-align: center;
}
.logo-row {
display: flex; align-items: center; justify-content: center;
gap: 12px; margin-bottom: 24px;
}
.kommune-logo {
width: 40px; height: 40px;
filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
}
.kommune-text { text-align: left; }
.kommune-name { font-size: 1.05em; font-weight: 700; letter-spacing: -0.01em; }
.kommune-sub { font-size: 0.72em; color: var(--sk-text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
h1 { font-size: 1.45em; font-weight: 700; margin-bottom: 4px; letter-spacing: -0.02em; }
.location { font-size: 0.88em; color: var(--sk-text-dim); margin-bottom: 28px; }
/* Temperatur-ring */
.temp-ring { position: relative; width: 200px; height: 200px; margin: 0 auto 20px; }
.temp-ring > svg { position: absolute; top: 0; left: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.bg-ring { fill: none; stroke: rgba(255,255,255,0.06); stroke-width: 6; }
.value-ring { fill: none; stroke: url(#tg); stroke-width: 6; stroke-linecap: round;
stroke-dasharray: 565; stroke-dashoffset: 565; transition: stroke-dashoffset 1.2s ease-out; }
.temp-value { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; }
.temp-number { font-family: 'DM Mono', monospace; font-size: 3.2em; font-weight: 400; line-height: 1; color: #fff; }
.temp-unit { font-size: 0.3em; color: var(--sk-text-dim); vertical-align: super; }
.temp-label { font-size: 0.78em; color: var(--sk-text-faint); margin-top: 4px; }
.status { font-size: 0.78em; color: var(--sk-text-dim); margin-bottom: 20px; min-height: 20px; }
/* Knapper */
button {
background: linear-gradient(135deg, var(--sk-green-dark), var(--sk-green));
color: white; border: none; border-radius: 14px; padding: 16px 32px;
font-family: 'DM Sans', sans-serif; font-size: 1em; font-weight: 600;
cursor: pointer; width: 100%;
transition: transform 0.15s, opacity 0.15s;
box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
button:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.3); }
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-secondary {
background: rgba(255,255,255,0.06);
border: 1px solid rgba(255,255,255,0.1);
margin-top: 10px; box-shadow: none;
}
.btn-secondary:hover { background: rgba(255,255,255,0.1); }
.error { color: #e07050; font-size: 0.78em; margin-top: 14px; min-height: 20px; }
.info-box {
background: rgba(82,183,136,0.08); border: 1px solid rgba(82,183,136,0.15);
border-radius: 12px; padding: 14px; margin-bottom: 20px;
font-size: 0.8em; color: var(--sk-text-dim); line-height: 1.5;
}
.divider { border: none; border-top: 1px solid var(--sk-border); margin: 24px 0 18px; }
/* QR */
.qr-section { text-align: center; }
.qr-label { font-size: 0.72em; color: var(--sk-text-faint); margin-bottom: 10px; }
.qr-code { display: inline-block; background: white; padding: 8px; border-radius: 8px; }
.qr-code svg { display: block; }
/* Footer */
.footer { font-size: 0.68em; color: var(--sk-text-faint); margin-top: 16px; line-height: 1.5; }
.footer a { color: var(--sk-green-pale); text-decoration: none; }
.footer a:hover { text-decoration: underline; }
/* Wave */
.wave { position: fixed; bottom: 0; left: 0; right: 0; height: 100px; z-index: 0; opacity: 0.12; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
.card { animation: fadeIn 0.6s ease-out; }
</style>
</head>
<body>
<!-- Gradient definisjon -->
<svg style="position:absolute;width:0;height:0;">
<defs>
<linearGradient id="tg" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" stop-color="#1a4d2e"/>
<stop offset="50%" stop-color="#2d6a4f"/>
<stop offset="100%" stop-color="#52b788"/>
</linearGradient>
</defs>
</svg>
<!-- Bølge-dekorasjon -->
<svg class="wave" viewBox="0 0 1440 100" preserveAspectRatio="none">
<path d="M0,50 C360,100 720,0 1080,50 C1260,75 1380,30 1440,50 L1440,100 L0,100 Z" fill="rgba(45,106,79,0.4)"/>
<path d="M0,70 C240,30 480,90 720,50 C960,10 1200,70 1440,40 L1440,100 L0,100 Z" fill="rgba(82,183,136,0.2)"/>
</svg>
<div class="card">
<div class="logo-row">
<img class="kommune-logo"
src="https://www.siljan.kommune.no/external/ssp/inter-v2/prod/files/img/siljan-logo.svg"
alt="Siljan kommunevåpen"
onerror="this.style.display='none'">
<div class="kommune-text">
<div class="kommune-name">Siljan kommune</div>
<div class="kommune-sub">Badetemperatur</div>
</div>
</div>
<h1 id="heading">Sjekk vannet!</h1>
<div class="location" id="location">Trykk for å måle vanntemperaturen</div>
<div id="infoBox" style="display:none;" class="info-box"></div>
<div class="temp-ring">
<svg viewBox="0 0 200 200">
<circle class="bg-ring" cx="100" cy="100" r="90"/>
<circle class="value-ring" id="ring" cx="100" cy="100" r="90"/>
</svg>
<div class="temp-value">
<div class="temp-number" id="tempNumber">--<span class="temp-unit">°C</span></div>
<div class="temp-label" id="tempLabel">vanntemperatur</div>
</div>
</div>
<div class="status" id="status"></div>
<button id="readBtn" onclick="readTemperature()">Mål temperatur</button>
<button id="lastBtn" class="btn-secondary" onclick="fetchLast()" style="display:none;">Vis sist registrerte temperatur</button>
<div class="error" id="error"></div>
<hr class="divider">
<div class="qr-section">
<div class="qr-label">Skann for å åpne på din telefon</div>
<div class="qr-code">
<!-- QR-kode placeholder — bytt med generert SVG for produksjon -->
<svg viewBox="0 0 140 140" width="120" height="120">
<rect width="140" height="140" fill="white"/>
<text x="70" y="75" font-size="10" text-anchor="middle" fill="#999" font-family="sans-serif">QR-kode</text>
</svg>
</div>
</div>
<div class="footer">
Veiledende temperatur. Kan avvike fra faktisk vanntemperatur.<br>
<a href="https://siljan.kommune.no">siljan.kommune.no</a> • Badetemperatur v0.5
</div>
</div>
<script>
// ========================================
// Siljan Badetemperatur v0.5
// BLE enhetsnavn-avlesning + Supabase push/read
// ========================================
const SUPA_URL = 'https://fdqjiubwnohtucpercro.supabase.co';
const SUPA_ANON = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZkcWppdWJ3bm9odHVjcGVyY3JvIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzQzMzMwOTAsImV4cCI6MjA4OTkwOTA5MH0.31n5oId96UEOB7Hf-rSCJ_DG57SNWNPJfeiCFDbW_vQ';
const hasBLE = !!(navigator.bluetooth);
// --- UI-oppdatering ---
function updRing(temp) {
const ring = document.getElementById('ring');
const circumference = 2 * Math.PI * 90;
const clamped = Math.max(0, Math.min(35, temp));
ring.style.strokeDashoffset = circumference * (1 - clamped / 35);
}
function updText(temp) {
const h = document.getElementById('heading');
const l = document.getElementById('tempLabel');
if (temp < 10) { h.textContent = 'Iskaldt!'; l.textContent = 'Kun for de tøffeste'; }
else if (temp < 15) { h.textContent = 'Friskt!'; l.textContent = 'Forfriskende bad'; }
else if (temp < 18) { h.textContent = 'Behagelig'; l.textContent = 'Fint badevann'; }
else if (temp < 22) { h.textContent = 'Deilig!'; l.textContent = 'Perfekt badetemperatur'; }
else { h.textContent = 'Tropisk!'; l.textContent = 'Hopp rett uti!'; }
}
function showTemp(temp, timeStr, source) {
document.getElementById('tempNumber').innerHTML =
temp.toFixed(1) + '<span class="temp-unit">°C</span>';
updRing(temp);
updText(temp);
const prefix = source === 'ble' ? 'Målt' : 'Sist registrert';
document.getElementById('status').textContent = prefix + ' ' + timeStr;
}
// --- Supabase: usynlig push ---
async function pushToSupa(sensorId, temp) {
try {
await fetch(SUPA_URL + '/rest/v1/badetemperatur', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'apikey': SUPA_ANON,
'Authorization': 'Bearer ' + SUPA_ANON,
'Prefer': 'return=minimal'
},
body: JSON.stringify({
sensor_id: sensorId,
temperatur: temp,
kilde: 'web_bluetooth'
})
});
} catch (e) {
// Stille feil — ikke vis til bruker
console.log('Supabase push feilet:', e.message);
}
}
// --- Supabase: hent siste registrering ---
async function fetchLast() {
const status = document.getElementById('status');
const error = document.getElementById('error');
error.textContent = '';
status.textContent = 'Henter siste registrering...';
try {
const resp = await fetch(
SUPA_URL + '/rest/v1/badetemperatur?temperatur=neq.96&order=rapportert.desc&limit=1', {
headers: {
'apikey': SUPA_ANON,
'Authorization': 'Bearer ' + SUPA_ANON
}
});
const data = await resp.json();
if (data && data.length > 0) {
const temp = parseFloat(data[0].temperatur);
const dt = new Date(data[0].rapportert);
const timeStr = dt.toLocaleDateString('no-NO', { day: 'numeric', month: 'short' })
+ ' kl. ' + dt.toLocaleTimeString('no-NO', { hour: '2-digit', minute: '2-digit' });
showTemp(temp, timeStr, 'supa');
document.getElementById('location').textContent = data[0].sensor_id || 'Badeplass';
} else {
status.textContent = 'Ingen registreringer ennå';
}
} catch (err) {
error.textContent = 'Kunne ikke hente data';
status.textContent = '';
console.log('Supabase fetch feilet:', err.message);
}
}
// --- BLE: les temperatur fra enhetsnavn ---
// Sensoren broadcaster navn som "Tjønna 25.5°C"
// Vi parser temperaturen direkte fra navnet - ingen tilkobling nødvendig!
function parseTempFromName(name) {
// "Tjønna 25.5°C" -> 25.5
const match = name.match(/Tj[øo]nna\s+([-\d.]+)/);
return match ? parseFloat(match[1]) : null;
}
async function readTemperature() {
const btn = document.getElementById('readBtn');
const status = document.getElementById('status');
const loc = document.getElementById('location');
const error = document.getElementById('error');
error.textContent = '';
btn.disabled = true;
status.textContent = 'Søker etter sensor...';
try {
const device = await navigator.bluetooth.requestDevice({
filters: [{ namePrefix: 'Tj' }]
});
const temp = parseTempFromName(device.name);
if (temp === null) {
error.textContent = 'Kunne ikke lese temperatur fra sensor.';
btn.disabled = false;
return;
}
const timeStr = 'kl. ' + new Date().toLocaleTimeString('no-NO', { hour: '2-digit', minute: '2-digit' });
showTemp(temp, timeStr, 'ble');
loc.textContent = 'Øverbøtjønna';
// Usynlig push til Supabase
pushToSupa('overbotjonna', temp);
} catch (err) {
if (err.name === 'NotFoundError') {
error.textContent = 'Fant ingen sensor i nærheten. Er du ved badeplassen?';
} else if (err.name === 'SecurityError') {
error.textContent = 'Bluetooth-tilgang ble avslått.';
} else if (err.message && err.message.includes('User cancelled')) {
error.textContent = '';
} else {
error.textContent = 'Kunne ikke lese sensor: ' + err.message;
}
status.textContent = '';
}
btn.disabled = false;
}
// --- Init: tilpass UI basert på BLE-støtte ---
(function init() {
const readBtn = document.getElementById('readBtn');
const lastBtn = document.getElementById('lastBtn');
const infoBox = document.getElementById('infoBox');
const loc = document.getElementById('location');
if (!hasBLE) {
// iOS / Safari / eldre nettlesere
readBtn.style.display = 'none';
lastBtn.style.display = 'block';
infoBox.style.display = 'block';
infoBox.innerHTML = 'Din nettleser støtter ikke Bluetooth-avlesning.<br>Trykk knappen for å se sist registrerte temperatur.';
loc.textContent = '';
fetchLast();
} else {
// Chrome / Android — vis begge knapper
lastBtn.style.display = 'block';
}
})();
</script>
</body>
</html>