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:
@@ -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;
|
||||
|
||||
38
pages/api/cpl/fetchAnalogInputsHistory.ts
Normal file
38
pages/api/cpl/fetchAnalogInputsHistory.ts
Normal 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." });
|
||||
}
|
||||
}
|
||||
@@ -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`;
|
||||
Reference in New Issue
Block a user