Files
CPLv4.0/services/fetchSystemspannung5VplusService.ts
ISA 859a8f1d64 feat: fetch-Services für Spannung und Temperatur für Dev- und Prod-Modus angepasst
- fetchSystemspannung5VplusService: Channel 110 (+5V), prod = /cpl?/dashboard.html
- fetchSystemspannung15VplusService: Channel 108 (+15V)
- fetchSystemspannung15VminusService: Channel 114 (-15V)
- fetchSystemspannung98VminusService: Channel 115 (-98V)
- fetchTemperaturAdWandlerService: Channel 116 (Temperatur AD-Wandler)
- fetchTemperaturProzessorService: Channel 117 (Temperatur Prozessor)

→ Dev-Mode verwendet API-Handler (/api/cpl/...)
→ Production-Mode nutzt CGI-kompatible URLs (/cpl?/dashboard.html&...)

Fehlerbehandlung integriert, Struktur für Wiederverwendung vereinheitlicht
2025-07-03 14:02:16 +02:00

30 lines
879 B
TypeScript

// services/fetchSystemspannung5VplusService.ts
/**
* Holt Messwerte für +5V aus der passenden JSON-Datei über die API
* @param typ - Typ der Daten: DIA0 = alle, DIA1 = stündlich, DIA2 = täglich
*/
export const fetchSystemspannung5VplusService = async (
type: "DIA0" | "DIA1" | "DIA2"
) => {
try {
const isDev = process.env.NODE_ENV === "development";
const channel = 110; // 110 = +5V
const from = "2025;01;01";
const to = "2025;07;31";
const path = isDev
? `/api/cpl/getSystemspannung5VplusHandler?typ=${type}`
: `/cpl?/dashboard.html&${type}=${from};${to};${channel};1;`;
const res = await fetch(path);
if (!res.ok) throw new Error("❌ Fehler beim Abrufen der +5V-Daten");
return await res.json();
} catch (err) {
console.error("❌ Fehler in fetchSystemspannung5VplusService:", err);
return null;
}
};