diff --git a/README.md b/README.md new file mode 100644 index 0000000..5dccedc --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# Battery heater + +## Cegasa battery parameters + +### SOC > 95% + +Charge Current Limit: 31.4 A + +### < 0º C + +Charge Current Limit: 0 A +Discharge Current Limit: 31.4 A + +### 0-º C + +Charge Current Limit: 31.4 A +Discharge Current Limit: 31.4 A + +### -7º C + +Charge Current Limit: 31.4 A +Discharge Current Limit: 62.8 A + +### 8-10º C + +Charge Current Limit: 62.8 A +Discharge Current Limit: 62.8 A + +### 11-º C + +Charge Current Limit: 62.8 A +Discharge Current Limit: 94.2 A + +### -º C + +Charge Current Limit: 94.2 A +Discharge Current Limit: 94.2 A diff --git a/batt_11_degree.png b/batt_11_degree.png new file mode 100644 index 0000000..fa287a6 Binary files /dev/null and b/batt_11_degree.png differ diff --git a/functions/aemet/package-lock.json b/functions/aemet/package-lock.json index b1896fc..89faeef 100644 --- a/functions/aemet/package-lock.json +++ b/functions/aemet/package-lock.json @@ -8,12 +8,43 @@ "name": "starter-template", "version": "1.0.0", "dependencies": { - "node-appwrite": "^20.2.1" + "fast-xml-parser": "^5.3.3", + "node-appwrite": "^20.2.1", + "typescript": "^5.4.5" }, "devDependencies": { + "@types/node": "^22.19.0", "prettier": "^3.2.5" } }, + "node_modules/@types/node": { + "version": "22.19.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.19.7.tgz", + "integrity": "sha512-MciR4AKGHWl7xwxkBa6xUGxQJ4VBOmPTF7sL+iGzuahOFaO0jHCsuEfS80pan1ef4gWId1oWOweIhrDEYLuaOw==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~6.21.0" + } + }, + "node_modules/fast-xml-parser": { + "version": "5.3.3", + "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-5.3.3.tgz", + "integrity": "sha512-2O3dkPAAC6JavuMm8+4+pgTk+5hoAs+CjZ+sWcQLkX9+/tHRuTkQh/Oaifr8qDmZ8iEHb771Ea6G8CdwkrgvYA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/NaturalIntelligence" + } + ], + "license": "MIT", + "dependencies": { + "strnum": "^2.1.0" + }, + "bin": { + "fxparser": "src/cli/cli.js" + } + }, "node_modules/node-appwrite": { "version": "20.2.1", "resolved": "https://registry.npmjs.org/node-appwrite/-/node-appwrite-20.2.1.tgz", @@ -43,6 +74,38 @@ "funding": { "url": "https://github.com/prettier/prettier?sponsor=1" } + }, + "node_modules/strnum": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/strnum/-/strnum-2.1.2.tgz", + "integrity": "sha512-l63NF9y/cLROq/yqKXSLtcMeeyOfnSQlfMSlzFt/K73oIaD8DGaQWd7Z34X9GPiKqP5rbSh84Hl4bOlLcjiSrQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/NaturalIntelligence" + } + ], + "license": "MIT" + }, + "node_modules/typescript": { + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", + "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", + "dev": true, + "license": "MIT" } } } diff --git a/functions/aemet/package.json b/functions/aemet/package.json index fb9c115..ebe1879 100644 --- a/functions/aemet/package.json +++ b/functions/aemet/package.json @@ -5,12 +5,16 @@ "main": "src/main.js", "type": "module", "scripts": { - "format": "prettier --write ." + "format": "prettier --write .", + "build": "tsc" }, "dependencies": { - "node-appwrite": "^20.2.1" + "fast-xml-parser": "^5.3.3", + "node-appwrite": "^20.2.1", + "typescript": "^5.4.5" }, "devDependencies": { + "@types/node": "^22.19.0", "prettier": "^3.2.5" } } diff --git a/functions/aemet/src/main.js b/functions/aemet/src/main.js deleted file mode 100644 index 0539b5e..0000000 --- a/functions/aemet/src/main.js +++ /dev/null @@ -1,35 +0,0 @@ -import { Client, Users } from 'node-appwrite'; - -// This Appwrite function will be executed every time your function is triggered -export default async ({ req, res, log, error }) => { - // You can use the Appwrite SDK to interact with other services - // For this example, we're using the Users service - const client = new Client() - .setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT) - .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID) - .setKey(req.headers['x-appwrite-key'] ?? ''); - const users = new Users(client); - - try { - const response = await users.list(); - // Log messages and errors to the Appwrite Console - // These logs won't be seen by your end users - log(`Total users: ${response.total}`); - } catch(err) { - error("Could not list users: " + err.message); - } - - // The req object contains the request data - if (req.path === "/ping") { - // Use res object to respond with text(), json(), or binary() - // Don't forget to return a response! - return res.text("Pong"); - } - - return res.json({ - motto: "Build like a team of hundreds_", - learn: "https://appwrite.io/docs", - connect: "https://appwrite.io/discord", - getInspired: "https://builtwith.appwrite.io", - }); -}; diff --git a/functions/aemet/src/main.ts b/functions/aemet/src/main.ts new file mode 100644 index 0000000..10a0a54 --- /dev/null +++ b/functions/aemet/src/main.ts @@ -0,0 +1,30 @@ +import { Client, Users } from 'node-appwrite'; +import { XMLParser } from 'fast-xml-parser'; + +// This Appwrite function will be executed every time your function is triggered +export default async ({ req, res, log, error }: any) => { + // You can use the Appwrite SDK to interact with other services + // For this example, we're using the Users service + const client = new Client() + .setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT ?? '') + .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID ?? '') + .setKey(req.headers['x-appwrite-key'] ?? ''); + const users = new Users(client); + + try { + const response = await fetch('https://www.aemet.es/xml/municipios_h/localidad_h_31019.xml'); + + if (!response.ok) { + throw new Error(`Error! status: ${response.status}`); + } + + const parser = new XMLParser(); + let json = parser.parse(await response.text()); + log(json) + return res.json({sucess: false, data: json}) + + } catch(err: any) { + error("Error fetching forecast: " + err.message); + return res.json({success: false, error: err.message}) + } +}; diff --git a/functions/aemet/tsconfig.json b/functions/aemet/tsconfig.json new file mode 100644 index 0000000..ad43694 --- /dev/null +++ b/functions/aemet/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "NodeNext", + "rootDir": "src", + "resolveJsonModule": true, + "allowJs": true, + "outDir": "dist", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitAny": true, + "skipLibCheck": true + } +}