Sûreté
demo-kit/ est ce qui simule l’appareil pour la démo sur la page de démarrage. L’appareil lui-même n’en a pas besoin.
demo-kit/ est ce qui simule l’appareil pour la démo sur la page de démarrage. L’appareil lui-même n’en a pas besoin.
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<meta name="color-scheme" content="light dark">
<title>Greenhouse</title>
<style>
:root {
--bg: #f3f0e6; --card: #fbf9f2; --ink: #22372a; --muted: #5f7362; --line: rgba(34,55,42,.1);
--hero1: #e9f0dc; --hero2: #d5e3cb; --halo: rgba(255,253,240,.75); --accent: #3f7d55; --soft: rgba(63,125,85,.12);
--water: #4f9fb5; --water2: #86c4d2; --warm: #cf7f55; --amber: #b9791f; --btn: #2f5d43; --btnink: #f7f5ea;
--glass: rgba(255,255,255,.55); --shadow: 0 1px 2px rgba(34,55,42,.05), 0 10px 30px -14px rgba(34,55,42,.22);
--serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Noto Serif", serif;
--sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #0f1f17; --card: #16291f; --ink: #e4eedd; --muted: #93ab98; --line: rgba(228,238,221,.1);
--hero1: #1d3a2a; --hero2: #13291d; --halo: rgba(170,225,180,.09); --accent: #8fd19e; --soft: rgba(143,209,158,.13);
--water: #62b8cc; --water2: #3d8fa6; --warm: #e59a70; --amber: #e3b05a; --btn: #a8dbb0; --btnink: #0f2418;
--glass: rgba(255,255,255,.05); --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 14px 34px -18px rgba(0,0,0,.6);
}
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.4 var(--sans); overflow-x: hidden;
-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; font-variant-numeric: tabular-nums; }
main { max-width: 820px; margin: 0 auto; display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr);
padding: calc(12px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left)); }
.col { display: grid; gap: 12px; align-content: start; min-width: 0; }
@media (min-width: 700px) { main { grid-template-columns: 1fr 1fr; gap: 14px 16px; } header, footer { grid-column: 1 / -1; } }
button, input { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.card { background: var(--card); border-radius: 26px; box-shadow: var(--shadow); border: 1px solid var(--line); min-width: 0; }
.lbl { font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
/* ---------- header ---------- */
header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 2px 4px 0; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand svg { width: 34px; height: 34px; flex: none; }
h1 { font: 600 23px/1.1 var(--serif); margin: 0; letter-spacing: -.01em; }
.brand p { margin: 1px 0 0; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { display: inline-flex; align-items: center; gap: 7px; padding: 6px 11px 6px 9px; border-radius: 99px; background: var(--soft);
font-size: 12px; font-weight: 600; white-space: nowrap; transition: background .4s; }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); position: relative; }
.pill i::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: var(--accent); animation: ping 2.4s ease-out infinite; }
.pill.off { background: rgba(185,121,31,.16); } .pill.off i, .pill.off i::after { background: var(--amber); }
.pill.wait i, .pill.wait i::after { background: var(--muted); }
@keyframes ping { 0% { transform: scale(1); opacity: .6 } 70%, 100% { transform: scale(2.6); opacity: 0 } }
/* ---------- hero ---------- */
.hero { background: linear-gradient(165deg, var(--hero1), var(--hero2)); padding: 14px 14px 16px; position: relative; overflow: hidden; transition: filter .6s; }
.off-line .hero { filter: saturate(.55); }
.hrow { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.mood { display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px 5px 9px; border-radius: 99px; background: var(--glass);
font-size: 12.5px; font-weight: 600; backdrop-filter: blur(6px); white-space: nowrap; }
.mood i { width: 8px; height: 8px; border-radius: 50%; background: var(--mc, var(--accent)); transition: background .6s; }
.ago { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scene { display: flex; align-items: flex-end; gap: 10px; margin-top: 2px; }
#plant { flex: 1; min-width: 0; height: auto; max-height: 300px; display: block; overflow: visible; }
#plant .st { fill: none; stroke: var(--stalk); stroke-width: 3.2; stroke-linecap: round; }
#plant .l0 .a { fill: var(--lb); } #plant .l0 .b { fill: var(--lb2); }
#plant .l1 .a { fill: var(--lf); } #plant .l1 .b { fill: var(--lf2); }
#plant .r { fill: none; stroke: rgba(255,255,255,.26); stroke-width: 1.1; stroke-linecap: round; }
#can { transform: translate(240px, 4px) rotate(10deg); opacity: 0; transition: transform .8s cubic-bezier(.3,1.25,.5,1), opacity .35s; }
.pour #can { transform: translate(190px, 42px) rotate(-24deg); opacity: 1; }
.drop { fill: var(--water); opacity: 0; }
.pour .drop { opacity: .9; animation: fall .85s cubic-bezier(.5,0,.9,.6) infinite both; animation-delay: calc(.55s + var(--d)); }
@keyframes fall { 0% { transform: translate(var(--x0), 58px) scale(.6); opacity: 0 } 12% { opacity: .95 }
92% { opacity: .95 } 100% { transform: translate(var(--x1), 168px) scale(1); opacity: 0 } }
.ring { fill: none; stroke: var(--water); stroke-width: 1.4; opacity: 0; transform-box: fill-box; transform-origin: center; }
.pour .ring { animation: ring 1.1s ease-out infinite; animation-delay: calc(1.2s + var(--d)); }
@keyframes ring { 0% { transform: scale(.2); opacity: .9 } 100% { transform: scale(1); opacity: 0 } }
.tank { flex: none; width: 62px; text-align: center; padding-bottom: 2px; }
.tank svg { width: 62px; height: 168px; display: block; }
.tank .gl { fill: var(--glass); stroke: var(--line); stroke-width: 1.5; }
.tank .w1 { fill: var(--water); } .tank .w2 { fill: var(--water2); opacity: .6; }
.tank.low .w1 { fill: var(--amber); } .tank.low .w2 { fill: var(--amber); opacity: .4; }
.tank .wv { animation: wave 3.2s linear infinite; } .tank .wv.s { animation-duration: 5.1s; animation-direction: reverse; }
@keyframes wave { to { transform: translateX(-64px) } }
#tw { transform: translateY(160px); transition: transform 1.4s cubic-bezier(.3,.9,.3,1); }
.tank .tk { stroke: var(--ink); opacity: .22; stroke-width: 1.5; stroke-linecap: round; }
.tank .bb { fill: #fff; opacity: 0; animation: bub 3.6s ease-in infinite; } .tank .bb.b2 { animation-delay: 1.7s; animation-duration: 4.4s; }
@keyframes bub { 0% { transform: translateY(0); opacity: 0 } 15% { opacity: .5 } 100% { transform: translateY(-60px); opacity: 0 } }
.tank b { display: block; font: 600 17px/1 var(--serif); margin-top: 7px; }
.tank span { font-size: 11px; color: var(--muted); }
.soil { display: flex; align-items: flex-end; gap: 16px; margin-top: 10px; }
.big { font: 600 46px/.95 var(--serif); letter-spacing: -.02em; margin-top: 3px; white-space: nowrap; }
.big small { font-size: 22px; margin-left: 2px; color: var(--muted); font-weight: 500; }
.meter { flex: 1; min-width: 0; padding-bottom: 5px; }
.bar { position: relative; height: 12px; border-radius: 99px; background: var(--glass); box-shadow: inset 0 0 0 1px var(--line); }
.bar i { position: absolute; inset: 0; border-radius: 99px; background: linear-gradient(90deg, var(--warm), #b9b05f 38%, var(--accent) 72%);
clip-path: inset(0 calc(100% - var(--v, 0%)) 0 0 round 99px); }
.bar u { position: absolute; top: -5px; bottom: -5px; width: 2px; margin-left: -1px; border-radius: 2px; background: var(--ink); opacity: .75;
transition: left .3s, opacity .3s; }
.bar u::after { content: ""; position: absolute; left: -4px; top: -6px; width: 10px; height: 10px; border-radius: 0 50% 50% 50%; transform: rotate(45deg) scale(.8); background: var(--water); }
.bar.noauto u { opacity: 0; }
.ends { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 7px; }
/* ---------- water button ---------- */
#water { position: relative; width: 100%; height: 60px; border-radius: 99px; background: var(--btn); color: var(--btnink); overflow: hidden;
font-weight: 650; font-size: 17px; display: flex; align-items: center; justify-content: center; gap: 10px; letter-spacing: .005em;
box-shadow: 0 12px 24px -14px var(--btn), var(--shadow); transition: transform .15s, opacity .3s, background .4s; }
#water:active { transform: scale(.975); }
#water svg { width: 22px; height: 22px; flex: none; position: relative; }
#water span { position: relative; }
#water small { position: relative; font-weight: 500; font-size: 12.5px; opacity: .8; }
#water .fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--water); opacity: 0; transition: opacity .4s; }
#water.on .fill { opacity: 1; }
#water.on svg { animation: bob .9s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(3px) } }
#water:disabled { opacity: .5; cursor: default; }
/* ---------- gauges ---------- */
.gauges { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.g { padding: 12px 6px 11px; text-align: center; border-radius: 22px; position: relative; }
.g svg { width: 100%; max-width: 92px; display: block; margin: 0 auto; }
.g .tr { fill: none; stroke: var(--line); stroke-width: 7; stroke-linecap: round; }
.g .va { fill: none; stroke: var(--c); stroke-width: 7; stroke-linecap: round; stroke-dasharray: 0 200; }
.g .ic { fill: none; stroke: var(--c); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.g b { display: block; font: 600 21px/1 var(--serif); margin-top: -38px; white-space: nowrap; }
.g b small { display: block; font: 500 11px/1 var(--sans); color: var(--muted); margin-top: 5px; }
.g > span { display: flex; align-items: center; justify-content: center; gap: 4px; font-size: 11.5px; color: var(--muted); margin-top: 9px; white-space: nowrap; }
.g > span svg { width: 13px; height: 13px; margin: 0; flex: none; }
.g.t { --c: var(--warm); } .g.h { --c: var(--water); } .g.l { --c: #d2a13c; }
/* ---------- chart ---------- */
.chart { padding: 14px 14px 10px; }
.chead { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.chead h2, .auto h2 { font: 600 16px/1.2 var(--serif); margin: 0; white-space: nowrap; }
@media (max-width: 379px) { .chips button { padding: 5px 8px; } .chips button i { display: none; } }
.chips { display: flex; gap: 2px; background: var(--soft); border-radius: 99px; padding: 3px; }
.chips button { padding: 5px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 5px;
transition: background .25s, color .25s; }
.chips button i { width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.chips button[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.csub { font-size: 12px; color: var(--muted); margin: 3px 0 4px; min-height: 17px; }
.plot { position: relative; height: 150px; touch-action: pan-y; }
.plot svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; overflow: visible; }
.plot .gr { stroke: var(--line); stroke-width: 1; } .plot text { fill: var(--muted); font-size: 10.5px; font-family: var(--sans); }
.plot .ln { fill: none; stroke: var(--sc); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.plot .ln.draw { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1s cubic-bezier(.4,0,.2,1) forwards; }
@keyframes draw { to { stroke-dashoffset: 0 } }
.plot .ar { fill: url(#cg); } .plot .ar.draw { animation: fade .9s ease-out both; } @keyframes fade { from { opacity: 0 } }
.plot .th { stroke: var(--water); stroke-width: 1.2; stroke-dasharray: 3 4; }
.plot .dot { fill: var(--sc); stroke: var(--card); stroke-width: 2; }
.plot .halo { fill: var(--sc); opacity: .25; transform-box: fill-box; transform-origin: center; animation: ping 2.4s ease-out infinite; }
.plot .cx { stroke: var(--muted); stroke-width: 1; opacity: .6; }
.tip { position: absolute; top: 0; padding: 4px 9px; border-radius: 10px; background: var(--ink); color: var(--bg); font-size: 12px; font-weight: 600;
white-space: nowrap; pointer-events: none; transform: translateX(-50%); opacity: 0; transition: opacity .15s; }
.tip small { font-weight: 400; opacity: .75; margin-left: 5px; }
/* ---------- auto ---------- */
.auto { padding: 14px 16px 16px; }
.arow { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.auto p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.sw { width: 52px; height: 31px; border-radius: 99px; background: var(--line); position: relative; flex: none; transition: background .3s; }
.sw::after { content: ""; position: absolute; left: 3px; top: 3px; width: 25px; height: 25px; border-radius: 50%; background: #fff;
box-shadow: 0 1px 4px rgba(0,0,0,.25); transition: transform .3s cubic-bezier(.3,1.4,.5,1); }
.sw[aria-checked="true"] { background: var(--accent); } .sw[aria-checked="true"]::after { transform: translateX(21px); }
.thr { margin-top: 14px; transition: opacity .3s; } .thr.dim { opacity: .4; }
.thr .arow { font-size: 13px; } .thr b { font: 600 17px/1 var(--serif); }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 30px; margin: 4px 0 0; background: none; display: block; }
input[type=range]::-webkit-slider-runnable-track { height: 8px; border-radius: 99px;
background: linear-gradient(90deg, var(--accent) var(--p, 50%), var(--line) var(--p, 50%)); }
input[type=range]::-moz-range-track { height: 8px; border-radius: 99px; background: linear-gradient(90deg, var(--accent) var(--p, 50%), var(--line) var(--p, 50%)); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; margin-top: -9px; border-radius: 50%; background: #fff;
border: 2px solid var(--accent); box-shadow: 0 2px 6px rgba(0,0,0,.2); }
input[type=range]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 2px solid var(--accent); }
footer { display: flex; justify-content: center; align-items: center; gap: 8px 18px; flex-wrap: wrap; color: var(--muted); font-size: 12px; padding: 4px 0 0; }
footer span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
footer svg { width: 16px; height: 16px; } footer rect { fill: var(--muted); opacity: .3; } footer rect.on { opacity: 1; }
#toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--ink); color: var(--bg);
padding: 9px 16px; border-radius: 99px; font-size: 13px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .3s, transform .3s; z-index: 9; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.card, #water { animation: rise .7s cubic-bezier(.2,.8,.2,1) both; }
.colB > :nth-child(1) { animation-delay: .08s } .colB > :nth-child(2) { animation-delay: .14s } .colB > :nth-child(3) { animation-delay: .2s }
@keyframes rise { from { opacity: 0; transform: translateY(10px) } }
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { animation: none !important; transition: none !important; }
.pour .drop { opacity: .9; } .plot .ln.draw { stroke-dasharray: none; }
}
</style>
</head>
<body>
<main id="app">
<header>
<div class="brand">
<svg viewBox="0 0 34 34" aria-hidden="true"><circle cx="17" cy="17" r="17" fill="var(--soft)"/>
<path d="M17 27c0-7 1-11 6-15M17 20c-1-4-4-6-8-6 0 4 3 7 8 6zM18.5 16c0-4 2.5-7 7-7.5 .5 4.5-2 7.5-7 7.5z" fill="none" stroke="var(--accent)" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>
<div><h1>Greenhouse</h1><p id="sub">Plant monitor</p></div>
</div>
<div class="pill wait" id="link" role="status"><i></i><span id="linkT">Connecting</span></div>
</header>
<div class="col colA">
<section class="card hero" id="hero" aria-label="Plant">
<div class="hrow"><div class="mood"><i id="moodI"></i><span id="mood">Waking up</span></div><div class="ago" id="ago"></div></div>
<div class="scene">
<svg id="plant" viewBox="14 18 232 232" role="img" aria-label="A plant in a pot. Its leaves droop when the soil is dry.">
<defs>
<linearGradient id="potG" x1="0" x2="1"><stop offset="0" stop-color="#e6a17c"/><stop offset=".55" stop-color="#d98a63"/><stop offset="1" stop-color="#bd7450"/></linearGradient>
<linearGradient id="canG" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#a9cfd9"/><stop offset="1" stop-color="#6fa5b6"/></linearGradient>
</defs>
<circle id="sun" cx="130" cy="120" r="98" fill="var(--halo)"/>
<ellipse cx="130" cy="240" rx="56" ry="6" fill="rgba(0,0,0,.13)"/>
<path d="M87 184h86l-9 47q-1.5 9-11 9h-46q-9.5 0-11-9z" fill="url(#potG)"/>
<path d="M87 184h86l-1.6 9H88.6z" fill="rgba(0,0,0,.12)"/>
<rect x="78" y="166" width="104" height="20" rx="8" fill="#e6a17c"/>
<ellipse cx="130" cy="171" rx="46" ry="5.5" fill="#9a5d42"/>
<ellipse id="soilE" cx="130" cy="172" rx="43" ry="4.5" fill="var(--soilc, #7a5a41)"/>
<g id="lv0" class="l0"></g>
<g id="lv1" class="l1"></g>
<g id="rings"><ellipse class="ring" style="--d:0s" cx="124" cy="172" rx="11" ry="2.5"/><ellipse class="ring" style="--d:.5s" cx="138" cy="172" rx="9" ry="2"/></g>
<g id="drops"></g>
<g id="can"><path d="M-19 1-49-17l-5 7 35 23z" fill="#7fb0bf"/><ellipse cx="-52" cy="-13" rx="4" ry="8.5" transform="rotate(-58 -52 -13)" fill="#5f97a9"/>
<path d="M21-9c20-3 20 22 0 18" fill="none" stroke="#6fa5b6" stroke-width="5" stroke-linecap="round"/>
<rect x="-22" y="-17" width="44" height="35" rx="9" fill="url(#canG)"/><ellipse cx="0" cy="-15" rx="17" ry="3.5" fill="#5f97a9"/></g>
</svg>
<div class="tank" id="tank">
<svg viewBox="0 0 64 172" role="img" aria-label="Water tank">
<defs><clipPath id="tc"><rect x="6" y="6" width="52" height="160" rx="20"/></clipPath></defs>
<rect class="gl" x="3" y="3" width="58" height="166" rx="23"/>
<g clip-path="url(#tc)"><g id="tw">
<path class="wv s w2" d="M-10 5q16-7 32 0t32 0 32 0 32 0 32 0v190h-160z"/>
<path class="wv w1" d="M0 7q16-6 32 0t32 0 32 0 32 0v190h-128z"/>
<circle class="bb" cx="22" cy="90" r="2.5"/><circle class="bb b2" cx="42" cy="110" r="1.8"/>
</g></g>
<path class="tk" d="M47 46h6M49 86h4M47 126h6"/>
<path d="M14 30q0-12 10-16" fill="none" stroke="#fff" stroke-width="3" stroke-linecap="round" opacity=".35"/>
</svg>
<b id="tankV">–</b><span id="tankL">Tank</span>
</div>
</div>
<div class="soil">
<div><div class="lbl">Soil moisture</div><div class="big"><span id="soilV">–</span><small>%</small></div></div>
<div class="meter"><div class="bar noauto" id="bar"><i id="barF"></i><u id="barT"></u></div><div class="ends"><span>Dry</span><span id="barL"></span><span>Wet</span></div></div>
</div>
</section>
<button id="water" type="button" disabled>
<i class="fill" id="wFill"></i>
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 2.5s6.5 7 6.5 12a6.5 6.5 0 0 1-13 0c0-5 6.5-12 6.5-12z" fill="currentColor"/><path d="M8.8 15a3.3 3.3 0 0 0 2.7 3.2" fill="none" stroke="var(--btn)" stroke-width="1.6" stroke-linecap="round" opacity=".7"/></svg>
<span id="wT">Water now</span><small id="wS"></small>
</button>
</div>
<div class="col colB">
<section class="gauges" aria-label="Air and light">
<div class="card g t"><svg viewBox="0 0 80 64" aria-hidden="true"><path class="tr" d="M14 57A30 30 0 1 1 66 57"/><path class="va" id="gT" pathLength="100" d="M14 57A30 30 0 1 1 66 57"/></svg><b><span id="tV">–</span><small>°C</small></b><span><svg viewBox="0 0 16 16" aria-hidden="true"><path class="ic" d="M6.5 3a1.5 1.5 0 0 1 3 0v6.2a3 3 0 1 1-3 0zM8 6v5"/></svg>Temperature</span></div>
<div class="card g h"><svg viewBox="0 0 80 64" aria-hidden="true"><path class="tr" d="M14 57A30 30 0 1 1 66 57"/><path class="va" id="gH" pathLength="100" d="M14 57A30 30 0 1 1 66 57"/></svg><b><span id="hV">–</span><small>%</small></b><span><svg viewBox="0 0 16 16" aria-hidden="true"><path class="ic" d="M8 1.8s4.2 4.6 4.2 7.9a4.2 4.2 0 0 1-8.4 0C3.8 6.4 8 1.8 8 1.8z"/></svg>Humidity</span></div>
<div class="card g l"><svg viewBox="0 0 80 64" aria-hidden="true"><path class="tr" d="M14 57A30 30 0 1 1 66 57"/><path class="va" id="gL" pathLength="100" d="M14 57A30 30 0 1 1 66 57"/></svg><b><span id="lV">–</span><small id="lU">lx</small></b><span><svg viewBox="0 0 16 16" aria-hidden="true"><path class="ic" d="M8 5.2a2.8 2.8 0 1 0 .01 0M8 1v1.3M8 13.7V15M1 8h1.3M13.7 8H15M3 3l1 1M12 12l1 1M3 13l1-1M12 4l1-1"/></svg><span id="lW">Light</span></span></div>
</section>
<section class="card chart" aria-label="Last 24 hours">
<div class="chead"><h2>Last 24 hours</h2>
<div class="chips" role="tablist">
<button role="tab" data-k="soil" aria-selected="true" style="--c:var(--accent)"><i></i>Soil</button>
<button role="tab" data-k="temperature" aria-selected="false" style="--c:var(--warm)"><i></i>Temp</button>
<button role="tab" data-k="humidity" aria-selected="false" style="--c:var(--water)"><i></i>Humidity</button>
</div></div>
<div class="csub" id="cSub"></div>
<div class="plot" id="plot"><svg id="cv" aria-hidden="true"></svg><div class="tip" id="tip"></div></div>
</section>
<section class="card auto" aria-label="Automatic watering">
<div class="arow"><div><h2>Auto-watering</h2><p id="aT">Waters by itself when the soil gets dry.</p></div>
<button class="sw" id="auto" role="switch" aria-checked="false" aria-label="Auto-watering"></button></div>
<div class="thr dim" id="thr"><div class="arow"><label for="th">Water when soil drops below</label><b id="thV">–</b></div>
<input id="th" type="range" min="10" max="80" step="1" value="35"></div>
</section>
</div>
<footer>
<span><svg viewBox="0 0 16 16" aria-hidden="true"><rect x="1" y="11" width="2.5" height="4" rx="1"/><rect x="5" y="8" width="2.5" height="7" rx="1"/><rect x="9" y="5" width="2.5" height="10" rx="1"/><rect x="13" y="2" width="2.5" height="13" rx="1"/></svg><span id="rssi">Wi-Fi</span></span>
<span id="up"></span>
</footer>
</main>
<div id="toast" role="alert"></div>
<script>
(function () {
'use strict';
var $ = function (id) { return document.getElementById(id); };
var NS = 'http://www.w3.org/2000/svg';
var RM = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
var WATER_SECONDS = 8;
var clamp = function (v, a, b) { return Math.max(a, Math.min(b, v)); };
var num = function (v) { return typeof v === 'number' && isFinite(v); };
function el(name, attrs, parent) {
var e = document.createElementNS(NS, name);
for (var k in attrs) e.setAttribute(k, attrs[k]);
if (parent) parent.appendChild(e);
return e;
}
function mix(a, b, t) { return 'rgb(' + a.map(function (v, i) { return Math.round(v + (b[i] - v) * t); }).join(',') + ')'; }
// ---------- the device ----------
function api(path, body) {
var init = body ? { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) } : undefined;
var late = new Promise(function (_, reject) { setTimeout(function () { reject(new Error('No answer')); }, 7000); });
return Promise.race([fetch(path, init), late]).then(function (r) {
return r.text().then(function (text) {
var data = null;
try { data = JSON.parse(text); } catch (e) { /* not JSON */ }
if (!r.ok || data === null) { var err = new Error((data && data.error) || 'The device answered ' + r.status); err.status = r.status; throw err; }
return data;
});
});
}
// ---------- values that glide to their target ----------
var tweens = {};
function tween(key, target, show) {
var t = tweens[key] || (tweens[key] = { cur: null, to: null, show: show });
t.to = num(target) ? target : null;
if (t.cur === null || t.to === null || RM) { t.cur = t.to; t.show(t.cur); }
}
function stepTweens(dt) {
for (var k in tweens) {
var t = tweens[k];
if (t.cur === null || t.to === null || t.cur === t.to) continue;
t.cur += (t.to - t.cur) * Math.min(1, dt * 3.2);
if (Math.abs(t.to - t.cur) < 0.02) t.cur = t.to;
t.show(t.cur);
}
}
function text(node, value) { if (node.textContent !== value) node.textContent = value; }
function arc(node, share) { node.style.strokeDasharray = (clamp(share, 0, 1) * 100).toFixed(1) + ' 200'; }
// ---------- the plant ----------
// angle from upright, stalk length, size, layer (0 behind, 1 in front)
var LEAVES = [[-52, 80, 1, 0], [50, 84, 1.02, 0], [-22, 104, .96, 0], [24, 100, .98, 0], [-78, 58, .84, 1], [76, 60, .86, 1], [-38, 68, .92, 1], [40, 66, .9, 1], [2, 86, 1.12, 1]];
var plant = $('plant');
var parts = LEAVES.map(function (leaf) {
var layer = $('lv' + leaf[3]);
var stalk = el('path', { 'class': 'st' }, layer);
var g = el('g', {}, layer);
el('path', { 'class': 'a', d: 'M0 0C-17-8-20-31 0-47 20-31 17-8 0 0z' }, g);
el('path', { 'class': 'b', d: 'M0 0C17-8 20-31 0-47z' }, g);
el('path', { 'class': 'r', d: 'M0-4V-39' }, g);
return { stalk: stalk, g: g };
});
for (var d = 0; d < 6; d++) {
var drop = el('path', { 'class': 'drop', d: 'M0-5C2.5-1.5 3.5 .5 3.5 2.2a3.5 3.5 0 0 1-7 0C-3.5 .5-2.5-1.5 0-5z' }, $('drops'));
drop.setAttribute('style', '--d:' + (d * .14).toFixed(2) + 's;--x0:' + (133 + (d % 3) * 2) + 'px;--x1:' + (118 + d * 5) + 'px;transform:translate(' + (131 - d) + 'px,' + (66 + d * 18) + 'px)');
}
var wilt = null, wiltTo = 0, pour = 0, lastWiltDrawn = -1;
function drawPlant(t, dt) {
if (wilt === null || RM) wilt = wiltTo; else wilt += (wiltTo - wilt) * Math.min(1, dt * 1.1);
pour += ((state && state.pump ? 1 : 0) - pour) * Math.min(1, dt * 3);
var w = wilt;
for (var i = 0; i < LEAVES.length; i++) {
var a0 = LEAVES[i][0], len = LEAVES[i][1], size = LEAVES[i][2], sign = a0 < 0 ? -1 : 1;
var sway = RM ? 0 : (Math.sin(t * .9 + i * 1.7) * 2 + Math.sin(t * .41 + i) * 1.3 + pour * Math.sin(t * 9 + i * 2) * 1.6) * (1 - .55 * w);
var angle = a0 * (1 + .42 * w) + sign * w * (Math.abs(a0) < 30 ? 36 : 14) + sway;
var length = len * (1 - .1 * w), rad = angle * Math.PI / 180;
var bx = 130 + a0 * .13, by = 172;
var tx = bx + length * Math.sin(rad), ty = by - length * Math.cos(rad);
parts[i].stalk.setAttribute('d', 'M' + bx.toFixed(1) + ' ' + by + 'Q' + (bx + a0 * .1).toFixed(1) + ' ' + (by - length * (.64 - .14 * w)).toFixed(1) + ' ' + tx.toFixed(1) + ' ' + ty.toFixed(1));
parts[i].g.setAttribute('transform', 'translate(' + tx.toFixed(1) + ' ' + ty.toFixed(1) + ') rotate(' + (angle + sign * (14 + w * 62) + sway * .7).toFixed(1) +
') scale(' + (size * (1 - .16 * w)).toFixed(3) + ' ' + (size * (1 - .06 * w)).toFixed(3) + ')');
}
if (Math.abs(w - lastWiltDrawn) > .004) {
lastWiltDrawn = w;
var c = Math.pow(w, 1.2);
plant.style.setProperty('--lf', mix([84, 168, 104], [178, 164, 92], c));
plant.style.setProperty('--lf2', mix([118, 196, 132], [201, 186, 112], c));
plant.style.setProperty('--lb', mix([58, 133, 82], [150, 140, 80], c));
plant.style.setProperty('--lb2', mix([76, 152, 98], [168, 157, 92], c));
plant.style.setProperty('--stalk', mix([62, 128, 80], [140, 135, 82], c));
}
}
// ---------- what the state looks like ----------
var state = null, history = null, series = 'soil', editingUntil = 0, pumpTotal = 0, pumpEnds = 0, busy = false;
var MOODS = [[62, 'Thriving', '#4fa565'], [48, 'Doing well', '#6fae5c'], [33, 'A little thirsty', '#c9a23c'], [-1, 'Very thirsty', '#cf7f55']];
function ago(seconds) {
if (seconds < 90) return 'just now';
if (seconds < 3600) return Math.round(seconds / 60) + ' min ago';
if (seconds < 172800) return Math.round(seconds / 3600) + ' h ago';
return Math.round(seconds / 86400) + ' d ago';
}
function span(seconds) {
var dd = Math.floor(seconds / 86400), h = Math.floor(seconds % 86400 / 3600), m = Math.floor(seconds % 3600 / 60);
return dd > 0 ? dd + ' d ' + h + ' h' : h > 0 ? h + ' h ' + m + ' min' : m + ' min';
}
function showThreshold(value, auto) {
$('bar').classList.toggle('noauto', !auto);
$('barT').style.left = value + '%';
text($('barL'), auto ? 'waters below ' + value + '%' : '');
text($('thV'), value + '%');
$('th').style.setProperty('--p', ((value - 10) / 70 * 100).toFixed(1) + '%');
$('thr').classList.toggle('dim', !auto);
text($('aT'), auto ? 'Waters by itself when the soil gets dry.' : 'Off. The plant waits for you.');
}
function apply(s) {
var wasPumping = state && state.pump;
state = s;
tween('soil', s.soil, function (v) {
text($('soilV'), v === null ? '–' : String(Math.round(v)));
$('barF').style.setProperty('--v', (v === null ? 0 : clamp(v, 4, 100)).toFixed(1) + '%');
if (v !== null) plant.style.setProperty('--soilc', mix([176, 143, 108], [70, 49, 36], clamp((v - 15) / 60, 0, 1)));
});
tween('tank', s.tank, function (v) {
text($('tankV'), v === null ? '–' : Math.round(v) + '%');
});
tween('t', s.temperature, function (v) { text($('tV'), v === null ? '–' : v.toFixed(1)); arc($('gT'), v === null ? 0 : v / 40); });
tween('h', s.humidity, function (v) { text($('hV'), v === null ? '–' : String(Math.round(v))); arc($('gH'), v === null ? 0 : v / 100); });
tween('l', s.light, function (v) {
text($('lV'), v === null ? '–' : v >= 1000 ? (v / 1000).toFixed(1) : String(Math.round(v)));
text($('lU'), v !== null && v >= 1000 ? 'klx' : 'lx');
arc($('gL'), v === null ? 0 : Math.log(v + 1) / Math.log(100000));
});
if (num(s.tank)) $('tw').style.transform = 'translateY(' + (160 - clamp(s.tank, 0, 100) * 1.5).toFixed(1) + 'px)';
var low = num(s.tank) && s.tank < 15, empty = num(s.tank) && s.tank < 5;
$('tank').classList.toggle('low', low);
text($('tankL'), empty ? 'Tank empty' : low ? 'Refill soon' : 'Tank');
if (num(s.light)) {
text($('lW'), s.light < 50 ? 'Dark' : s.light < 1500 ? 'Dim light' : s.light < 12000 ? 'Soft light' : s.light < 40000 ? 'Bright' : 'Full sun');
$('sun').style.opacity = (.35 + .65 * clamp(Math.log(s.light + 1) / Math.log(40000), 0, 1)).toFixed(2);
}
if (num(s.soil)) wiltTo = Math.pow(clamp((70 - s.soil) / 52, 0, 1), 1.2);
var mood = MOODS[3];
for (var i = MOODS.length - 1; i >= 0; i--) if (num(s.soil) && s.soil >= MOODS[i][0]) mood = MOODS[i];
text($('mood'), s.pump ? 'Drinking' : num(s.soil) ? mood[1] : 'No soil reading');
$('moodI').style.setProperty('--mc', s.pump ? 'var(--water)' : mood[2]);
text($('ago'), s.pump ? 'Watering now' : num(s.lastWateredSecondsAgo) ? 'Watered ' + ago(s.lastWateredSecondsAgo) : 'Not watered since restart');
$('hero').classList.toggle('pour', s.pump === true);
var left = num(s.pumpSecondsLeft) ? s.pumpSecondsLeft : 0;
if (s.pump) {
if (!wasPumping || left > pumpTotal) pumpTotal = Math.max(left, 1);
pumpEnds = performance.now() + left * 1000;
} else pumpTotal = 0;
if (wasPumping && !s.pump) setTimeout(loadHistory, 2500);
drawButton();
if (Date.now() > editingUntil) {
$('auto').setAttribute('aria-checked', s.auto ? 'true' : 'false');
if (num(s.threshold)) { $('th').value = String(Math.round(s.threshold)); showThreshold(Math.round(s.threshold), s.auto === true); }
}
var bars = !num(s.rssi) ? 0 : s.rssi >= -55 ? 4 : s.rssi >= -67 ? 3 : s.rssi >= -78 ? 2 : 1;
Array.prototype.forEach.call(document.querySelectorAll('footer rect'), function (r, n) { r.setAttribute('class', n < bars ? 'on' : ''); });
text($('rssi'), num(s.rssi) ? 'Wi-Fi ' + Math.round(s.rssi) + ' dBm' : 'Wi-Fi');
text($('up'), num(s.uptimeSeconds) ? 'Running for ' + span(s.uptimeSeconds) : '');
if (RM) drawPlant(0, 1);
}
function drawButton() {
var b = $('water'), s = state;
if (!s) return;
var empty = num(s.tank) && s.tank < 5;
b.classList.toggle('on', s.pump === true);
b.disabled = busy || (!s.pump && empty);
if (s.pump) {
var left = Math.max(0, (pumpEnds - performance.now()) / 1000);
$('wFill').style.width = (clamp(1 - left / pumpTotal, 0, 1) * 100).toFixed(1) + '%';
text($('wT'), 'Watering');
text($('wS'), Math.ceil(left) + ' s · tap to stop');
} else {
$('wFill').style.width = '0';
text($('wT'), empty ? 'The tank is empty' : 'Water now');
text($('wS'), '');
}
}
var toastTimer = 0;
function toast(message) {
var t = $('toast');
t.textContent = message;
t.classList.add('show');
clearTimeout(toastTimer);
toastTimer = setTimeout(function () { t.classList.remove('show'); }, 3200);
}
function online(ok) {
$('link').className = 'pill' + (ok ? '' : ' off');
text($('linkT'), ok ? 'Live' : 'Offline, retrying');
$('app').classList.toggle('off-line', !ok);
}
// ---------- the chart: one measure at a time, so there is one axis ----------
var UNITS = { soil: '%', temperature: '°C', humidity: '%' };
var COLORS = { soil: 'var(--accent)', temperature: 'var(--warm)', humidity: 'var(--water)' };
var NAMES = { soil: 'Soil moisture', temperature: 'Temperature', humidity: 'Humidity' };
var chart = null;
function smooth(points) {
// A monotone curve: it never swings past a sample, however sharp the jump after a watering.
var n = points.length, d = 'M' + points[0][0].toFixed(1) + ' ' + points[0][1].toFixed(1), slope = [], m = [], i;
if (n < 3) return d + points.slice(1).map(function (p) { return 'L' + p[0].toFixed(1) + ' ' + p[1].toFixed(1); }).join('');
for (i = 0; i < n - 1; i++) slope.push((points[i + 1][1] - points[i][1]) / (points[i + 1][0] - points[i][0]));
m.push(slope[0]);
for (i = 1; i < n - 1; i++) m.push(slope[i - 1] * slope[i] <= 0 ? 0 : 2 * slope[i - 1] * slope[i] / (slope[i - 1] + slope[i]));
m.push(slope[n - 2]);
for (i = 0; i < n - 1; i++) {
var h = (points[i + 1][0] - points[i][0]) / 3;
d += 'C' + (points[i][0] + h).toFixed(1) + ' ' + (points[i][1] + m[i] * h).toFixed(1) + ' ' + (points[i + 1][0] - h).toFixed(1) + ' ' +
(points[i + 1][1] - m[i + 1] * h).toFixed(1) + ' ' + points[i + 1][0].toFixed(1) + ' ' + points[i + 1][1].toFixed(1);
}
return d;
}
function drawChart(animate) {
var svg = $('cv'), box = $('plot');
while (svg.firstChild) svg.removeChild(svg.firstChild);
chart = null;
var values = history && Array.isArray(history[series]) ? history[series].filter(num) : [];
if (values.length < 2) { text($('cSub'), history ? 'Collecting the first readings' : ''); return; }
var W = box.clientWidth || 320, H = box.clientHeight || 150, L = 28, R = 8, T = 10, B = 20;
svg.setAttribute('viewBox', '0 0 ' + W + ' ' + H);
svg.style.setProperty('--sc', COLORS[series]);
var min = Math.min.apply(null, values), max = Math.max.apply(null, values), lo, hi;
if (series === 'temperature') { lo = Math.floor((min - 1) / 2) * 2; hi = Math.ceil((max + 1) / 2) * 2; }
else { lo = Math.max(0, Math.floor((min - 8) / 10) * 10); hi = Math.min(100, Math.ceil((max + 8) / 10) * 10); }
if (hi - lo < 4) hi = lo + 4;
var step = history.intervalSeconds > 0 ? history.intervalSeconds : 900, n = values.length, slots = Math.max(n - 1, Math.round(86400 / step) - 1);
var x = function (i) { return L + (W - L - R) * (slots - (n - 1 - i)) / slots; };
var y = function (v) { return T + (H - T - B) * (1 - (v - lo) / (hi - lo)); };
var defs = el('defs', {}, svg), grad = el('linearGradient', { id: 'cg', x1: 0, y1: 0, x2: 0, y2: 1 }, defs);
el('stop', { offset: 0, 'stop-color': COLORS[series], 'stop-opacity': .32 }, grad);
el('stop', { offset: 1, 'stop-color': COLORS[series], 'stop-opacity': 0 }, grad);
for (var g = 0; g <= 2; g++) {
var gv = lo + (hi - lo) * g / 2, gy = y(gv);
el('path', { 'class': 'gr', d: 'M' + L + ' ' + gy + 'H' + (W - R) }, svg);
el('text', { x: L - 6, y: gy + 3.5, 'text-anchor': 'end' }, svg).textContent = String(Math.round(gv));
}
[[24, 'start'], [18, 'middle'], [12, 'middle'], [6, 'middle'], [0, 'end']].forEach(function (tick) {
el('text', { x: L + (W - L - R) * (1 - tick[0] / 24), y: H - 4, 'text-anchor': tick[1] }, svg).textContent = tick[0] === 0 ? 'now' : '−' + tick[0] + ' h';
});
var points = values.map(function (v, i) { return [x(i), y(v)]; });
var line = smooth(points);
el('path', { 'class': 'ar' + (animate ? ' draw' : ''), d: line + 'V' + (H - B) + 'H' + points[0][0].toFixed(1) + 'z' }, svg);
if (series === 'soil' && state && state.auto && num(state.threshold) && state.threshold > lo && state.threshold < hi) {
el('path', { 'class': 'th', d: 'M' + L + ' ' + y(state.threshold).toFixed(1) + 'H' + (W - R) }, svg);
}
el('path', { 'class': 'ln' + (animate ? ' draw' : ''), d: line, pathLength: 1 }, svg);
var end = points[n - 1];
el('circle', { 'class': 'halo', cx: end[0], cy: end[1], r: 5 }, svg);
el('circle', { 'class': 'dot', cx: end[0], cy: end[1], r: 4 }, svg);
var cross = el('g', { style: 'display:none' }, svg);
el('path', { 'class': 'cx', d: 'M0 ' + T + 'V' + (H - B) }, cross);
el('circle', { 'class': 'dot', r: 4.5 }, cross);
var digits = series === 'temperature' ? 1 : 0;
text($('cSub'), NAMES[series] + ' · low ' + min.toFixed(digits) + ' ' + UNITS[series] + ' · high ' + max.toFixed(digits) + ' ' + UNITS[series]);
chart = { points: points, values: values, cross: cross, step: step, digits: digits, W: W };
}
function probe(event) {
if (!chart) return;
var rect = $('plot').getBoundingClientRect(), px = (event.clientX - rect.left) * chart.W / rect.width, best = 0;
chart.points.forEach(function (p, i) { if (Math.abs(p[0] - px) < Math.abs(chart.points[best][0] - px)) best = i; });
var p = chart.points[best], back = (chart.points.length - 1 - best) * chart.step, tip = $('tip');
chart.cross.style.display = '';
chart.cross.setAttribute('transform', 'translate(' + p[0].toFixed(1) + ' 0)');
chart.cross.lastChild.setAttribute('cy', p[1].toFixed(1));
tip.textContent = chart.values[best].toFixed(chart.digits) + ' ' + UNITS[series];
var when = document.createElement('small');
when.textContent = back < 450 ? 'now' : back < 3600 ? Math.round(back / 60) + ' min ago' : (back / 3600).toFixed(back % 3600 ? 1 : 0) + ' h ago';
tip.appendChild(when);
tip.style.left = clamp(p[0] * rect.width / chart.W, 50, rect.width - 50) + 'px';
tip.style.top = (p[1] > 46 ? p[1] - 36 : p[1] + 14) + 'px';
tip.style.opacity = '1';
}
function unprobe() { if (chart) chart.cross.style.display = 'none'; $('tip').style.opacity = '0'; }
$('plot').addEventListener('pointermove', probe);
$('plot').addEventListener('pointerdown', probe);
['pointerleave', 'pointerup', 'pointercancel'].forEach(function (name) { $('plot').addEventListener(name, unprobe); });
Array.prototype.forEach.call(document.querySelectorAll('.chips button'), function (chip) {
chip.addEventListener('click', function () {
series = chip.getAttribute('data-k');
Array.prototype.forEach.call(document.querySelectorAll('.chips button'), function (other) { other.setAttribute('aria-selected', other === chip ? 'true' : 'false'); });
unprobe();
drawChart(true);
});
});
var resizeTimer = 0;
window.addEventListener('resize', function () { clearTimeout(resizeTimer); resizeTimer = setTimeout(function () { drawChart(false); }, 150); });
// ---------- controls ----------
$('water').addEventListener('click', function () {
if (!state || busy) return;
busy = true;
drawButton();
api('/pump', state.pump ? { on: false } : { seconds: WATER_SECONDS })
.then(apply, function (error) { toast(error.message); })
.then(function () { busy = false; drawButton(); });
});
function sendConfig() {
editingUntil = Date.now() + 2500;
api('/config', { auto: $('auto').getAttribute('aria-checked') === 'true', threshold: Number($('th').value) })
.then(function (s) { editingUntil = 0; apply(s); drawChart(false); }, function (error) { editingUntil = 0; toast(error.message); });
}
$('auto').addEventListener('click', function () {
var on = this.getAttribute('aria-checked') !== 'true';
this.setAttribute('aria-checked', on ? 'true' : 'false');
showThreshold(Number($('th').value), on);
sendConfig();
});
var configTimer = 0;
$('th').addEventListener('input', function () {
editingUntil = Date.now() + 2500;
showThreshold(Number(this.value), $('auto').getAttribute('aria-checked') === 'true');
clearTimeout(configTimer);
configTimer = setTimeout(sendConfig, 450);
});
// ---------- the bar of the app follows the page between light and dark ----------
var dark = window.matchMedia('(prefers-color-scheme: dark)');
function theme() {
var bridge = window.connectivitizer;
if (bridge && typeof bridge.setTheme === 'function') bridge.setTheme(dark.matches ? null : { background: '#f3f0e6', foreground: '#22372a' });
}
if (dark.addEventListener) dark.addEventListener('change', theme);
theme();
// ---------- running ----------
function loadHistory() {
api('/history').then(function (h) { var first = !history; history = h; drawChart(first); }, function () { /* the next round asks again */ });
}
function poll() {
api('/state').then(function (s) { online(true); apply(s); if (!history) loadHistory(); }, function () { online(false); })
.then(function () { setTimeout(poll, 1000); });
}
var before = 0;
function frame(now) {
var dt = Math.min(.1, (now - before) / 1000 || 0);
before = now;
stepTweens(dt);
drawPlant(now / 1000, dt);
if (state && state.pump) drawButton();
requestAnimationFrame(frame);
}
drawPlant(0, 1);
if (!RM) requestAnimationFrame(frame);
poll();
setInterval(loadHistory, 60000);
})();
</script>
</body>
</html>