From bfbc77c92e34105ac086e65cfb7e08740d4e6a61 Mon Sep 17 00:00:00 2001 From: proddy Date: Sun, 7 Apr 2024 15:50:19 +0200 Subject: [PATCH] add standalone test for web uploading - https://github.com/emsesp/EMS-ESP32/issues/1564 --- .gitignore | 22 +- interface/.gitignore | 7 - interface/package.json | 23 +- interface/vite.config.ts | 5 +- interface/yarn.lock | 332 +++-- mock-api/.editorconfig | 10 - mock-api/.gitattributes | 4 - mock-api/.gitignore | 9 - mock-api/es_server.ts | 2 +- mock-api/old_server.js | 2800 ------------------------------------- mock-api/package.json | 5 +- mock-api/rest_server.ts | 116 +- mock-api/upload_server.ts | 57 + mock-api/yarn.lock | 10 +- test/api_test.http | 18 +- 15 files changed, 293 insertions(+), 3127 deletions(-) delete mode 100644 interface/.gitignore delete mode 100644 mock-api/.editorconfig delete mode 100644 mock-api/.gitattributes delete mode 100644 mock-api/.gitignore delete mode 100644 mock-api/old_server.js create mode 100644 mock-api/upload_server.ts diff --git a/.gitignore b/.gitignore index f680ef353..fb5e5348d 100644 --- a/.gitignore +++ b/.gitignore @@ -30,7 +30,7 @@ stats.html *.sln *.sw? .pnp.* -.yarn/* +*/.yarn/* !.yarn/patches !.yarn/plugins !.yarn/releases @@ -39,6 +39,16 @@ stats.html yarn.lock analyse.html interface/vite.config.ts.timestamp* +*.local +# i18n generated files +interface/src/i18n/i18n-react.tsx +interface/src/i18n/i18n-types.ts +interface/src/i18n/i18n-util.ts +interface/src/i18n/i18n-util.sync.ts +interface/src/i18n/i18n-util.async.ts +# mock-api uploads +*/uploads/* +!uploads/README.md # scripts test.sh @@ -46,18 +56,10 @@ scripts/run.sh scripts/__pycache__ scripts/stackdmp.txt -# i18n generated files -interface/src/i18n/i18n-react.tsx -interface/src/i18n/i18n-types.ts -interface/src/i18n/i18n-util.ts -interface/src/i18n/i18n-util.sync.ts -interface/src/i18n/i18n-util.async.ts - # sonar .scannerwork/ sonar/ bw-output/ -# testing +# standalone executable for testing emsesp - diff --git a/interface/.gitignore b/interface/.gitignore deleted file mode 100644 index 557f4c6a6..000000000 --- a/interface/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -.pnp.* -.yarn/* -!.yarn/patches -!.yarn/plugins -!.yarn/releases -!.yarn/sdks -!.yarn/versions \ No newline at end of file diff --git a/interface/package.json b/interface/package.json index 368dcc9bc..682d5f5d8 100644 --- a/interface/package.json +++ b/interface/package.json @@ -14,8 +14,9 @@ "preview-standalone": "typesafe-i18n --no-watch && vite build && concurrently -c \"auto\" \"npm:mock-api\" \"vite preview\"", "mock-api": "bun --watch ../mock-api/rest_server.ts", "mock-es": "bun --watch ../mock-api/es_server.ts", + "mock-upload": "bun --watch ../mock-api/upload_server.ts", "old_mock-api": "bun --watch ../mock-api/server.js", - "standalone": "concurrently -c \"auto\" \"typesafe-i18n\" \"npm:mock-api\" \"npm:mock-es\" \"vite\"", + "standalone": "concurrently -c \"auto\" \"typesafe-i18n\" \"npm:mock-api\" \"npm:mock-es\" \"npm:mock-upload\" \"vite\"", "old_standalone": "concurrently -c \"auto\" \"typesafe-i18n\" \"npm:old_mock-api\" \"vite\"", "typesafe-i18n": "typesafe-i18n --no-watch", "webUI": "node progmem-generator.js", @@ -24,19 +25,19 @@ }, "dependencies": { "@alova/adapter-xhr": "^1.0.3", - "@babel/core": "^7.24.3", + "@babel/core": "^7.24.4", "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.5", - "@mui/icons-material": "^5.15.14", - "@mui/material": "^5.15.14", + "@mui/icons-material": "^5.15.15", + "@mui/material": "^5.15.15", "@table-library/react-table-library": "4.1.7", "@types/imagemin": "^8.0.5", "@types/lodash-es": "^4.17.12", - "@types/node": "^20.12.2", + "@types/node": "^20.12.5", "@types/react": "^18.2.74", - "@types/react-dom": "^18.2.23", + "@types/react-dom": "^18.2.24", "@types/react-router-dom": "^5.3.3", - "alova": "^2.18.2", + "alova": "^2.18.3", "async-validator": "^4.2.5", "eslint-plugin-prettier": "^5.1.3", "history": "^5.3.0", @@ -50,7 +51,7 @@ "react-router-dom": "^6.22.3", "react-toastify": "^10.0.5", "typesafe-i18n": "^5.26.2", - "typescript": "^5.4.3" + "typescript": "^5.4.4" }, "devDependencies": { "@preact/compat": "^17.1.2", @@ -58,7 +59,7 @@ "@typescript-eslint/eslint-plugin": "^7.5.0", "@typescript-eslint/parser": "^7.5.0", "concurrently": "^8.2.2", - "eslint": "^8.57.0", + "eslint": "^9.0.0", "eslint-config-prettier": "^9.1.0", "eslint-import-resolver-typescript": "^3.6.1", "eslint-plugin-autofix": "^1.1.0", @@ -68,8 +69,8 @@ "preact": "^10.20.1", "prettier": "^3.2.5", "rollup-plugin-visualizer": "^5.12.0", - "terser": "^5.30.2", - "vite": "^5.2.7", + "terser": "^5.30.3", + "vite": "^5.2.8", "vite-plugin-imagemin": "^0.6.1", "vite-tsconfig-paths": "^4.3.2" }, diff --git a/interface/vite.config.ts b/interface/vite.config.ts index e1349f5c2..87286bff6 100644 --- a/interface/vite.config.ts +++ b/interface/vite.config.ts @@ -13,7 +13,6 @@ export default defineConfig(({ command, mode }) => { open: true, port: mode == 'production' ? 4173 : 3000, proxy: { - '/rest': 'http://localhost:3080', '/api': { target: 'http://localhost:3080', changeOrigin: true, @@ -23,7 +22,9 @@ export default defineConfig(({ command, mode }) => { target: 'http://localhost:3081', changeOrigin: true, secure: false - } + }, + '/rest/uploadFile': 'http://localhost:3082', // this must come first to work! + '/rest': 'http://localhost:3080' } } }; diff --git a/interface/yarn.lock b/interface/yarn.lock index b8d3201ad..bd8c9afdd 100644 --- a/interface/yarn.lock +++ b/interface/yarn.lock @@ -46,7 +46,7 @@ __metadata: languageName: node linkType: hard -"@babel/core@npm:^7.22.1, @babel/core@npm:^7.24.3": +"@babel/core@npm:^7.22.1": version: 7.24.3 resolution: "@babel/core@npm:7.24.3" dependencies: @@ -69,6 +69,29 @@ __metadata: languageName: node linkType: hard +"@babel/core@npm:^7.24.4": + version: 7.24.4 + resolution: "@babel/core@npm:7.24.4" + dependencies: + "@ampproject/remapping": "npm:^2.2.0" + "@babel/code-frame": "npm:^7.24.2" + "@babel/generator": "npm:^7.24.4" + "@babel/helper-compilation-targets": "npm:^7.23.6" + "@babel/helper-module-transforms": "npm:^7.23.3" + "@babel/helpers": "npm:^7.24.4" + "@babel/parser": "npm:^7.24.4" + "@babel/template": "npm:^7.24.0" + "@babel/traverse": "npm:^7.24.1" + "@babel/types": "npm:^7.24.0" + convert-source-map: "npm:^2.0.0" + debug: "npm:^4.1.0" + gensync: "npm:^1.0.0-beta.2" + json5: "npm:^2.2.3" + semver: "npm:^6.3.1" + checksum: 10/1e049f8df26be0fe5be36173fd7c33dfb004eeeec28152fea83c90e71784f9a6f2237296f43a2ee7d9041e2a33a05f43da48ce2d4e0cd473a682328ca07ce7e0 + languageName: node + linkType: hard + "@babel/generator@npm:^7.24.1": version: 7.24.1 resolution: "@babel/generator@npm:7.24.1" @@ -81,6 +104,18 @@ __metadata: languageName: node linkType: hard +"@babel/generator@npm:^7.24.4": + version: 7.24.4 + resolution: "@babel/generator@npm:7.24.4" + dependencies: + "@babel/types": "npm:^7.24.0" + "@jridgewell/gen-mapping": "npm:^0.3.5" + "@jridgewell/trace-mapping": "npm:^0.3.25" + jsesc: "npm:^2.5.1" + checksum: 10/69e1772dcf8f95baec951f422cca091d59a3f29b5eedc989ad87f7262289b94625983f6fe654302ca17aae0a32f9232332b83fcc85533311d6267b09c58b1061 + languageName: node + linkType: hard + "@babel/helper-annotate-as-pure@npm:^7.22.5": version: 7.22.5 resolution: "@babel/helper-annotate-as-pure@npm:7.22.5" @@ -210,6 +245,17 @@ __metadata: languageName: node linkType: hard +"@babel/helpers@npm:^7.24.4": + version: 7.24.4 + resolution: "@babel/helpers@npm:7.24.4" + dependencies: + "@babel/template": "npm:^7.24.0" + "@babel/traverse": "npm:^7.24.1" + "@babel/types": "npm:^7.24.0" + checksum: 10/54a9d0f86f2803fcc216cfa23b66b871ea0fa0a892af1c9a79075872c2437de71afbb150ed8216f30e00b19a0b9c5c9d5845173d170e1ebfbbf8887839b89dde + languageName: node + linkType: hard + "@babel/highlight@npm:^7.24.2": version: 7.24.2 resolution: "@babel/highlight@npm:7.24.2" @@ -231,6 +277,15 @@ __metadata: languageName: node linkType: hard +"@babel/parser@npm:^7.24.4": + version: 7.24.4 + resolution: "@babel/parser@npm:7.24.4" + bin: + parser: ./bin/babel-parser.js + checksum: 10/3742cc5068036287e6395269dce5a2735e6349cdc8d4b53297c75f98c580d7e1c8cb43235623999d151f2ef975d677dbc2c2357573a1855caa71c271bf3046c9 + languageName: node + linkType: hard + "@babel/plugin-syntax-jsx@npm:^7.23.3": version: 7.24.1 resolution: "@babel/plugin-syntax-jsx@npm:7.24.1" @@ -662,27 +717,27 @@ __metadata: languageName: node linkType: hard -"@eslint/eslintrc@npm:^2.1.4": - version: 2.1.4 - resolution: "@eslint/eslintrc@npm:2.1.4" +"@eslint/eslintrc@npm:^3.0.2": + version: 3.0.2 + resolution: "@eslint/eslintrc@npm:3.0.2" dependencies: ajv: "npm:^6.12.4" debug: "npm:^4.3.2" - espree: "npm:^9.6.0" - globals: "npm:^13.19.0" + espree: "npm:^10.0.1" + globals: "npm:^14.0.0" ignore: "npm:^5.2.0" import-fresh: "npm:^3.2.1" js-yaml: "npm:^4.1.0" minimatch: "npm:^3.1.2" strip-json-comments: "npm:^3.1.1" - checksum: 10/7a3b14f4b40fc1a22624c3f84d9f467a3d9ea1ca6e9a372116cb92507e485260359465b58e25bcb6c9981b155416b98c9973ad9b796053fd7b3f776a6946bce8 + checksum: 10/04e3d7de2b16fd59ba8985ecd6922eb488e630f94e4433858567a8a6c99b478bb7b47854b166b830b44905759547d0a03654eb1265952c812d5d1d70e3e4ccf9 languageName: node linkType: hard -"@eslint/js@npm:8.57.0": - version: 8.57.0 - resolution: "@eslint/js@npm:8.57.0" - checksum: 10/3c501ce8a997cf6cbbaf4ed358af5492875e3550c19b9621413b82caa9ae5382c584b0efa79835639e6e0ddaa568caf3499318e5bdab68643ef4199dce5eb0a0 +"@eslint/js@npm:9.0.0": + version: 9.0.0 + resolution: "@eslint/js@npm:9.0.0" + checksum: 10/b14b20af72410ef53e3e77e7d83cc1d6e6554b0092ceb9f969d25d765f4d775b4be32b0cd99bbfd6ce72eb2e4fb6b39b42a159b31909fbe1b3a5e88d75211687 languageName: node linkType: hard @@ -724,14 +779,14 @@ __metadata: languageName: node linkType: hard -"@humanwhocodes/config-array@npm:^0.11.14": - version: 0.11.14 - resolution: "@humanwhocodes/config-array@npm:0.11.14" +"@humanwhocodes/config-array@npm:^0.12.3": + version: 0.12.3 + resolution: "@humanwhocodes/config-array@npm:0.12.3" dependencies: - "@humanwhocodes/object-schema": "npm:^2.0.2" + "@humanwhocodes/object-schema": "npm:^2.0.3" debug: "npm:^4.3.1" minimatch: "npm:^3.0.5" - checksum: 10/3ffb24ecdfab64014a230e127118d50a1a04d11080cbb748bc21629393d100850496456bbcb4e8c438957fe0934430d731042f1264d6a167b62d32fc2863580a + checksum: 10/b05f528c110aa1657d95d213e4ad2662f4161e838806af01a4d3f3b6ee3878d9b6f87d1b10704917f5c2f116757cb5c818480c32c4c4c6f84fe775a170b5f758 languageName: node linkType: hard @@ -742,10 +797,10 @@ __metadata: languageName: node linkType: hard -"@humanwhocodes/object-schema@npm:^2.0.2": - version: 2.0.2 - resolution: "@humanwhocodes/object-schema@npm:2.0.2" - checksum: 10/ef915e3e2f34652f3d383b28a9a99cfea476fa991482370889ab14aac8ecd2b38d47cc21932526c6d949da0daf4a4a6bf629d30f41b0caca25e146819cbfa70e +"@humanwhocodes/object-schema@npm:^2.0.3": + version: 2.0.3 + resolution: "@humanwhocodes/object-schema@npm:2.0.3" + checksum: 10/05bb99ed06c16408a45a833f03a732f59bf6184795d4efadd33238ff8699190a8c871ad1121241bb6501589a9598dc83bf25b99dcbcf41e155cdf36e35e937a3 languageName: node linkType: hard @@ -837,16 +892,16 @@ __metadata: languageName: node linkType: hard -"@mui/core-downloads-tracker@npm:^5.15.14": - version: 5.15.14 - resolution: "@mui/core-downloads-tracker@npm:5.15.14" - checksum: 10/0a1c63d906af594d0a7fb63d1d574482b3916351ea8908e8621c8bfa16ac38cf4edb5a334f0e28084f583ac928b587cab6e031f992195e0a590186faba13b9a5 +"@mui/core-downloads-tracker@npm:^5.15.15": + version: 5.15.15 + resolution: "@mui/core-downloads-tracker@npm:5.15.15" + checksum: 10/3e99a04e03f66d5fa5f0c23cdce0f9fa2331ba08c99a75dc2347ccaa1c6ed520153e04aaeb0d613c9dca099a3e6242558a6284c33d93f95cc65e3243b17860bc languageName: node linkType: hard -"@mui/icons-material@npm:^5.15.14": - version: 5.15.14 - resolution: "@mui/icons-material@npm:5.15.14" +"@mui/icons-material@npm:^5.15.15": + version: 5.15.15 + resolution: "@mui/icons-material@npm:5.15.15" dependencies: "@babel/runtime": "npm:^7.23.9" peerDependencies: @@ -856,18 +911,18 @@ __metadata: peerDependenciesMeta: "@types/react": optional: true - checksum: 10/a5033b67d4ff455f5fdd91fc51d26d967d634e861cde194b9dde02a8cc3f557d1b3f7e0b3175bc654b8e944f2118d46620485734ecd9d2ed4a6f748386447933 + checksum: 10/e8810d7ffbba914baf21509e5d664f5f23bdba5d2a7ec7c485a3c7ddbbcb417e555c31feff2a3fa9c7d7fa0d22d4380f32488559ab3b170d891641dbc2161b22 languageName: node linkType: hard -"@mui/material@npm:^5.15.14": - version: 5.15.14 - resolution: "@mui/material@npm:5.15.14" +"@mui/material@npm:^5.15.15": + version: 5.15.15 + resolution: "@mui/material@npm:5.15.15" dependencies: "@babel/runtime": "npm:^7.23.9" "@mui/base": "npm:5.0.0-beta.40" - "@mui/core-downloads-tracker": "npm:^5.15.14" - "@mui/system": "npm:^5.15.14" + "@mui/core-downloads-tracker": "npm:^5.15.15" + "@mui/system": "npm:^5.15.15" "@mui/types": "npm:^7.2.14" "@mui/utils": "npm:^5.15.14" "@types/react-transition-group": "npm:^4.4.10" @@ -889,7 +944,7 @@ __metadata: optional: true "@types/react": optional: true - checksum: 10/a2c3355b39b86472bf2debb84d6c032b1ea4ba691fbda0f25803f2702f9106130bb85a7d2757545ce97540fe185f07cf24574d5786a29df26baa298ff7db063b + checksum: 10/e2803d078243ee5489bf693f7e9d421061dfda79b6ce74762f3a81e3c519cf69c18af179e4267fc9d0ce799898e6b3d7eac029e7dcfbea12dab5e867d641984b languageName: node linkType: hard @@ -931,9 +986,9 @@ __metadata: languageName: node linkType: hard -"@mui/system@npm:^5.15.14": - version: 5.15.14 - resolution: "@mui/system@npm:5.15.14" +"@mui/system@npm:^5.15.15": + version: 5.15.15 + resolution: "@mui/system@npm:5.15.15" dependencies: "@babel/runtime": "npm:^7.23.9" "@mui/private-theming": "npm:^5.15.14" @@ -955,7 +1010,7 @@ __metadata: optional: true "@types/react": optional: true - checksum: 10/64a9eac1bebefad3042cce28a75d0af2828aa71acd4c32fb0267f5e68bc75b16a093b6fb30709db83ec32130f14f1d67c1c27457ef62733e54a9d04f9b027cee + checksum: 10/90a84ad0bc1b401b6e53b13fe9cfe8a34668e84885d391abf5ab80b3cd0f37370be25cb40af253cdd468746386282fed24964315933fcb28d2d6e62de0db7bf1 languageName: node linkType: hard @@ -1419,12 +1474,12 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:^20.12.2": - version: 20.12.2 - resolution: "@types/node@npm:20.12.2" +"@types/node@npm:^20.12.5": + version: 20.12.5 + resolution: "@types/node@npm:20.12.5" dependencies: undici-types: "npm:~5.26.4" - checksum: 10/f1f0ebfe475aefa183763b856e0023b81b76554196e8676a45b9fcfd1012cdd20d32adefb3c0330001c0011e074676603c34c24821a4924228250ea13a75da43 + checksum: 10/7b647ea6679016e4e58e1aa439c46b610230ffcbe19173911fbf1d1fa329ec6fd1eeba4e3e2d8743206d3b00d5a0cad75f1c90189e1d1ec057eb48df1a1dd747 languageName: node linkType: hard @@ -1442,12 +1497,12 @@ __metadata: languageName: node linkType: hard -"@types/react-dom@npm:^18.2.23": - version: 18.2.23 - resolution: "@types/react-dom@npm:18.2.23" +"@types/react-dom@npm:^18.2.24": + version: 18.2.24 + resolution: "@types/react-dom@npm:18.2.24" dependencies: "@types/react": "npm:*" - checksum: 10/8311c67767b0aafb5cd94176a90f801f0f5f6930731d57caaa04bb0d87fdef6bc6f723a116d9777d2082ec022682acaad7a62d04dc27e330e818cf34f2ef2703 + checksum: 10/bbd4005f2f65b7606505e9b8759b6e99e222d503602765594ea327893fb7061de8951279baef47a1932f04d94d1865daea05a32f9fcf6f9f1143dbabce5b33de languageName: node linkType: hard @@ -1657,38 +1712,31 @@ __metadata: languageName: node linkType: hard -"@ungap/structured-clone@npm:^1.2.0": - version: 1.2.0 - resolution: "@ungap/structured-clone@npm:1.2.0" - checksum: 10/c6fe89a505e513a7592e1438280db1c075764793a2397877ff1351721fe8792a966a5359769e30242b3cd023f2efb9e63ca2ca88019d73b564488cc20e3eab12 - languageName: node - linkType: hard - "EMS-ESP@workspace:.": version: 0.0.0-use.local resolution: "EMS-ESP@workspace:." dependencies: "@alova/adapter-xhr": "npm:^1.0.3" - "@babel/core": "npm:^7.24.3" + "@babel/core": "npm:^7.24.4" "@emotion/react": "npm:^11.11.4" "@emotion/styled": "npm:^11.11.5" - "@mui/icons-material": "npm:^5.15.14" - "@mui/material": "npm:^5.15.14" + "@mui/icons-material": "npm:^5.15.15" + "@mui/material": "npm:^5.15.15" "@preact/compat": "npm:^17.1.2" "@preact/preset-vite": "npm:^2.8.2" "@table-library/react-table-library": "npm:4.1.7" "@types/imagemin": "npm:^8.0.5" "@types/lodash-es": "npm:^4.17.12" - "@types/node": "npm:^20.12.2" + "@types/node": "npm:^20.12.5" "@types/react": "npm:^18.2.74" - "@types/react-dom": "npm:^18.2.23" + "@types/react-dom": "npm:^18.2.24" "@types/react-router-dom": "npm:^5.3.3" "@typescript-eslint/eslint-plugin": "npm:^7.5.0" "@typescript-eslint/parser": "npm:^7.5.0" - alova: "npm:^2.18.2" + alova: "npm:^2.18.3" async-validator: "npm:^4.2.5" concurrently: "npm:^8.2.2" - eslint: "npm:^8.57.0" + eslint: "npm:^9.0.0" eslint-config-prettier: "npm:^9.1.0" eslint-import-resolver-typescript: "npm:^3.6.1" eslint-plugin-autofix: "npm:^1.1.0" @@ -1709,10 +1757,10 @@ __metadata: react-router-dom: "npm:^6.22.3" react-toastify: "npm:^10.0.5" rollup-plugin-visualizer: "npm:^5.12.0" - terser: "npm:^5.30.2" + terser: "npm:^5.30.3" typesafe-i18n: "npm:^5.26.2" - typescript: "npm:^5.4.3" - vite: "npm:^5.2.7" + typescript: "npm:^5.4.4" + vite: "npm:^5.2.8" vite-plugin-imagemin: "npm:^0.6.1" vite-tsconfig-paths: "npm:^4.3.2" languageName: unknown @@ -1734,7 +1782,7 @@ __metadata: languageName: node linkType: hard -"acorn@npm:^8.8.2, acorn@npm:^8.9.0": +"acorn@npm:^8.11.3, acorn@npm:^8.8.2, acorn@npm:^8.9.0": version: 8.11.3 resolution: "acorn@npm:8.11.3" bin: @@ -1774,10 +1822,10 @@ __metadata: languageName: node linkType: hard -"alova@npm:^2.18.2": - version: 2.18.2 - resolution: "alova@npm:2.18.2" - checksum: 10/715d97c5b80c2b3541b7b5dd203bb7496d7308a49682df31ed007c12a7d716ee910f3da852accc2398c2283db3808748678074cb87324b5d77bb991018431bf3 +"alova@npm:^2.18.3": + version: 2.18.3 + resolution: "alova@npm:2.18.3" + checksum: 10/0a76cd8aed07a8af0409efb1f39e1c6c6423eb763dbc86b937052497157bdbe10faf77d01b8785934fbd74deb78efe6303949b0b2d410a24bbc687671ec3ae6c languageName: node linkType: hard @@ -2834,15 +2882,6 @@ __metadata: languageName: node linkType: hard -"doctrine@npm:^3.0.0": - version: 3.0.0 - resolution: "doctrine@npm:3.0.0" - dependencies: - esutils: "npm:^2.0.2" - checksum: 10/b4b28f1df5c563f7d876e7461254a4597b8cabe915abe94d7c5d1633fed263fcf9a85e8d3836591fc2d040108e822b0d32758e5ec1fe31c590dc7e08086e3e48 - languageName: node - linkType: hard - "dom-helpers@npm:^5.0.1": version: 5.2.1 resolution: "dom-helpers@npm:5.2.1" @@ -3666,57 +3705,60 @@ __metadata: languageName: node linkType: hard -"eslint-scope@npm:^7.2.2": - version: 7.2.2 - resolution: "eslint-scope@npm:7.2.2" +"eslint-scope@npm:^8.0.1": + version: 8.0.1 + resolution: "eslint-scope@npm:8.0.1" dependencies: esrecurse: "npm:^4.3.0" estraverse: "npm:^5.2.0" - checksum: 10/5c660fb905d5883ad018a6fea2b49f3cb5b1cbf2cd4bd08e98646e9864f9bc2c74c0839bed2d292e90a4a328833accc197c8f0baed89cbe8d605d6f918465491 + checksum: 10/458513863d3c79005b599f40250437bddba923f18549058ea45820a8d3d4bbc67fe292751d522a0cab69dd01fe211ffde5c1a5fc867e86f2d28727b1d61610da languageName: node linkType: hard -"eslint-visitor-keys@npm:^3.3.0, eslint-visitor-keys@npm:^3.4.1, eslint-visitor-keys@npm:^3.4.3": +"eslint-visitor-keys@npm:^3.3.0, eslint-visitor-keys@npm:^3.4.1": version: 3.4.3 resolution: "eslint-visitor-keys@npm:3.4.3" checksum: 10/3f357c554a9ea794b094a09bd4187e5eacd1bc0d0653c3adeb87962c548e6a1ab8f982b86963ae1337f5d976004146536dcee5d0e2806665b193fbfbf1a9231b languageName: node linkType: hard -"eslint@npm:^8.57.0": - version: 8.57.0 - resolution: "eslint@npm:8.57.0" +"eslint-visitor-keys@npm:^4.0.0": + version: 4.0.0 + resolution: "eslint-visitor-keys@npm:4.0.0" + checksum: 10/c7617166e6291a15ce2982b5c4b9cdfb6409f5c14562712d12e2584480cdf18609694b21d7dad35b02df0fa2cd037505048ded54d2f405c64f600949564eb334 + languageName: node + linkType: hard + +"eslint@npm:^9.0.0": + version: 9.0.0 + resolution: "eslint@npm:9.0.0" dependencies: "@eslint-community/eslint-utils": "npm:^4.2.0" "@eslint-community/regexpp": "npm:^4.6.1" - "@eslint/eslintrc": "npm:^2.1.4" - "@eslint/js": "npm:8.57.0" - "@humanwhocodes/config-array": "npm:^0.11.14" + "@eslint/eslintrc": "npm:^3.0.2" + "@eslint/js": "npm:9.0.0" + "@humanwhocodes/config-array": "npm:^0.12.3" "@humanwhocodes/module-importer": "npm:^1.0.1" "@nodelib/fs.walk": "npm:^1.2.8" - "@ungap/structured-clone": "npm:^1.2.0" ajv: "npm:^6.12.4" chalk: "npm:^4.0.0" cross-spawn: "npm:^7.0.2" debug: "npm:^4.3.2" - doctrine: "npm:^3.0.0" escape-string-regexp: "npm:^4.0.0" - eslint-scope: "npm:^7.2.2" - eslint-visitor-keys: "npm:^3.4.3" - espree: "npm:^9.6.1" + eslint-scope: "npm:^8.0.1" + eslint-visitor-keys: "npm:^4.0.0" + espree: "npm:^10.0.1" esquery: "npm:^1.4.2" esutils: "npm:^2.0.2" fast-deep-equal: "npm:^3.1.3" - file-entry-cache: "npm:^6.0.1" + file-entry-cache: "npm:^8.0.0" find-up: "npm:^5.0.0" glob-parent: "npm:^6.0.2" - globals: "npm:^13.19.0" graphemer: "npm:^1.4.0" ignore: "npm:^5.2.0" imurmurhash: "npm:^0.1.4" is-glob: "npm:^4.0.0" is-path-inside: "npm:^3.0.3" - js-yaml: "npm:^4.1.0" json-stable-stringify-without-jsonify: "npm:^1.0.1" levn: "npm:^0.4.1" lodash.merge: "npm:^4.6.2" @@ -3727,11 +3769,22 @@ __metadata: text-table: "npm:^0.2.0" bin: eslint: bin/eslint.js - checksum: 10/00496e218b23747a7a9817bf58b522276d0dc1f2e546dceb4eea49f9871574088f72f1f069a6b560ef537efa3a75261b8ef70e51ef19033da1cc4c86a755ef15 + checksum: 10/5cf03e14eb114f95bc4e553c8ae2da65ec09d519779beb08e326d98518bce647ce9c8bf3467bcea4cab35a2657cc3a8e945717e784afa4b1bdb9d1ecd9173ba0 languageName: node linkType: hard -"espree@npm:^9.0.0, espree@npm:^9.6.0, espree@npm:^9.6.1": +"espree@npm:^10.0.1": + version: 10.0.1 + resolution: "espree@npm:10.0.1" + dependencies: + acorn: "npm:^8.11.3" + acorn-jsx: "npm:^5.3.2" + eslint-visitor-keys: "npm:^4.0.0" + checksum: 10/557d6cfb4894b1489effcaed8702682086033f8a2449568933bc59493734733d750f2a87907ba575844d3933340aea2d84288f5e67020c6152f6fd18a86497b2 + languageName: node + linkType: hard + +"espree@npm:^9.0.0": version: 9.6.1 resolution: "espree@npm:9.6.1" dependencies: @@ -3973,12 +4026,12 @@ __metadata: languageName: node linkType: hard -"file-entry-cache@npm:^6.0.1": - version: 6.0.1 - resolution: "file-entry-cache@npm:6.0.1" +"file-entry-cache@npm:^8.0.0": + version: 8.0.0 + resolution: "file-entry-cache@npm:8.0.0" dependencies: - flat-cache: "npm:^3.0.4" - checksum: 10/099bb9d4ab332cb93c48b14807a6918a1da87c45dce91d4b61fd40e6505d56d0697da060cb901c729c90487067d93c9243f5da3dc9c41f0358483bfdebca736b + flat-cache: "npm:^4.0.0" + checksum: 10/afe55c4de4e0d226a23c1eae62a7219aafb390859122608a89fa4df6addf55c7fd3f1a2da6f5b41e7cdff496e4cf28bbd215d53eab5c817afa96d2b40c81bfb0 languageName: node linkType: hard @@ -4103,14 +4156,13 @@ __metadata: languageName: node linkType: hard -"flat-cache@npm:^3.0.4": - version: 3.2.0 - resolution: "flat-cache@npm:3.2.0" +"flat-cache@npm:^4.0.0": + version: 4.0.1 + resolution: "flat-cache@npm:4.0.1" dependencies: flatted: "npm:^3.2.9" - keyv: "npm:^4.5.3" - rimraf: "npm:^3.0.2" - checksum: 10/02381c6ece5e9fa5b826c9bbea481d7fd77645d96e4b0b1395238124d581d10e56f17f723d897b6d133970f7a57f0fab9148cbbb67237a0a0ffe794ba60c0c70 + keyv: "npm:^4.5.4" + checksum: 10/58ce851d9045fffc7871ce2bd718bc485ad7e777bf748c054904b87c351ff1080c2c11da00788d78738bfb51b71e4d5ea12d13b98eb36e3358851ffe495b62dc languageName: node linkType: hard @@ -4424,12 +4476,10 @@ __metadata: languageName: node linkType: hard -"globals@npm:^13.19.0": - version: 13.24.0 - resolution: "globals@npm:13.24.0" - dependencies: - type-fest: "npm:^0.20.2" - checksum: 10/62c5b1997d06674fc7191d3e01e324d3eda4d65ac9cc4e78329fa3b5c4fd42a0e1c8722822497a6964eee075255ce21ccf1eec2d83f92ef3f06653af4d0ee28e +"globals@npm:^14.0.0": + version: 14.0.0 + resolution: "globals@npm:14.0.0" + checksum: 10/03939c8af95c6df5014b137cac83aa909090c3a3985caef06ee9a5a669790877af8698ab38007e4c0186873adc14c0b13764acc754b16a754c216cc56aa5f021 languageName: node linkType: hard @@ -5513,7 +5563,7 @@ __metadata: languageName: node linkType: hard -"keyv@npm:^4.5.3": +"keyv@npm:^4.5.4": version: 4.5.4 resolution: "keyv@npm:4.5.4" dependencies: @@ -7049,17 +7099,6 @@ __metadata: languageName: node linkType: hard -"rimraf@npm:^3.0.2": - version: 3.0.2 - resolution: "rimraf@npm:3.0.2" - dependencies: - glob: "npm:^7.1.3" - bin: - rimraf: bin.js - checksum: 10/063ffaccaaaca2cfd0ef3beafb12d6a03dd7ff1260d752d62a6077b5dfff6ae81bea571f655bb6b589d366930ec1bdd285d40d560c0dae9b12f125e54eb743d5 - languageName: node - linkType: hard - "rollup-plugin-visualizer@npm:^5.12.0": version: 5.12.0 resolution: "rollup-plugin-visualizer@npm:5.12.0" @@ -7861,9 +7900,9 @@ __metadata: languageName: node linkType: hard -"terser@npm:^5.30.2": - version: 5.30.2 - resolution: "terser@npm:5.30.2" +"terser@npm:^5.30.3": + version: 5.30.3 + resolution: "terser@npm:5.30.3" dependencies: "@jridgewell/source-map": "npm:^0.3.3" acorn: "npm:^8.8.2" @@ -7871,7 +7910,7 @@ __metadata: source-map-support: "npm:~0.5.20" bin: terser: bin/terser - checksum: 10/df671714eb9160cc61d340ddbe6e54f66060bc893c2d420090e10df7f1a2e459725a56dc2e547e992c021ad4523b81eabc8f5a551c53505def80b7320a72506a + checksum: 10/f4ee378065a327c85472f351ac232fa47ec84d4f15df7ec58c044b41e3c063cf11aaedd90dcfe9c7f2a6ef01d4aab23deb61622301170dc77d0a8b6a6a83cf5e languageName: node linkType: hard @@ -8011,13 +8050,6 @@ __metadata: languageName: node linkType: hard -"type-fest@npm:^0.20.2": - version: 0.20.2 - resolution: "type-fest@npm:0.20.2" - checksum: 10/8907e16284b2d6cfa4f4817e93520121941baba36b39219ea36acfe64c86b9dbc10c9941af450bd60832c8f43464974d51c0957f9858bc66b952b66b6914cbb9 - languageName: node - linkType: hard - "typed-array-buffer@npm:^1.0.2": version: 1.0.2 resolution: "typed-array-buffer@npm:1.0.2" @@ -8081,23 +8113,23 @@ __metadata: languageName: node linkType: hard -"typescript@npm:^5.4.3": - version: 5.4.3 - resolution: "typescript@npm:5.4.3" +"typescript@npm:^5.4.4": + version: 5.4.4 + resolution: "typescript@npm:5.4.4" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 10/de4c69f49a7ad4b1ea66a6dcc8b055ac34eb56af059a069d8988dd811c5e649be07e042e5bf573e8d0ac3ec2f30e6c999aa651cd09f6e9cbc6113749e8b6be20 + checksum: 10/bade322d88fd93c8179e262aca9ba7f7b4417c09117879819c87946578c782ab123e3acb4733046a6e38714c47ef927360045a1f9292a1bff3a05a6577d27ca2 languageName: node linkType: hard -"typescript@patch:typescript@npm%3A^5.4.3#optional!builtin": - version: 5.4.3 - resolution: "typescript@patch:typescript@npm%3A5.4.3#optional!builtin::version=5.4.3&hash=5adc0c" +"typescript@patch:typescript@npm%3A^5.4.4#optional!builtin": + version: 5.4.4 + resolution: "typescript@patch:typescript@npm%3A5.4.4#optional!builtin::version=5.4.4&hash=5adc0c" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 10/5aedd97595582b08aadb8a70e8e3ddebaf5a9c1e5ad4d6503c2fcfc15329b5cf8d01145b09913e9555683ac16c5123a96be32b6d72614098ebd42df520eed9b1 + checksum: 10/88aff3244c31d4c6ede05b4fd28732fc8935a7fc638f2a3dcbbb767d1ac98e4b077f21ec74bc97f43c9307bc3f27e2359def1d793f9918c3429a744408fd75b4 languageName: node linkType: hard @@ -8278,9 +8310,9 @@ __metadata: languageName: node linkType: hard -"vite@npm:^5.2.7": - version: 5.2.7 - resolution: "vite@npm:5.2.7" +"vite@npm:^5.2.8": + version: 5.2.8 + resolution: "vite@npm:5.2.8" dependencies: esbuild: "npm:^0.20.1" fsevents: "npm:~2.3.3" @@ -8314,7 +8346,7 @@ __metadata: optional: true bin: vite: bin/vite.js - checksum: 10/a00173446c8392069a70a92be78b060f7e5895f28c229eb25198953daa55c16ffbddcd4e8f015f220b2b1113e12d30e7a892221de34be336b222a12cddbb78a4 + checksum: 10/caa40343c2c4e6d8e257fccb4c3029f62909c319a86063ce727ed550925c0a834460b0d1ca20c4d6c915f35302aa1052f6ec5193099a47ce21d74b9b817e69e1 languageName: node linkType: hard diff --git a/mock-api/.editorconfig b/mock-api/.editorconfig deleted file mode 100644 index 1ed453a37..000000000 --- a/mock-api/.editorconfig +++ /dev/null @@ -1,10 +0,0 @@ -root = true - -[*] -end_of_line = lf -insert_final_newline = true - -[*.{js,json,yml}] -charset = utf-8 -indent_style = space -indent_size = 2 diff --git a/mock-api/.gitattributes b/mock-api/.gitattributes deleted file mode 100644 index af3ad1281..000000000 --- a/mock-api/.gitattributes +++ /dev/null @@ -1,4 +0,0 @@ -/.yarn/** linguist-vendored -/.yarn/releases/* binary -/.yarn/plugins/**/* binary -/.pnp.* binary linguist-generated diff --git a/mock-api/.gitignore b/mock-api/.gitignore deleted file mode 100644 index 9c8f18108..000000000 --- a/mock-api/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -.pnp.* -.yarn/* -!.yarn/patches -!.yarn/plugins -!.yarn/releases -!.yarn/sdks -!.yarn/versions -uploads/* -!uploads/README.md \ No newline at end of file diff --git a/mock-api/es_server.ts b/mock-api/es_server.ts index c72cdc6a5..18e2e9509 100644 --- a/mock-api/es_server.ts +++ b/mock-api/es_server.ts @@ -64,4 +64,4 @@ rest_server.get(ES_LOG_ENDPOINT, (_req, res) => { }); // start eventsource server -rest_server.listen(port, () => console.log(`EMS-ESP EventSource server running on http://localhost:${port}/`)); +rest_server.listen(port, () => console.log(`EMS-ESP EventSource mock server running on http://localhost:${port}/`)); diff --git a/mock-api/old_server.js b/mock-api/old_server.js deleted file mode 100644 index 12e17ac92..000000000 --- a/mock-api/old_server.js +++ /dev/null @@ -1,2800 +0,0 @@ -const express = require('express'); -const compression = require('compression'); -const path = require('path'); -const msgpack = require('@msgpack/msgpack'); -const multer = require('multer'); // https://www.npmjs.com/package/multer#readme - -// REST API -const rest_server = express(); -const port = 3080; - -rest_server.use(compression()); -rest_server.use(express.static(path.join(__dirname, '../interface/build'))); -rest_server.use(express.json()); - -// uploads -const upload = multer({ dest: '../mock-api/uploads' }); - -function progress_middleware(req, res, next) { - console.log('Uploading file... '); - let progress = 0; - const file_size = req.headers['content-length']; - - // set event listener - req.on('data', async (chunk) => { - progress += chunk.length; - const percentage = (progress / file_size) * 100; - console.log(`Progress: ${Math.round(percentage)}%`); - // await delay(1000); // slow it down - delay_blocking(1000); // slow it down - }); - next(); // invoke next middleware which is multer -} - -// delays -const delay = (ms) => new Promise((res) => setTimeout(res, ms)); -function delay_blocking(milliseconds) { - var start = new Date().getTime(); - // for (var i = 0; i < 1e7; i++) { - while (true) { - if (new Date().getTime() - start > milliseconds) { - break; - } - } -} - -// endpoints -const API_ENDPOINT_ROOT = '/api/'; -const REST_ENDPOINT_ROOT = '/rest/'; - -// network poll -let countWifiScanPoll = 0; - -// LOG -const LOG_SETTINGS_ENDPOINT = REST_ENDPOINT_ROOT + 'logSettings'; -log_settings = { - level: 6, - max_messages: 50, - compact: false -}; - -const FETCH_LOG_ENDPOINT = REST_ENDPOINT_ROOT + 'fetchLog'; -let fetch_log = { - events: [ - { - t: '000+00:00:00.001', - l: 3, - i: 1, - n: 'system', - m: 'this is message 3' - }, - { - t: '000+00:00:00.002', - l: 4, - i: 2, - n: 'ntp', - m: 'this is message 4' - }, - { - t: '000+00:00:00.002', - l: 5, - i: 3, - n: 'mqtt', - m: 'this is message 5' - }, - { - t: '000+00:00:00.002', - l: 6, - i: 444, - n: 'command', - m: 'this is message 6' - }, - { - t: '000+00:00:00.002', - l: 7, - i: 5555, - n: 'emsesp', - m: 'this is message 7' - }, - { - t: '000+00:00:00.002', - l: 8, - i: 666666, - n: 'thermostat', - m: 'this is message 8' - } - ] -}; - -// NTP -const NTP_STATUS_ENDPOINT = REST_ENDPOINT_ROOT + 'ntpStatus'; -const NTP_SETTINGS_ENDPOINT = REST_ENDPOINT_ROOT + 'ntpSettings'; -const TIME_ENDPOINT = REST_ENDPOINT_ROOT + 'time'; -ntp_settings = { - enabled: true, - server: 'time.google.com', - tz_label: 'Europe/Amsterdam', - tz_format: 'CET-1CEST,M3.5.0,M10.5.0/3' -}; -const ntp_status = { - status: 1, - utc_time: '2021-04-01T14:25:42Z', - local_time: '2021-04-01T16:25:42', - server: 'time.google.com', - uptime: 856 -}; - -// AP -const AP_SETTINGS_ENDPOINT = REST_ENDPOINT_ROOT + 'apSettings'; -const AP_STATUS_ENDPOINT = REST_ENDPOINT_ROOT + 'apStatus'; -ap_settings = { - provision_mode: 1, - ssid: 'ems-esp', - password: 'ems-esp-neo', - local_ip: '192.168.4.1', - gateway_ip: '192.168.4.1', - subnet_mask: '255.255.255.0', - channel: 1, - ssid_hidden: true, - max_clients: 4 -}; -ap_status = { - status: 1, - ip_address: '192.168.4.1', - mac_address: '3C:61:05:03:AB:2D', - station_num: 0 -}; - -// NETWORK -const NETWORK_SETTINGS_ENDPOINT = REST_ENDPOINT_ROOT + 'networkSettings'; -const NETWORK_STATUS_ENDPOINT = REST_ENDPOINT_ROOT + 'networkStatus'; -const SCAN_NETWORKS_ENDPOINT = REST_ENDPOINT_ROOT + 'scanNetworks'; -const LIST_NETWORKS_ENDPOINT = REST_ENDPOINT_ROOT + 'listNetworks'; -network_settings = { - ssid: 'myWifi', - password: 'myPassword', - hostname: 'ems-esp', - nosleep: true, - tx_power: 0, - bandwidth20: false, - static_ip_config: false, - enableMDNS: true, - enableCORS: false, - CORSOrigin: '*', - enableIPv6: false, - local_ip: '', - gateway_ip: '', - subnet_mask: '', - dns_ip_1: '', - dns_ip_2: '' -}; -const network_status = { - status: 3, - local_ip: '10.10.10.101', - mac_address: '3C:61:05:03:AB:2C', - rssi: -41, - ssid: 'home', - bssid: '06:ED:DA:FE:B4:68', - channel: 11, - subnet_mask: '255.255.255.0', - gateway_ip: '10.10.10.1', - dns_ip_1: '10.10.10.1', - dns_ip_2: '0.0.0.0' -}; -const list_networks = { - networks: [ - { - rssi: -40, - ssid: '', - bssid: 'FC:EC:DA:FD:B4:68', - channel: 11, - encryption_type: 3 - }, - { - rssi: -41, - ssid: 'home', - bssid: '02:EC:DA:FD:B4:68', - channel: 11, - encryption_type: 3 - }, - { - rssi: -42, - ssid: '', - bssid: '06:EC:DA:FD:B4:68', - channel: 11, - encryption_type: 3 - }, - { - rssi: -73, - ssid: '', - bssid: 'FC:EC:DA:17:D4:7E', - channel: 1, - encryption_type: 3 - }, - { - rssi: -73, - ssid: 'office', - bssid: '02:EC:DA:17:D4:7E', - channel: 1, - encryption_type: 3 - }, - { - rssi: -75, - ssid: 'Erica', - bssid: 'C8:D7:19:9A:88:BD', - channel: 2, - encryption_type: 3 - }, - { - rssi: -75, - ssid: '', - bssid: 'C6:C9:E3:FF:A5:DE', - channel: 2, - encryption_type: 3 - }, - { - rssi: -76, - ssid: 'Bruin', - bssid: 'C0:C9:E3:FF:A5:DE', - channel: 2, - encryption_type: 3 - } - ] -}; - -// OTA -const OTA_SETTINGS_ENDPOINT = REST_ENDPOINT_ROOT + 'otaSettings'; -ota_settings = { - enabled: true, - port: 8266, - password: 'ems-esp-neo' -}; - -// MQTT -const MQTT_SETTINGS_ENDPOINT = REST_ENDPOINT_ROOT + 'mqttSettings'; -const MQTT_STATUS_ENDPOINT = REST_ENDPOINT_ROOT + 'mqttStatus'; -mqtt_settings = { - enabled: true, - host: '192.168.1.4', - port: 1883, - base: 'ems-esp', - username: '', - password: '', - client_id: 'ems-esp', - keep_alive: 60, - clean_session: true, - entity_format: 1, - publish_time_boiler: 10, - publish_time_thermostat: 10, - publish_time_solar: 10, - publish_time_mixer: 10, - publish_time_other: 10, - publish_time_sensor: 10, - publish_time_heartbeat: 60, - mqtt_qos: 0, - rootCA: '', - mqtt_retain: false, - ha_enabled: true, - nested_format: 1, - discovery_type: 0, - discovery_prefix: 'homeassistant', - send_response: true, - publish_single: false -}; -const mqtt_status = { - enabled: true, - connected: true, - client_id: 'ems-esp', - disconnect_reason: 0, - mqtt_fails: 0, - mqtt_queued: 1, - connect_count: 2 -}; - -// SYSTEM -const FEATURES_ENDPOINT = REST_ENDPOINT_ROOT + 'features'; -const VERIFY_AUTHORIZATION_ENDPOINT = REST_ENDPOINT_ROOT + 'verifyAuthorization'; -const SYSTEM_STATUS_ENDPOINT = REST_ENDPOINT_ROOT + 'systemStatus'; -const SECURITY_SETTINGS_ENDPOINT = REST_ENDPOINT_ROOT + 'securitySettings'; -const RESTART_ENDPOINT = REST_ENDPOINT_ROOT + 'restart'; -const FACTORY_RESET_ENDPOINT = REST_ENDPOINT_ROOT + 'factoryReset'; -const UPLOAD_FILE_ENDPOINT = REST_ENDPOINT_ROOT + 'uploadFile'; -const SIGN_IN_ENDPOINT = REST_ENDPOINT_ROOT + 'signIn'; -const GENERATE_TOKEN_ENDPOINT = REST_ENDPOINT_ROOT + 'generateToken'; - -let system_status = { - emsesp_version: '3.x-demo', - esp_platform: 'ESP32', - max_alloc_heap: 89, - psram_size: 0, - free_psram: 0, - cpu_freq_mhz: 240, - free_heap: 143, - sdk_version: 'v4.4.2', - flash_chip_size: 4096, - flash_chip_speed: 40000000, - fs_used: 40, - fs_free: 24, - app_used: 1863, - app_free: 121, - uptime: '000+00:15:42.707' -}; -security_settings = { - jwt_secret: 'naughty!', - users: [ - { username: 'admin', password: 'admin', admin: true }, - { username: 'guest', password: 'guest', admin: false } - ] -}; -const features = { - version: 'v3.6-demo', - // platform: 'ESP32' - platform: 'ESP32-S3' -}; -const verify_authentication = { access_token: '1234' }; -const signin = { - access_token: - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiYWRtaW4iOnRydWUsInZlcnNpb24iOiIzLjAuMmIwIn0.MsHSgoJKI1lyYz77EiT5ZN3ECMrb4mPv9FNy3udq0TU' -}; -const generate_token = { token: '1234' }; - -// EMS-ESP Project specific -const EMSESP_SETTINGS_ENDPOINT = REST_ENDPOINT_ROOT + 'settings'; -const EMSESP_CORE_DATA_ENDPOINT = REST_ENDPOINT_ROOT + 'coreData'; -const EMSESP_SENSOR_DATA_ENDPOINT = REST_ENDPOINT_ROOT + 'sensorData'; -const EMSESP_DEVICES_ENDPOINT = REST_ENDPOINT_ROOT + 'devices'; -const EMSESP_SCANDEVICES_ENDPOINT = REST_ENDPOINT_ROOT + 'scanDevices'; -const EMSESP_DEVICEDATA_ENDPOINT = REST_ENDPOINT_ROOT + 'deviceData'; -const EMSESP_DEVICEENTITIES_ENDPOINT = REST_ENDPOINT_ROOT + 'deviceEntities'; -const EMSESP_STATUS_ENDPOINT = REST_ENDPOINT_ROOT + 'status'; -const EMSESP_BOARDPROFILE_ENDPOINT = REST_ENDPOINT_ROOT + 'boardProfile'; -const EMSESP_WRITE_VALUE_ENDPOINT = REST_ENDPOINT_ROOT + 'writeDeviceValue'; -const EMSESP_WRITE_SENSOR_ENDPOINT = REST_ENDPOINT_ROOT + 'writeTemperatureSensor'; -const EMSESP_WRITE_ANALOG_ENDPOINT = REST_ENDPOINT_ROOT + 'writeAnalogSensor'; -const EMSESP_CUSTOMIZATION_ENTITIES_ENDPOINT = REST_ENDPOINT_ROOT + 'customizationEntities'; -const EMSESP_RESET_CUSTOMIZATIONS_ENDPOINT = REST_ENDPOINT_ROOT + 'resetCustomizations'; -const EMSESP_WRITE_SCHEDULE_ENDPOINT = REST_ENDPOINT_ROOT + 'schedule'; -const EMSESP_WRITE_ENTITIES_ENDPOINT = REST_ENDPOINT_ROOT + 'entities'; - -const emsesp_info = { - System: { - version: '3.7.0', - uptime: '001+06:40:34.018', - 'uptime (seconds)': 110434, - freemem: 131, - 'reset reason': 'Software reset CPU / Software reset CPU', - 'Sensor sensors': 3 - }, - Network: { - connection: 'Ethernet', - hostname: 'ems-esp', - MAC: 'A8:03:2A:62:64:CF', - 'IPv4 address': '192.168.1.134/255.255.255.0', - 'IPv4 gateway': '192.168.1.1', - 'IPv4 nameserver': '192.168.1.1' - }, - Status: { - 'bus status': 'connected', - 'bus protocol': 'Buderus', - 'telegrams received': 84986, - 'read requests sent': 14748, - 'write requests sent': 3, - 'incomplete telegrams': 8, - 'tx fails': 0, - 'rx line quality': 100, - 'tx line quality': 100, - MQTT: 'connected', - 'MQTT publishes': 46336, - 'MQTT publish fails': 0, - 'Sensor reads': 22086, - 'Sensor fails': 0 - }, - Devices: [ - { - type: 'Boiler', - name: 'Nefit GBx72/Trendline/Cerapur/Greenstar Si/27i (DeviceID:0x08 ProductID:123, Version:06.01)', - handlers: - '0x10 0x11 0xC2 0x14 0x15 0x1C 0x18 0x19 0x1A 0x35 0x16 0x33 0x34 0x26 0x2A 0xD1 0xE3 0xE4 0xE5 0xE6 0xE9 0xEA' - }, - { - type: 'Thermostat', - name: 'RC20/Moduline 300 (DeviceID:0x17, ProductID:77, Version:03.03)', - handlers: '0xA3 0x06 0xA2 0x12 0x91 0xA8' - } - ] -}; - -settings = { - locale: 'en', - tx_mode: 4, - ems_bus_id: 11, - syslog_enabled: false, - syslog_level: 3, - trace_raw: false, - syslog_mark_interval: 0, - syslog_host: '192.168.1.4', - syslog_port: 514, - shower_timer: true, - shower_alert: true, - shower_alert_trigger: 7, - shower_alert_coldshot: 10, - rx_gpio: 23, - tx_gpio: 5, - phy_type: 0, - eth_power: 0, - eth_phy_addr: 0, - eth_clock_mode: 0, - dallas_gpio: 3, - dallas_parasite: false, - led_gpio: 2, - hide_led: false, - notoken_api: false, - readonly_mode: false, - low_clock: false, - telnet_enabled: true, - analog_enabled: false, - pbutton_gpio: 0, - board_profile: 'S32', - bool_format: 1, - bool_dashboard: 1, - enum_format: 1, - fahrenheit: false -}; - -// this is used in customizations -const emsesp_devices = { - devices: [ - { - i: 2, - s: 'Thermostat (RC20/Moduline 300)', - t: 5, - tn: 'thermostat' - }, - { - i: 7, - s: 'Boiler (GBx72/Trendline/Cerapur/Greenstar Si/27i)', - t: 4, - tn: 'boiler' - }, - { - i: 4, - s: 'Thermostat (RC100/Moduline 1000/1010)', - t: 5, - tn: 'thermostat' - } - ] -}; - -const emsesp_coredata = { - connected: true, - // devices: [], - devices: [ - { - id: 7, - t: 4, - tn: 'Boiler', - b: 'Nefit', - n: 'GBx72/Trendline/Cerapur/Greenstar Si/27i', - // n: 'Enviline/Compress 6000AW/Hybrid 3000-7000iAW/SupraEco/Geo 5xx/WLW196i/WSW196i', - d: 8, - p: 123, - v: '06.01', - e: 69 - }, - { - id: 3, - t: 4, - tn: 'Boiler', - b: 'Buderus', - n: 'GB125/GB135/MC10', - d: 8, - p: 123, - v: '06.01', - e: 73 - }, - { - id: 1, - t: 5, - tn: 'Thermostat', - b: 'Buderus', - n: 'RC35', - d: 24, - p: 86, - v: '04.01', - e: 57 - }, - { - id: 2, - t: 5, - tn: 'Thermostat', - b: '', - n: 'RC20/Moduline 300', - d: 23, - p: 77, - v: '03.03', - e: 6 - }, - { - id: 4, - t: 5, - tn: 'Thermostat', - b: 'Buderus', - n: 'RC100/Moduline 1000/1010', - d: 16, - p: 165, - v: '04.01', - e: 3 - }, - { - id: 5, - t: 6, - tn: 'Mixer Module', - b: 'Buderus', - n: 'MM10', - d: 32, - p: 69, - v: '01.01', - e: 6 - }, - { - id: 6, - t: 7, - tn: 'Solar Module', - b: 'Buderus', - n: 'SM10', - d: 48, - p: 73, - v: '01.02', - e: 22 - }, - { - id: 99, - t: 17, - tn: 'Custom', - b: '', - n: 'Custom Entities', - d: 1, - p: 1, - v: '', - e: 1 - } - ] -}; - -const emsesp_sensordata = { - // ts: [], - ts: [ - { id: '28-233D-9497-0C03', n: 'Dallas 1', t: 25.7, o: 1.2, u: 1 }, - { id: '28-243D-7437-1E3A', n: 'Dallas 2 outside', t: 26.1, o: 0, u: 1 }, - { id: '28-243E-7437-1E3B', n: 'Zolder', t: 27.1, o: 0, u: 16 }, - { id: '28-183D-1892-0C33', n: 'Roof', o: 2, u: 1 } // no temperature - ], - // as: [], - as: [ - { id: 1, g: 36, n: 'motor', v: 0, u: 0, o: 17, f: 0, t: 0, d: false }, - { id: 2, g: 37, n: 'External switch', v: 13, u: 0, o: 17, f: 0, t: 1, d: false }, - { id: 3, g: 39, n: 'Pulse count', v: 144, u: 0, o: 0, f: 0, t: 2, d: false }, - { id: 4, g: 40, n: 'Pressure', v: 16, u: 17, o: 0, f: 0, t: 3, d: false } - ], - analog_enabled: true -}; - -const status = { - status: 0, - // status: 2, - tx_mode: 1, - uptime: 77186, - num_devices: 2, - num_sensors: 1, - num_analogs: 1, - stats: [ - { id: 0, s: 56506, f: 11, q: 100 }, - { id: 1, s: 9026, f: 0, q: 100 }, - { id: 2, s: 33, f: 2, q: 95 }, - { id: 3, s: 56506, f: 11, q: 100 }, - { id: 4, s: 0, f: 0, q: 100 }, - { id: 5, s: 12, f: 10, q: 20 }, - { id: 6, s: 0, f: 0, q: 0 } - ] -}; - -// Dashboard data -// 1 - RC35 thermo -// 2 - RC20 thermo -// 3 - Buderus GB125 boiler -// 4 - RC100 themo -// 5 - Mixer MM10 -// 6 - Solar SM10 -// 7 - Nefit Trendline boiler -// 99 - Custom - -const emsesp_devicedata_1 = { - data: [ - { - v: '22(816) 01.05.2023 13:07 (1 min)', - u: 0, - id: '00last error code' - }, - { - v: '05.05.2023 09:44', - u: 0, - id: '00date/time', - c: 'datetime', - h: '< NTP | dd.mm.yyyy-hh:mm:ss-day(0-6)-dst(0/1) >' - }, - { - v: -2.4, - u: 2, - id: '00internal temperature offset', - c: 'intoffset', - m: -5, - x: 5, - s: 0.1 - }, - { - v: -11, - u: 1, - id: '00minimal external temperature', - c: 'minexttemp', - m: -30, - x: 0, - s: 1 - }, - { - v: 29.5, - u: 1, - id: '00temperature sensor 1' - }, - { - v: 32.5, - u: 1, - id: '00temperature sensor 2' - }, - { - v: 'on', - u: 0, - id: '00damping outdoor temperature', - c: 'damping', - l: ['off', 'on'] - }, - { - v: 13, - u: 1, - id: '00damped outdoor temperature' - }, - { - v: 'medium', - u: 0, - id: '00building type', - c: 'building', - l: ['light', 'medium', 'heavy'] - }, - { - v: 'auto', - u: 0, - id: '00dhw mode', - c: 'wwmode', - l: ['off', 'on', 'auto'] - }, - { - v: 'off', - u: 0, - id: '00dhw circulation pump mode', - c: 'wwcircmode', - l: ['off', 'on', 'auto'] - }, - { - v: 'std prog', - u: 0, - id: '00dhw program', - c: 'wwprogmode', - l: ['std prog', 'own prog'] - }, - { - v: 'std prog', - u: 0, - id: '00dhw circulation program', - c: 'wwcircprog', - l: ['std prog', 'own prog'] - }, - { - v: 'off', - u: 0, - id: '00dhw disinfecting', - c: 'wwdisinfecting', - l: ['off', 'on'] - }, - { - v: 'tu', - u: 0, - id: '00dhw disinfection day', - c: 'wwdisinfectday', - l: ['mo', 'tu', 'we', 'th', 'fr', 'sa', 'su', 'all'] - }, - { - v: 1, - u: 0, - id: '00dhw disinfection hour', - c: 'wwdisinfecthour', - m: 0, - x: 23, - s: 1 - }, - { - v: 60, - u: 1, - id: '00dhw maximum temperature', - c: 'wwmaxtemp', - m: 60, - x: 80, - s: 1 - }, - { - v: 'on', - u: 0, - id: '00dhw one time key function', - c: 'wwonetimekey', - l: ['off', 'on'] - }, - { - v: '00 mo 06:00 on', - u: 0, - id: '00dhw program switchtime', - c: 'wwswitchtime', - h: ' [ not_set | day hh:mm on|off ]' - }, - { - v: '00 mo 06:30 on', - u: 0, - id: '00dhw circulation program switchtime', - c: 'wwcircswitchtime', - h: ' [ not_set | day hh:mm on|off ]' - }, - { - v: '01.01.2000-01.01.2000', - u: 0, - id: '00dhw holiday dates', - c: 'wwholidays', - h: 'dd.mm.yyyy-dd.mm.yyyy' - }, - { - v: '01.01.2019-12.01.2019', - u: 0, - id: '00dhw vacation dates', - c: 'wwvacations', - h: 'dd.mm.yyyy-dd.mm.yyyy' - }, - { - v: 21, - u: 1, - id: '00hc2 selected room temperature', - c: 'hc2/seltemp', - m: 0, - x: 30, - s: 0.5 - }, - { - v: 'auto', - u: 0, - id: '00hc2 mode', - c: 'hc2/mode', - l: ['night', 'day', 'auto'] - }, - { - v: 'day', - u: 0, - id: '00hc2 mode type' - }, - { - v: 21, - u: 1, - id: '00hc2 day temperature', - c: 'hc2/daytemp', - m: 5, - x: 30, - s: 0.5 - }, - { - v: 17, - u: 1, - id: '00hc2 night temperature', - c: 'hc2/nighttemp', - m: 5, - x: 30, - s: 0.5 - }, - { - v: 58, - u: 1, - id: '00hc2 design temperature', - c: 'hc2/designtemp', - m: 30, - x: 90, - s: 1 - }, - { - v: 0, - u: 2, - id: '00hc2 offset temperature', - c: 'hc2/offsettemp', - m: -5, - x: 5, - s: 0.5 - }, - { - v: 15, - u: 1, - id: '00hc2 holiday temperature', - c: 'hc2/holidaytemp', - m: 5, - x: 30, - s: 0.5 - }, - { - v: 34, - u: 1, - id: '00hc2 target flow temperature' - }, - { - v: 17, - u: 1, - id: '00hc2 summer temperature', - c: 'hc2/summertemp', - m: 9, - x: 25, - s: 1 - }, - { - v: 'winter', - u: 0, - id: '00hc2 summer mode' - }, - { - v: 'off', - u: 0, - id: '00hc2 holiday mode' - }, - { - v: -10, - u: 1, - id: '00hc2 nofrost temperature', - c: 'hc2/nofrosttemp', - m: -20, - x: 10, - s: 1 - }, - { - v: 'outdoor', - u: 0, - id: '00hc2 nofrost mode', - c: 'hc2/nofrostmode', - l: ['off', 'outdoor', 'room'] - }, - { - v: 0, - u: 2, - id: '00hc2 room influence', - c: 'hc2/roominfluence', - m: 0, - x: 10, - s: 1 - }, - { - v: 15, - u: 1, - id: '00hc2 min flow temperature', - c: 'hc2/minflowtemp', - m: 5, - x: 70, - s: 1 - }, - { - v: 85, - u: 1, - id: '00hc2 max flow temperature', - c: 'hc2/maxflowtemp', - m: 30, - x: 90, - s: 1 - }, - { - v: 0, - u: 2, - id: '00hc2 flow temperature offset for mixer', - c: 'hc2/flowtempoffset', - m: 0, - x: 20, - s: 1 - }, - { - v: 'radiator', - u: 0, - id: '00hc2 heating type', - c: 'hc2/heatingtype', - l: ['off', 'radiator', 'convector', 'floor'] - }, - { - v: 'outdoor', - u: 0, - id: '00hc2 reduce mode', - c: 'hc2/reducemode', - l: ['nofrost', 'reduce', 'room', 'outdoor'] - }, - { - v: 'outdoor', - u: 0, - id: '00hc2 control mode', - c: 'hc2/controlmode', - l: ['outdoor', 'room'] - }, - { - v: 'RC3x', - u: 0, - id: '00hc2 control device', - c: 'hc2/control', - l: ['off', 'RC20', 'RC3x'] - }, - { - v: '01.01.2000-01.01.2000', - u: 0, - id: '00hc2 holiday dates', - c: 'hc2/holidays', - h: 'dd.mm.yyyy-dd.mm.yyyy' - }, - { - v: '01.01.2020-12.01.2020', - u: 0, - id: '00hc2 vacation dates', - c: 'hc2/vacations', - h: 'dd.mm.yyyy-dd.mm.yyyy' - }, - { - v: 'own 1', - u: 0, - id: '00hc2 program', - c: 'hc2/program', - l: ['own 1', 'family', 'morning', 'evening', 'am', 'pm', 'midday', 'singles', 'seniors', 'new', 'own 2'] - }, - { - v: 0, - u: 7, - id: '00hc2 pause time', - c: 'hc2/pause', - m: 0, - x: 99, - s: 1 - }, - { - v: 0, - u: 7, - id: '00hc2 party time', - c: 'hc2/party', - m: 0, - x: 99, - s: 1 - }, - { - v: 0, - u: 1, - id: '00hc2 temporary set temperature automode', - c: 'hc2/tempautotemp', - m: 0, - x: 30, - s: 0.5 - }, - { - v: -20, - u: 1, - id: '00hc2 no reduce below temperature', - c: 'hc2/noreducetemp', - m: -30, - x: 10, - s: 1 - }, - { - v: 8, - u: 1, - id: '00hc2 off/reduce switch temperature', - c: 'hc2/reducetemp', - m: -20, - x: 10, - s: 1 - }, - { - v: 5, - u: 1, - id: '00hc2 vacations off/reduce switch temperature', - c: 'hc2/vacreducetemp', - m: -20, - x: 10, - s: 1 - }, - { - v: 'outdoor', - u: 0, - id: '00hc2 vacations reduce mode', - c: 'hc2/vacreducemode', - l: ['nofrost', 'reduce', 'room', 'outdoor'] - }, - { - v: 'off', - u: 0, - id: '00hc2 dhw priority', - c: 'hc2/wwprio', - l: ['off', 'on'] - }, - { - v: '00 mo 05:50 on', - u: 0, - id: '00hc2 own1 program switchtime', - c: 'hc2/switchtime1', - h: ' [ not_set | day hh:mm on|off ]' - }, - { - v: '00 mo 06:30 on', - u: 0, - id: '00hc2 own2 program switchtime', - c: 'hc2/switchtime2', - h: ' [ not_set | day hh:mm on|off ]' - } - ] -}; - -const emsesp_devicedata_2 = { - data: [ - { - v: '(0)', - u: 0, - id: '08my custom error code' - }, - { - v: '14:54:39 06/06/2021', - u: 0, - id: '00date/time' - }, - { - v: 18.2, - u: 1, - id: '00Chosen Room Temperature', - c: 'hc1/seltemp', - m: 5, - x: 52, - s: 0.5 - }, - { - v: 22.6, - u: 1, - id: '00hc1 current room temperature' - }, - { - v: 'auto', - u: 0, - id: '00hc1 mode', - c: 'hc1/mode', - l: ['off', 'on', 'auto'] - }, - { - v: '00 mo 00:00 T1', - u: 0, - id: '00hc1 program switchtime', - c: 'hc1/switchtime', - h: ' [ not_set | day hh:mm Tn ]' - } - ] -}; - -const emsesp_devicedata_3 = { - data: [ - { - v: '', - u: 0, - id: '08reset', - c: 'reset', - l: ['-', 'maintenance', 'error'] - }, - { - v: 34, - u: 1, - id: '08selected flow temperature', - c: 'selflowtemp', - m: 0, - x: 90, - s: 1 - }, - { - v: 30.7, - u: 1, - id: '08current flow temperature' - }, - { - v: 176544, - u: 0, - id: '08burner starts' - }, - { - v: '6L(517) 18.01.2023 10:18 (0 min)', - u: 0, - id: '08last error code' - }, - { - v: 'off', - u: 0, - id: '00force heating off', - c: 'heatingoff', - l: ['off', 'on'] - }, - { - v: 'off', - u: 0, - id: '00heating active' - }, - { - v: 'off', - u: 0, - id: '00tapwater active' - }, - { - v: 0, - u: 3, - id: '00heating pump modulation' - }, - { - v: 15, - u: 1, - id: '00outside temperature' - }, - { - v: 30.7, - u: 1, - id: '00actual boiler temperature' - }, - { - v: 29, - u: 1, - id: '00exhaust temperature' - }, - { - v: 'off', - u: 0, - id: '00gas' - }, - { - v: 'off', - u: 0, - id: '00gas stage 2' - }, - { - v: 0, - u: 9, - id: '00flame current' - }, - { - v: 'off', - u: 0, - id: '00heating pump' - }, - { - v: 'off', - u: 0, - id: '00fan' - }, - { - v: 'off', - u: 0, - id: '00ignition' - }, - { - v: 'off', - u: 0, - id: '00oil preheating' - }, - { - v: 'on', - u: 0, - id: '00heating activated', - c: 'heatingactivated', - l: ['off', 'on'] - }, - { - v: 90, - u: 1, - id: '00heating temperature', - c: 'heatingtemp', - m: 0, - x: 90, - s: 1 - }, - { - v: 100, - u: 3, - id: '00boiler pump max power', - c: 'pumpmodmax', - m: 0, - x: 100, - s: 1 - }, - { - v: 100, - u: 3, - id: '00boiler pump min power', - c: 'pumpmodmin', - m: 0, - x: 100, - s: 1 - }, - { - v: 'deltaP-2', - u: 0, - id: '00boiler pump mode', - c: 'pumpmode', - l: ['proportional', 'deltaP-1', 'deltaP-2', 'deltaP-3', 'deltaP-4'] - }, - { - v: 6, - u: 8, - id: '00pump delay', - c: 'pumpdelay', - m: 0, - x: 60, - s: 1 - }, - { - v: 15, - u: 8, - id: '00burner min period', - c: 'burnminperiod', - m: 0, - x: 120, - s: 1 - }, - { - v: 0, - u: 3, - id: '00burner min power', - c: 'burnminpower', - m: 0, - x: 100, - s: 1 - }, - { - v: 100, - u: 3, - id: '00burner max power', - c: 'burnmaxpower', - m: 0, - x: 254, - s: 1 - }, - { - v: -8, - u: 2, - id: '00hysteresis on temperature', - c: 'boilhyston', - m: -20, - x: 0, - s: 1 - }, - { - v: 15, - u: 2, - id: '00hysteresis off temperature', - c: 'boilhystoff', - m: 0, - x: 20, - s: 1 - }, - { - v: -8, - u: 2, - id: '00hysteresis stage 2 on temperature', - c: 'boil2hyston', - m: -20, - x: 0, - s: 1 - }, - { - v: 8, - u: 2, - id: '00hysteresis stage 2 off temperature', - c: 'boil2hystoff', - m: 0, - x: 20, - s: 1 - }, - { - v: 34, - u: 1, - id: '00set flow temperature' - }, - { - v: 100, - u: 3, - id: '00burner set power' - }, - { - v: 100, - u: 3, - id: '00burner selected max power', - c: 'selburnpow', - m: 0, - x: 254, - s: 1 - }, - { - v: 0, - u: 3, - id: '00burner current power' - }, - { - v: 822273, - u: 8, - id: '00total burner operating time' - }, - { - v: 0, - u: 8, - id: '00burner stage 2 operating time' - }, - { - v: 787124, - u: 8, - id: '00total heat operating time' - }, - { - v: 173700, - u: 0, - id: '00burner starts heating' - }, - { - v: 5495341, - u: 8, - id: '00total UBA operating time' - }, - { - v: '0Y', - u: 0, - id: '00service code' - }, - { - v: 0, - u: 0, - id: '00service code number' - }, - { - v: 'H00', - u: 0, - id: '00maintenance message' - }, - { - v: 'date', - u: 0, - id: '00maintenance scheduled', - c: 'maintenance', - l: ['off', 'time', 'date', 'manual'] - }, - { - v: 6000, - u: 7, - id: '00time to next maintenance', - c: 'maintenancetime', - m: 0, - x: 31999, - s: 1 - }, - { - v: '30.06.2023', - u: 0, - id: '00next maintenance date', - c: 'maintenancedate', - h: 'dd.mm.yyyy' - }, - { - v: 46, - u: 1, - id: '00dhw set temperature' - }, - { - v: 47, - u: 1, - id: '00dhw selected temperature', - c: 'wwseltemp', - m: 0, - x: 254, - s: 1 - }, - { - v: 'buffer', - u: 0, - id: '00dhw type' - }, - { - v: 'hot', - u: 0, - id: '00dhw comfort', - c: 'wwcomfort', - l: ['hot', 'eco', 'intelligent'] - }, - { - v: 40, - u: 2, - id: '00dhw flow temperature offset', - c: 'wwflowtempoffset', - m: 0, - x: 100, - s: 1 - }, - { - v: 'on', - u: 0, - id: '00dhw circulation pump available', - c: 'wwcircpump', - l: ['off', 'on'] - }, - { - v: 'chargepump', - u: 0, - id: '00dhw charging type' - }, - { - v: -5, - u: 2, - id: '00dhw hysteresis on temperature', - c: 'wwhyston', - m: -126, - x: 126, - s: 1 - }, - { - v: -1, - u: 2, - id: '00dhw hysteresis off temperature', - c: 'wwhystoff', - m: -126, - x: 126, - s: 1 - }, - { - v: 70, - u: 1, - id: '00dhw disinfection temperature', - c: 'wwdisinfectiontemp', - m: 0, - x: 254, - s: 1 - }, - { - v: 'continuous', - u: 0, - id: '00dhw circulation pump mode', - c: 'wwcircmode', - l: ['off', '1x3min', '2x3min', '3x3min', '4x3min', '5x3min', '6x3min', 'continuous'] - }, - { - v: 'off', - u: 0, - id: '00dhw circulation active', - c: 'wwcirc', - l: ['off', 'on'] - }, - { - v: 60.7, - u: 1, - id: '00dhw current intern temperature' - }, - { - v: 0, - u: 4, - id: '00dhw current tap water flow' - }, - { - v: 60.7, - u: 1, - id: '00dhw storage intern temperature' - }, - { - v: 'on', - u: 0, - id: '00dhw activated', - c: 'wwactivated', - l: ['off', 'on'] - }, - { - v: 'off', - u: 0, - id: '00dhw one time charging', - c: 'wwonetime', - l: ['off', 'on'] - }, - { - v: 'off', - u: 0, - id: '00dhw disinfecting', - c: 'wwdisinfecting', - l: ['off', 'on'] - }, - { - v: 'off', - u: 0, - id: '00dhw charging' - }, - { - v: 'off', - u: 0, - id: '00dhw recharging' - }, - { - v: 'on', - u: 0, - id: '00dhw temperature ok' - }, - { - v: 'off', - u: 0, - id: '00dhw active' - }, - { - v: 'off', - u: 0, - id: '00dhw 3-way valve active' - }, - { - v: 0, - u: 3, - id: '00dhw set pump power' - }, - { - v: 6976, - u: 0, - id: '00dhw starts' - }, - { - v: 80644, - u: 8, - id: '00dhw active time' - } - ] -}; - -const emsesp_devicedata_4 = { - data: [ - { - v: 16, - u: 1, - id: '08hc2 selected room temperature', - c: 'hc2/seltemp' - }, - { - v: 18.6, - u: 1, - id: '02hc2 current room temperature', - c: '' - }, - { - v: 'off', - u: 0, - id: '02hc2 mode', - c: 'hc2/mode', - l: ['off', 'on', 'auto'] - } - ] -}; - -const emsesp_devicedata_5 = { - data: [ - { - v: 30, - u: 1, - id: '00hc2 flow temperature (TC1)' - }, - { - v: 100, - u: 3, - id: '00hc2 mixing valve actuator (VC1)' - }, - { - v: 34, - u: 1, - id: '00hc2 setpoint flow temperature', - c: 'hc2/flowsettemp', - m: 0, - x: 254, - s: 1 - }, - { - v: 'off', - u: 0, - id: '00hc2 pump status (PC1)', - c: 'hc2/pumpstatus', - l: ['off', 'on'] - }, - { - v: 'on', - u: 0, - id: '00hc2 activated', - c: 'hc2/activated', - l: ['off', 'on'] - }, - { - v: 120, - u: 14, - id: '00hc2 time to set valve', - c: 'hc2/valvesettime', - m: 10, - x: 120, - s: 10 - } - ] -}; - -const emsesp_devicedata_6 = { - data: [ - { - v: 43.9, - u: 1, - id: '00collector temperature (TS1)' - }, - { - v: 28.3, - u: 1, - id: '00cylinder bottom temperature (TS2)' - }, - { - v: 'on', - u: 0, - id: '00pump (PS1)' - }, - { - v: 181884, - u: 8, - id: '00pump working time' - }, - { - v: 90, - u: 1, - id: '00maximum cylinder temperature', - c: 'cylmaxtemp', - m: 0, - x: 254, - s: 1 - }, - { - v: 'off', - u: 0, - id: '00collector shutdown' - }, - { - v: 'off', - u: 0, - id: '00cyl heated' - }, - { - v: 32, - u: 3, - id: '00pump modulation (PS1)' - }, - { - v: 30, - u: 3, - id: '00minimum pump modulation', - c: 'pumpminmod', - m: 0, - x: 100, - s: 1 - }, - { - v: 10, - u: 2, - id: '00pump turn on difference', - c: 'turnondiff', - m: 0, - x: 254, - s: 1 - }, - { - v: 5, - u: 2, - id: '00pump turn off difference', - c: 'turnoffdiff', - m: 0, - x: 254, - s: 1 - }, - { - v: 899, - u: 12, - id: '00actual solar power' - }, - { - v: 94, - u: 6, - id: '00energy last hour' - }, - { - v: 3, - u: 4, - id: '00maximum solar flow', - c: 'maxflow', - m: 0, - x: 25, - s: 0.1 - }, - { - v: 37, - u: 1, - id: '00dhw minimum temperature', - c: 'wwmintemp', - m: 0, - x: 254, - s: 1 - }, - { - v: 'on', - u: 0, - id: '00solarmodule enabled', - c: 'solarenabled', - l: ['off', 'on'] - }, - { - v: 11, - u: 0, - id: '00unknown setting 3', - c: 'setting3', - m: 0, - x: 254, - s: 1 - }, - { - v: 2, - u: 0, - id: '00unknown setting 4', - c: 'setting4', - m: 0, - x: 254, - s: 1 - }, - { - v: 0, - u: 0, - id: '00unknown datafield 11' - }, - { - v: 1, - u: 0, - id: '00unknown datafield 12' - }, - { - v: 0, - u: 0, - id: '00unknown datafield 1' - }, - { - v: 0, - u: 0, - id: '00unknown datafield 0' - } - ] -}; - -const emsesp_devicedata_7 = { - data: [ - { v: '', u: 0, id: '08reset', c: 'reset', l: ['-', 'maintenance', 'error'] }, - { v: 'off', u: 0, id: '08heating active' }, - { v: 'off', u: 0, id: '04tapwater active' }, - { v: 5, u: 1, id: '04selected flow temperature', c: 'selflowtemp' }, - { v: 0, u: 3, id: '0Eburner selected max power', c: 'selburnpow' }, - { v: 0, u: 3, id: '00heating pump modulation' }, - { v: 53.4, u: 1, id: '00current flow temperature' }, - { v: 52.7, u: 1, id: '00return temperature' }, - { v: 1.3, u: 10, id: '00system pressure' }, - { v: 54.9, u: 1, id: '00actual boiler temperature' }, - { v: 'off', u: 0, id: '00gas' }, - { v: 'off', u: 0, id: '00gas stage 2' }, - { v: 0, u: 9, id: '00flame current' }, - { v: 'off', u: 0, id: '00heating pump' }, - { v: 'off', u: 0, id: '00fan' }, - { v: 'off', u: 0, id: '00ignition' }, - { v: 'off', u: 0, id: '00oil preheating' }, - { v: 'on', u: 0, id: '00heating activated', c: 'heatingactivated', l: ['off', 'on'] }, - { v: 80, u: 1, id: '00heating temperature', c: 'heatingtemp' }, - { v: 70, u: 3, id: '00burner pump max power', c: 'pumpmodmax' }, - { v: 30, u: 3, id: '00burner pump min power', c: 'pumpmodmin' }, - { v: 1, u: 8, id: '00pump delay', c: 'pumpdelay' }, - { v: 10, u: 8, id: '00burner min period', c: 'burnminperiod' }, - { v: 0, u: 3, id: '00burner min power', c: 'burnminpower' }, - { v: 50, u: 3, id: '00burner max power', c: 'burnmaxpower' }, - { v: -6, u: 2, id: '00hysteresis on temperature', c: 'boilhyston' }, - { v: 6, u: 2, id: '00hysteresis off temperature', c: 'boilhystoff' }, - { v: 0, u: 1, id: '00set flow temperature' }, - { v: 0, u: 3, id: '00burner set power' }, - { v: 0, u: 3, id: '00burner current power' }, - { v: 326323, u: 0, id: '00burner starts' }, - { v: 553437, u: 8, id: '00total burner operating time' }, - { v: 451286, u: 8, id: '00total heat operating time' }, - { v: 4672173, u: 8, id: '00total UBA operating time' }, - { v: '1C(210) 06.06.2020 12:07 (0 min)', u: 0, id: '00last error code' }, - { v: '0H', u: 0, id: '00service code' }, - { v: 203, u: 0, id: '00service code number' }, - { v: 'H00', u: 0, id: '00maintenance message' }, - { v: 'manual', u: 0, id: '00maintenance scheduled', c: 'maintenance', l: ['off', 'time', 'date', 'manual'] }, - { v: 6000, u: 7, id: '00time to next maintenance', c: 'maintenancetime' }, - { v: '01.01.2012', u: 0, id: '00next maintenance date', c: 'maintenancedate', h: 'dd.mm.yyyy' }, - { v: 'on', u: 0, id: '00dhw turn on/off', c: 'wwtapactivated', l: ['off', 'on'] }, - { v: 62, u: 1, id: '00dhw set temperature' }, - { v: 60, u: 1, id: '00dhw selected temperature', c: 'wwseltemp' }, - { v: 'flow', u: 0, id: '00dhw type' }, - { v: 'hot', u: 0, id: '00dhw comfort', c: 'wwcomfort', l: ['hot', 'eco', 'intelligent'] }, - { v: 40, u: 2, id: '00dhw flow temperature offset', c: 'wwflowtempoffset' }, - { v: 100, u: 3, id: '00dhw max power', c: 'wwmaxpower' }, - { v: 'off', u: 0, id: '00dhw circulation pump available', c: 'wwcircpump', l: ['off', 'on'] }, - { v: '3-way valve', u: 0, id: '00dhw charging type' }, - { v: -5, u: 2, id: '00dhw hysteresis on temperature', c: 'wwhyston' }, - { v: 0, u: 2, id: '00dhw hysteresis off temperature', c: 'wwhystoff' }, - { v: 70, u: 1, id: '00dhw disinfection temperature', c: 'wwdisinfectiontemp' }, - { - v: 'off', - u: 0, - id: '00dhw circulation pump mode', - c: 'wwcircmode', - l: ['off', '1x3min', '2x3min', '3x3min', '4x3min', '5x3min', '6x3min', 'continuous'] - }, - { v: 'off', u: 0, id: '00dhw circulation active', c: 'wwcirc', l: ['off', 'on'] }, - { v: 47.3, u: 1, id: '00dhw current intern temperature' }, - { v: 0, u: 4, id: '00dhw current tap water flow' }, - { v: 47.3, u: 1, id: '00dhw storage intern temperature' }, - { v: 'on', u: 0, id: '00dhw activated', c: 'wwactivated', l: ['off', 'on'] }, - { v: 'off', u: 0, id: '00dhw one time charging', c: 'wwonetime', l: ['off', 'on'] }, - { v: 'off', u: 0, id: '00dhw disinfecting', c: 'wwdisinfecting', l: ['off', 'on'] }, - { v: 'off', u: 0, id: '00dhw charging' }, - { v: 'off', u: 0, id: '00dhw recharging' }, - { v: 'on', u: 0, id: '00dhw temperature ok' }, - { v: 'off', u: 0, id: '00dhw active' }, - { v: 'on', u: 0, id: '00dhw 3way valve active' }, - { v: 0, u: 3, id: '00dhw set pump power' }, - { v: 288768, u: 0, id: '00dhw starts' }, - { v: 102151, u: 8, id: '00dhw active time' } - ] -}; - -const emsesp_devicedata_99 = { - data: [ - { - v: 5, - u: 1, - id: '00boiler_flowtemp', - c: 'boiler_flowtemp' - } - ] -}; - -// CUSTOM ENTITIES -let emsesp_customentities = { - // entities: [] - entities: [ - { - id: 0, - device_id: 8, - type_id: 24, - offset: 0, - factor: 1, - name: 'boiler_flowtemp', - uom: 1, - value_type: 1, - writeable: true - } - ] -}; - -// SCHEDULE -let emsesp_schedule = { - schedule: [ - { - id: 1, - active: true, - flags: 6, - time: '07:30', - cmd: 'hc1/mode', - value: 'day', - name: 'day_mode' - }, - { - id: 2, - active: true, - flags: 31, - time: '23:00', - cmd: 'hc1/mode', - value: 'night', - name: 'night_mode' - }, - { - id: 3, - active: true, - flags: 10, - time: '00:00', - cmd: 'thermostat/hc2/seltemp', - value: '20', - name: 'temp_20' - }, - { - id: 4, - active: false, - flags: 1, - time: '04:00', - cmd: 'system/restart', - value: '', - name: 'auto_restart' - } - ] -}; - -// CUSTOMIZATIONS -const emsesp_deviceentities_1 = [{ v: 'dummy value', n: 'dummy name', id: 'dummy', m: 0, w: false }]; -const emsesp_deviceentities_3 = [{ v: 'dummy value', n: 'dummy name', id: 'dummy', m: 0, w: false }]; -const emsesp_deviceentities_5 = [{ v: 'dummy value', n: 'dummy name', id: 'dummy', m: 0, w: false }]; -const emsesp_deviceentities_6 = [{ v: 'dummy value', n: 'dummy name', id: 'dummy', m: 0, w: false }]; - -const emsesp_deviceentities_2 = [ - { - v: '(0)', - n: 'error code', - cn: 'my custom error code', - id: 'errorcode', - m: 8, - w: false - }, - { - v: '14:54:39 06/06/2021', - n: 'date/time', - id: 'datetime', - m: 0, - w: false - }, - { - v: 18.2, - n: 'Chosen Room Temperature', - id: 'hc1/seltemp', - m: 0, - mi: 5, - ma: 52, - w: true - }, - { - v: 22.6, - n: 'hc1 current room temperature', - id: 'hc1/curtemp', - m: 0, - w: false - }, - { - v: 'auto', - n: 'hc1 mode', - id: 'hc1/mode', - m: 0, - w: true - } -]; - -const emsesp_deviceentities_7 = [ - { u: 0, n: '!reset', id: 'reset', m: 8, w: false }, - { v: false, n: 'heating active', id: 'heatingactive', m: 8, w: false }, - { v: false, n: 'tapwater active', id: 'tapwateractive', m: 4, w: false }, - { v: 5, n: 'selected flow temperature', id: 'selflowtemp', m: 4, w: true }, - { v: 0, n: 'burner selected max power', id: 'selburnpow', m: 14, w: true }, - { v: 0, n: 'heating pump modulation', id: 'heatingpumpmod', m: 0, w: false }, - { n: 'heating pump 2 modulation', id: 'heatingpump2mod', m: 0, w: false }, - { n: 'outside temperature', id: 'outdoortemp', m: 0, w: false }, - { v: 53, n: 'current flow temperature', id: 'curflowtemp', m: 0, w: false }, - { v: 51.8, n: 'return temperature', id: 'rettemp', m: 0, w: false }, - { n: 'mixing switch temperature', id: 'switchtemp', m: 0, w: false }, - { v: 1.3, n: 'system pressure', id: 'syspress', m: 0, w: false }, - { v: 54.6, n: 'actual boiler temperature', id: 'boiltemp', m: 0, w: false }, - { n: 'exhaust temperature', id: 'exhausttemp', m: 0, w: false }, - { v: false, n: 'gas', id: 'burngas', m: 0, w: false }, - { v: false, n: 'gas stage 2', id: 'burngas2', m: 0, w: false }, - { v: 0, n: 'flame current', id: 'flamecurr', m: 0, w: false }, - { v: false, n: 'heating pump', id: 'heatingpump', m: 0, w: false }, - { v: false, n: 'fan', id: 'fanwork', m: 0, w: false }, - { v: false, n: 'ignition', id: 'ignwork', m: 0, w: false }, - { v: false, n: 'oil preheating', id: 'oilpreheat', m: 0, w: false }, - { v: true, n: 'heating activated', id: 'heatingactivated', m: 0, w: false }, - { v: 80, n: 'heating temperature', id: 'heatingtemp', m: 0, w: false }, - { v: 70, n: 'burner pump max power', id: 'pumpmodmax', m: 0, w: false }, - { v: 30, n: 'burner pump min power', id: 'pumpmodmin', m: 0, w: false }, - { v: 1, n: 'pump delay', id: 'pumpdelay', m: 0, w: false }, - { v: 10, n: 'burner min period', id: 'burnminperiod', m: 0, w: false }, - { v: 0, n: 'burner min power', id: 'burnminpower', m: 0, w: false }, - { v: 50, n: 'burner max power', id: 'burnmaxpower', m: 0, w: false }, - { v: -6, n: 'hysteresis on temperature', id: 'boilhyston', m: 0, w: false }, - { v: 6, n: 'hysteresis off temperature', id: 'boilhystoff', m: 0, w: false }, - { v: 0, n: 'set flow temperature', id: 'setflowtemp', m: 0, w: true }, - { v: 0, n: 'burner set power', id: 'setburnpow', m: 0, w: false }, - { v: 0, n: 'burner current power', id: 'curburnpow', m: 0, w: false }, - { v: 326323, n: 'burner starts', id: 'burnstarts', m: 0, w: false }, - { v: 553437, n: 'total burner operating time', id: 'burnworkmin', m: 0, w: false }, - { v: 451286, n: 'total heat operating time', id: 'heatworkmin', m: 0, w: false }, - { v: 4672175, n: 'total UBA operating time', id: 'ubauptime', m: 0, w: false }, - { v: '1C(210) 06.06.2020 12:07 (0 min)', n: 'last error code', id: 'lastcode', m: 0, w: false }, - { v: '0H', n: 'service code', id: 'servicecode', m: 0, w: false }, - { v: 203, n: 'service code number', id: 'servicecodenumber', m: 0, w: false }, - { v: 'H00', n: 'maintenance message', id: 'maintenancemessage', m: 0, w: false }, - { v: 'manual', n: 'maintenance scheduled', id: 'maintenance', m: 0, w: false }, - { v: 6000, n: 'time to next maintenance', id: 'maintenancetime', m: 0, w: false }, - { v: '01.01.2012', n: 'next maintenance date', id: 'maintenancedate', m: 0, w: false }, - { v: true, n: 'dhw turn on/off', id: 'wwtapactivated', m: 0, w: false }, - { v: 62, n: 'dhw set temperature', id: 'wwsettemp', m: 0, w: false }, - { v: 60, n: 'dhw selected temperature', id: 'wwseltemp', m: 0, w: true }, - { n: 'dhw selected lower temperature', id: 'wwseltemplow', m: 2 }, - { n: 'dhw selected temperature for off', id: 'wwseltempoff', m: 2 }, - { n: 'dhw single charge temperature', id: 'wwseltempsingle', m: 2 }, - { v: 'flow', n: 'dhw type', id: 'wwtype', m: 0, w: false }, - { v: 'hot', n: 'dhw comfort', id: 'wwcomfort', m: 0, w: false }, - { v: 40, n: 'dhw flow temperature offset', id: 'wwflowtempoffset', m: 0, w: false }, - { v: 100, n: 'dhw max power', id: 'wwmaxpower', m: 0, w: false }, - { v: false, n: 'dhw circulation pump available', id: 'wwcircpump', m: 0, w: false }, - { v: '3-way valve', n: 'dhw charging type', id: 'wwchargetype', m: 0, w: false }, - { v: -5, n: 'dhw hysteresis on temperature', id: 'wwhyston', m: 0, w: false }, - { v: 0, n: 'dhw hysteresis off temperature', id: 'wwhystoff', m: 0, w: false }, - { v: 70, n: 'dhw disinfection temperature', id: 'wwdisinfectiontemp', m: 0, w: false }, - { v: 'off', n: 'dhw circulation pump mode', id: 'wwcircmode', m: 0, w: false }, - { v: false, n: 'dhw circulation active', id: 'wwcirc', m: 0, w: false }, - { v: 46.4, n: 'dhw current intern temperature', id: 'wwcurtemp', m: 0, w: false }, - { n: 'dhw current extern temperature', id: 'wwcurtemp2', m: 2 }, - { v: 0, n: 'dhw current tap water flow', id: 'wwcurflow', m: 0, w: false }, - { v: 46.3, n: 'dhw storage intern temperature', id: 'wwstoragetemp1', m: 0, w: false }, - { n: 'dhw storage extern temperature', id: 'wwstoragetemp2', m: 2 }, - { v: true, n: 'dhw activated', id: 'wwactivated', m: 0, w: false }, - { v: false, n: 'dhw one time charging', id: 'wwonetime', m: 0, w: false }, - { v: false, n: 'dhw disinfecting', id: 'wwdisinfecting', m: 0, w: false }, - { v: false, n: 'dhw charging', id: 'wwcharging', m: 0, w: false }, - { v: false, n: 'dhw recharging', id: 'wwrecharging', m: 0, w: false }, - { v: true, n: 'dhw temperature ok', id: 'wwtempok', m: 0, w: false }, - { v: false, n: 'dhw active', id: 'wwactive', m: 0, w: false }, - { v: true, n: 'dhw 3way valve active', id: 'ww3wayvalve', m: 0, w: false }, - { v: 0, n: 'dhw set pump power', id: 'wwsetpumppower', m: 0, w: true }, - { n: 'dhw mixer temperature', id: 'wwmixertemp', m: 2 }, - { n: 'dhw cylinder middle temperature (TS3)', id: 'wwcylmiddletemp', m: 2 }, - { v: 288768, n: 'dhw starts', id: 'wwstarts', m: 0, w: false }, - { v: 102151, n: 'dhw active time', id: 'wwworkm', m: 0, w: false } -]; - -const emsesp_deviceentities_4 = [ - { - v: 16, - n: 'hc2 selected room temperature', - id: 'hc2/seltemp', - m: 8, - w: true - }, - { - v: 18.5, - n: 'hc2 current room temperature', - id: 'hc2/curtemp', - m: 2, - w: false - }, - { - v: 'off', - n: 'hc2 mode', - id: 'hc2/mode', - m: 2, - w: true - } -]; - -// LOG -rest_server.post(FETCH_LOG_ENDPOINT, (req, res) => { - console.log('command: fetchLog'); - res.sendStatus(200); -}); -rest_server.get(LOG_SETTINGS_ENDPOINT, (req, res) => { - res.json(log_settings); -}); -rest_server.post(LOG_SETTINGS_ENDPOINT, (req, res) => { - log_settings = req.body; - console.log(JSON.stringify(log_settings)); - res.sendStatus(200); -}); - -// NETWORK -rest_server.get(NETWORK_STATUS_ENDPOINT, (req, res) => { - res.json(network_status); -}); -rest_server.get(NETWORK_SETTINGS_ENDPOINT, (req, res) => { - res.json(network_settings); -}); -rest_server.post(NETWORK_SETTINGS_ENDPOINT, (req, res) => { - network_settings = req.body; - console.log(JSON.stringify(network_settings)); - res.sendStatus(200); -}); -rest_server.get(LIST_NETWORKS_ENDPOINT, (req, res) => { - if (countWifiScanPoll++ === 3) { - // console.log('done, have list'); - res.json(list_networks); // send list - } else { - // console.log('...waiting #' + countWifiScanPoll); - res.sendStatus(200); // waiting.... - } -}); -rest_server.get(SCAN_NETWORKS_ENDPOINT, (req, res) => { - console.log('start scan networks'); - countWifiScanPoll = 0; // stop the poll - res.sendStatus(200); // always 202, poll for list -}); - -// AP -rest_server.get(AP_SETTINGS_ENDPOINT, (req, res) => { - res.json(ap_settings); -}); -rest_server.get(AP_STATUS_ENDPOINT, (req, res) => { - console.log('get apStatus', ap_status); - res.json(ap_status); -}); -rest_server.post(AP_SETTINGS_ENDPOINT, (req, res) => { - ap_settings = req.body; - console.log('post apSettings', ap_settings); - res.sendStatus(200); -}); - -// OTA -rest_server.get(OTA_SETTINGS_ENDPOINT, (req, res) => { - res.json(ota_settings); -}); -rest_server.post(OTA_SETTINGS_ENDPOINT, (req, res) => { - ota_settings = req.body; - console.log(JSON.stringify(ota_settings)); - res.sendStatus(200); -}); - -// MQTT -rest_server.get(MQTT_SETTINGS_ENDPOINT, (req, res) => { - res.json(mqtt_settings); -}); -rest_server.post(MQTT_SETTINGS_ENDPOINT, (req, res) => { - mqtt_settings = req.body; - console.log(JSON.stringify(mqtt_settings)); - res.sendStatus(200); -}); -rest_server.get(MQTT_STATUS_ENDPOINT, (req, res) => { - res.json(mqtt_status); -}); - -// NTP -rest_server.get(NTP_SETTINGS_ENDPOINT, (req, res) => { - res.json(ntp_settings); -}); -rest_server.post(NTP_SETTINGS_ENDPOINT, (req, res) => { - ntp_settings = req.body; - console.log(JSON.stringify(ntp_settings)); - res.sendStatus(200); -}); -rest_server.get(NTP_STATUS_ENDPOINT, (req, res) => { - res.json(ntp_status); -}); -rest_server.post(TIME_ENDPOINT, (req, res) => { - res.sendStatus(200); -}); - -// SYSTEM -rest_server.get(SYSTEM_STATUS_ENDPOINT, (req, res) => { - console.log('get systemStatus'); - // create some random data to see if caching works - system_status.fs_used = Math.floor(Math.random() * (Math.floor(200) - 100) + 100); - res.json(system_status); -}); -rest_server.get(SECURITY_SETTINGS_ENDPOINT, (req, res) => { - res.json(security_settings); -}); -rest_server.post(SECURITY_SETTINGS_ENDPOINT, (req, res) => { - security_settings = req.body; - console.log(JSON.stringify(security_settings)); - res.sendStatus(200); -}); -rest_server.get(FEATURES_ENDPOINT, (req, res) => { - res.json(features); -}); -rest_server.get(VERIFY_AUTHORIZATION_ENDPOINT, (req, res) => { - res.json(verify_authentication); -}); -rest_server.post(RESTART_ENDPOINT, async (req, res) => { - console.log('command: restart'); - // await delay(1000); - res.sendStatus(200); -}); -rest_server.post(FACTORY_RESET_ENDPOINT, (req, res) => { - console.log('command: reset'); - res.sendStatus(200); -}); - -rest_server.post(UPLOAD_FILE_ENDPOINT, progress_middleware, upload.single('file'), (req, res) => { - console.log('command: uploadFile completed.'); - if (req.file) { - const filename = req.file.originalname; - const ext = filename.substring(filename.lastIndexOf('.') + 1); - console.log(req.file); - console.log('ext: ' + ext); - - if (ext === 'bin' || ext === 'json') { - return res.sendStatus(200); - } else if (ext === 'md5') { - return res.json({ md5: 'ef4304fc4d9025a58dcf25d71c882d2c' }); - } - } - return res.sendStatus(400); -}); - -rest_server.post(SIGN_IN_ENDPOINT, (req, res) => { - console.log('Signed in'); - res.json(signin); -}); - -rest_server.get(GENERATE_TOKEN_ENDPOINT, (req, res) => { - res.json(generate_token); -}); - -// EMS-ESP Project stuff -rest_server.post(EMSESP_RESET_CUSTOMIZATIONS_ENDPOINT, (req, res) => { - console.log('Removing all customizations...'); - res.sendStatus(200); -}); -rest_server.get(EMSESP_SETTINGS_ENDPOINT, (req, res) => { - console.log('Get settings: ' + JSON.stringify(settings)); - res.json(settings); -}); -rest_server.post(EMSESP_SETTINGS_ENDPOINT, (req, res) => { - settings = req.body; - console.log('Write settings: ' + JSON.stringify(settings)); - // res.sendStatus(205); // restart needed - res.sendStatus(200); // no restart needed -}); -rest_server.get(EMSESP_CORE_DATA_ENDPOINT, (req, res) => { - console.log('send back core data...'); - res.json(emsesp_coredata); -}); -rest_server.get(EMSESP_SENSOR_DATA_ENDPOINT, (req, res) => { - console.log('send back sensor data...'); - // console.log(emsesp_sensordata); - res.json(emsesp_sensordata); -}); -rest_server.get(EMSESP_DEVICES_ENDPOINT, (req, res) => { - console.log('send back list of devices...'); - res.json(emsesp_devices); -}); -rest_server.post(EMSESP_SCANDEVICES_ENDPOINT, (req, res) => { - console.log('Scan devices...'); - res.sendStatus(200); -}); -rest_server.get(EMSESP_STATUS_ENDPOINT, (req, res) => { - res.json(status); -}); - -rest_server.get(EMSESP_DEVICEDATA_ENDPOINT, (req, res) => { - const id = Number(req.query.id); - console.log('send back device data for ' + id); - let data = {}; - - if (id === 1) { - data = emsesp_devicedata_1; - } - if (id === 2) { - data = emsesp_devicedata_2; - } - if (id === 3) { - data = emsesp_devicedata_3; - } - if (id === 4) { - data = emsesp_devicedata_4; - } - if (id === 5) { - data = emsesp_devicedata_5; - } - if (id === 6) { - data = emsesp_devicedata_6; - } - if (id === 7) { - data = emsesp_devicedata_7; - } - if (id === 99) { - data = emsesp_devicedata_99; - } - res.write(msgpack.encode(data), 'binary'); - res.end(null, 'binary'); -}); - -rest_server.get(EMSESP_DEVICEENTITIES_ENDPOINT, (req, res) => { - const id = Number(req.query.id); - console.log('deviceentities for device ' + id + ' received'); - let data = null; - - if (id === 1) { - data = emsesp_deviceentities_1; - } - if (id === 2) { - data = emsesp_deviceentities_2; - } - if (id === 3) { - data = emsesp_deviceentities_3; - } - if (id === 4) { - data = emsesp_deviceentities_4; - } - if (id === 5) { - data = emsesp_deviceentities_5; - } - if (id === 6) { - data = emsesp_deviceentities_6; - } - if (id === 7) { - data = emsesp_deviceentities_7; - } - res.write(msgpack.encode(data), 'binary'); - res.end(null, 'binary'); -}); - -function updateMask(entity, de, dd) { - const current_mask = parseInt(entity.slice(0, 2), 16); - - // strip of any min/max ranges - const shortname_with_customname = entity.slice(2).split('>')[0]; - const shortname = shortname_with_customname.split('|')[0]; - const new_custom_name = shortname_with_customname.split('|')[1]; - const has_min_max = entity.slice(2).split('>')[1]; - - // find in de - de_objIndex = de.findIndex((obj) => obj.id === shortname); - if (de_objIndex !== -1) { - // get current name - if (de[de_objIndex].cn) { - fullname = de[de_objIndex].cn; - } else { - fullname = de[de_objIndex].n; - } - - // find in dd, either looking for fullname or custom name - // console.log('looking for ' + fullname + ' in ' + dd.data); - dd_objIndex = dd.data.findIndex((obj) => obj.id.slice(2) === fullname); - if (dd_objIndex !== -1) { - let changed = new Boolean(false); - - // see if the mask has changed - const old_mask = parseInt(dd.data[dd_objIndex].id.slice(0, 2), 16); - if (old_mask !== current_mask) { - changed = true; - console.log('mask has changed to ' + current_mask.toString(16)); - } - - // see if the custom name has changed - const old_custom_name = dd.data[dd_objIndex].cn; - console.log('comparing names, old (' + old_custom_name + ') with new (' + new_custom_name + ')'); - if (old_custom_name !== new_custom_name) { - changed = true; - new_fullname = new_custom_name; - console.log('name has changed to ' + new_custom_name); - } else { - new_fullname = fullname; - } - - // see if min or max has changed - // get current min/max values if they exist - const current_min = dd.data[dd_objIndex].min; - const current_max = dd.data[dd_objIndex].max; - new_min = current_min; - new_max = current_max; - if (has_min_max) { - new_min = parseInt(has_min_max.split('<')[0]); - new_max = parseInt(has_min_max.split('<')[1]); - if (current_min !== new_min || current_max !== new_max) { - changed = true; - console.log('min/max has changed to ' + new_min + '/' + new_max); - } - } - - if (changed === true) { - console.log( - 'Updating ' + dd.data[dd_objIndex].id + ' -> ' + current_mask.toString(16).padStart(2, '0') + new_fullname - ); - de[de_objIndex].m = current_mask; - de[de_objIndex].cn = new_fullname; - if (new_min) { - de[de_objIndex].mi = new_min; - } - if (new_max) { - de[de_objIndex].ma = new_max; - } - dd.data[dd_objIndex].id = current_mask.toString(16).padStart(2, '0') + new_fullname; - dd.data[dd_objIndex].cn = new_fullname; - } - - console.log('new dd:'); - console.log(dd.data[dd_objIndex]); - console.log('new de:'); - console.log(de[de_objIndex]); - } else { - console.log('error, dd not found'); - } - } else { - console.log("can't locate record for shortname " + shortname); - } -} - -rest_server.post(EMSESP_CUSTOMIZATION_ENTITIES_ENDPOINT, (req, res) => { - const id = req.body.id; - console.log('customization id = ' + id); - console.log(req.body.entity_ids); - for (const entity of req.body.entity_ids) { - if (id === 7) { - updateMask(entity, emsesp_deviceentities_7, emsesp_devicedata_7); - } else if (id === 1) { - updateMask(entity, emsesp_deviceentities_1, emsesp_devicedata_1); - } else if (id === 2) { - updateMask(entity, emsesp_deviceentities_2, emsesp_devicedata_2); - } else if (id === 3) { - updateMask(entity, emsesp_deviceentities_3, emsesp_devicedata_3); - } else if (id === 4) { - updateMask(entity, emsesp_deviceentities_4, emsesp_devicedata_4); - } else if (id === 5) { - updateMask(entity, emsesp_deviceentities_5, emsesp_devicedata_5); - } else if (id === 6) { - updateMask(entity, emsesp_deviceentities_6, emsesp_devicedata_6); - } - } - res.sendStatus(200); -}); - -rest_server.post(EMSESP_WRITE_SCHEDULE_ENDPOINT, (req, res) => { - console.log('write schedule'); - console.log(req.body); - emsesp_schedule = req.body; - res.sendStatus(200); -}); - -rest_server.post(EMSESP_WRITE_ENTITIES_ENDPOINT, (req, res) => { - console.log('write entities'); - console.log(req.body); - emsesp_customentities = req.body; - res.sendStatus(200); -}); - -rest_server.post(EMSESP_WRITE_VALUE_ENDPOINT, async (req, res) => { - const command = req.body.c; - const value = req.body.v; - const id = req.body.id; - console.log('Write device value for id : ' + id); - console.log(' data: ' + JSON.stringify(req.body)); - - if (id === 1) { - objIndex = emsesp_devicedata_1.data.findIndex((obj) => obj.c == command); - emsesp_devicedata_1.data[objIndex].v = value; - } - if (id === 2) { - objIndex = emsesp_devicedata_2.data.findIndex((obj) => obj.c == command); - emsesp_devicedata_2.data[objIndex].v = value; - } - if (id === 3) { - objIndex = emsesp_devicedata_3.data.findIndex((obj) => obj.c == command); - emsesp_devicedata_3.data[objIndex].v = value; - } - if (id === 4) { - objIndex = emsesp_devicedata_4.data.findIndex((obj) => obj.c == command); - emsesp_devicedata_4.data[objIndex].v = value; - } - if (id === 5) { - objIndex = emsesp_devicedata_5.data.findIndex((obj) => obj.c == command); - emsesp_devicedata_5.data[objIndex].v = value; - } - if (id === 6) { - objIndex = emsesp_devicedata_6.data.findIndex((obj) => obj.c == command); - emsesp_devicedata_6.data[objIndex].v = value; - } - if (id === 7) { - objIndex = emsesp_devicedata_7.data.findIndex((obj) => obj.c == command); - emsesp_devicedata_7.data[objIndex].v = value; - } - - // custom entities - if (id === 99) { - objIndex = emsesp_devicedata_99.data.findIndex((obj) => obj.c == command); - emsesp_devicedata_99.data[objIndex].v = value; - } - - await delay(1000); // wait to show spinner - // res.sendStatus(400); // bad request - - res.sendStatus(200); -}); - -rest_server.post(EMSESP_WRITE_SENSOR_ENDPOINT, (req, res) => { - const ts = req.body; - console.log('Write temperaure sensor: ' + JSON.stringify(ts)); - objIndex = emsesp_sensordata.ts.findIndex((obj) => obj.id == ts.id); - if (objIndex !== -1) { - emsesp_sensordata.ts[objIndex].n = ts.name; - emsesp_sensordata.ts[objIndex].o = ts.offset; - } else { - console.log('not found'); - } - res.sendStatus(200); -}); - -rest_server.post(EMSESP_WRITE_ANALOG_ENDPOINT, (req, res) => { - const as = req.body; - console.log('Write analog sensor: ' + JSON.stringify(as)); - objIndex = emsesp_sensordata.as.findIndex((obj) => obj.g == as.gpio); - - if (objIndex === -1) { - console.log('new analog entry found'); - emsesp_sensordata.as.push({ - id: as.id, - g: as.gpio, - n: as.name, - f: as.factor, - o: as.offset, - u: as.uom, - t: as.type, - d: as.deleted - }); - } else { - if (as.deleted) { - console.log('removing analog gpio' + as.gpio + ' index ' + objIndex); - emsesp_sensordata.as[objIndex].d = true; - var filtered = emsesp_sensordata.as.filter(function (value, index, arr) { - return !value.d; - }); - emsesp_sensordata.as = filtered; - } else { - console.log('updating analog gpio' + as.gpio + ' index ' + objIndex); - emsesp_sensordata.as[objIndex].n = as.name; - emsesp_sensordata.as[objIndex].f = as.factor; - emsesp_sensordata.as[objIndex].o = as.offset; - emsesp_sensordata.as[objIndex].u = as.uom; - emsesp_sensordata.as[objIndex].t = as.type; - } - } - - res.sendStatus(200); -}); - -rest_server.get(EMSESP_BOARDPROFILE_ENDPOINT, (req, res) => { - const board_profile = req.query.boardProfile; - - // default values - const data = { - board_profile: board_profile, - led_gpio: settings.led_gpio, - dallas_gpio: settings.dallas_gpio, - rx_gpio: settings.rx_gpio, - tx_gpio: settings.tx_gpio, - pbutton_gpio: settings.pbutton_gpio, - phy_type: settings.phy_type, - eth_power: settings.eth_power, - eth_phy_addr: settings.eth_phy_addr, - eth_clock_mode: settings.eth_clock_mode - }; - - if (board_profile == 'S32') { - // BBQKees Gateway S32 - data.led_gpio = 2; - data.dallas_gpio = 18; - data.rx_gpio = 23; - data.tx_gpio = 5; - data.pbutton_gpio = 0; - data.phy_type = 0; - data.eth_power = 0; - data.eth_phy_addr = 0; - data.eth_clock_mode = 0; - } else if (board_profile == 'E32') { - // BBQKees Gateway E32 - data.led_gpio = 2; - data.dallas_gpio = 4; - data.rx_gpio = 5; - data.tx_gpio = 17; - data.pbutton_gpio = 33; - data.phy_type = 1; - data.eth_power = 16; - data.eth_phy_addr = 1; - data.eth_clock_mode = 0; - } else if (board_profile == 'MH-ET') { - // MH-ET Live D1 Mini - data.led_gpio = 2; - data.dallas_gpio = 18; - data.rx_gpio = 23; - data.tx_gpio = 5; - data.pbutton_gpio = 0; - data.phy_type = 0; - data.eth_power = 0; - data.eth_phy_addr = 0; - data.eth_clock_mode = 0; - } else if (board_profile == 'NODEMCU') { - // NodeMCU 32S - data.led_gpio = 2; - data.dallas_gpio = 18; - data.rx_gpio = 23; - data.tx_gpio = 5; - data.pbutton_gpio = 0; - data.phy_type = 0; - data.eth_power = 0; - data.eth_phy_addr = 0; - data.eth_clock_mode = 0; - } else if (board_profile == 'LOLIN') { - // Lolin D32 - data.led_gpio = 2; - data.dallas_gpio = 18; - data.rx_gpio = 17; - data.tx_gpio = 16; - data.pbutton_gpio = 0; - data.phy_type = 0; - data.eth_power = 0; - data.eth_phy_addr = 0; - data.eth_clock_mode = 0; - } else if (board_profile == 'OLIMEX') { - // Olimex ESP32-EVB (uses U1TXD/U1RXD/BUTTON, no LED or Dallas) - data.led_gpio = 0; - data.dallas_gpio = 0; - data.rx_gpio = 36; - data.tx_gpio = 4; - data.pbutton_gpio = 34; - data.phy_type = 1; - data.eth_power = -1; - data.eth_phy_addr = 0; - data.eth_clock_mode = 0; - } else if (board_profile == 'OLIMEXPOE') { - // Olimex ESP32-POE - data.led_gpio = 0; - data.dallas_gpio = 0; - data.rx_gpio = 36; - data.tx_gpio = 4; - data.pbutton_gpio = 34; - data.phy_type = 1; - data.eth_power = 12; - data.eth_phy_addr = 0; - data.eth_clock_mode = 3; - } else if (board_profile == 'C3MINI') { - // Lolin C3 mini - data.led_gpio = 7; - data.dallas_gpio = 1; - data.rx_gpio = 4; - data.tx_gpio = 5; - data.pbutton_gpio = 9; - data.phy_type = 0; - data.eth_power = 0; - data.eth_phy_addr = 0; - data.eth_clock_mode = 0; - } else if (board_profile == 'S2MINI') { - // Lolin C3 mini - data.led_gpio = 15; - data.dallas_gpio = 7; - data.rx_gpio = 11; - data.tx_gpio = 12; - data.pbutton_gpio = 0; - data.phy_type = 0; - data.eth_power = 0; - data.eth_phy_addr = 0; - data.eth_clock_mode = 0; - } else if (board_profile == 'S3MINI') { - // Liligo S3 mini - data.led_gpio = 17; - data.dallas_gpio = 18; - data.rx_gpio = 8; - data.tx_gpio = 5; - data.pbutton_gpio = 0; - data.phy_type = 0; - data.eth_power = 0; - data.eth_phy_addr = 0; - data.eth_clock_mode = 0; - } - - console.log('boardProfile GET. Sending back, profile: ' + board_profile + ', ' + 'data: ' + JSON.stringify(data)); - - // res.sendStatus(400); // send back an error, for testing - res.json(data); -}); - -// EMS-ESP API specific - -rest_server.post(API_ENDPOINT_ROOT, (req, res) => { - console.log('Generic API POST'); - console.log(req.body); - if (req.body.device === 'system') { - if (req.body.entity === 'info') { - console.log('sending system info: ' + JSON.stringify(emsesp_info)); - res.json(emsesp_info); - } else if (req.body.entity === 'settings') { - console.log('sending system settings: ' + JSON.stringify(settings)); - res.json(settings); - } else { - res.sendStatus(200); - } - } else { - res.sendStatus(200); - } -}); -rest_server.get(API_ENDPOINT_ROOT, (req, res) => { - console.log('Generic API GET'); - res.sendStatus(200); -}); - -const SYSTEM_INFO_ENDPOINT = API_ENDPOINT_ROOT + 'system/info'; -rest_server.post(SYSTEM_INFO_ENDPOINT, (req, res) => { - console.log('System Info POST: ' + JSON.stringify(req.body)); - res.sendStatus(200); -}); -rest_server.get(SYSTEM_INFO_ENDPOINT, (req, res) => { - console.log('System Info GET'); - res.json(emsesp_info); -}); - -const GET_SETTINGS_ENDPOINT = REST_ENDPOINT_ROOT + 'getSettings'; -rest_server.get(GET_SETTINGS_ENDPOINT, (req, res) => { - console.log('getSettings'); - res.json(settings); -}); - -const GET_CUSTOMIZATIONS_ENDPOINT = REST_ENDPOINT_ROOT + 'getCustomizations'; -rest_server.get(GET_CUSTOMIZATIONS_ENDPOINT, (req, res) => { - console.log('getCustomization'); - // not implemented yet - res.sendStatus(200); -}); - -const GET_ENTITIES_ENDPOINT = REST_ENDPOINT_ROOT + 'getEntities'; -rest_server.get(GET_ENTITIES_ENDPOINT, (req, res) => { - console.log('getEntities'); - res.json(emsesp_customentities); -}); - -const GET_SCHEDULE_ENDPOINT = REST_ENDPOINT_ROOT + 'getSchedule'; -rest_server.get(GET_SCHEDULE_ENDPOINT, (req, res) => { - console.log('getSchedule'); - res.json(emsesp_schedule); -}); - -const SCHEDULE_ENDPOINT = REST_ENDPOINT_ROOT + 'schedule'; -rest_server.get(SCHEDULE_ENDPOINT, (req, res) => { - console.log('Sending Schedule data'); - res.json(emsesp_schedule); -}); - -const ENTITIES_ENDPOINT = REST_ENDPOINT_ROOT + 'customentities'; -rest_server.get(ENTITIES_ENDPOINT, (req, res) => { - console.log('Sending Custom Entities data'); - res.json(emsesp_customentities); -}); - -// start server -const expressServer = rest_server.listen(port, () => - console.log(`Legacy EMS-ESP REST API server running on http://localhost:${port}/`) -); - -// event source -var count = 8; -var log_index = 0; -const ES_ENDPOINT_ROOT = '/es/'; -const ES_LOG_ENDPOINT = ES_ENDPOINT_ROOT + 'log'; -rest_server.get(ES_LOG_ENDPOINT, function (req, res) { - res.setHeader('Content-Type', 'text/event-stream'); - res.setHeader('Cache-Control', 'no-cache'); - res.setHeader('Access-Control-Allow-Origin', '*'); - res.setHeader('Connection', 'keep-alive'); - res.flushHeaders(); - - var timer = setInterval(function () { - count += 1; - log_index += 1; - const data = { - t: '000+00:00:00.000', - l: 3, // error - i: count, - n: 'system', - m: 'incoming message #' + count + '/' + log_index - }; - const sseFormattedResponse = `data: ${JSON.stringify(data)}\n\n`; - res.write(sseFormattedResponse); - res.flush(); // this is important - - // if buffer is full, start over - if (log_index > 50) { - fetch_log.events = []; - log_index = 0; - } - fetch_log.events.push(data); // append to buffer - }, 5000); -}); diff --git a/mock-api/package.json b/mock-api/package.json index 7f9b02ac9..ab40293d9 100644 --- a/mock-api/package.json +++ b/mock-api/package.json @@ -6,13 +6,14 @@ "license": "MIT", "scripts": { "mock-api": "bun --watch rest_server.ts", - "mock-es": "bun --watch es_server.ts" + "mock-es": "bun --watch es_server.ts", + "mock-upload": "bun --watch upload_server.ts" }, "dependencies": { "@msgpack/msgpack": "^2.8.0", "compression": "^1.7.4", "express": "^4.19.2", - "itty-router": "^5.0.5", + "itty-router": "^5.0.9", "multer": "^1.4.5-lts.1" }, "packageManager": "yarn@4.1.1", diff --git a/mock-api/rest_server.ts b/mock-api/rest_server.ts index b205e1cce..e64ac0eb3 100644 --- a/mock-api/rest_server.ts +++ b/mock-api/rest_server.ts @@ -1,15 +1,11 @@ import { AutoRouter, error, status } from 'itty-router'; import { Encoder } from '@msgpack/msgpack'; -// import busboy from 'busboy'; -// import multer from 'multer'; -// const upload = multer({ dest: '../mock-api/uploads' }); - const encoder = new Encoder(); const router = AutoRouter({ port: 3080, - missing: () => error(404, 'Error, not found') + missing: () => error(404, 'Error, endpoint not found') }); const REST_ENDPOINT_ROOT = '/rest/'; @@ -24,17 +20,6 @@ const headers = { // GLOBAL VARIABLES let countWifiScanPoll = 0; // wifi network scan -// FUNCTIONS -// const delay = (ms) => new Promise((res) => setTimeout(res, ms)); -// function delay_blocking(milliseconds) { -// var start = new Date().getTime(); -// for (var i = 0; i < 1e7; i++) { -// if (new Date().getTime() - start > milliseconds) { -// break; -// } -// } -// } - function updateMask(entity: any, de: any, dd: any) { const current_mask = parseInt(entity.slice(0, 2), 16); @@ -364,7 +349,6 @@ const ESPSYSTEM_STATUS_ENDPOINT = REST_ENDPOINT_ROOT + 'ESPSystemStatus'; const SECURITY_SETTINGS_ENDPOINT = REST_ENDPOINT_ROOT + 'securitySettings'; const RESTART_ENDPOINT = REST_ENDPOINT_ROOT + 'restart'; const FACTORY_RESET_ENDPOINT = REST_ENDPOINT_ROOT + 'factoryReset'; -const UPLOAD_FILE_ENDPOINT = REST_ENDPOINT_ROOT + 'uploadFile'; // SYSTEM SIGNIN const VERIFY_AUTHORIZATION_ENDPOINT = REST_ENDPOINT_ROOT + 'verifyAuthorization'; @@ -2394,107 +2378,9 @@ router .get(VERIFY_AUTHORIZATION_ENDPOINT, () => verify_authentication) .post(RESTART_ENDPOINT, () => status(200)) .post(FACTORY_RESET_ENDPOINT, () => status(200)) - .post(UPLOAD_FILE_ENDPOINT, () => status(404)) // TODO remove upload when fixed .post(SIGN_IN_ENDPOINT, () => signin) .get(GENERATE_TOKEN_ENDPOINT, () => generate_token); -// uploads // TODO fix uploading later - -// const progress_middleware = async (req: any) => { -// console.log('progress_middleware'); -// let progress = 0; -// const file_size = req.headers['content-length']; - -// // set event listener -// req.on('data', async (chunk) => { -// progress += chunk.length; -// const percentage = (progress / file_size) * 100; -// console.log(`Progress: ${Math.round(percentage)}%`); -// delay_blocking(200); // slow it down -// }); -// // next(); // invoke next middleware which is multer -// }; - -// const withContent = async (request) => { -// const { headers } = request; -// const type = headers.get('content-type'); - -// // console.log(Object.getOwnPropertyNames(Object.getPrototypeOf(request))); - -// if (type?.includes('form-data')) { -// console.log('withContent: got formdata'); -// // request.content = await request.formData(); - -// // const bb = busboy({ headers: request.headers }); -// // console.log('bb created'); -// // bb.on('file', (name, file, info) => { -// // const { filename, encoding, mimeType } = info; -// // console.log(`File [${name}]: filename: %j, encoding: %j, mimeType: %j`, filename, encoding, mimeType); -// // request.filename = filename; - -// // file -// // .on('data', (data) => { -// // console.log(`File [${name}] got ${data.length} bytes`); -// // }) -// // .on('close', () => { -// // console.log(`File [${name}] done`); -// // }); -// // }); -// // bb.on('field', (name, val, info) => { -// // console.log(`Field [${name}]: value: %j`, val); -// // }); -// // bb.on('close', () => { -// // console.log('Done parsing form!'); -// // // res.writeHead(303, { Connection: 'close', Location: '/' }); -// // // res.end(); -// // }); -// } -// }; - -// const makeMiddleware = (req) => { -// console.log('makeMiddleware'); -// // const bb = busboy({ headers: req.headers }); - -// // bb.on('error', (err) => { -// // // Send this error along to the global error handler -// // console.log('Error' + err); -// // return; -// // }); -// // bb.on('file', (name, file, info) => { -// // const { filename, encoding, mimeType } = info; -// // console.log(`File [${name}]: filename: %j, encoding: %j, mimeType: %j`, filename, encoding, mimeType); -// // req.filename = filename; - -// // file -// // .on('data', (data) => { -// // console.log(`File [${name}] got ${data.length} bytes`); -// // }) -// // .on('close', () => { -// // console.log(`File [${name}] done`); -// // }); -// // }); -// // bb.end(req.rawBody); -// // req.pipe(bb); -// }; - -// router.post(UPLOAD_FILE_ENDPOINT, withContent, makeMiddleware, progress_middleware, ({ filename }) => { -// console.log('filename: ' + filename); - -// // if (req.file) { -// // const filename = req.file.originalname; -// // const ext = filename.substring(filename.lastIndexOf('.') + 1); -// // console.log(req.file); -// // console.log('ext: ' + ext); - -// // if (ext === 'bin' || ext === 'json') { -// // return res.sendStatus(200); -// // } else if (ext === 'md5') { -// // return res.json({ md5: 'ef4304fc4d9025a58dcf25d71c882d2c' }); -// // } -// // } -// return new Response('OK', { status: 200 }); -// }); - // // EMS-ESP Project stuff // diff --git a/mock-api/upload_server.ts b/mock-api/upload_server.ts new file mode 100644 index 000000000..6bfd9c577 --- /dev/null +++ b/mock-api/upload_server.ts @@ -0,0 +1,57 @@ +import express from 'express'; +import multer from 'multer'; + +const rest_server = express(); +const port = 3082; +const upload = multer({ dest: './uploads' }); + +const UPLOAD_FILE_ENDPOINT = '/rest/uploadFile'; + +// delay functions, 2 different types +const delay = (ms) => new Promise((res) => setTimeout(res, ms)); + +function delay_blocking(milliseconds) { + var start = new Date().getTime(); + // for (var i = 0; i < 1e7; i++) { + while (true) { + if (new Date().getTime() - start > milliseconds) { + break; + } + } +} + +function progress_middleware(req, res, next) { + let progress = 0; + const file_size = req.headers['content-length']; + console.log('Uploading file. Size ' + file_size + ' bytes'); + + // set event listener + req.on('data', async (chunk) => { + progress += chunk.length; + const percentage = (progress / file_size) * 100; + console.log(`Progress: ${Math.round(percentage)}%`); + // await delay(1000); // slow it down + delay_blocking(1000); // slow it down + }); + next(); // invoke next middleware which is multer +} + +rest_server.post(UPLOAD_FILE_ENDPOINT, progress_middleware, upload.single('file'), (req, res) => { + if (req.file) { + const filename = req.file.originalname; + const ext = filename.substring(filename.lastIndexOf('.') + 1); + console.log(req.file); + + if (ext === 'bin' || ext === 'json') { + console.log('Received firmware or json file, extension: ' + ext); + return res.sendStatus(200); + } else if (ext === 'md5') { + return res.json({ md5: 'ef4304fc4d9025a58dcf25d71c882d2c' }); + } + } + console.log('Invalid file extension'); + return res.sendStatus(400); +}); + +// start server +rest_server.listen(port, () => console.log(`EMS-ESP File Upload mock server running on http://localhost:${port}/`)); diff --git a/mock-api/yarn.lock b/mock-api/yarn.lock index d7a59555a..9af4b0f4b 100644 --- a/mock-api/yarn.lock +++ b/mock-api/yarn.lock @@ -140,7 +140,7 @@ __metadata: "@types/multer": "npm:^1.4.11" compression: "npm:^1.7.4" express: "npm:^4.19.2" - itty-router: "npm:^5.0.5" + itty-router: "npm:^5.0.9" multer: "npm:^1.4.5-lts.1" languageName: unknown linkType: soft @@ -526,10 +526,10 @@ __metadata: languageName: node linkType: hard -"itty-router@npm:^5.0.5": - version: 5.0.5 - resolution: "itty-router@npm:5.0.5" - checksum: 10/b10ddeb65568e4ed5eb5a99b5e5e660bae62d53ab88ffdf56a9045d6323a87f561a000f3d8835dcd15451c565fd01083e049122e46d55ffd24fa675f9446971c +"itty-router@npm:^5.0.9": + version: 5.0.9 + resolution: "itty-router@npm:5.0.9" + checksum: 10/b11684cfcb08658620d878ad1a62bcd140491909610d48bd3b83e278cd898acfa9fcd63af126c6705647a5c69911f82f5a54bb2de8dc2ea395dbaf2bcb6faf45 languageName: node linkType: hard diff --git a/test/api_test.http b/test/api_test.http index e5e9e506d..f5b34fae9 100755 --- a/test/api_test.http +++ b/test/api_test.http @@ -6,6 +6,7 @@ @host = http://ems-esp.local @host_dev = http://10.10.10.20 @host_standalone = http://localhost:3080 +@host_standalone2 = http://localhost:3082 @token = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiYWRtaW4iOnRydWV9.2bHpWya2C7Q12WjNUBD6_7N3RCD7CMl-EGhyQVzFdDg @@ -113,4 +114,19 @@ GET {{host_dev}}/api/thermostat/seltemp GET {{host_standalone}}/api/system/info -### \ No newline at end of file +### + +POST {{host_standalone2}}/rest/uploadFile +Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW + +------WebKitFormBoundary7MA4YWxkTrZu0gW +Content-Disposition: form-data; name="text" + +title +------WebKitFormBoundary7MA4YWxkTrZu0gW +Content-Disposition: form-data; name="file"; filename="emsesp_settings.json" +Content-Type: application/json + +< ./standalone_file_export/emsesp_settings.json +------WebKitFormBoundary7MA4YWxkTrZu0gW-- +