Skip to content

Instantly share code, notes, and snippets.

@philippe86220
Created February 7, 2026 08:26
Show Gist options
  • Select an option

  • Save philippe86220/af5898f898b77dc47a2916fc9a1f2dc7 to your computer and use it in GitHub Desktop.

Select an option

Save philippe86220/af5898f898b77dc47a2916fc9a1f2dc7 to your computer and use it in GitHub Desktop.
UNO-Q mouvements température humidité lux
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>UNO Q - Capteurs</title>
<style>
body { font-family: system-ui, -apple-system, Arial, sans-serif; padding: 16px; }
.box { border: 1px solid #ddd; border-radius: 12px; padding: 12px; max-width: 560px; }
.row { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: 1px dashed #eee; }
.row:last-child { border-bottom: none; }
.k { color: #555; }
.v { font-weight: 700; }
</style>
</head>
<body>
<h2>UNO Q - Etat en temps reel</h2>
<div class="box">
<div class="row"><span class="k">Date / heure</span><span class="v" id="now">-</span></div>
<div class="row"><span class="k">Derniere presence</span><span class="v" id="presence">-</span></div>
<div class="row"><span class="k">Temperature</span><span class="v" id="temp">-</span></div>
<div class="row"><span class="k">Humidite</span><span class="v" id="hum">-</span></div>
<div class="row"><span class="k">Lumiere</span><span class="v" id="lux">-</span></div>
</div>
<script>
function fmtPresence(t, mm) {
if (!t) return "-";
if (mm === null || mm === undefined) return t;
return t + " (" + mm + " mm)";
}
async function refresh() {
try {
const r = await fetch("/api/state", { cache: "no-store" });
const s = await r.json();
document.getElementById("now").textContent = s.now || "-";
document.getElementById("presence").textContent =
fmtPresence(s.last_presence_time, s.last_presence_mm);
document.getElementById("temp").textContent =
(s.temp == null) ? "-" : (s.temp.toFixed(2) + " C");
document.getElementById("hum").textContent =
(s.hum == null) ? "-" : (s.hum.toFixed(2) + " %");
document.getElementById("lux").textContent =
(s.lux == null) ? "-" : (s.lux + " lux");
} catch (e) {
// ignore
}
}
refresh();
setInterval(refresh, 1000);
</script>
</body>
</html>
# SPDX-FileCopyrightText: Copyright (C) ARDUINO SRL (http://www.arduino.cc)
# SPDX-License-Identifier: MPL-2.0
import datetime
import threading
from zoneinfo import ZoneInfo
from arduino.app_utils import App, Bridge
from arduino.app_bricks.web_ui import WebUI
TZ_FR = ZoneInfo("Europe/Paris")
print("Python ready", flush=True)
web = WebUI() # Serves ./assets/index.html automatically
_lock = threading.Lock()
_state = {
"lux": None,
"temp": None,
"hum": None,
"last_presence_time": "",
"last_presence_mm": None,
}
def now_str():
return datetime.datetime.now(tz=TZ_FR).strftime("%Y-%m-%d %H:%M:%S")
def update_sensors(lux, temp, hum):
with _lock:
_state["lux"] = int(lux)
_state["temp"] = float(temp)
_state["hum"] = float(hum)
def presence_mm(mm):
with _lock:
_state["last_presence_time"] = now_str()
_state["last_presence_mm"] = int(mm)
return True
Bridge.provide("update_sensors", update_sensors)
Bridge.provide("presence_mm", presence_mm)
def api_state(_req=None):
with _lock:
payload = {
"now": now_str(),
"lux": _state["lux"],
"temp": _state["temp"],
"hum": _state["hum"],
"last_presence_time": _state["last_presence_time"],
"last_presence_mm": _state["last_presence_mm"],
}
return payload
# Expose JSON endpoint
web.expose_api("GET", "/api/state", api_state)
App.run() # blocks
#include <Arduino.h>
#include <Arduino_RouterBridge.h>
#include <Arduino_Modulino.h>
ModulinoLight light;
ModulinoThermo thermo;
ModulinoDistance distance;
const int SEUIL_MM = 800; // presence si < 80 cm
const unsigned long COOLDOWN_MS = 10000; // 1 notif max toutes les 10 s
unsigned long lastSendMs = 0;
void setup() {
Bridge.begin();
Monitor.begin();
Modulino.begin();
light.begin();
thermo.begin();
distance.begin();
delay(5000); // laisser Python demarrer
}
void loop() {
// 1) Capteurs periodiques (1 Hz)
static unsigned long lastSensorsMs = 0;
unsigned long now = millis();
if (now - lastSensorsMs >= 1000) {
lastSensorsMs = now;
light.update();
int lux = light.getAL();
float temp = thermo.getTemperature();
float hum = thermo.getHumidity();
Bridge.call("update_sensors", lux, temp, hum);
Monitor.print("lux="); Monitor.print(lux);
Monitor.print(" temp="); Monitor.print(temp, 2);
Monitor.print(" hum="); Monitor.println(hum, 2);
}
// 2) Detection presence via distance (20 ms)
if (distance.available()) {
int mm = (int)distance.get();
bool presence = (mm > 0 && mm < SEUIL_MM);
if (presence && (now - lastSendMs >= COOLDOWN_MS)) {
lastSendMs = now;
Bridge.call("presence_mm", mm);
Monitor.print("PRESENCE mm="); Monitor.println(mm);
}
}
delay(20);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment