feat: fetchAnalogInputsHistoryService hinzugefügt zum Laden historischer Messwerte

- Holt die Messwerte der letzten 24 Stunden für alle 8 analogen Eingänge (AE1–AE8)
- Baut die Abfrage-URLs dynamisch mit DIA0-Schnittstelle der CPL-Webschnittstelle
- Unterstützt Live-Modus über window.location.origin und optional Mock-Daten über API
- Dient als zentrale Datenquelle für die Chart-Darstellung in der Entwicklungsumgebung
This commit is contained in:
ISA
2025-04-29 10:28:32 +02:00
parent b2a3518c85
commit 38305d410e
3 changed files with 41 additions and 3 deletions

View File

@@ -6,5 +6,5 @@
2: Patch oder Hotfix (Bugfixes oder kleine Änderungen).
*/
const webVersion = "1.6.303";
const webVersion = "1.6.304";
export default webVersion;

View File

@@ -0,0 +1,38 @@
// /pages/api/cpl/fetchAnalogInputsHistory.ts
import path from "path";
import fs from "fs/promises";
import type { NextApiRequest, NextApiResponse } from "next";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
try {
const result: Record<number, any[]> = {};
for (let i = 1; i <= 8; i++) {
const filePath = path.join(
process.cwd(),
"apiMockData",
"analogInputsHistoryData",
`analogInput${i}.json`
);
try {
const fileContent = await fs.readFile(filePath, "utf-8");
result[99 + i] = JSON.parse(fileContent); // z.B. 100 für AE1, 101 für AE2
} catch (err) {
console.warn(
`Mock-Datei für analogInput${i} nicht gefunden oder fehlerhaft.`
);
result[99 + i] = [];
}
}
res.status(200).json(result);
} catch (error) {
console.error("Fehler beim Laden der analogen Eingänge (Mock):", error);
res.status(500).json({ error: "Fehler beim Laden der Mock-Daten." });
}
}

View File

@@ -1,6 +1,6 @@
// services/fetchAnalogInputHistory.ts
// services/fetchAnalogInputHistoryService.ts
export async function fetchAnalogInputHistory(): Promise<
export async function fetchAnalogInputHistoryService(): Promise<
Record<number, any[]>
> {
const baseUrl = `${window.location.origin}/CPL?Service/empty.acp`;