influxdb
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| influxdb [2025/11/15 20:41] – [Zaehlerständeim Haus] lars | influxdb [2025/11/15 23:12] (current) – [Zaehlerständeim Haus] lars | ||
|---|---|---|---|
| Line 111: | Line 111: | ||
| Diverse Besonderheiten werden darin bearbeitet wie etwa die Umrechnung der eingelesenen Gaszaehlerwerte in m³ in kWh (x9,76608) oder der Austausch des Wasserzaehlers am 27.05.2021. | Diverse Besonderheiten werden darin bearbeitet wie etwa die Umrechnung der eingelesenen Gaszaehlerwerte in m³ in kWh (x9,76608) oder der Austausch des Wasserzaehlers am 27.05.2021. | ||
| + | Die Übertragung von ECAS nach InfluxDB hat am 15.11.2025 stattgefunden. | ||
| + | === Eingabe via Webseite === | ||
| + | |||
| + | Mit ChatGPT und einiger eigener Arbeit ist diese PHP-Seite herausgekommen, | ||
| + | Damit kann ich neue Werte aufnehmen. | ||
| + | <code php> | ||
| + | <?php | ||
| + | ?> | ||
| + | < | ||
| + | <html lang=" | ||
| + | < | ||
| + | <meta charset=" | ||
| + | < | ||
| + | < | ||
| + | body { font-family: | ||
| + | h1 { text-align: center; } | ||
| + | form { max-width: 420px; margin: auto; background: white; padding: 2rem; border-radius: | ||
| + | input, select, button { padding: 0.7rem; font-size: 1rem; border: 1px solid #ccc; border-radius: | ||
| + | button { background: #007bff; border: none; color: white; cursor: pointer; transition: background 0.2s; } | ||
| + | button: | ||
| + | .info { text-align: center; color: #555; margin-bottom: | ||
| + | .success { color: green; text-align: center; } | ||
| + | .error { color: red; text-align: center; } | ||
| + | </ | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | <?php | ||
| + | // --- CONFIG --- | ||
| + | $influx_url = " | ||
| + | $org = " | ||
| + | $bucket = " | ||
| + | $token = " | ||
| + | |||
| + | function query_influx_selected() { | ||
| + | global $influx_url, | ||
| + | $zaehler_list = [' | ||
| + | $results = []; | ||
| + | |||
| + | foreach ($zaehler_list as $z) { | ||
| + | $flux = <<< | ||
| + | from(bucket: | ||
| + | |> range(start: | ||
| + | |> filter(fn: (r) => r._measurement == " | ||
| + | |> filter(fn: (r) => r[" | ||
| + | FLUX; | ||
| + | |||
| + | // Gas: nur Einträge ohne Einheit kWh | ||
| + | if ($z === ' | ||
| + | $flux .= " | ||
| + | } | ||
| + | |||
| + | $flux .= " | ||
| + | $flux .= " | ||
| + | $flux .= " | ||
| + | |||
| + | $curl = curl_init(); | ||
| + | curl_setopt_array($curl, | ||
| + | CURLOPT_URL => " | ||
| + | CURLOPT_RETURNTRANSFER => true, | ||
| + | CURLOPT_POST => true, | ||
| + | CURLOPT_HTTPHEADER => [ | ||
| + | " | ||
| + | " | ||
| + | ], | ||
| + | CURLOPT_POSTFIELDS => $flux | ||
| + | ]); | ||
| + | /* | ||
| + | print "< | ||
| + | | ||
| + | print " ?> -->"; | ||
| + | print PHP_EOL; | ||
| + | */ | ||
| + | |||
| + | $resp = curl_exec($curl); | ||
| + | curl_close($curl); | ||
| + | |||
| + | $results[$z] = null; | ||
| + | $lines = explode(" | ||
| + | foreach ($lines as $line) { | ||
| + | /* | ||
| + | print "< | ||
| + | print $line; | ||
| + | print " ?> -->"; | ||
| + | print PHP_EOL; | ||
| + | */ | ||
| + | if (strpos($line, | ||
| + | $parts = str_getcsv($line, | ||
| + | /* | ||
| + | print "< | ||
| + | print count($parts); | ||
| + | print implode(" | ||
| + | print " ?> -->"; | ||
| + | print PHP_EOL; | ||
| + | */ | ||
| + | if (count($parts) < 6) continue; | ||
| + | /* | ||
| + | print "< | ||
| + | print " | ||
| + | print "time: $parts[3] "; | ||
| + | print " ?> -->"; | ||
| + | print PHP_EOL; | ||
| + | */ | ||
| + | $value = $parts[4] ?? null; | ||
| + | $time = $parts[3] ?? null; | ||
| + | if ($value !== null) { | ||
| + | $results[$z] = [' | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | return $results; | ||
| + | } | ||
| + | |||
| + | $latest_selected = query_influx_selected(); | ||
| + | ?> | ||
| + | <!-- Letzte Werte aus InfluxDB --> | ||
| + | <?php foreach ($latest_selected as $k => $v): ?> | ||
| + | <!-- <?= $k ?>: <?= $v ? $v[' | ||
| + | <?php endforeach; ?> | ||
| + | <div class=" | ||
| + | <form method=" | ||
| + | < | ||
| + | <select name=" | ||
| + | <option value=" | ||
| + | <option value=" | ||
| + | <option value=" | ||
| + | </ | ||
| + | </ | ||
| + | < | ||
| + | <input type=" | ||
| + | </ | ||
| + | < | ||
| + | <input type=" | ||
| + | </ | ||
| + | < | ||
| + | <input type=" | ||
| + | </ | ||
| + | <button type=" | ||
| + | </ | ||
| + | < | ||
| + | const latestAll = <?= json_encode($latest_selected) ?>; | ||
| + | const latestInfo = document.getElementById(' | ||
| + | const zaehlerSelect = document.getElementById(' | ||
| + | function updateLatest() { | ||
| + | const selected = zaehlerSelect.value; | ||
| + | const data = latestAll[selected]; | ||
| + | if (data) { | ||
| + | latestInfo.textContent = `Letzter Wert: ${data.value} — Datum: ${data.time}`; | ||
| + | } else { | ||
| + | latestInfo.textContent = 'Keine Daten vorhanden.'; | ||
| + | } | ||
| + | } | ||
| + | zaehlerSelect.addEventListener(' | ||
| + | updateLatest(); | ||
| + | </ | ||
| + | <?php | ||
| + | if ($_SERVER[' | ||
| + | $z = $_POST[' | ||
| + | $zeit = $_POST[' | ||
| + | $wert = $_POST[' | ||
| + | $bem = trim($_POST[' | ||
| + | $ts = strtotime($zeit) * 1000000000; | ||
| + | |||
| + | $lines_to_write = []; | ||
| + | |||
| + | // Gas: m³ mit tag " | ||
| + | if ($z === ' | ||
| + | $lines_to_write[] = " | ||
| + | $kwh = $wert * 9.76608; | ||
| + | $lines_to_write[] = " | ||
| + | } elseif ($z===' | ||
| + | $lines_to_write[] = " | ||
| + | } elseif ($z===' | ||
| + | $lines_to_write[] = " | ||
| + | } else { | ||
| + | $lines_to_write[] = " | ||
| + | } | ||
| + | |||
| + | foreach ($lines_to_write as $line) { | ||
| + | $curl = curl_init(); | ||
| + | curl_setopt_array($curl, | ||
| + | $response = curl_exec($curl); | ||
| + | $status = curl_getinfo($curl, | ||
| + | curl_close($curl); | ||
| + | if ($status >=200 && $status< | ||
| + | else echo "< | ||
| + | } | ||
| + | } | ||
| + | ?> | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | Die Seite ist im webserver auf inuk gehostet. Die URL ist [[http:// | ||
influxdb.1763235690.txt.gz · Last modified: by lars
