yoda-sailing 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -4
- package/public/dashboard.js +76 -0
- package/public/index.html +14 -0
- package/public/style.css +8 -0
- package/README.md +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yoda-sailing",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Read-only Signal K webapp for viewing Ruuvi acceleration axes.",
|
|
5
|
+
"keywords": ["signalk-webapp", "signalk-category-instruments", "ruuvi"],
|
|
6
|
+
"files": ["public"],
|
|
7
|
+
"signalk": { "displayName": "YODA Dashboard" },
|
|
8
|
+
"license": "UNLICENSED"
|
|
9
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const axes = ['X', 'Y', 'Z'];
|
|
2
|
+
const readings = document.querySelector('#sensors');
|
|
3
|
+
const status = document.querySelector('#status');
|
|
4
|
+
const formatter = new Intl.NumberFormat('fr-FR', { maximumFractionDigits: 3 });
|
|
5
|
+
|
|
6
|
+
function findSensors(data) {
|
|
7
|
+
const sensors = new Map();
|
|
8
|
+
|
|
9
|
+
function walk(value, path) {
|
|
10
|
+
if (!value || typeof value !== 'object') return;
|
|
11
|
+
const match = /^(.*?)(?:\.)?Acc([XYZ])axis$/i.exec(path);
|
|
12
|
+
if (match && /^ruuvi/i.test(match[1]) && Object.hasOwn(value, 'value')) {
|
|
13
|
+
const [, sensor, axis] = match;
|
|
14
|
+
const samples = sensors.get(sensor) ?? {};
|
|
15
|
+
samples[axis.toUpperCase()] = value;
|
|
16
|
+
sensors.set(sensor, samples);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
for (const [key, child] of Object.entries(value)) {
|
|
20
|
+
if (key !== 'meta' && key !== 'values') walk(child, path ? path + '.' + key : key);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
walk(data, '');
|
|
25
|
+
return sensors;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function render(sensors) {
|
|
29
|
+
readings.replaceChildren();
|
|
30
|
+
for (const [sensor, samples] of sensors) {
|
|
31
|
+
const card = document.createElement('section');
|
|
32
|
+
const heading = document.createElement('h2');
|
|
33
|
+
heading.textContent = sensor;
|
|
34
|
+
const list = document.createElement('dl');
|
|
35
|
+
for (const axis of axes) {
|
|
36
|
+
const sample = samples[axis];
|
|
37
|
+
const label = document.createElement('dt');
|
|
38
|
+
label.textContent = axis;
|
|
39
|
+
const entry = document.createElement('dd');
|
|
40
|
+
const units = sample?.meta?.units;
|
|
41
|
+
entry.textContent = Number.isFinite(sample?.value)
|
|
42
|
+
? formatter.format(sample.value) + (units ? ' ' + units : '')
|
|
43
|
+
: '—';
|
|
44
|
+
list.append(label, entry);
|
|
45
|
+
}
|
|
46
|
+
const timestamp = Math.max(...Object.values(samples).map(sample => Date.parse(sample.timestamp)).filter(Number.isFinite));
|
|
47
|
+
const time = document.createElement('time');
|
|
48
|
+
time.textContent = Number.isFinite(timestamp)
|
|
49
|
+
? 'Dernière mesure reçue · ' + new Date(timestamp).toLocaleTimeString('fr-FR')
|
|
50
|
+
: 'Horodatage indisponible';
|
|
51
|
+
card.append(heading, list, time);
|
|
52
|
+
readings.append(card);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function refresh() {
|
|
57
|
+
try {
|
|
58
|
+
const response = await fetch('/signalk/v1/api/vessels/self', {
|
|
59
|
+
cache: 'no-store',
|
|
60
|
+
signal: AbortSignal.timeout(10000)
|
|
61
|
+
});
|
|
62
|
+
if (!response.ok) throw new Error('HTTP ' + response.status);
|
|
63
|
+
const sensors = findSensors(await response.json());
|
|
64
|
+
render(sensors);
|
|
65
|
+
status.textContent = sensors.size
|
|
66
|
+
? 'Signal K connecté'
|
|
67
|
+
: 'Aucune accélération Ruuvi trouvée dans Signal K.';
|
|
68
|
+
} catch (error) {
|
|
69
|
+
status.textContent = 'Lecture Signal K indisponible. Nouvelle tentative dans 5 s.';
|
|
70
|
+
readings.replaceChildren();
|
|
71
|
+
} finally {
|
|
72
|
+
setTimeout(refresh, 5000);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
refresh();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="fr">
|
|
3
|
+
<meta charset="utf-8">
|
|
4
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
5
|
+
<title>YODA Dashboard</title>
|
|
6
|
+
<link rel="stylesheet" href="./style.css">
|
|
7
|
+
<main>
|
|
8
|
+
<h1>YODA Dashboard</h1>
|
|
9
|
+
<p>Accélérations Ruuvi · repère propre à chaque capteur</p>
|
|
10
|
+
<p id="status" role="status">Connexion à Signal K…</p>
|
|
11
|
+
<div id="sensors"></div>
|
|
12
|
+
</main>
|
|
13
|
+
<script src="./dashboard.js" defer></script>
|
|
14
|
+
</html>
|
package/public/style.css
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
:root { color-scheme: dark; font-family: system-ui, sans-serif; background: #101c27; color: #e8f4f6; }
|
|
2
|
+
main { margin: 3rem auto; width: min(94%, 56rem); }
|
|
3
|
+
#status, time { color: #adc8ce; }
|
|
4
|
+
#sensors { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 1rem; }
|
|
5
|
+
section { border: 1px solid #38515e; border-radius: 0.75rem; background: #172936; padding: 1rem; }
|
|
6
|
+
h2 { margin-top: 0; }
|
|
7
|
+
dl { display: grid; grid-template-columns: auto 1fr; gap: .55rem 1rem; font-variant-numeric: tabular-nums; }
|
|
8
|
+
dd { margin: 0; text-align: right; }
|
package/README.md
DELETED