From ab58a3dfd32f3536bb07f06ceca6b984bc0a8a48 Mon Sep 17 00:00:00 2001 From: Proddy Date: Wed, 3 Jan 2024 22:55:44 +0100 Subject: [PATCH 01/94] add spacing --- interface/src/framework/system/UploadFileForm.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/src/framework/system/UploadFileForm.tsx b/interface/src/framework/system/UploadFileForm.tsx index c33019df3..e0df328ed 100644 --- a/interface/src/framework/system/UploadFileForm.tsx +++ b/interface/src/framework/system/UploadFileForm.tsx @@ -136,6 +136,7 @@ const UploadFileForm: FC = () => { {LL.UPLOAD_TEXT()}
+
{LL.RESTART_TEXT(1)}.
From 5fcad37fb9e88dfd35a15b2a2002af7e0fb5cd0a Mon Sep 17 00:00:00 2001 From: Proddy Date: Wed, 3 Jan 2024 22:56:03 +0100 Subject: [PATCH 02/94] ok to show devices if no ems connection --- interface/src/project/DashboardDevices.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/project/DashboardDevices.tsx b/interface/src/project/DashboardDevices.tsx index abbb07b18..4fb862693 100644 --- a/interface/src/project/DashboardDevices.tsx +++ b/interface/src/project/DashboardDevices.tsx @@ -420,7 +420,7 @@ const DashboardDevices: FC = () => { )} - {coreData.connected && ( + {coreData.devices.length && ( {(tableList: any) => ( <> From d6856e8a236fd3c68418ffbda7df222cd0bd66f5 Mon Sep 17 00:00:00 2001 From: Proddy Date: Wed, 3 Jan 2024 22:56:16 +0100 Subject: [PATCH 03/94] optimized chunking --- interface/vite.config.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/interface/vite.config.ts b/interface/vite.config.ts index bb76b59ab..b5b69c560 100644 --- a/interface/vite.config.ts +++ b/interface/vite.config.ts @@ -1,4 +1,4 @@ -import { defineConfig } from 'vite'; +import { defineConfig, splitVendorChunkPlugin } from 'vite'; import viteTsconfigPaths from 'vite-tsconfig-paths'; import preact from '@preact/preset-vite'; import viteImagemin from 'vite-plugin-imagemin'; @@ -44,6 +44,7 @@ export default defineConfig(({ command, mode }) => { plugins: [ preact(), viteTsconfigPaths(), + splitVendorChunkPlugin(), { ...viteImagemin({ verbose: false, @@ -112,6 +113,20 @@ export default defineConfig(({ command, mode }) => { nameCache: null, safari10: false, toplevel: false + }, + + rollupOptions: { + output: { + manualChunks(id: string) { + if (id.includes('node_modules')) { + // creating a chunk to react routes deps. Reducing the vendor chunk size + if (id.includes('react-router-dom') || id.includes('@remix-run') || id.includes('react-router')) { + return '@react-router'; + } + return 'vendor'; + } + } + } } } }; From c45fd232272953a6114fc522bccfc0bc616a9adb Mon Sep 17 00:00:00 2001 From: Proddy Date: Wed, 3 Jan 2024 22:56:26 +0100 Subject: [PATCH 04/94] package update --- interface/package.json | 18 +- interface/yarn.lock | 363 +++++++++++++++++++++++++---------------- 2 files changed, 231 insertions(+), 150 deletions(-) diff --git a/interface/package.json b/interface/package.json index 5489c4e60..15f79bc2c 100644 --- a/interface/package.json +++ b/interface/package.json @@ -21,16 +21,16 @@ }, "dependencies": { "@alova/adapter-xhr": "^1.0.2", - "@babel/core": "^7.23.6", + "@babel/core": "^7.23.7", "@emotion/react": "^11.11.3", "@emotion/styled": "^11.11.0", - "@mui/icons-material": "^5.15.2", - "@mui/material": "^5.15.2", + "@mui/icons-material": "^5.15.3", + "@mui/material": "^5.15.3", "@table-library/react-table-library": "4.1.7", "@types/imagemin": "^8.0.5", "@types/lodash-es": "^4.17.12", - "@types/node": "^20.10.5", - "@types/react": "^18.2.45", + "@types/node": "^20.10.6", + "@types/react": "^18.2.46", "@types/react-dom": "^18.2.18", "@types/react-router-dom": "^5.3.3", "alova": "^2.16.2", @@ -51,9 +51,9 @@ }, "devDependencies": { "@preact/compat": "^17.1.2", - "@preact/preset-vite": "^2.7.0", - "@typescript-eslint/eslint-plugin": "^6.16.0", - "@typescript-eslint/parser": "^6.16.0", + "@preact/preset-vite": "^2.8.1", + "@typescript-eslint/eslint-plugin": "^6.17.0", + "@typescript-eslint/parser": "^6.17.0", "concurrently": "^8.2.2", "eslint": "^8.56.0", "eslint-config-airbnb": "^19.0.4", @@ -72,7 +72,7 @@ "terser": "^5.26.0", "vite": "^5.0.10", "vite-plugin-imagemin": "^0.6.1", - "vite-tsconfig-paths": "^4.2.2" + "vite-tsconfig-paths": "^4.2.3" }, "packageManager": "yarn@4.0.2" } diff --git a/interface/yarn.lock b/interface/yarn.lock index 2164fce85..edde8f336 100644 --- a/interface/yarn.lock +++ b/interface/yarn.lock @@ -86,26 +86,26 @@ __metadata: languageName: node linkType: hard -"@babel/core@npm:^7.23.6": - version: 7.23.6 - resolution: "@babel/core@npm:7.23.6" +"@babel/core@npm:^7.23.7": + version: 7.23.7 + resolution: "@babel/core@npm:7.23.7" dependencies: "@ampproject/remapping": "npm:^2.2.0" "@babel/code-frame": "npm:^7.23.5" "@babel/generator": "npm:^7.23.6" "@babel/helper-compilation-targets": "npm:^7.23.6" "@babel/helper-module-transforms": "npm:^7.23.3" - "@babel/helpers": "npm:^7.23.6" + "@babel/helpers": "npm:^7.23.7" "@babel/parser": "npm:^7.23.6" "@babel/template": "npm:^7.22.15" - "@babel/traverse": "npm:^7.23.6" + "@babel/traverse": "npm:^7.23.7" "@babel/types": "npm:^7.23.6" 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: a72ba71d2f557d09ff58a5f0846344b9cea9dfcbd7418729a3a74d5b0f37a5ca024942fef4d19f248de751928a1be3d5cb0488746dd8896009dd55b974bb552e + checksum: 956841695ea801c8b4196d01072e6c1062335960715a6fcfd4009831003b526b00627c78b373ed49b1658c3622c71142f7ff04235fe839cac4a1a25ed51b90aa languageName: node linkType: hard @@ -304,14 +304,14 @@ __metadata: languageName: node linkType: hard -"@babel/helpers@npm:^7.23.6": - version: 7.23.6 - resolution: "@babel/helpers@npm:7.23.6" +"@babel/helpers@npm:^7.23.7": + version: 7.23.7 + resolution: "@babel/helpers@npm:7.23.7" dependencies: "@babel/template": "npm:^7.22.15" - "@babel/traverse": "npm:^7.23.6" + "@babel/traverse": "npm:^7.23.7" "@babel/types": "npm:^7.23.6" - checksum: 2a85fd2bcbc15a6c94dbe7b9e94d8920f9de76d164179d6895fee89c4339079d9e3e56f572bf19b5e7d1e6f1997d7fbaeaa686b47d35136852631dfd09e85c2f + checksum: ec07061dc871d406ed82c8757c4d7a510aaf15145799fb0a2c3bd3c72ca101fe82a02dd5f83ca604fbbba5de5408dd731bb1452150562bed4f3b0a2846f81f61 languageName: node linkType: hard @@ -439,9 +439,9 @@ __metadata: languageName: node linkType: hard -"@babel/traverse@npm:^7.23.6": - version: 7.23.6 - resolution: "@babel/traverse@npm:7.23.6" +"@babel/traverse@npm:^7.23.7": + version: 7.23.7 + resolution: "@babel/traverse@npm:7.23.7" dependencies: "@babel/code-frame": "npm:^7.23.5" "@babel/generator": "npm:^7.23.6" @@ -453,7 +453,7 @@ __metadata: "@babel/types": "npm:^7.23.6" debug: "npm:^4.3.1" globals: "npm:^11.1.0" - checksum: ee4434a3ce792ee8956b64d76843caa1dda4779bb621ed9f951dd3551965bf1f292f097011c9730ecbc0b57f02434b1fa5a771610a2ef570726b0df0fc3332d9 + checksum: 3215e59429963c8dac85c26933372cdd322952aa9930e4bc5ef2d0e4bd7a1510d1ecf8f8fd860ace5d4d9fe496d23805a1ea019a86410aee4111de5f63ee84f9 languageName: node linkType: hard @@ -953,7 +953,7 @@ __metadata: languageName: node linkType: hard -"@jridgewell/sourcemap-codec@npm:^1.4.10, @jridgewell/sourcemap-codec@npm:^1.4.14": +"@jridgewell/sourcemap-codec@npm:^1.4.10, @jridgewell/sourcemap-codec@npm:^1.4.14, @jridgewell/sourcemap-codec@npm:^1.4.15": version: 1.4.15 resolution: "@jridgewell/sourcemap-codec@npm:1.4.15" checksum: 89960ac087781b961ad918978975bcdf2051cd1741880469783c42de64239703eab9db5230d776d8e6a09d73bb5e4cb964e07d93ee6e2e7aea5a7d726e865c09 @@ -970,14 +970,14 @@ __metadata: languageName: node linkType: hard -"@mui/base@npm:5.0.0-beta.29": - version: 5.0.0-beta.29 - resolution: "@mui/base@npm:5.0.0-beta.29" +"@mui/base@npm:5.0.0-beta.30": + version: 5.0.0-beta.30 + resolution: "@mui/base@npm:5.0.0-beta.30" dependencies: "@babel/runtime": "npm:^7.23.6" "@floating-ui/react-dom": "npm:^2.0.4" - "@mui/types": "npm:^7.2.11" - "@mui/utils": "npm:^5.15.2" + "@mui/types": "npm:^7.2.12" + "@mui/utils": "npm:^5.15.3" "@popperjs/core": "npm:^2.11.8" clsx: "npm:^2.0.0" prop-types: "npm:^15.8.1" @@ -988,20 +988,20 @@ __metadata: peerDependenciesMeta: "@types/react": optional: true - checksum: a651464968af6ebb775c24d2b9badc735b1d595e526ff7f8181186e6eed0735b14af8324db22a8744039ad79ce6dbb7c62920bb92a57959a66cf8e72d68af9aa + checksum: 55e18d59ac96f5bbfbfdadd907751f5e6a4f74f611b5e99fe5f8002c76fa117b62c159f52ea0f12574a66460d62734082438cff19cb73e3fca9dc22f82f6eaf2 languageName: node linkType: hard -"@mui/core-downloads-tracker@npm:^5.15.2": - version: 5.15.2 - resolution: "@mui/core-downloads-tracker@npm:5.15.2" - checksum: 8c88ac73a1d87c8ce565f6295dcd084c643580848e8f59159402e9db89975263da06305a0e605d3744479e917c2d297319496534bca9df8338e203162f1e7c33 +"@mui/core-downloads-tracker@npm:^5.15.3": + version: 5.15.3 + resolution: "@mui/core-downloads-tracker@npm:5.15.3" + checksum: 002451af1aa555c0163c0ffacde5c15062e0ae0f30b81945e1a0befe7b6c5d14924a2b068b7b5f713c177ee3eecca4fc250d590d11206a6b5465700c399a34d1 languageName: node linkType: hard -"@mui/icons-material@npm:^5.15.2": - version: 5.15.2 - resolution: "@mui/icons-material@npm:5.15.2" +"@mui/icons-material@npm:^5.15.3": + version: 5.15.3 + resolution: "@mui/icons-material@npm:5.15.3" dependencies: "@babel/runtime": "npm:^7.23.6" peerDependencies: @@ -1011,20 +1011,20 @@ __metadata: peerDependenciesMeta: "@types/react": optional: true - checksum: 6dad9fa436889ab89217d428f38b1f7868eb5db0b8aa2b16086f6e81666763767a29db8897e76d078919df7349a149c6e16da1aea1b3ae48ca0b7ee1e0d9d458 + checksum: 2393a9dcd0834cdda728b8ebca5d8f6acbfc34316346aaea257e32961abf7cf578419df196b50223b89b3e2556098aea283786ca4eeedaf58be3d204f499f6bc languageName: node linkType: hard -"@mui/material@npm:^5.15.2": - version: 5.15.2 - resolution: "@mui/material@npm:5.15.2" +"@mui/material@npm:^5.15.3": + version: 5.15.3 + resolution: "@mui/material@npm:5.15.3" dependencies: "@babel/runtime": "npm:^7.23.6" - "@mui/base": "npm:5.0.0-beta.29" - "@mui/core-downloads-tracker": "npm:^5.15.2" - "@mui/system": "npm:^5.15.2" - "@mui/types": "npm:^7.2.11" - "@mui/utils": "npm:^5.15.2" + "@mui/base": "npm:5.0.0-beta.30" + "@mui/core-downloads-tracker": "npm:^5.15.3" + "@mui/system": "npm:^5.15.3" + "@mui/types": "npm:^7.2.12" + "@mui/utils": "npm:^5.15.3" "@types/react-transition-group": "npm:^4.4.10" clsx: "npm:^2.0.0" csstype: "npm:^3.1.2" @@ -1044,16 +1044,16 @@ __metadata: optional: true "@types/react": optional: true - checksum: 1ce902070022c40009e01208e95d0d61205ffdbcf4fadd16e6337acdfccfb1c66004525ffe277691c7f3fbdfcebb998f1544c054a31164d580cb040e8a7d2d80 + checksum: fe8d318aed036b649a82e4833254f833ece028b6a25cec001991e6864d9e520752df6a746b6ca856c0310cc9aae16697aa77ddf53a85c889bb5d04c5aa5c1dcb languageName: node linkType: hard -"@mui/private-theming@npm:^5.15.2": - version: 5.15.2 - resolution: "@mui/private-theming@npm:5.15.2" +"@mui/private-theming@npm:^5.15.3": + version: 5.15.3 + resolution: "@mui/private-theming@npm:5.15.3" dependencies: "@babel/runtime": "npm:^7.23.6" - "@mui/utils": "npm:^5.15.2" + "@mui/utils": "npm:^5.15.3" prop-types: "npm:^15.8.1" peerDependencies: "@types/react": ^17.0.0 || ^18.0.0 @@ -1061,13 +1061,13 @@ __metadata: peerDependenciesMeta: "@types/react": optional: true - checksum: 2b1665044fd77286068100bd5c67ba3a31320084b442788e1c0224359b6e8e3213505676fa1db451c970b2e432811b12cbcf2f882c9063d37497dbfcfcd8811e + checksum: 4404a7d9545974631b329f391df72fa54edb5aefa6d32d9656b200284613e8ea1bdd3d0add2abe7278f1343dd5cf7552c7e4d2aaf5593f292c7db3cd63ddff21 languageName: node linkType: hard -"@mui/styled-engine@npm:^5.15.2": - version: 5.15.2 - resolution: "@mui/styled-engine@npm:5.15.2" +"@mui/styled-engine@npm:^5.15.3": + version: 5.15.3 + resolution: "@mui/styled-engine@npm:5.15.3" dependencies: "@babel/runtime": "npm:^7.23.6" "@emotion/cache": "npm:^11.11.0" @@ -1082,19 +1082,19 @@ __metadata: optional: true "@emotion/styled": optional: true - checksum: c004a37f4343139896059a706e96175a0f8975cc8807bcea96c099a68a94cf24d7869e685b06511389c9a6e4412acac5ef07614659983a7782f203012b78315b + checksum: 6775f92cda9f17428baf5b95e5849f31eead92485e332902ff29bd49bd03fbe2f5e762ebcdd122f7f31e102ec42cda29cbb5fdef79f5d03f416705d119b69e75 languageName: node linkType: hard -"@mui/system@npm:^5.15.2": - version: 5.15.2 - resolution: "@mui/system@npm:5.15.2" +"@mui/system@npm:^5.15.3": + version: 5.15.3 + resolution: "@mui/system@npm:5.15.3" dependencies: "@babel/runtime": "npm:^7.23.6" - "@mui/private-theming": "npm:^5.15.2" - "@mui/styled-engine": "npm:^5.15.2" - "@mui/types": "npm:^7.2.11" - "@mui/utils": "npm:^5.15.2" + "@mui/private-theming": "npm:^5.15.3" + "@mui/styled-engine": "npm:^5.15.3" + "@mui/types": "npm:^7.2.12" + "@mui/utils": "npm:^5.15.3" clsx: "npm:^2.0.0" csstype: "npm:^3.1.2" prop-types: "npm:^15.8.1" @@ -1110,25 +1110,25 @@ __metadata: optional: true "@types/react": optional: true - checksum: 05335cc7856750a930e5eef4eaf3e935c1d6dd78add48e86d1d976736adea71c5f37f3c329fd0a8f5fd9d11e40775ab5a62192dc056d240cb365416ad4db5568 + checksum: 7b71cad3c3b4f8136cf51a9e7040440073201618eaa5d0fcbd8830e3c3f35eb8a38303bb2bc9da84e0c95844193fdb4238af50e1f1d74a8e9fa79500a49c31db languageName: node linkType: hard -"@mui/types@npm:^7.2.11": - version: 7.2.11 - resolution: "@mui/types@npm:7.2.11" +"@mui/types@npm:^7.2.12": + version: 7.2.12 + resolution: "@mui/types@npm:7.2.12" peerDependencies: "@types/react": ^17.0.0 || ^18.0.0 peerDependenciesMeta: "@types/react": optional: true - checksum: 57d47e455aeef066c38260ddededbb41b3a3830acc013a597e8434cb5291fc4fc85e76cf354c6d5ecee3894bb13c7723423b58e753485d7e6d06ca54f7d76cf7 + checksum: 7d3ef53fee7eddc063d2083dc129f7d6d38b472a9196c3522fc5a75e66849fbf2b824be3f6aee11dc02c4475864e544026e6051ffb9d33f5dc1fc2a2279a8b72 languageName: node linkType: hard -"@mui/utils@npm:^5.15.2": - version: 5.15.2 - resolution: "@mui/utils@npm:5.15.2" +"@mui/utils@npm:^5.15.3": + version: 5.15.3 + resolution: "@mui/utils@npm:5.15.3" dependencies: "@babel/runtime": "npm:^7.23.6" "@types/prop-types": "npm:^15.7.11" @@ -1140,7 +1140,7 @@ __metadata: peerDependenciesMeta: "@types/react": optional: true - checksum: 9ede26d8e2b456a5ecf088d4e2d6903613be57eae97fcd30a9f31ff2c35a0e4329c728bd20c94c6f3468038935c3101a040c2cfb7dd6ff7a490811af0675d90a + checksum: c4d66e34332f448527c6dea66a7011f95dc230ccaf5a3ee898a6fd69b77a3584af1fd644d095dc7edb2d480e5c050db06f9b9ec9dea3bc5091a80cf8b676f709 languageName: node linkType: hard @@ -1217,9 +1217,9 @@ __metadata: languageName: node linkType: hard -"@preact/preset-vite@npm:^2.7.0": - version: 2.7.0 - resolution: "@preact/preset-vite@npm:2.7.0" +"@preact/preset-vite@npm:^2.8.1": + version: 2.8.1 + resolution: "@preact/preset-vite@npm:2.8.1" dependencies: "@babel/plugin-transform-react-jsx": "npm:^7.22.15" "@babel/plugin-transform-react-jsx-development": "npm:^7.22.5" @@ -1228,11 +1228,13 @@ __metadata: babel-plugin-transform-hook-names: "npm:^1.0.2" debug: "npm:^4.3.4" kolorist: "npm:^1.8.0" + magic-string: "npm:0.30.5" + node-html-parser: "npm:^6.1.10" resolve: "npm:^1.22.8" peerDependencies: "@babel/core": 7.x vite: 2.x || 3.x || 4.x || 5.x - checksum: dc0420ea1b6718fbf02d395e44642bd74736dcc23236e645bc390bae3371f359dec65ec1aa9358e77d73354d9d2d7af0ae71eec11e99aac335fe85b49dcd9d54 + checksum: ac91fc701e078d2910b386b9e793f5429f9db04e3c56ea0f41f5f777fb21f5610acd9091def7bb2da9aaadbb9e687e1c276ff0d636fe3427ebd452dce5f98838 languageName: node linkType: hard @@ -1566,12 +1568,12 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:^20.10.5": - version: 20.10.5 - resolution: "@types/node@npm:20.10.5" +"@types/node@npm:^20.10.6": + version: 20.10.6 + resolution: "@types/node@npm:20.10.6" dependencies: undici-types: "npm:~5.26.4" - checksum: 4a378428d2c9f692b19801a5a3d20dc4c0ad5d4a3d103350f8b401af439941a9aa5efeadc8eb9db13c66c620318bc7f336abfc8934f82fd32c4a689d85068c6f + checksum: 08471220d3cbbb6669835c4b78541edf5eface8f2c2e36c550cfa4ff73da73071c90e200a06359fac25d6564127597c23e178128058fb676824ec23d5178a017 languageName: node linkType: hard @@ -1646,14 +1648,14 @@ __metadata: languageName: node linkType: hard -"@types/react@npm:^18.2.45": - version: 18.2.45 - resolution: "@types/react@npm:18.2.45" +"@types/react@npm:^18.2.46": + version: 18.2.46 + resolution: "@types/react@npm:18.2.46" dependencies: "@types/prop-types": "npm:*" "@types/scheduler": "npm:*" csstype: "npm:^3.0.2" - checksum: bd27fd8a959fa776965997af89cb04e43e7868416850fdff421b5539f389efa35acae3d55915c9f32d7b00fb388550302bf8a7f06010abf9ad431e5bf58cb774 + checksum: 10fb28a5b8504106512ce3b154c45d1ac045c31633786773a29f003b3079b434060368bb56f95ef6c39510835ceec4fb8fdc271d6ca2b9cdd979379cf53f126b languageName: node linkType: hard @@ -1689,15 +1691,15 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/eslint-plugin@npm:^6.16.0": - version: 6.16.0 - resolution: "@typescript-eslint/eslint-plugin@npm:6.16.0" +"@typescript-eslint/eslint-plugin@npm:^6.17.0": + version: 6.17.0 + resolution: "@typescript-eslint/eslint-plugin@npm:6.17.0" dependencies: "@eslint-community/regexpp": "npm:^4.5.1" - "@typescript-eslint/scope-manager": "npm:6.16.0" - "@typescript-eslint/type-utils": "npm:6.16.0" - "@typescript-eslint/utils": "npm:6.16.0" - "@typescript-eslint/visitor-keys": "npm:6.16.0" + "@typescript-eslint/scope-manager": "npm:6.17.0" + "@typescript-eslint/type-utils": "npm:6.17.0" + "@typescript-eslint/utils": "npm:6.17.0" + "@typescript-eslint/visitor-keys": "npm:6.17.0" debug: "npm:^4.3.4" graphemer: "npm:^1.4.0" ignore: "npm:^5.2.4" @@ -1710,44 +1712,44 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: 4bedce948ac3c20492a59813ee5d4f1f2306310857864dfaac2736f6c38e18785002c36844fd64c9fbdf3059fc390b29412be105fd7a118177f1eeeb1eb533f7 + checksum: f2a5774e9cc03e491a5a488501e5622c7eebd766f5a4fc2c30642864a3b89b0807946bde33a678f326ba7032f3f6a51aa0bf9c2d10adc823804fc9fb47db55a6 languageName: node linkType: hard -"@typescript-eslint/parser@npm:^6.16.0": - version: 6.16.0 - resolution: "@typescript-eslint/parser@npm:6.16.0" +"@typescript-eslint/parser@npm:^6.17.0": + version: 6.17.0 + resolution: "@typescript-eslint/parser@npm:6.17.0" dependencies: - "@typescript-eslint/scope-manager": "npm:6.16.0" - "@typescript-eslint/types": "npm:6.16.0" - "@typescript-eslint/typescript-estree": "npm:6.16.0" - "@typescript-eslint/visitor-keys": "npm:6.16.0" + "@typescript-eslint/scope-manager": "npm:6.17.0" + "@typescript-eslint/types": "npm:6.17.0" + "@typescript-eslint/typescript-estree": "npm:6.17.0" + "@typescript-eslint/visitor-keys": "npm:6.17.0" debug: "npm:^4.3.4" peerDependencies: eslint: ^7.0.0 || ^8.0.0 peerDependenciesMeta: typescript: optional: true - checksum: 3d941ce345dc2ce29957e2110957662873d514b094b8939923c3281d858c11cd1f9058db862644afe14f68d087770f39a0a1f9e523a2013ed5d2fdf3421b34d0 + checksum: 2ed0ed4a5b30e953430ce3279df3655af09fa1caed2abf11804d239717daefc32a22864f6620ef57bb9c684c74a99a13241384fea5096e961385e3678fc2e920 languageName: node linkType: hard -"@typescript-eslint/scope-manager@npm:6.16.0": - version: 6.16.0 - resolution: "@typescript-eslint/scope-manager@npm:6.16.0" +"@typescript-eslint/scope-manager@npm:6.17.0": + version: 6.17.0 + resolution: "@typescript-eslint/scope-manager@npm:6.17.0" dependencies: - "@typescript-eslint/types": "npm:6.16.0" - "@typescript-eslint/visitor-keys": "npm:6.16.0" - checksum: 3360aae4b85f5c31d20ad48d771cc09a6f8f6b1811b00d94f06e55b5a09c610ac75631b1c4edecb3bec682d41351b87e7d14d42bee84aa032064d0e13463035b + "@typescript-eslint/types": "npm:6.17.0" + "@typescript-eslint/visitor-keys": "npm:6.17.0" + checksum: fe09c628553c9336e6a36d32c1d34e78ebd20aa02130a6bf535329621ba5a98aaac171f607bc6e4d17b3478c42e7de6476376636897ce3f227c754eb99acd07e languageName: node linkType: hard -"@typescript-eslint/type-utils@npm:6.16.0": - version: 6.16.0 - resolution: "@typescript-eslint/type-utils@npm:6.16.0" +"@typescript-eslint/type-utils@npm:6.17.0": + version: 6.17.0 + resolution: "@typescript-eslint/type-utils@npm:6.17.0" dependencies: - "@typescript-eslint/typescript-estree": "npm:6.16.0" - "@typescript-eslint/utils": "npm:6.16.0" + "@typescript-eslint/typescript-estree": "npm:6.17.0" + "@typescript-eslint/utils": "npm:6.17.0" debug: "npm:^4.3.4" ts-api-utils: "npm:^1.0.1" peerDependencies: @@ -1755,23 +1757,23 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: 5964b87a87252bed278a248eb568902babd7c34defd3af8c3df371926d96aec716f33f1dc14bde170e93f73ed1b0af6e591e647853d0f33f378e2c7b3b73fc5b + checksum: dc7938429193acfda61b7282197ec046039e2c4da41cdcddf4daaf300d10229e4e23bb0fcf0503b19c0b99a874849c8a9f5bb35ce106260f56a14106d2b41d8c languageName: node linkType: hard -"@typescript-eslint/types@npm:6.16.0": - version: 6.16.0 - resolution: "@typescript-eslint/types@npm:6.16.0" - checksum: 236ca318c2440c95068e5d4d147e2bfed62447775e18695e21c8ca04a341a74d01c37ed2b417629b7bf2fb91ad4fd5e2a6570215d16fc24dd1507ce6973b4e22 +"@typescript-eslint/types@npm:6.17.0": + version: 6.17.0 + resolution: "@typescript-eslint/types@npm:6.17.0" + checksum: 87ab1b5a3270ab34b917c22a2fb90a9ad7d9f3b19d73a337bc9efbe65f924da13482c97e8ccbe3bd3d081aa96039eeff50de41c1da2a2128066429b931cdb21d languageName: node linkType: hard -"@typescript-eslint/typescript-estree@npm:6.16.0": - version: 6.16.0 - resolution: "@typescript-eslint/typescript-estree@npm:6.16.0" +"@typescript-eslint/typescript-estree@npm:6.17.0": + version: 6.17.0 + resolution: "@typescript-eslint/typescript-estree@npm:6.17.0" dependencies: - "@typescript-eslint/types": "npm:6.16.0" - "@typescript-eslint/visitor-keys": "npm:6.16.0" + "@typescript-eslint/types": "npm:6.17.0" + "@typescript-eslint/visitor-keys": "npm:6.17.0" debug: "npm:^4.3.4" globby: "npm:^11.1.0" is-glob: "npm:^4.0.3" @@ -1781,34 +1783,34 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: 8e1ef03ecabaf3791b11240a51217836dbb74850e458258db77ac5eab5508cd9c63fb671924993d1e7654718c0c857c3550d51ecba0845fe489d143bb858e1b1 + checksum: 1671b0d2f2fdf07074fb1e2524d61935cec173bd8db6e482cc5b2dcc77aed3ffa831396736ffa0ee2fdbddd8585ae9ca8d6c97bcaea1385b23907a1ec0508f83 languageName: node linkType: hard -"@typescript-eslint/utils@npm:6.16.0": - version: 6.16.0 - resolution: "@typescript-eslint/utils@npm:6.16.0" +"@typescript-eslint/utils@npm:6.17.0": + version: 6.17.0 + resolution: "@typescript-eslint/utils@npm:6.17.0" dependencies: "@eslint-community/eslint-utils": "npm:^4.4.0" "@types/json-schema": "npm:^7.0.12" "@types/semver": "npm:^7.5.0" - "@typescript-eslint/scope-manager": "npm:6.16.0" - "@typescript-eslint/types": "npm:6.16.0" - "@typescript-eslint/typescript-estree": "npm:6.16.0" + "@typescript-eslint/scope-manager": "npm:6.17.0" + "@typescript-eslint/types": "npm:6.17.0" + "@typescript-eslint/typescript-estree": "npm:6.17.0" semver: "npm:^7.5.4" peerDependencies: eslint: ^7.0.0 || ^8.0.0 - checksum: 84dd02f7c8e47fae699cc222da5cbea08b28c6e1cc7827860430bc86c2a17ee3f86e198a4356902b95930f85785aa662266ea9c476f69bf80c6a5f648e55f9f4 + checksum: 37c63afcf66124bf84808699997953b8c84a378aa2c490a771b611d82cdac8499c58fac8eeb8378528e97660b59563d99297bfec4b982cd68760b0ffe54aa714 languageName: node linkType: hard -"@typescript-eslint/visitor-keys@npm:6.16.0": - version: 6.16.0 - resolution: "@typescript-eslint/visitor-keys@npm:6.16.0" +"@typescript-eslint/visitor-keys@npm:6.17.0": + version: 6.17.0 + resolution: "@typescript-eslint/visitor-keys@npm:6.17.0" dependencies: - "@typescript-eslint/types": "npm:6.16.0" + "@typescript-eslint/types": "npm:6.17.0" eslint-visitor-keys: "npm:^3.4.1" - checksum: 19e559f14ea0092585a374b8c5f1aca9b6b271fc23909d9857de9cf71a1e1d3abc0afd237e9c02d7a5fbdfe8e3be7853cf9fedf40a6f16bac3495cb7f4e67982 + checksum: a2aed0e1437fdab8858ab9c7c8e355f8b72a5fa4b0adc54f28b8a2bbc29d4bb93214968ee940f83d013d0a4b83d00cd4eeeb05fb4c2c7d0ead324c6793f7d6d4 languageName: node linkType: hard @@ -1824,22 +1826,22 @@ __metadata: resolution: "EMS-ESP@workspace:." dependencies: "@alova/adapter-xhr": "npm:^1.0.2" - "@babel/core": "npm:^7.23.6" + "@babel/core": "npm:^7.23.7" "@emotion/react": "npm:^11.11.3" "@emotion/styled": "npm:^11.11.0" - "@mui/icons-material": "npm:^5.15.2" - "@mui/material": "npm:^5.15.2" + "@mui/icons-material": "npm:^5.15.3" + "@mui/material": "npm:^5.15.3" "@preact/compat": "npm:^17.1.2" - "@preact/preset-vite": "npm:^2.7.0" + "@preact/preset-vite": "npm:^2.8.1" "@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.10.5" - "@types/react": "npm:^18.2.45" + "@types/node": "npm:^20.10.6" + "@types/react": "npm:^18.2.46" "@types/react-dom": "npm:^18.2.18" "@types/react-router-dom": "npm:^5.3.3" - "@typescript-eslint/eslint-plugin": "npm:^6.16.0" - "@typescript-eslint/parser": "npm:^6.16.0" + "@typescript-eslint/eslint-plugin": "npm:^6.17.0" + "@typescript-eslint/parser": "npm:^6.17.0" alova: "npm:^2.16.2" async-validator: "npm:^4.2.5" concurrently: "npm:^8.2.2" @@ -1873,7 +1875,7 @@ __metadata: typescript: "npm:^5.3.3" vite: "npm:^5.0.10" vite-plugin-imagemin: "npm:^0.6.1" - vite-tsconfig-paths: "npm:^4.2.2" + vite-tsconfig-paths: "npm:^4.2.3" languageName: unknown linkType: soft @@ -2833,6 +2835,19 @@ __metadata: languageName: node linkType: hard +"css-select@npm:^5.1.0": + version: 5.1.0 + resolution: "css-select@npm:5.1.0" + dependencies: + boolbase: "npm:^1.0.0" + css-what: "npm:^6.1.0" + domhandler: "npm:^5.0.2" + domutils: "npm:^3.0.1" + nth-check: "npm:^2.0.1" + checksum: d486b1e7eb140468218a5ab5af53257e01f937d2173ac46981f6b7de9c5283d55427a36715dc8decfc0c079cf89259ac5b41ef58f6e1a422eee44ab8bfdc78da + languageName: node + linkType: hard + "css-tree@npm:^1.1.2, css-tree@npm:^1.1.3": version: 1.1.3 resolution: "css-tree@npm:1.1.3" @@ -2843,7 +2858,7 @@ __metadata: languageName: node linkType: hard -"css-what@npm:^6.0.1": +"css-what@npm:^6.0.1, css-what@npm:^6.1.0": version: 6.1.0 resolution: "css-what@npm:6.1.0" checksum: c67a3a2d0d81843af87f8bf0a4d0845b0f952377714abbb2884e48942409d57a2110eabee003609d02ee487b054614bdfcfc59ee265728ff105bd5aa221c1d0e @@ -3137,7 +3152,18 @@ __metadata: languageName: node linkType: hard -"domelementtype@npm:^2.0.1, domelementtype@npm:^2.2.0": +"dom-serializer@npm:^2.0.0": + version: 2.0.0 + resolution: "dom-serializer@npm:2.0.0" + dependencies: + domelementtype: "npm:^2.3.0" + domhandler: "npm:^5.0.2" + entities: "npm:^4.2.0" + checksum: e3bf9027a64450bca0a72297ecdc1e3abb7a2912268a9f3f5d33a2e29c1e2c3502c6e9f860fc6625940bfe0cfb57a44953262b9e94df76872fdfb8151097eeb3 + languageName: node + linkType: hard + +"domelementtype@npm:^2.0.1, domelementtype@npm:^2.2.0, domelementtype@npm:^2.3.0": version: 2.3.0 resolution: "domelementtype@npm:2.3.0" checksum: ee837a318ff702622f383409d1f5b25dd1024b692ef64d3096ff702e26339f8e345820f29a68bcdcea8cfee3531776b3382651232fbeae95612d6f0a75efb4f6 @@ -3153,6 +3179,15 @@ __metadata: languageName: node linkType: hard +"domhandler@npm:^5.0.2, domhandler@npm:^5.0.3": + version: 5.0.3 + resolution: "domhandler@npm:5.0.3" + dependencies: + domelementtype: "npm:^2.3.0" + checksum: 809b805a50a9c6884a29f38aec0a4e1b4537f40e1c861950ed47d10b049febe6b79ab72adaeeebb3cc8fc1cd33f34e97048a72a9265103426d93efafa78d3e96 + languageName: node + linkType: hard + "domutils@npm:^2.8.0": version: 2.8.0 resolution: "domutils@npm:2.8.0" @@ -3164,6 +3199,17 @@ __metadata: languageName: node linkType: hard +"domutils@npm:^3.0.1": + version: 3.1.0 + resolution: "domutils@npm:3.1.0" + dependencies: + dom-serializer: "npm:^2.0.0" + domelementtype: "npm:^2.3.0" + domhandler: "npm:^5.0.3" + checksum: 9a169a6e57ac4c738269a73ab4caf785114ed70e46254139c1bbc8144ac3102aacb28a6149508395ae34aa5d6a40081f4fa5313855dc8319c6d8359866b6dfea + languageName: node + linkType: hard + "download@npm:^6.2.2": version: 6.2.5 resolution: "download@npm:6.2.5" @@ -3280,6 +3326,13 @@ __metadata: languageName: node linkType: hard +"entities@npm:^4.2.0": + version: 4.5.0 + resolution: "entities@npm:4.5.0" + checksum: ede2a35c9bce1aeccd055a1b445d41c75a14a2bb1cd22e242f20cf04d236cdcd7f9c859eb83f76885327bfae0c25bf03303665ee1ce3d47c5927b98b0e3e3d48 + languageName: node + linkType: hard + "env-paths@npm:^2.2.0": version: 2.2.1 resolution: "env-paths@npm:2.2.1" @@ -4950,6 +5003,15 @@ __metadata: languageName: node linkType: hard +"he@npm:1.2.0": + version: 1.2.0 + resolution: "he@npm:1.2.0" + bin: + he: bin/he + checksum: d09b2243da4e23f53336e8de3093e5c43d2c39f8d0d18817abfa32ce3e9355391b2edb4bb5edc376aea5d4b0b59d6a0482aab4c52bc02ef95751e4b818e847f1 + languageName: node + linkType: hard + "history@npm:^5.3.0": version: 5.3.0 resolution: "history@npm:5.3.0" @@ -6037,6 +6099,15 @@ __metadata: languageName: node linkType: hard +"magic-string@npm:0.30.5": + version: 0.30.5 + resolution: "magic-string@npm:0.30.5" + dependencies: + "@jridgewell/sourcemap-codec": "npm:^1.4.15" + checksum: c8a6b25f813215ca9db526f3a407d6dc0bf35429c2b8111d6f1c2cf6cf6afd5e2d9f9cd189416a0e3959e20ecd635f73639f9825c73de1074b29331fe36ace59 + languageName: node + linkType: hard + "make-dir@npm:^1.0.0, make-dir@npm:^1.2.0": version: 1.3.0 resolution: "make-dir@npm:1.3.0" @@ -6373,6 +6444,16 @@ __metadata: languageName: node linkType: hard +"node-html-parser@npm:^6.1.10": + version: 6.1.12 + resolution: "node-html-parser@npm:6.1.12" + dependencies: + css-select: "npm:^5.1.0" + he: "npm:1.2.0" + checksum: 83e6b8bc2921522ca0eba7f2bdaad6d4a182cb3e578444504e2603fb35604a95a5787430be04066799669a27c6d3886a89c792b1848307bfad9028b9483752a0 + languageName: node + linkType: hard + "node-releases@npm:^2.0.13": version: 2.0.13 resolution: "node-releases@npm:2.0.13" @@ -8674,9 +8755,9 @@ __metadata: languageName: node linkType: hard -"vite-tsconfig-paths@npm:^4.2.2": - version: 4.2.2 - resolution: "vite-tsconfig-paths@npm:4.2.2" +"vite-tsconfig-paths@npm:^4.2.3": + version: 4.2.3 + resolution: "vite-tsconfig-paths@npm:4.2.3" dependencies: debug: "npm:^4.1.1" globrex: "npm:^0.1.2" @@ -8686,7 +8767,7 @@ __metadata: peerDependenciesMeta: vite: optional: true - checksum: 790b9a48dd69b6e93bc41455ef0cc63fc8149b40a6d344784067fc2487b0a02f2d6a6d71396214dab7537a52c5e1ddfc88c363232fa707377db161d05e8f68cd + checksum: ba6abe5d18fc1c1e494e1f1d8a7db56445c2a40e15aadb5d47a9c66cc5372d6f69b94ff0b1e47b67659d6ecaeddebab0a9d11e40b1c3c36c0115800736a6c760 languageName: node linkType: hard From 1316fe950951ea0b23460c931af7f2204bf9ea1b Mon Sep 17 00:00:00 2001 From: Proddy Date: Wed, 3 Jan 2024 22:57:13 +0100 Subject: [PATCH 05/94] 3.6.5-dev.8 --- CHANGELOG_LATEST.md | 4 +++- src/version.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index 97513fc8f..802232884 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -10,7 +10,7 @@ - heatpump energy meters [#1463](https://github.com/emsesp/EMS-ESP32/issues/1463) - heatpump max power [#1475](https://github.com/emsesp/EMS-ESP32/issues/1475) - checkbox for MQTT-TLS enable [#1474](https://github.com/emsesp/EMS-ESP32/issues/1474) -- added SK (Slovencina) language. Thanks @misa1515 +- added SK (Slovenian) language. Thanks @misa1515 - CPU info [#1497](https://github.com/emsesp/EMS-ESP32/pull/1497) ## Fixed @@ -18,6 +18,8 @@ - exhaust temperature for some boilers - add back boil2hyst [#1477](https://github.com/emsesp/EMS-ESP32/issues/1477) - subscribed MQTT topics not detecting changes by EMS-ESP [#1494](https://github.com/emsesp/EMS-ESP32/issues/1494) +- changed HA name and grouping to be consistent [#1528](https://github.com/emsesp/EMS-ESP32/issues/1528) +- MQTT autodiscovery in Domoticz not working [#1360](https://github.com/emsesp/EMS-ESP32/issues/1528) ## Changed diff --git a/src/version.h b/src/version.h index 2ccdaa2ab..3b890a031 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define EMSESP_APP_VERSION "3.6.5-dev.7" +#define EMSESP_APP_VERSION "3.6.5-dev.8" From 78bd0a1b76b1821ec627f9b982294be13d4c51d8 Mon Sep 17 00:00:00 2001 From: Proddy Date: Wed, 3 Jan 2024 22:57:59 +0100 Subject: [PATCH 06/94] espressif 6.5.0 --- platformio.ini | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/platformio.ini b/platformio.ini index e708d80b7..be35b8abb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -2,8 +2,8 @@ ; override any settings with your own local ones in pio_local.ini [platformio] -default_envs = esp32_4M -; default_envs = lolin_s3 +; default_envs = esp32_4M +default_envs = lolin_s3 ; default_envs = esp32_16M ; default_envs = standalone @@ -13,8 +13,6 @@ extra_configs = [common] core_build_flags = - -D CORE_DEBUG_LEVEL=0 - -D NDEBUG -D ARDUINO_ARCH_ESP32=1 -D ESP32=1 ; -std=gnu++17 @@ -33,13 +31,14 @@ build_flags = -D NO_GLOBAL_ARDUINOOTA -D ARDUINOJSON_ENABLE_STD_STRING=1 -D ARDUINOJSON_USE_DOUBLE=0 - ; -D CONFIG_UART_ISR_IN_IRAM + -D ARDUINOTRACE_ENABLE=0 + -D CONFIG_ETH_ENABLED unbuild_flags = ${common.core_unbuild_flags} [espressi32_base] -platform = espressif32@6.4.0 +platform = espressif32@6.5.0 framework = arduino board_build.filesystem = littlefs build_flags = ${common.build_flags} @@ -69,7 +68,7 @@ extra_scripts = [env] monitor_speed = 115200 -monitor_raw = yes +monitor_filters = esp32_exception_decoder upload_speed = 921600 build_type = release lib_ldf_mode = chain+ @@ -178,7 +177,8 @@ build_flags = -lpthread -std=gnu++11 -Og -ggdb build_src_flags = - -Wall -Wextra -Werror -Wswitch-enum -Wno-unused-parameter -Wno-inconsistent-missing-override -Wno-unused-lambda-capture -Wno-sign-compare + ; -Wall -Wextra -Werror -Wswitch-enum -Wno-unused-parameter -Wno-inconsistent-missing-override -Wno-unused-lambda-capture -Wno-sign-compare + ; -Wall -Wextra -Werror -Wno-missing-braces -I./lib_standalone -I./lib/ArduinoJson/src @@ -201,4 +201,4 @@ build_src_filter = +<../lib/espMqttClient/src> +<../lib/espMqttClient/src/Transport> lib_compat_mode = off -lib_ldf_mode = off \ No newline at end of file +lib_ldf_mode = off From e525552e10bac2da72e9120645417582d9989aa4 Mon Sep 17 00:00:00 2001 From: Proddy Date: Wed, 3 Jan 2024 22:58:21 +0100 Subject: [PATCH 07/94] wifi console help text --- src/console.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/console.cpp b/src/console.cpp index 06fd98aba..1902561b2 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -237,7 +237,7 @@ static void setup_commands(std::shared_ptr & commands) { networkSettings.password = password2.c_str(); return StateUpdateResult::CHANGED; }); - shell.println("Use `wifi reconnect` to save and apply the new settings"); + shell.println("WiFi password updated"); } else { shell.println("Passwords do not match"); } @@ -272,7 +272,7 @@ static void setup_commands(std::shared_ptr & commands) { networkSettings.ssid = arguments.front().c_str(); return StateUpdateResult::CHANGED; }); - shell.println("Use `wifi reconnect` to save and apply the new settings"); + shell.println("WiFi ssid updated"); }); From cb5f707b2d5e7e27374bf7e599efae9ca3c2bcfb Mon Sep 17 00:00:00 2001 From: Proddy Date: Wed, 3 Jan 2024 23:00:07 +0100 Subject: [PATCH 08/94] use add_ha_sections_to_doc(), add via_device, add check for domoticz --- src/analogsensor.cpp | 8 +-- src/mqtt.cpp | 105 +++++++++++++++++------------ src/mqtt.h | 9 ++- src/shower.cpp | 21 +----- src/temperaturesensor.cpp | 17 ++--- src/web/WebCustomEntityService.cpp | 7 +- src/web/WebSchedulerService.cpp | 7 +- 7 files changed, 83 insertions(+), 91 deletions(-) diff --git a/src/analogsensor.cpp b/src/analogsensor.cpp index 61f6cca7f..045dbbdae 100644 --- a/src/analogsensor.cpp +++ b/src/analogsensor.cpp @@ -615,13 +615,7 @@ void AnalogSensor::publish_values(const bool force) { config["stat_cla"] = "measurement"; } - JsonObject dev = config.createNestedObject("dev"); - dev["name"] = Mqtt::basename() + " Analog"; - JsonArray ids = dev.createNestedArray("ids"); - ids.add(Mqtt::basename() + "-analog"); - - // add "availability" section - Mqtt::add_avty_to_doc(stat_t, config.as(), val_cond); + Mqtt::add_ha_sections_to_doc("analog", stat_t, config.as(), true, val_cond); sensor.ha_registered = Mqtt::queue_ha(topic, config.as()); } diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 3b0745405..0a96f0cea 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -542,7 +542,7 @@ void Mqtt::ha_status() { JsonObject dev = doc.createNestedObject("dev"); dev["name"] = Mqtt::basename(); dev["sw"] = "v" + std::string(EMSESP_APP_VERSION); - dev["mf"] = "proddy"; + dev["mf"] = "EMS-ESP"; dev["mdl"] = "EMS-ESP"; #ifndef EMSESP_STANDALONE dev["cu"] = "http://" + (EMSESP::system_.ethernet_connected() ? ETH.localIP().toString() : WiFi.localIP().toString()); @@ -739,10 +739,11 @@ bool Mqtt::publish_ha_sensor_config(DeviceValue & dv, const char * model, const dev_json["name"] = Mqtt::basename() + " " + cap_name; free(cap_name); + // create only once per category if (create_device_config) { dev_json["mf"] = brand; dev_json["mdl"] = model; - dev_json["via_device"] = "ems-esp"; + dev_json["via_device"] = Mqtt::basename(); } // calculate the min and max @@ -1136,8 +1137,8 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev } } - doc["dev"] = dev_json; // add the dev json object to the end - add_avty_to_doc(stat_t, doc.as(), val_cond); // add "availability" section + doc["dev"] = dev_json; // add the dev json object to the end + add_ha_sections_to_doc("", stat_t, doc.as(), false, val_cond); // no name, since the "dev" has already been added return queue_ha(topic, doc.as()); } @@ -1245,18 +1246,8 @@ bool Mqtt::publish_ha_climate_config(const uint8_t tag, const bool has_roomtemp, modes.add("heat"); modes.add("off"); - JsonObject dev = doc.createNestedObject("dev"); - JsonArray ids = dev.createNestedArray("ids"); - - char ha_device[40]; - snprintf(ha_device, sizeof(ha_device), "%s-thermostat", Mqtt::basename().c_str()); - ids.add(ha_device); - // device name must be different to the entity name, take the ids value we just created - dev["name"] = ha_device; - - // add "availability" section - add_avty_to_doc(topic_t, doc.as(), seltemp_cond, has_roomtemp ? currtemp_cond : nullptr, hc_mode_cond); + add_ha_sections_to_doc("thermostat", topic_t, doc.as(), false, seltemp_cond, has_roomtemp ? currtemp_cond : nullptr, hc_mode_cond); return queue_ha(topic, doc.as()); // publish the config payload with retain flag } @@ -1280,42 +1271,68 @@ std::string Mqtt::tag_to_topic(uint8_t device_type, uint8_t tag) { } } -// adds "availability" section to HA Discovery config -void Mqtt::add_avty_to_doc(const char * state_t, const JsonObject & doc, const char * cond1, const char * cond2, const char * negcond) { - const char * tpl_draft = "{{'online' if %s else 'offline'}}"; - char tpl[150]; - JsonArray avty = doc.createNestedArray("avty"); - - StaticJsonDocument<512> avty_json; - - snprintf(tpl, sizeof(tpl), "%s/status", Mqtt::base().c_str()); - avty_json["t"] = tpl; - snprintf(tpl, sizeof(tpl), tpl_draft, "value == 'online'"); - avty_json["val_tpl"] = tpl; - avty.add(avty_json); - avty_json.clear(); - avty_json["t"] = state_t; - snprintf(tpl, sizeof(tpl), tpl_draft, cond1 == nullptr ? "value is defined" : cond1); - avty_json["val_tpl"] = tpl; - avty.add(avty_json); - - if (cond2 != nullptr) { - avty_json.clear(); - avty_json["t"] = state_t; - snprintf(tpl, sizeof(tpl), tpl_draft, cond2); - avty_json["val_tpl"] = tpl; - avty.add(avty_json); +// adds availability, dev, ids to the config section to HA Discovery config +void Mqtt::add_ha_sections_to_doc(const std::string & name, + const char * state_t, + const JsonObject & config, + const bool is_first, + const char * cond1, + const char * cond2, + const char * negcond) { + // adds dev section to HA Discovery config + if (!name.empty()) { + JsonObject dev = config.createNestedObject("dev"); + auto cap_name = name; + cap_name[0] = toupper(name[0]); // capitalize first letter + dev["name"] = Mqtt::basename() + " " + cap_name; + // if it's the first in the category, attach the group to the main HA device + if (is_first) { + dev["mf"] = "EMS-ESP"; + dev["mdl"] = cap_name; + dev["via_device"] = Mqtt::basename(); + } + JsonArray ids = dev.createNestedArray("ids"); + ids.add(Mqtt::basename() + "-" + Helpers::toLower(name)); } - if (negcond != nullptr) { + // adds "availability" section to HA Discovery config + // but not for Domoticz + if (discovery_type() == discoveryType::HOMEASSISTANT) { + const char * tpl_draft = "{{'online' if %s else 'offline'}}"; + char tpl[150]; + JsonArray avty = config.createNestedArray("avty"); + + StaticJsonDocument<512> avty_json; + + snprintf(tpl, sizeof(tpl), "%s/status", Mqtt::base().c_str()); + avty_json["t"] = tpl; + snprintf(tpl, sizeof(tpl), tpl_draft, "value == 'online'"); + avty_json["val_tpl"] = tpl; + avty.add(avty_json); avty_json.clear(); avty_json["t"] = state_t; - snprintf(tpl, sizeof(tpl), "{{'offline' if %s else 'online'}}", negcond); + snprintf(tpl, sizeof(tpl), tpl_draft, cond1 == nullptr ? "value is defined" : cond1); avty_json["val_tpl"] = tpl; avty.add(avty_json); - } - doc["avty_mode"] = "all"; + if (cond2 != nullptr) { + avty_json.clear(); + avty_json["t"] = state_t; + snprintf(tpl, sizeof(tpl), tpl_draft, cond2); + avty_json["val_tpl"] = tpl; + avty.add(avty_json); + } + + if (negcond != nullptr) { + avty_json.clear(); + avty_json["t"] = state_t; + snprintf(tpl, sizeof(tpl), "{{'offline' if %s else 'online'}}", negcond); + avty_json["val_tpl"] = tpl; + avty.add(avty_json); + } + + config["avty_mode"] = "all"; + } } } // namespace emsesp \ No newline at end of file diff --git a/src/mqtt.h b/src/mqtt.h index 53f4b631f..6854cc334 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -217,8 +217,13 @@ class Mqtt { static std::string tag_to_topic(uint8_t device_type, uint8_t tag); - static void - add_avty_to_doc(const char * state_t, const JsonObject & doc, const char * cond1 = nullptr, const char * cond2 = nullptr, const char * negcond = nullptr); + static void add_ha_sections_to_doc(const std::string & name, + const char * state_t, + const JsonObject & doc, + const bool is_first = false, + const char * cond1 = nullptr, + const char * cond2 = nullptr, + const char * negcond = nullptr); private: static uuid::log::Logger logger_; diff --git a/src/shower.cpp b/src/shower.cpp index 3da18df2d..aba136de1 100644 --- a/src/shower.cpp +++ b/src/shower.cpp @@ -210,12 +210,7 @@ void Shower::set_shower_state(bool state, bool force) { doc["pl_off"] = Helpers::render_boolean(result, false); } - JsonObject dev = doc.createNestedObject("dev"); - dev["name"] = "EMS-ESP Shower"; - JsonArray ids = dev.createNestedArray("ids"); - ids.add(Mqtt::basename() + "-shower"); - - Mqtt::add_avty_to_doc(stat_t, doc.as()); // add "availability" section + Mqtt::add_ha_sections_to_doc("shower", stat_t, doc.as(), true); snprintf(topic, sizeof(topic), "binary_sensor/%s/shower_active/config", Mqtt::basename().c_str()); ha_configdone_ = Mqtt::queue_ha(topic, doc.as()); // publish the config payload with retain flag @@ -240,12 +235,7 @@ void Shower::set_shower_state(bool state, bool force) { doc["dev_cla"] = "duration"; // doc["ent_cat"] = "diagnostic"; - JsonObject dev2 = doc.createNestedObject("dev"); - dev2["name"] = "EMS-ESP Shower"; - JsonArray ids2 = dev2.createNestedArray("ids"); - ids2.add(Mqtt::basename() + "-shower"); - - Mqtt::add_avty_to_doc(stat_t, doc.as(), "value_json.duration is defined"); // add "availability" section + Mqtt::add_ha_sections_to_doc("shower", stat_t, doc.as(), "value_json.duration is defined"); snprintf(topic, sizeof(topic), "sensor/%s/shower_duration/config", Mqtt::basename().c_str()); Mqtt::queue_ha(topic, doc.as()); // publish the config payload with retain flag @@ -267,12 +257,7 @@ void Shower::set_shower_state(bool state, bool force) { doc["val_tpl"] = "{{value_json.timestamp if value_json.timestamp is defined else 0}}"; // doc["ent_cat"] = "diagnostic"; - JsonObject dev3 = doc.createNestedObject("dev"); - dev3["name"] = "EMS-ESP Shower"; - JsonArray ids3 = dev3.createNestedArray("ids"); - ids3.add(Mqtt::basename() + "-shower"); - - Mqtt::add_avty_to_doc(stat_t, doc.as(), "value_json.timestamp is defined"); // add "availability" section + Mqtt::add_ha_sections_to_doc("shower", stat_t, doc.as(), "value_json.timestamp is defined"); snprintf(topic, sizeof(topic), "sensor/%s/shower_timestamp/config", Mqtt::basename().c_str()); Mqtt::queue_ha(topic, doc.as()); // publish the config payload with retain flag diff --git a/src/temperaturesensor.cpp b/src/temperaturesensor.cpp index 31c50599b..504853eb3 100644 --- a/src/temperaturesensor.cpp +++ b/src/temperaturesensor.cpp @@ -527,7 +527,14 @@ void TemperatureSensor::publish_values(const bool force) { snprintf(val_obj, sizeof(val_obj), "value_json['%s']", sensor.name().c_str()); snprintf(val_cond, sizeof(val_cond), "%s is defined", val_obj); } - config["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + " else -55}}"; + + // for the value template, there's a problem still with Domoticz probably due to the special characters. + // See https://github.com/emsesp/EMS-ESP32/issues/1360 + if (Mqtt::discovery_type() == Mqtt::discoveryType::DOMOTICZ) { + config["val_tpl"] = (std::string) "{{" + val_obj + "}}"; + } else { + config["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + " else -55}}"; + } char uniq_s[70]; if (Mqtt::entity_format() == Mqtt::entityFormat::MULTI_SHORT) { @@ -543,13 +550,7 @@ void TemperatureSensor::publish_values(const bool force) { snprintf(name, sizeof(name), "%s", sensor.name().c_str()); config["name"] = name; - JsonObject dev = config.createNestedObject("dev"); - dev["name"] = Mqtt::basename() + " Temperature"; - JsonArray ids = dev.createNestedArray("ids"); - ids.add(Mqtt::basename() + "-temperature"); - - // add "availability" section - Mqtt::add_avty_to_doc(stat_t, config.as(), val_cond); + Mqtt::add_ha_sections_to_doc("temperature", stat_t, config.as(), true, val_cond); char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; // use '_' as HA doesn't like '-' in the topic name diff --git a/src/web/WebCustomEntityService.cpp b/src/web/WebCustomEntityService.cpp index 5400fcf6a..4f318a07f 100644 --- a/src/web/WebCustomEntityService.cpp +++ b/src/web/WebCustomEntityService.cpp @@ -426,13 +426,8 @@ void WebCustomEntityService::publish(const bool force) { config["pl_off"] = Helpers::render_boolean(result, false); } } - JsonObject dev = config.createNestedObject("dev"); - dev["name"] = Mqtt::basename() + " Custom"; - JsonArray ids = dev.createNestedArray("ids"); - ids.add(Mqtt::basename() + "-custom"); + Mqtt::add_ha_sections_to_doc("custom", stat_t, config.as(), true, val_cond); - // add "availability" section - Mqtt::add_avty_to_doc(stat_t, config.as(), val_cond); ha_created |= Mqtt::queue_ha(topic, config.as()); } } diff --git a/src/web/WebSchedulerService.cpp b/src/web/WebSchedulerService.cpp index bb2b91c52..2036fde97 100644 --- a/src/web/WebSchedulerService.cpp +++ b/src/web/WebSchedulerService.cpp @@ -287,13 +287,8 @@ void WebSchedulerService::publish(const bool force) { config["pl_off"] = Helpers::render_boolean(result, false); } - JsonObject dev = config.createNestedObject("dev"); - dev["name"] = Mqtt::basename() + " Scheduler"; - JsonArray ids = dev.createNestedArray("ids"); - ids.add(Mqtt::basename() + "-scheduler"); + Mqtt::add_ha_sections_to_doc("scheduler", stat_t, config.as(), true, val_cond); - // add "availability" section - Mqtt::add_avty_to_doc(stat_t, config.as(), val_cond); ha_created |= Mqtt::queue_ha(topic, config.as()); } } From 8384344c5a9f60140aba6e3215d6afb132e353ec Mon Sep 17 00:00:00 2001 From: Proddy Date: Wed, 3 Jan 2024 23:03:41 +0100 Subject: [PATCH 09/94] no need to pretty json output --- src/web/WebAPIService.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/web/WebAPIService.cpp b/src/web/WebAPIService.cpp index 5c340038c..74d33df29 100644 --- a/src/web/WebAPIService.cpp +++ b/src/web/WebAPIService.cpp @@ -106,13 +106,16 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject & input) { emsesp::EMSESP::system_.refreshHeapMem(); // output json buffer - size_t buffer = EMSESP_JSON_SIZE_XXXLARGE; - auto * response = new PrettyAsyncJsonResponse(false, buffer); + size_t buffer = EMSESP_JSON_SIZE_XXXLARGE; + AsyncJsonResponse * response = new AsyncJsonResponse(false, buffer); + + // add more mem if needed - won't be needed in ArduinoJson 7 while (!response->getSize()) { delete response; buffer -= 1024; - response = new PrettyAsyncJsonResponse(false, buffer); + response = new AsyncJsonResponse(false, buffer); } + JsonObject output = response->getRoot(); // call command From c9efd095e74ce483bfc236338e3363da18adde8f Mon Sep 17 00:00:00 2001 From: Proddy Date: Wed, 3 Jan 2024 23:56:23 +0100 Subject: [PATCH 10/94] show network hostname in webui --- CHANGELOG_LATEST.md | 1 + interface/src/framework/network/NetworkStatusForm.tsx | 10 ++++++++++ lib/framework/NetworkStatus.cpp | 6 ++++-- mock-api/Handler.ts | 9 +++++---- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index 802232884..f47f97d78 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -12,6 +12,7 @@ - checkbox for MQTT-TLS enable [#1474](https://github.com/emsesp/EMS-ESP32/issues/1474) - added SK (Slovenian) language. Thanks @misa1515 - CPU info [#1497](https://github.com/emsesp/EMS-ESP32/pull/1497) +- Show network hostname in Web UI under Network Status ## Fixed diff --git a/interface/src/framework/network/NetworkStatusForm.tsx b/interface/src/framework/network/NetworkStatusForm.tsx index 9d94d2490..3a731c4ca 100644 --- a/interface/src/framework/network/NetworkStatusForm.tsx +++ b/interface/src/framework/network/NetworkStatusForm.tsx @@ -1,5 +1,6 @@ import DeviceHubIcon from '@mui/icons-material/DeviceHub'; import DnsIcon from '@mui/icons-material/Dns'; +import GiteIcon from '@mui/icons-material/Gite'; import RefreshIcon from '@mui/icons-material/Refresh'; import RouterIcon from '@mui/icons-material/Router'; import SettingsInputAntennaIcon from '@mui/icons-material/SettingsInputAntenna'; @@ -115,6 +116,15 @@ const NetworkStatusForm: FC = () => { + + + + + + + + + {isWiFi(data) && ( <> diff --git a/lib/framework/NetworkStatus.cpp b/lib/framework/NetworkStatus.cpp index 6aea4580f..546e7f8b5 100644 --- a/lib/framework/NetworkStatus.cpp +++ b/lib/framework/NetworkStatus.cpp @@ -19,9 +19,11 @@ void NetworkStatus::networkStatus(AsyncWebServerRequest * request) { // see if Ethernet is connected if (ethernet_connected) { - root["status"] = 10; // custom code #10 - ETHERNET_STATUS_CONNECTED + root["status"] = 10; // custom code #10 - ETHERNET_STATUS_CONNECTED + root["hostname"] = ETH.getHostname(); } else { - root["status"] = (uint8_t)wifi_status; + root["status"] = (uint8_t)wifi_status; + root["hostname"] = WiFi.getHostname(); } // for both connections show ethernet diff --git a/mock-api/Handler.ts b/mock-api/Handler.ts index fc519a0eb..13c39e707 100644 --- a/mock-api/Handler.ts +++ b/mock-api/Handler.ts @@ -249,7 +249,8 @@ const network_status = { 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' + dns_ip_2: '0.0.0.0', + hostname: 'ems-esp' }; const list_networks = { networks: [ @@ -650,9 +651,9 @@ const emsesp_devices = { }; const emsesp_coredata = { - connected: true, - // devices: [], - devices: [ + connected: false, + devices: [], + devices2: [ { id: 7, t: 4, From d16e77bba3693f0d0e81add3e24583fbf055078f Mon Sep 17 00:00:00 2001 From: Proddy Date: Wed, 3 Jan 2024 23:56:31 +0100 Subject: [PATCH 11/94] updated example --- pio_local.ini_example | 69 ++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/pio_local.ini_example b/pio_local.ini_example index 99fa32ed0..65f1a9177 100644 --- a/pio_local.ini_example +++ b/pio_local.ini_example @@ -1,7 +1,7 @@ -; example custom platformio.ini file for EMS-ESP +; example custom platformio ini file for EMS-ESP [common] -; custom build flags: +; custom build flags to use in my_build_flags ; -DEMSESP_WIFI_TWEAK ; experimental WiFi tweaks for stability ; -DEMSESP_UART_DEBUG ; debugging UART ; -DEMSESP_DEBUG ; enables DEBUG to the log. Will generate a lot of extra traffic on Console and Syslog @@ -11,42 +11,65 @@ ; -DEMSESP_TEST ; enable the tests. EN language only ; -DEMSESP_DE_ONLY ; only DE translated entity names ; -DEMSESP_EN_ONLY ; only EN translated entity names -; my_build_flags = -DEMSESP_DEBUG +; my_build_flags = -DEMSESP_TEST +; my_build_flags = -DEMSESP_DEBUG -DEMSESP_TEST [platformio] -default_envs = esp32_4M +; default_envs = esp32_4M ; default_envs = esp32_16M ; default_envs = lolin_s3 ; default_envs = standalone -; default_envs = debug +; default_envs = debug +; default_envs = custom [env:esp32_4M] -; update to arduino 3, IDF 5 -platform = https://github.com/Jason2866/platform-espressif32.git#Arduino/IDF5 -; ; if using OTA enter your details below ; upload_protocol = espota ; upload_flags = ; --port=8266 ; --auth=ems-esp-neo ; upload_port = ems-esp.local -; for USB use -upload_port = /dev/ttyUSB* +; for USB use one of these: +; upload_port = /dev/ttyUSB* ; upload_port = COM5 -; override arduino espressif core -platform = espressif32 ; take latest -; platform = espressif32@5.3.0 -; platform = espressif32@6.3.2 -; platform = espressif32@6.4.0 - -extra_scripts = - pre:scripts/build_interface.py ; comment out if you don't want to re-build the WebUI each time - scripts/rename_fw.py - ; post:scripts/app-tls-size.py - [env:esp32_16M] +[env:custom] +; use for ESP-S boards with 4MB flash +platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.10.03/platform-espressif32-2023.10.03.zip +; use for S3 boards: +; platform = espressif32 +framework = arduino +board = esp32dev +board_build.filesystem = littlefs +board_build.f_cpu = 240000000L +board_upload.flash_size = 4MB +board_build.partitions = esp32_partition_4M.csv +board_upload.use_1200bps_touch = false +board_upload.wait_for_upload_port = true +upload_port = /dev/ttyUSB0 +extra_scripts = + pre:scripts/build_interface.py + scripts/rename_fw.py +build_unflags = ${common.unbuild_flags} +build_flags = + ${common.core_build_flags} + ${factory_settings.build_flags} + ${common.my_build_flags} + -D ONEWIRE_CRC16=0 + -D NO_GLOBAL_ARDUINOOTA + -D ARDUINOJSON_ENABLE_STD_STRING=1 + -D ARDUINOJSON_USE_DOUBLE=0 + ; -D ARDUINOTRACE_ENABLE=1 + -D TASMOTA_SDK + ; -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_WARN + -D EMSESP_TEST + -D EMSESP_DEBUG + -D CONFIG_ETH_ENABLED + -D TASMOTA_SDK + '-DEMSESP_DEFAULT_BOARD_PROFILE="Test"' + [env:lolin_s3] upload_port = /dev/ttyACM0 extra_scripts = @@ -61,7 +84,6 @@ board = esp32dev framework = arduino platform = espressif32 board_build.partitions = esp32_partition_debug.csv -; board_build.partitions = esp32_partition_4M.csv board_upload.flash_size = 4MB board_build.filesystem = littlefs upload_protocol = esptool @@ -73,6 +95,5 @@ debug_init_break = tbreak setup build_flags = ${factory_settings.build_flags} -DEMSESP_EN_ONLY -DCORE_DEBUG_LEVEL=5 -DONEWIRE_CRC16=0 -DNO_GLOBAL_ARDUINOOTA -DARDUINOJSON_ENABLE_STD_STRING=1 -DESP32=1 -DARDUINO_ARCH_ESP32=1 upload_port = /dev/ttyUSB0 extra_scripts = - ; pre:scripts/build_interface.py ; comment out if you don't want to re-build the WebUI each time scripts/rename_fw.py - ; post:scripts/app-tls-size.py + post:scripts/app-tls-size.py From 55ce551868c17016837db456b3743dd1ebc13e7c Mon Sep 17 00:00:00 2001 From: Proddy Date: Wed, 3 Jan 2024 23:56:52 +0100 Subject: [PATCH 12/94] added hostname to network status --- interface/src/types/network.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/src/types/network.ts b/interface/src/types/network.ts index 70df69b1c..8740eb9b4 100644 --- a/interface/src/types/network.ts +++ b/interface/src/types/network.ts @@ -33,6 +33,7 @@ export interface NetworkStatus { gateway_ip: string; dns_ip_1: string; dns_ip_2: string; + hostname: string; } export interface NetworkSettings { From 3f42c4d56ba1650e7be324e5b504ce1c8b6ef866 Mon Sep 17 00:00:00 2001 From: Proddy Date: Wed, 3 Jan 2024 23:57:00 +0100 Subject: [PATCH 13/94] fix typo --- interface/src/project/DashboardDevices.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/project/DashboardDevices.tsx b/interface/src/project/DashboardDevices.tsx index 4fb862693..f59047e3f 100644 --- a/interface/src/project/DashboardDevices.tsx +++ b/interface/src/project/DashboardDevices.tsx @@ -420,7 +420,7 @@ const DashboardDevices: FC = () => { )} - {coreData.devices.length && ( + {coreData.devices.length !== 0 && (
{(tableList: any) => ( <> From b6dbf93de284daad4fb779cf20f2c1a839c402b1 Mon Sep 17 00:00:00 2001 From: Proddy Date: Thu, 4 Jan 2024 18:08:31 +0100 Subject: [PATCH 14/94] add missing setContentType --- lib_standalone/AsyncJson.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib_standalone/AsyncJson.h b/lib_standalone/AsyncJson.h index 2ec4a6322..265b96a22 100644 --- a/lib_standalone/AsyncJson.h +++ b/lib_standalone/AsyncJson.h @@ -175,6 +175,9 @@ class AsyncJsonResponse { void setCode(uint16_t) { } + + void setContentType(const char * s) { + } }; typedef std::function ArJsonRequestHandlerFunction; From b0076cd5dac099d634975275f3c9140f0ccddd44 Mon Sep 17 00:00:00 2001 From: Proddy Date: Thu, 4 Jan 2024 18:08:41 +0100 Subject: [PATCH 15/94] change comments --- interface/src/project/api.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/project/api.ts b/interface/src/project/api.ts index 98d65f92f..509e238e1 100644 --- a/interface/src/project/api.ts +++ b/interface/src/project/api.ts @@ -20,7 +20,7 @@ export const readCoreData = () => alovaInstance.Get(`/rest/coreData`); export const readDeviceData = (id: number) => alovaInstance.Get('/rest/deviceData', { // alovaInstance.Get(`/rest/deviceData/${id}`, { - params: { id }, // TODO remove later + params: { id }, // TODO replace later responseType: 'arraybuffer' // uses msgpack }); export const writeDeviceValue = (data: any) => alovaInstance.Post('/rest/writeDeviceValue', data); @@ -56,7 +56,7 @@ export const getSchedule = () => alovaInstance.Get('/rest/getSchedule'); export const readDeviceEntities = (id: number) => // alovaInstance.Get(`/rest/deviceEntities/${id}`, { alovaInstance.Get(`/rest/deviceEntities`, { - params: { id }, // TODO remove later + params: { id }, // TODO replace later responseType: 'arraybuffer', transformData(data: any) { return data.map((de: DeviceEntity) => ({ ...de, o_m: de.m, o_cn: de.cn, o_mi: de.mi, o_ma: de.ma })); From a3b6656be79905e635ae87562c97781d457384a0 Mon Sep 17 00:00:00 2001 From: Proddy Date: Thu, 4 Jan 2024 18:09:00 +0100 Subject: [PATCH 16/94] add additional Domoticz to discovery_type --- interface/src/framework/mqtt/MqttSettingsForm.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/src/framework/mqtt/MqttSettingsForm.tsx b/interface/src/framework/mqtt/MqttSettingsForm.tsx index 6b1d1323b..6a8688dbf 100644 --- a/interface/src/framework/mqtt/MqttSettingsForm.tsx +++ b/interface/src/framework/mqtt/MqttSettingsForm.tsx @@ -273,6 +273,7 @@ const MqttSettingsForm: FC = () => { > Home Assistant Domoticz + Domoticz (latest) From 4c27cb831e2c3708b9f91c9272ae2b266b8b24c3 Mon Sep 17 00:00:00 2001 From: Proddy Date: Thu, 4 Jan 2024 18:09:18 +0100 Subject: [PATCH 17/94] update tests for temp sensors --- src/test/test.cpp | 3 ++- src/test/test.h | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/test.cpp b/src/test/test.cpp index 2503eea88..ce12a7fdd 100644 --- a/src/test/test.cpp +++ b/src/test/test.cpp @@ -286,7 +286,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const emsesp::EMSESP::temperaturesensor_.test(); // shell.invoke_command("show devices"); - shell.invoke_command("show values"); + // shell.invoke_command("show values"); shell.invoke_command("call system allvalues"); // shell.invoke_command("call system publish"); // shell.invoke_command("show mqtt"); @@ -705,6 +705,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const if (command == "temperature") { shell.printfln("Testing adding Temperature sensor"); emsesp::EMSESP::temperaturesensor_.test(); + shell.invoke_command("show values"); ok = true; } diff --git a/src/test/test.h b/src/test/test.h index 1ae7a5a83..5bf4d8641 100644 --- a/src/test/test.h +++ b/src/test/test.h @@ -58,7 +58,6 @@ namespace emsesp { // #define EMSESP_DEBUG_DEFAULT "custom_entities" // #define EMSESP_DEBUG_DEFAULT "heat_exchange" - class Test { public: static void run_test(uuid::console::Shell & shell, const std::string & command, const std::string & data = ""); From 9ca47627d263bd30fba2e826fd10bcc6032e9e2e Mon Sep 17 00:00:00 2001 From: Proddy Date: Thu, 4 Jan 2024 18:09:29 +0100 Subject: [PATCH 18/94] updated example pio --- pio_local.ini_example | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pio_local.ini_example b/pio_local.ini_example index 65f1a9177..6ac2a6cb1 100644 --- a/pio_local.ini_example +++ b/pio_local.ini_example @@ -20,7 +20,7 @@ ; default_envs = lolin_s3 ; default_envs = standalone ; default_envs = debug -; default_envs = custom +default_envs = custom [env:esp32_4M] ; if using OTA enter your details below @@ -37,6 +37,7 @@ [env:custom] ; use for ESP-S boards with 4MB flash +; make sure -D TASMOTA_SDK is also enabled platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.10.03/platform-espressif32-2023.10.03.zip ; use for S3 boards: ; platform = espressif32 @@ -50,7 +51,7 @@ board_upload.use_1200bps_touch = false board_upload.wait_for_upload_port = true upload_port = /dev/ttyUSB0 extra_scripts = - pre:scripts/build_interface.py + ; pre:scripts/build_interface.py scripts/rename_fw.py build_unflags = ${common.unbuild_flags} build_flags = @@ -66,8 +67,8 @@ build_flags = ; -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_WARN -D EMSESP_TEST -D EMSESP_DEBUG - -D CONFIG_ETH_ENABLED - -D TASMOTA_SDK + -D CONFIG_ETH_ENABLED + ; -D TASMOTA_SDK '-DEMSESP_DEFAULT_BOARD_PROFILE="Test"' [env:lolin_s3] From 35ee8c33b3343c8e8fc18c56dbf1fb032ee855da Mon Sep 17 00:00:00 2001 From: Proddy Date: Thu, 4 Jan 2024 18:09:42 +0100 Subject: [PATCH 19/94] add comment --- src/temperaturesensor.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/temperaturesensor.h b/src/temperaturesensor.h index 3d7363054..f4350707f 100644 --- a/src/temperaturesensor.h +++ b/src/temperaturesensor.h @@ -62,6 +62,7 @@ class TemperatureSensor { bool apply_customization(); + // initial values int16_t temperature_c = EMS_VALUE_SHORT_NOTSET; bool read = false; bool ha_registered = false; From 591b8afcb0748dbf061dace8617b2330ab5fe721 Mon Sep 17 00:00:00 2001 From: Proddy Date: Thu, 4 Jan 2024 18:10:16 +0100 Subject: [PATCH 20/94] restructuring and added additional domoticz support --- src/temperaturesensor.cpp | 59 +++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/src/temperaturesensor.cpp b/src/temperaturesensor.cpp index 504853eb3..ba209fc7a 100644 --- a/src/temperaturesensor.cpp +++ b/src/temperaturesensor.cpp @@ -108,11 +108,14 @@ void TemperatureSensor::loop() { if (++scanretry_ > SCAN_MAX) { // every 30 sec scanretry_ = 0; #ifdef EMSESP_DEBUG_SENSOR - LOG_ERROR("Bus reset failed"); + LOG_DEBUG("Error: Bus reset failed"); #endif +#ifndef EMSESP_TEST + // don't reset if running in test mode where we simulate sensors for (auto & sensor : sensors_) { sensor.temperature_c = EMS_VALUE_SHORT_NOTSET; } +#endif } } } @@ -202,6 +205,7 @@ void TemperatureSensor::loop() { bus_.depower(); } // check for missing sensors after some samples + // but don't do this if running in test mode where we simulate sensors if (++scancnt_ > SCAN_MAX) { for (auto & sensor : sensors_) { if (!sensor.read) { @@ -309,6 +313,7 @@ bool TemperatureSensor::update(const std::string & id, const std::string & name, // if HA is enabled then delete the old record if (Mqtt::ha_enabled()) { remove_ha_topic(id); + sensor.ha_registered = false; // force HA configs to be re-created } sensor.set_name(name); @@ -458,6 +463,7 @@ void TemperatureSensor::remove_ha_topic(const std::string & id) { if (!Mqtt::ha_enabled()) { return; } + LOG_DEBUG("Removing HA config for temperature sensor ID %s", id.c_str()); // use '_' as HA doesn't like '-' in the topic name std::string sensorid = id; @@ -474,7 +480,6 @@ void TemperatureSensor::publish_values(const bool force) { } uint8_t num_sensors = sensors_.size(); - if (num_sensors == 0) { return; } @@ -485,19 +490,30 @@ void TemperatureSensor::publish_values(const bool force) { } } - DynamicJsonDocument doc(120 * num_sensors); + DynamicJsonDocument doc(150 * num_sensors); + + // used to see if we need to create the [devs] discovery section, as this needs only to be done once for all sensors + bool is_first_ha = true; + if (Mqtt::ha_enabled()) { + for (auto & sensor : sensors_) { + if (sensor.ha_registered) { + is_first_ha = false; + break; + } + } + } for (auto & sensor : sensors_) { bool has_value = Helpers::hasValue(sensor.temperature_c); - char val[10]; - if (Mqtt::is_nested()) { - JsonObject dataSensor = doc.createNestedObject(sensor.id()); - dataSensor["name"] = sensor.name(); - if (has_value) { - dataSensor["temp"] = serialized(Helpers::render_value(val, sensor.temperature_c, 10, EMSESP::system_.fahrenheit() ? 2 : 0)); + if (has_value) { + char val[10]; + if (Mqtt::is_nested()) { + JsonObject dataSensor = doc.createNestedObject(sensor.id()); + dataSensor["name"] = sensor.name(); + dataSensor["temp"] = serialized(Helpers::render_value(val, sensor.temperature_c, 10, EMSESP::system_.fahrenheit() ? 2 : 0)); + } else { + doc[sensor.name()] = serialized(Helpers::render_value(val, sensor.temperature_c, 10, EMSESP::system_.fahrenheit() ? 2 : 0)); } - } else if (has_value) { - doc[sensor.name()] = serialized(Helpers::render_value(val, sensor.temperature_c, 10, EMSESP::system_.fahrenheit() ? 2 : 0)); } // create the HA MQTT config @@ -509,7 +525,7 @@ void TemperatureSensor::publish_values(const bool force) { } else if (!sensor.ha_registered || force) { LOG_DEBUG("Recreating HA config for sensor ID %s", sensor.id().c_str()); - StaticJsonDocument config; + StaticJsonDocument config; // this needs to be large because of all the copying in add_ha_sections_to_doc() config["dev_cla"] = "temperature"; char stat_t[50]; @@ -518,8 +534,8 @@ void TemperatureSensor::publish_values(const bool force) { config["unit_of_meas"] = EMSdevice::uom_to_string(DeviceValueUOM::DEGREES); - char val_obj[50]; - char val_cond[95]; + char val_obj[70]; + char val_cond[170]; if (Mqtt::is_nested()) { snprintf(val_obj, sizeof(val_obj), "value_json['%s'].temp", sensor.id().c_str()); snprintf(val_cond, sizeof(val_cond), "value_json['%s'] is defined and %s is defined", sensor.id().c_str(), val_obj); @@ -530,10 +546,10 @@ void TemperatureSensor::publish_values(const bool force) { // for the value template, there's a problem still with Domoticz probably due to the special characters. // See https://github.com/emsesp/EMS-ESP32/issues/1360 - if (Mqtt::discovery_type() == Mqtt::discoveryType::DOMOTICZ) { - config["val_tpl"] = (std::string) "{{" + val_obj + "}}"; - } else { + if (Mqtt::discovery_type() == Mqtt::discoveryType::HOMEASSISTANT) { config["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + " else -55}}"; + } else { + config["val_tpl"] = (std::string) "{{" + val_obj + "}}"; // ommit value conditional Jinja2 template code } char uniq_s[70]; @@ -550,7 +566,7 @@ void TemperatureSensor::publish_values(const bool force) { snprintf(name, sizeof(name), "%s", sensor.name().c_str()); config["name"] = name; - Mqtt::add_ha_sections_to_doc("temperature", stat_t, config.as(), true, val_cond); + Mqtt::add_ha_sections_to_doc("temperature", stat_t, config.as(), is_first_ha, val_cond); char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; // use '_' as HA doesn't like '-' in the topic name @@ -569,7 +585,6 @@ void TemperatureSensor::publish_values(const bool force) { Mqtt::queue_publish(topic, doc.as()); } - // skip crc from id TemperatureSensor::Sensor::Sensor(const uint8_t addr[]) : internal_id_(((uint64_t)addr[0] << 48) | ((uint64_t)addr[1] << 40) | ((uint64_t)addr[2] << 32) | ((uint64_t)addr[3] << 24) | ((uint64_t)addr[4] << 16) @@ -629,15 +644,17 @@ void TemperatureSensor::test() { // add 2 temperature sensors uint8_t addr[ADDR_LEN] = {1, 2, 3, 4, 5, 6, 7, 8}; sensors_.emplace_back(addr); + // sensors_.back().apply_customization(); sensors_.back().temperature_c = 123; sensors_.back().read = true; - sensors_.back().apply_customization(); + publish_sensor(sensors_.back()); // call publish single uint8_t addr2[ADDR_LEN] = {11, 12, 13, 14, 15, 16, 17, 18}; sensors_.emplace_back(addr2); + // sensors_.back().apply_customization(); sensors_.back().temperature_c = 456; sensors_.back().read = true; - sensors_.back().apply_customization(); + publish_sensor(sensors_.back()); // call publish single } #endif From e62fc14b6dc9d9a1a99d1fb91e6af4ac85e43b87 Mon Sep 17 00:00:00 2001 From: Proddy Date: Thu, 4 Jan 2024 18:10:53 +0100 Subject: [PATCH 21/94] support domoticz - MQTT autodiscovery in Domoticz not working #1360 --- src/mqtt.cpp | 37 +++++++++++++++++------------- src/mqtt.h | 4 ++-- src/web/WebCustomEntityService.cpp | 2 +- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 0a96f0cea..6a5a24edf 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -863,8 +863,8 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev case DeviceValueType::USHORT: case DeviceValueType::ULONG: // number - https://www.home-assistant.io/integrations/number.mqtt - // Domoticz does not support number, use sensor - if (discovery_type() == discoveryType::HOMEASSISTANT) { + // older Domoticz does not support number, use sensor + if (discovery_type() == discoveryType::HOMEASSISTANT || discovery_type() == discoveryType::DOMOTICZ_LATEST) { snprintf(topic, sizeof(topic), "number/%s", config_topic); readonly_sensors = false; } else { @@ -1296,39 +1296,44 @@ void Mqtt::add_ha_sections_to_doc(const std::string & name, } // adds "availability" section to HA Discovery config - // but not for Domoticz - if (discovery_type() == discoveryType::HOMEASSISTANT) { - const char * tpl_draft = "{{'online' if %s else 'offline'}}"; - char tpl[150]; - JsonArray avty = config.createNestedArray("avty"); + JsonArray avty = config.createNestedArray("avty"); + StaticJsonDocument avty_json; - StaticJsonDocument<512> avty_json; + const char * tpl_draft = "{{'online' if %s else 'offline'}}"; - snprintf(tpl, sizeof(tpl), "%s/status", Mqtt::base().c_str()); - avty_json["t"] = tpl; - snprintf(tpl, sizeof(tpl), tpl_draft, "value == 'online'"); - avty_json["val_tpl"] = tpl; - avty.add(avty_json); + // EMS-ESP status check + char tpl[150]; + snprintf(tpl, sizeof(tpl), "%s/status", Mqtt::base().c_str()); + avty_json["t"] = tpl; + snprintf(tpl, sizeof(tpl), tpl_draft, "value == 'online'"); + avty_json["val_tpl"] = tpl; + avty.add(avty_json); // returns 0 if no mem + + // skip conditional Jinja2 templates if not home assistant + if (discovery_type() == discoveryType::HOMEASSISTANT) { + // condition 1 avty_json.clear(); avty_json["t"] = state_t; snprintf(tpl, sizeof(tpl), tpl_draft, cond1 == nullptr ? "value is defined" : cond1); avty_json["val_tpl"] = tpl; - avty.add(avty_json); + avty.add(avty_json); // returns 0 if no mem + // condition 2 if (cond2 != nullptr) { avty_json.clear(); avty_json["t"] = state_t; snprintf(tpl, sizeof(tpl), tpl_draft, cond2); avty_json["val_tpl"] = tpl; - avty.add(avty_json); + avty.add(avty_json); // returns 0 if no mem } + // negative condition if (negcond != nullptr) { avty_json.clear(); avty_json["t"] = state_t; snprintf(tpl, sizeof(tpl), "{{'offline' if %s else 'online'}}", negcond); avty_json["val_tpl"] = tpl; - avty.add(avty_json); + avty.add(avty_json); // returns 0 if no mem } config["avty_mode"] = "all"; diff --git a/src/mqtt.h b/src/mqtt.h index 6854cc334..c965e0e51 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -35,7 +35,7 @@ using mqtt_sub_function_p = std::function; class Mqtt { public: - enum discoveryType : uint8_t { HOMEASSISTANT, DOMOTICZ }; + enum discoveryType : uint8_t { HOMEASSISTANT, DOMOTICZ, DOMOTICZ_LATEST }; enum entityFormat : uint8_t { SINGLE_LONG, SINGLE_SHORT, MULTI_SHORT }; void loop(); @@ -219,7 +219,7 @@ class Mqtt { static void add_ha_sections_to_doc(const std::string & name, const char * state_t, - const JsonObject & doc, + const JsonObject & config, const bool is_first = false, const char * cond1 = nullptr, const char * cond2 = nullptr, diff --git a/src/web/WebCustomEntityService.cpp b/src/web/WebCustomEntityService.cpp index 4f318a07f..7eaed6026 100644 --- a/src/web/WebCustomEntityService.cpp +++ b/src/web/WebCustomEntityService.cpp @@ -397,7 +397,7 @@ void WebCustomEntityService::publish(const bool force) { snprintf(topic, sizeof(topic), "switch/%s/custom_%s/config", Mqtt::basename().c_str(), entityItem.name.c_str()); } else if (entityItem.value_type == DeviceValueType::STRING) { snprintf(topic, sizeof(topic), "sensor/%s/custom_%s/config", Mqtt::basename().c_str(), entityItem.name.c_str()); - } else if (Mqtt::discovery_type() == Mqtt::discoveryType::HOMEASSISTANT) { + } else if (Mqtt::discovery_type() == Mqtt::discoveryType::HOMEASSISTANT || Mqtt::discovery_type() == Mqtt::discoveryType::DOMOTICZ_LATEST) { snprintf(topic, sizeof(topic), "number/%s/custom_%s/config", Mqtt::basename().c_str(), entityItem.name.c_str()); } else { snprintf(topic, sizeof(topic), "sensor/%s/custom_%s/config", Mqtt::basename().c_str(), entityItem.name.c_str()); From df33a24951f204a5bed5242342a240dcfa295af4 Mon Sep 17 00:00:00 2001 From: Proddy Date: Thu, 4 Jan 2024 18:11:08 +0100 Subject: [PATCH 22/94] fix add_ha_sections_to_doc calls --- src/shower.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shower.cpp b/src/shower.cpp index aba136de1..ba2a912f0 100644 --- a/src/shower.cpp +++ b/src/shower.cpp @@ -210,7 +210,7 @@ void Shower::set_shower_state(bool state, bool force) { doc["pl_off"] = Helpers::render_boolean(result, false); } - Mqtt::add_ha_sections_to_doc("shower", stat_t, doc.as(), true); + Mqtt::add_ha_sections_to_doc("shower", stat_t, doc.as(), true); // create first dev & ids snprintf(topic, sizeof(topic), "binary_sensor/%s/shower_active/config", Mqtt::basename().c_str()); ha_configdone_ = Mqtt::queue_ha(topic, doc.as()); // publish the config payload with retain flag @@ -235,7 +235,7 @@ void Shower::set_shower_state(bool state, bool force) { doc["dev_cla"] = "duration"; // doc["ent_cat"] = "diagnostic"; - Mqtt::add_ha_sections_to_doc("shower", stat_t, doc.as(), "value_json.duration is defined"); + Mqtt::add_ha_sections_to_doc("shower", stat_t, doc.as(), false, "value_json.duration is defined"); snprintf(topic, sizeof(topic), "sensor/%s/shower_duration/config", Mqtt::basename().c_str()); Mqtt::queue_ha(topic, doc.as()); // publish the config payload with retain flag @@ -257,7 +257,7 @@ void Shower::set_shower_state(bool state, bool force) { doc["val_tpl"] = "{{value_json.timestamp if value_json.timestamp is defined else 0}}"; // doc["ent_cat"] = "diagnostic"; - Mqtt::add_ha_sections_to_doc("shower", stat_t, doc.as(), "value_json.timestamp is defined"); + Mqtt::add_ha_sections_to_doc("shower", stat_t, doc.as(), false, "value_json.timestamp is defined"); snprintf(topic, sizeof(topic), "sensor/%s/shower_timestamp/config", Mqtt::basename().c_str()); Mqtt::queue_ha(topic, doc.as()); // publish the config payload with retain flag From af237c4fc0e42c8e9c091af9699aa9f00e149e7f Mon Sep 17 00:00:00 2001 From: Proddy Date: Thu, 4 Jan 2024 23:43:30 +0100 Subject: [PATCH 23/94] Arduino v7 --- lib/ArduinoJson/.clang-format | 12 + lib/ArduinoJson/.prettierignore | 1 + lib/ArduinoJson/ArduinoJson.h | 2 +- lib/ArduinoJson/CHANGELOG.md | 889 ++---------------- lib/ArduinoJson/CONTRIBUTING.md | 10 + lib/ArduinoJson/LICENSE.txt | 2 +- lib/ArduinoJson/README.md | 76 +- lib/ArduinoJson/SUPPORT.md | 27 + lib/ArduinoJson/keywords.txt | 40 - lib/ArduinoJson/library.properties | 11 - lib/ArduinoJson/src/ArduinoJson.h | 2 +- lib/ArduinoJson/src/ArduinoJson.hpp | 13 +- .../src/ArduinoJson/Array/ArrayData.hpp | 57 ++ .../src/ArduinoJson/Array/ArrayImpl.hpp | 50 + .../src/ArduinoJson/Array/ElementProxy.hpp | 19 +- .../src/ArduinoJson/Array/JsonArray.hpp | 176 ++-- .../src/ArduinoJson/Array/JsonArrayConst.hpp | 106 +-- .../src/ArduinoJson/Array/JsonArrayImpl.hpp | 36 - .../ArduinoJson/Array/JsonArrayIterator.hpp | 93 +- .../src/ArduinoJson/Array/Utilities.hpp | 18 +- .../ArduinoJson/Collection/CollectionData.hpp | 118 ++- .../ArduinoJson/Collection/CollectionImpl.hpp | 234 ++--- .../src/ArduinoJson/Configuration.hpp | 80 +- .../Deserialization/DeserializationError.hpp | 2 +- .../DeserializationOptions.hpp | 2 +- .../ArduinoJson/Deserialization/Filter.hpp | 13 +- .../Deserialization/NestingLimit.hpp | 2 +- .../ArduinoJson/Deserialization/Reader.hpp | 4 +- .../Readers/ArduinoStreamReader.hpp | 4 +- .../Readers/ArduinoStringReader.hpp | 2 +- .../Deserialization/Readers/FlashReader.hpp | 2 +- .../Readers/IteratorReader.hpp | 2 +- .../Deserialization/Readers/RamReader.hpp | 2 +- .../Readers/StdStreamReader.hpp | 2 +- .../Deserialization/Readers/VariantReader.hpp | 2 +- .../Deserialization/deserialize.hpp | 79 +- .../Document/BasicJsonDocument.hpp | 168 ---- .../Document/DynamicJsonDocument.hpp | 32 - .../src/ArduinoJson/Document/JsonDocument.hpp | 289 +++--- .../Document/StaticJsonDocument.hpp | 61 -- .../src/ArduinoJson/Json/EscapeSequence.hpp | 2 +- .../src/ArduinoJson/Json/JsonDeserializer.hpp | 96 +- .../src/ArduinoJson/Json/JsonSerializer.hpp | 64 +- .../src/ArduinoJson/Json/Latch.hpp | 2 +- .../ArduinoJson/Json/PrettyJsonSerializer.hpp | 43 +- .../src/ArduinoJson/Json/TextFormatter.hpp | 2 +- .../src/ArduinoJson/Json/Utf16.hpp | 2 +- lib/ArduinoJson/src/ArduinoJson/Json/Utf8.hpp | 2 +- .../src/ArduinoJson/Memory/Alignment.hpp | 2 +- .../src/ArduinoJson/Memory/Allocator.hpp | 49 + .../src/ArduinoJson/Memory/MemoryPool.hpp | 253 ----- .../ArduinoJson/Memory/ResourceManager.hpp | 127 +++ .../src/ArduinoJson/Memory/StringBuilder.hpp | 80 ++ .../src/ArduinoJson/Memory/StringNode.hpp | 73 ++ .../src/ArduinoJson/Memory/StringPool.hpp | 105 +++ .../src/ArduinoJson/Memory/VariantPool.hpp | 63 ++ .../ArduinoJson/Memory/VariantPoolImpl.hpp | 81 ++ .../ArduinoJson/Memory/VariantPoolList.hpp | 188 ++++ .../src/ArduinoJson/Misc/SerializedValue.hpp | 4 +- .../MsgPack/MsgPackDeserializer.hpp | 75 +- .../ArduinoJson/MsgPack/MsgPackSerializer.hpp | 69 +- .../src/ArduinoJson/MsgPack/endianess.hpp | 2 +- .../src/ArduinoJson/MsgPack/ieee754.hpp | 2 +- lib/ArduinoJson/src/ArduinoJson/Namespace.hpp | 22 +- .../src/ArduinoJson/Numbers/FloatParts.hpp | 2 +- .../src/ArduinoJson/Numbers/FloatTraits.hpp | 2 +- .../src/ArduinoJson/Numbers/JsonFloat.hpp | 2 +- .../src/ArduinoJson/Numbers/JsonInteger.hpp | 4 +- .../ArduinoJson/Numbers/arithmeticCompare.hpp | 2 +- .../src/ArduinoJson/Numbers/convertNumber.hpp | 2 +- .../src/ArduinoJson/Numbers/parseNumber.hpp | 4 +- .../src/ArduinoJson/Object/JsonObject.hpp | 181 ++-- .../ArduinoJson/Object/JsonObjectConst.hpp | 112 +-- .../src/ArduinoJson/Object/JsonObjectImpl.hpp | 85 -- .../ArduinoJson/Object/JsonObjectIterator.hpp | 92 +- .../src/ArduinoJson/Object/JsonPair.hpp | 54 +- .../src/ArduinoJson/Object/MemberProxy.hpp | 21 +- .../src/ArduinoJson/Object/ObjectData.hpp | 73 ++ .../src/ArduinoJson/Object/ObjectImpl.hpp | 45 + .../src/ArduinoJson/Polyfills/alias_cast.hpp | 2 +- .../src/ArduinoJson/Polyfills/assert.hpp | 2 +- .../src/ArduinoJson/Polyfills/attributes.hpp | 18 +- .../src/ArduinoJson/Polyfills/ctype.hpp | 2 +- .../src/ArduinoJson/Polyfills/integer.hpp | 16 +- .../src/ArduinoJson/Polyfills/limits.hpp | 10 +- .../src/ArduinoJson/Polyfills/math.hpp | 2 +- .../src/ArduinoJson/Polyfills/mpl/max.hpp | 2 +- .../src/ArduinoJson/Polyfills/pgmspace.hpp | 2 +- .../Polyfills/pgmspace_generic.hpp | 2 +- .../ArduinoJson/Polyfills/preprocessor.hpp | 2 +- .../src/ArduinoJson/Polyfills/type_traits.hpp | 2 +- .../Polyfills/type_traits/conditional.hpp | 2 +- .../Polyfills/type_traits/declval.hpp | 2 +- .../Polyfills/type_traits/enable_if.hpp | 2 +- .../type_traits/integral_constant.hpp | 2 +- .../Polyfills/type_traits/is_array.hpp | 2 +- .../Polyfills/type_traits/is_base_of.hpp | 2 +- .../Polyfills/type_traits/is_class.hpp | 2 +- .../Polyfills/type_traits/is_const.hpp | 2 +- .../Polyfills/type_traits/is_convertible.hpp | 2 +- .../Polyfills/type_traits/is_enum.hpp | 2 +- .../type_traits/is_floating_point.hpp | 2 +- .../Polyfills/type_traits/is_integral.hpp | 2 +- .../Polyfills/type_traits/is_pointer.hpp | 2 +- .../Polyfills/type_traits/is_same.hpp | 2 +- .../Polyfills/type_traits/is_signed.hpp | 2 +- .../Polyfills/type_traits/is_unsigned.hpp | 2 +- .../Polyfills/type_traits/make_unsigned.hpp | 2 +- .../Polyfills/type_traits/make_void.hpp | 2 +- .../Polyfills/type_traits/remove_const.hpp | 2 +- .../Polyfills/type_traits/remove_cv.hpp | 2 +- .../type_traits/remove_reference.hpp | 2 +- .../Polyfills/type_traits/type_identity.hpp | 2 +- .../src/ArduinoJson/Polyfills/utility.hpp | 19 +- .../Serialization/CountingDecorator.hpp | 2 +- .../src/ArduinoJson/Serialization/Writer.hpp | 2 +- .../Writers/ArduinoStringWriter.hpp | 8 +- .../Serialization/Writers/DummyWriter.hpp | 2 +- .../Serialization/Writers/PrintWriter.hpp | 2 +- .../Writers/StaticStringWriter.hpp | 2 +- .../Serialization/Writers/StdStreamWriter.hpp | 2 +- .../Serialization/Writers/StdStringWriter.hpp | 6 +- .../src/ArduinoJson/Serialization/measure.hpp | 8 +- .../ArduinoJson/Serialization/serialize.hpp | 8 +- .../StringStorage/StringCopier.hpp | 72 -- .../ArduinoJson/StringStorage/StringMover.hpp | 48 - .../StringStorage/StringStorage.hpp | 24 - .../Strings/Adapters/FlashString.hpp | 10 +- .../Strings/Adapters/JsonString.hpp | 7 +- .../Strings/Adapters/RamString.hpp | 18 +- .../Strings/Adapters/StringObject.hpp | 2 +- .../src/ArduinoJson/Strings/IsString.hpp | 2 +- .../src/ArduinoJson/Strings/JsonString.hpp | 4 +- .../src/ArduinoJson/Strings/StoragePolicy.hpp | 18 - .../src/ArduinoJson/Strings/StringAdapter.hpp | 2 +- .../ArduinoJson/Strings/StringAdapters.hpp | 2 +- .../src/ArduinoJson/Strings/StringTraits.hpp | 2 +- .../src/ArduinoJson/Variant/Converter.hpp | 4 +- .../src/ArduinoJson/Variant/ConverterImpl.hpp | 213 +++-- .../src/ArduinoJson/Variant/JsonVariant.hpp | 28 +- .../ArduinoJson/Variant/JsonVariantConst.hpp | 74 +- .../ArduinoJson/Variant/JsonVariantCopier.hpp | 34 + .../Variant/JsonVariantVisitor.hpp | 61 ++ .../src/ArduinoJson/Variant/SlotFunctions.hpp | 45 - .../ArduinoJson/Variant/VariantAttorney.hpp | 26 +- .../ArduinoJson/Variant/VariantCompare.hpp | 123 +-- .../ArduinoJson/Variant/VariantContent.hpp | 23 +- .../src/ArduinoJson/Variant/VariantData.hpp | 478 +++++++--- .../Variant/VariantDataVisitor.hpp | 24 + .../ArduinoJson/Variant/VariantFunctions.hpp | 113 --- .../src/ArduinoJson/Variant/VariantImpl.hpp | 152 --- .../ArduinoJson/Variant/VariantOperators.hpp | 2 +- .../ArduinoJson/Variant/VariantRefBase.hpp | 200 ++-- .../Variant/VariantRefBaseImpl.hpp | 176 ++++ .../src/ArduinoJson/Variant/VariantSlot.hpp | 98 +- .../src/ArduinoJson/Variant/VariantTag.hpp | 2 +- .../src/ArduinoJson/Variant/VariantTo.hpp | 2 +- .../src/ArduinoJson/Variant/Visitor.hpp | 54 -- .../src/ArduinoJson/compatibility.hpp | 123 ++- lib/ArduinoJson/src/ArduinoJson/version.hpp | 12 +- lib/ArduinoJson/src/CMakeLists.txt | 2 +- lib/ESPAsyncWebServer/AsyncJson.h | 49 +- lib/framework/APStatus.cpp | 2 +- lib/framework/APStatus.h | 2 +- lib/framework/AuthenticationService.cpp | 2 +- lib/framework/FSPersistence.h | 21 +- lib/framework/FeaturesService.cpp | 2 +- lib/framework/FeaturesService.h | 2 +- lib/framework/HttpEndpoint.h | 47 +- lib/framework/MqttStatus.cpp | 2 +- lib/framework/MqttStatus.h | 2 +- lib/framework/NTPStatus.cpp | 2 +- lib/framework/NTPStatus.h | 2 +- lib/framework/NetworkStatus.cpp | 2 +- lib/framework/SecurityManager.h | 2 +- lib/framework/SecuritySettingsService.cpp | 12 +- lib/framework/SecuritySettingsService.h | 4 +- lib/framework/StatefulService.h | 8 - lib/framework/SystemStatus.cpp | 2 +- lib/framework/SystemStatus.h | 2 +- lib/framework/UploadFileService.cpp | 6 +- lib/framework/WebSocketTxRx.h | 216 ----- lib/framework/WiFiScanner.cpp | 6 +- lib/framework/WiFiScanner.h | 2 +- lib_standalone/AsyncJson.h | 39 +- lib_standalone/FSPersistence.h | 17 +- lib_standalone/HttpEndpoint.h | 43 +- lib_standalone/SecuritySettingsService.cpp | 10 +- lib_standalone/SecuritySettingsService.h | 4 +- lib_standalone/StatefulService.h | 8 - mock-api/Handler.ts | 8 +- src/analogsensor.cpp | 10 +- src/command.cpp | 4 +- src/console.cpp | 10 +- src/default_settings.h | 2 +- src/devices/thermostat.cpp | 4 +- src/emsdevice.cpp | 22 +- src/emsesp.cpp | 22 +- src/emsesp.h | 11 - src/mqtt.cpp | 46 +- src/mqtt.h | 2 +- src/shower.cpp | 16 +- src/system.cpp | 54 +- src/temperaturesensor.cpp | 10 +- src/test/test.cpp | 19 +- src/web/WebAPIService.cpp | 31 +- src/web/WebCustomEntityService.cpp | 36 +- src/web/WebCustomizationService.cpp | 41 +- src/web/WebDataService.cpp | 35 +- src/web/WebLogService.cpp | 10 +- src/web/WebSchedulerService.cpp | 24 +- src/web/WebSettingsService.cpp | 2 +- src/web/WebStatusService.cpp | 20 +- 213 files changed, 3827 insertions(+), 4406 deletions(-) create mode 100644 lib/ArduinoJson/.clang-format create mode 100644 lib/ArduinoJson/.prettierignore create mode 100644 lib/ArduinoJson/CONTRIBUTING.md create mode 100644 lib/ArduinoJson/SUPPORT.md delete mode 100644 lib/ArduinoJson/keywords.txt delete mode 100644 lib/ArduinoJson/library.properties create mode 100644 lib/ArduinoJson/src/ArduinoJson/Array/ArrayData.hpp create mode 100644 lib/ArduinoJson/src/ArduinoJson/Array/ArrayImpl.hpp delete mode 100644 lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayImpl.hpp delete mode 100644 lib/ArduinoJson/src/ArduinoJson/Document/BasicJsonDocument.hpp delete mode 100644 lib/ArduinoJson/src/ArduinoJson/Document/DynamicJsonDocument.hpp delete mode 100644 lib/ArduinoJson/src/ArduinoJson/Document/StaticJsonDocument.hpp create mode 100644 lib/ArduinoJson/src/ArduinoJson/Memory/Allocator.hpp delete mode 100644 lib/ArduinoJson/src/ArduinoJson/Memory/MemoryPool.hpp create mode 100644 lib/ArduinoJson/src/ArduinoJson/Memory/ResourceManager.hpp create mode 100644 lib/ArduinoJson/src/ArduinoJson/Memory/StringBuilder.hpp create mode 100644 lib/ArduinoJson/src/ArduinoJson/Memory/StringNode.hpp create mode 100644 lib/ArduinoJson/src/ArduinoJson/Memory/StringPool.hpp create mode 100644 lib/ArduinoJson/src/ArduinoJson/Memory/VariantPool.hpp create mode 100644 lib/ArduinoJson/src/ArduinoJson/Memory/VariantPoolImpl.hpp create mode 100644 lib/ArduinoJson/src/ArduinoJson/Memory/VariantPoolList.hpp delete mode 100644 lib/ArduinoJson/src/ArduinoJson/Object/JsonObjectImpl.hpp create mode 100644 lib/ArduinoJson/src/ArduinoJson/Object/ObjectData.hpp create mode 100644 lib/ArduinoJson/src/ArduinoJson/Object/ObjectImpl.hpp delete mode 100644 lib/ArduinoJson/src/ArduinoJson/StringStorage/StringCopier.hpp delete mode 100644 lib/ArduinoJson/src/ArduinoJson/StringStorage/StringMover.hpp delete mode 100644 lib/ArduinoJson/src/ArduinoJson/StringStorage/StringStorage.hpp delete mode 100644 lib/ArduinoJson/src/ArduinoJson/Strings/StoragePolicy.hpp create mode 100644 lib/ArduinoJson/src/ArduinoJson/Variant/JsonVariantCopier.hpp create mode 100644 lib/ArduinoJson/src/ArduinoJson/Variant/JsonVariantVisitor.hpp delete mode 100644 lib/ArduinoJson/src/ArduinoJson/Variant/SlotFunctions.hpp create mode 100644 lib/ArduinoJson/src/ArduinoJson/Variant/VariantDataVisitor.hpp delete mode 100644 lib/ArduinoJson/src/ArduinoJson/Variant/VariantFunctions.hpp delete mode 100644 lib/ArduinoJson/src/ArduinoJson/Variant/VariantImpl.hpp create mode 100644 lib/ArduinoJson/src/ArduinoJson/Variant/VariantRefBaseImpl.hpp delete mode 100644 lib/ArduinoJson/src/ArduinoJson/Variant/Visitor.hpp delete mode 100644 lib/framework/WebSocketTxRx.h diff --git a/lib/ArduinoJson/.clang-format b/lib/ArduinoJson/.clang-format new file mode 100644 index 000000000..0853a7826 --- /dev/null +++ b/lib/ArduinoJson/.clang-format @@ -0,0 +1,12 @@ +# http://clang.llvm.org/docs/ClangFormatStyleOptions.html + +BasedOnStyle: Google +Standard: c++11 +AllowShortFunctionsOnASingleLine: Empty +IncludeBlocks: Preserve +IndentPPDirectives: AfterHash +DerivePointerAlignment: false + +# Always break after if to get accurate coverage +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false diff --git a/lib/ArduinoJson/.prettierignore b/lib/ArduinoJson/.prettierignore new file mode 100644 index 000000000..dd449725e --- /dev/null +++ b/lib/ArduinoJson/.prettierignore @@ -0,0 +1 @@ +*.md diff --git a/lib/ArduinoJson/ArduinoJson.h b/lib/ArduinoJson/ArduinoJson.h index 15c218f48..993959949 100644 --- a/lib/ArduinoJson/ArduinoJson.h +++ b/lib/ArduinoJson/ArduinoJson.h @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #include "src/ArduinoJson.h" diff --git a/lib/ArduinoJson/CHANGELOG.md b/lib/ArduinoJson/CHANGELOG.md index 28c506ab2..796e21bc6 100644 --- a/lib/ArduinoJson/CHANGELOG.md +++ b/lib/ArduinoJson/CHANGELOG.md @@ -1,854 +1,111 @@ ArduinoJson: change log ======================= -v6.21.3 (2023-07-23) -------- +v7.0.0 (2024-01-03) +------ -* Fix compatibility with the Blynk libary (issue #1914) +* Remove `BasicJsonDocument` +* Remove `StaticJsonDocument` +* Add abstract `Allocator` class +* Merge `DynamicJsonDocument` with `JsonDocument` +* Remove `JSON_ARRAY_SIZE()`, `JSON_OBJECT_SIZE()`, and `JSON_STRING_SIZE()` +* Remove `ARDUINOJSON_ENABLE_STRING_DEDUPLICATION` (string deduplication cannot be disabled anymore) +* Remove `JsonDocument::capacity()` +* Store the strings in the heap +* Reference-count shared strings +* Always store `serialized("string")` by copy (#1915) +* Remove the zero-copy mode of `deserializeJson()` and `deserializeMsgPack()` * Fix double lookup in `to()` * Fix double call to `size()` in `serializeMsgPack()` * Include `ARDUINOJSON_SLOT_OFFSET_SIZE` in the namespace name +* Remove `JsonVariant::shallowCopy()` +* `JsonDocument`'s capacity grows as needed, no need to pass it to the constructor anymore +* `JsonDocument`'s allocator is not monotonic anymore, removed values get recycled * Show a link to the documentation when user passes an unsupported input type - -v6.21.2 (2023-04-12) -------- - -* Fix compatibility with the Zephyr Project (issue #1905) -* Allow using PROGMEM outside of Arduino (issue #1903) -* Set default for `ARDUINOJSON_ENABLE_PROGMEM` to `1` on AVR - -v6.21.1 (2023-03-27) -------- - -* Double speed of `DynamicJsonDocument::garbageCollect()` -* Fix compatibility with GCC 5.2 (issue #1897) - -v6.21.0 (2023-03-14) -------- - -* Drop support for C++98/C++03. Minimum required is C++11. -* Remove `ARDUINOJSON_NAMESPACE`; use `ArduinoJson` instead. -* Make string support generic (issue #1807) - -v6.20.1 (2023-02-08) -------- - -* Remove explicit exclusion of `as()` and `as()` (issue #1860) - If you try to call them, you'll now get the same error message as any unsupported type. - You could also add a custom converter for `char*` and `char`. - -v6.20.0 (2022-12-26) -------- - -* Add `JsonVariant::shallowCopy()` (issue #1343) -* Fix `9.22337e+18 is outside the range of representable values of type 'long'` -* Fix comparison operators for `JsonArray`, `JsonArrayConst`, `JsonObject`, and `JsonObjectConst` -* Fix lax parsing of `true`, `false`, and `null` (issue #1781) -* Remove undocumented `accept()` functions -* Rename `addElement()` to `add()` -* Remove `getElement()`, `getOrAddElement()`, `getMember()`, and `getOrAddMember()` -* Remove undocumented `JsonDocument::data()` and `JsonDocument::memoryPool()` -* Remove undocumented `JsonArrayIterator::internal()` and `JsonObjectIterator::internal()` -* Rename things in `ARDUINOJSON_NAMESPACE` to match the public names -* Add documentation to most public symbols -* Remove support for naked `char` (was deprecated since 6.18.0) +* Remove `JsonDocument::memoryUsage()` +* Remove `JsonDocument::garbageCollect()` +* Add `deserializeJson(JsonVariant, ...)` and `deserializeMsgPack(JsonVariant, ...)` (#1226) +* Call `shrinkToFit()` in `deserializeJson()` and `deserializeMsgPack()` +* `serializeJson()` and `serializeMsgPack()` replace the content of `std::string` and `String` instead of appending to it +* Replace `add()` with `add()` (`add(T)` is still supported) +* Remove `createNestedArray()` and `createNestedObject()` (use `to()` and `to()` instead) > ### BREAKING CHANGES > -> This release hides `JsonVariant`'s functions that were only intended for internal use. -> If you were using them in your programs, you must replace with `operator[]` and `to()`, like so: -> -> ```c++ -> // before -> JsonVariant a = variant.getElement(idx); -> JsonVariant b = variant.getOrAddElement(idx); -> JsonVariant c = variant.getMember(key); -> JsonVariant d = variant.getOrAddMember(key); +> As every major release, ArduinoJson 7 introduces several breaking changes. +> I added some stubs so that most existing programs should compile, but I highty recommend you upgrade your code. > -> // after -> JsonVariant a = variant[idx]; -> JsonVariant b = idx < variant.size() ? variant[idx] : variant[idx].to(); -> JsonVariant c = variant[key]; -> JsonVariant d = variant.containsKey(key) ? variant[key] : variant[key].to(); -> ``` - -v6.19.4 (2022-04-05) -------- - -* Add `ElementProxy::memoryUsage()` -* Add `MemberProxy::memoryUsage()` (issue #1730) -* Add implicit conversion from `JsonDocument` to `JsonVariant` -* Fix comparisons operators with `const JsonDocument&` - -v6.19.3 (2022-03-08) -------- - -* Fix `call of overloaded 'String(const char*, int)' is ambiguous` -* Fix `JsonString` operator `==` and `!=` for non-zero-terminated string -* Fix `-Wsign-conversion` on GCC 8 (issue #1715) -* MessagePack: serialize round floats as integers (issue #1718) - -v6.19.2 (2022-02-14) -------- - -* Fix `cannot convert 'pgm_p' to 'const void*'` (issue #1707) - -v6.19.1 (2022-01-14) -------- - -* Fix crash when adding an object member in a too small `JsonDocument` -* Fix filter not working in zero-copy mode (issue #1697) - -v6.19.0 (2022-01-08) -------- - -* Remove `ARDUINOJSON_EMBEDDED_MODE` and assume we run on an embedded platform. - Dependent settings (like `ARDUINOJSON_DEFAULT_NESTING_LIMIT`) must be set individually. -* Change the default of `ARDUINOJSON_USE_DOUBLE` to `1` -* Change the default of `ARDUINOJSON_USE_LONG_LONG` to `1` on 32-bit platforms -* Add `as()` and `is()` -* Add safe bool idiom in `JsonString` -* Add support for NUL in string values (issue #1646) -* Add support for arbitrary array rank in `copyArray()` -* Add support for `char[][]` in `copyArray()` -* Remove `DeserializationError == bool` and `DeserializationError != bool` -* Renamed undocumented function `isUndefined()` to `isUnbound()` -* Fix `JsonVariant::memoryUsage()` for raw strings -* Fix `call of overloaded 'swap(BasicJsonDocument&, BasicJsonDocument&)' is ambiguous` (issue #1678) -* Fix inconsistent pool capacity between `BasicJsonDocument`'s copy and move constructors -* Fix inconsistent pool capacity between `BasicJsonDocument`'s copy and move assignments -* Fix return type of `StaticJsonDocument::operator=` -* Avoid pool reallocation in `BasicJsonDocument`'s copy assignment if capacity is the same -* Avoid including `Arduino.h` when all its features are disabled (issue #1692, PR #1693 by @paulocsanz) -* Assume `PROGMEM` is available as soon as `ARDUINO` is defined (consequence of #1693) - -v6.18.5 (2021-09-28) -------- - -* Set `ARDUINOJSON_EMBEDDED_MODE` to `1` on Nios II (issue #1657) - -v6.18.4 (2021-09-06) -------- - -* Fixed error `'dummy' may be used uninitialized` on GCC 11 -* Fixed error `expected unqualified-id before 'const'` on GCC 11 (issue #1622) -* Filter: exact match takes precedence over wildcard (issue #1628) -* Fixed deserialization of `\u0000` (issue #1646) - -v6.18.3 (2021-07-27) -------- - -* Changed return type of `convertToJson()` and `Converter::toJson()` to `void` -* Added `as()` and `is()` - -v6.18.2 (2021-07-19) -------- - -* Removed a symlink because the Arduino Library Specification forbids it - -v6.18.1 (2021-07-03) -------- - -* Fixed support for `volatile float` and `volatile double` (issue #1557) -* Fixed error `[Pe070]: incomplete type is not allowed` on IAR (issue #1560) -* Fixed `serializeJson(doc, String)` when allocation fails (issue #1572) -* Fixed clang-tidy warnings (issue #1574, PR #1577 by @armandas) -* Added fake class `InvalidConversion` to easily identify invalid conversions (issue #1585) -* Added support for `std::string_view` (issue #1578, PR #1554 by @0xFEEDC0DE64) -* Fixed warning `definition of implicit copy constructor for 'MsgPackDeserializer' is deprecated because it has a user-declared copy assignment operator` -* Added `JsonArray::clear()` (issue #1597) -* Fixed `JsonVariant::as()` (issue #1601) -* Added support for ESP-IDF component build (PR #1562 by @qt1, PR #1599 by @andreaskuster) - -v6.18.0 (2021-05-05) -------- - -* Added support for custom converters (issue #687) -* Added support for `Printable` (issue #1444) -* Removed support for `char` values, see below (issue #1498) -* `deserializeJson()` leaves `\uXXXX` unchanged instead of returning `NotSupported` -* `deserializeMsgPack()` inserts `null` instead of returning `NotSupported` -* Removed `DeserializationError::NotSupported` -* Added `JsonVariant::is()` (issue #1412) -* Added `JsonVariant::is()` (issue #1412) -* Changed `JsonVariantConst::is()` to return `false` (issue #1412) -* Simplified `JsonVariant::as()` to always return `T` (see below) -* Updated folders list in `.mbedignore` (PR #1515 by @AGlass0fMilk) -* Fixed member-call-on-null-pointer in `getMember()` when array is empty -* `serializeMsgPack(doc, buffer, size)` doesn't add null-terminator anymore (issue #1545) -* `serializeJson(doc, buffer, size)` adds null-terminator only if there is enough room -* PlatformIO: set `build.libArchive` to `false` (PR #1550 by @askreet) - -> ### BREAKING CHANGES -> -> #### Support for `char` removed -> -> We cannot cast a `JsonVariant` to a `char` anymore, so the following will break: -> ```c++ -> char age = doc["age"]; // error: no matching function for call to 'variantAs(VariantData*&)' -> ``` -> Instead, you must use another integral type, such as `int8_t`: -> ```c++ -> int8_t age = doc["age"]; // OK -> ``` -> -> Similarly, we cannot assign from a `char` anymore, so the following will break: -> ```c++ -> char age; -> doc["age"] = age; // error: no matching function for call to 'VariantRef::set(const char&)' -> ``` -> Instead, you must use another integral type, such as `int8_t`: -> ```c++ -> int8_t age; -> doc["age"] = age; // OK -> ``` -> A deprecation warning with the message "Support for `char` is deprecated, use `int8_t` or `uint8_t` instead" was added to allow a smooth transition. -> -> #### `as()` always returns `T` -> -> Previously, `JsonVariant::as()` could return a type different from `T`. -> The most common example is `as()` that returned a `const char*`. -> While this feature simplified a few use cases, it was confusing and complicated the -> implementation of custom converters. -> -> Starting from this version, `as` doesn't try to auto-correct the return type and always return `T`, -> which means that you cannot write this anymore: -> -> ```c++ -> Serial.println(doc["sensor"].as()); // error: invalid conversion from 'const char*' to 'char*' [-fpermissive] -> ``` +> #### `JsonDocument` > -> Instead, you must write: +> In ArduinoJson 6, you could allocate the memory pool on the stack (with `StaticJsonDocument`) or in the heap (with `DynamicJsonDocument`). +> In ArduinoJson 7, the memory pool is always allocated in the heap, so `StaticJsonDocument` and `DynamicJsonDocument` have been merged into `JsonDocument`. > -> ```c++ -> Serial.println(doc["sensor"].as()); // OK -> ``` -> -> A deprecation warning with the message "Replace `as()` with `as()`" was added to allow a smooth transition. -> -> #### `DeserializationError::NotSupported` removed -> -> On a different topic, `DeserializationError::NotSupported` has been removed. -> Instead of returning this error: -> -> * `deserializeJson()` leaves `\uXXXX` unchanged (only when `ARDUINOJSON_DECODE_UNICODE` is `0`) -> * `deserializeMsgPack()` replaces unsupported values with `null`s -> -> #### Const-aware `is()` -> -> Lastly, a very minor change concerns `JsonVariantConst::is()`. -> It used to return `true` for `JsonArray` and `JsonOject`, but now it returns `false`. -> Instead, you must use `JsonArrayConst` and `JsonObjectConst`. - -v6.17.3 (2021-02-15) -------- - -* Made `JsonDocument`'s destructor protected (issue #1480) -* Added missing calls to `client.stop()` in `JsonHttpClient.ino` (issue #1485) -* Fixed error `expected ')' before 'char'` when `isdigit()` is a macro (issue #1487) -* Fixed error `definition of implicit copy constructor is deprecated` on Clang 10 -* PlatformIO: set framework compatibility to `*` (PR #1490 by @maxgerhardt) - -v6.17.2 (2020-11-14) -------- - -* Fixed invalid conversion error in `operator|(JsonVariant, char*)` (issue #1432) -* Changed the default value of `ARDUINOJSON_ENABLE_PROGMEM` (issue #1433). - It now checks that the `pgm_read_XXX` macros are defined before enabling `PROGMEM`. - -v6.17.1 (2020-11-07) -------- - -* Fixed error `ambiguous overload for 'operator|'` (issue #1411) -* Fixed `operator|(MemberProxy, JsonObject)` (issue #1415) -* Allowed more than 32767 values in non-embedded mode (issue #1414) - -v6.17.0 (2020-10-19) -------- - -* Added a build failure when nullptr is defined as a macro (issue #1355) -* Added `JsonDocument::overflowed()` which tells if the memory pool was too small (issue #1358) -* Added `DeserializationError::EmptyInput` which tells if the input was empty -* Added `DeserializationError::f_str()` which returns a `const __FlashStringHelper*` (issue #846) -* Added `operator|(JsonVariantConst, JsonVariantConst)` -* Added filtering for MessagePack (issue #1298, PR #1394 by Luca Passarella) -* Moved float convertion tables to PROGMEM -* Fixed `JsonVariant::set((char*)0)` which returned false instead of true (issue #1368) -* Fixed error `No such file or directory #include ` (issue #1381) - -v6.16.1 (2020-08-04) -------- - -* Fixed `deserializeJson()` that stopped reading after `{}` (issue #1335) - -v6.16.0 (2020-08-01) -------- - -* Added comparisons (`>`, `>=`, `==`, `!=`, `<`, and `<=`) between `JsonVariant`s -* Added string deduplication (issue #1303) -* Added `JsonString::operator!=` -* Added wildcard key (`*`) for filters (issue #1309) -* Set `ARDUINOJSON_DECODE_UNICODE` to `1` by default -* Fixed `copyArray()` not working with `String`, `ElementProxy`, and `MemberProxy` -* Fixed error `getOrAddElement is not a member of ElementProxy` (issue #1311) -* Fixed excessive stack usage when compiled with `-Og` (issues #1210 and #1314) -* Fixed `Warning[Pa093]: implicit conversion from floating point to integer` on IAR compiler (PR #1328 by @stawiski) - -v6.15.2 (2020-05-15) -------- - -* CMake: don't build tests when imported in another project -* CMake: made project arch-independent -* Visual Studio: fixed error C2766 with flag `/Zc:__cplusplus` (issue #1250) -* Added support for `JsonDocument` to `copyArray()` (issue #1255) -* Added support for `enum`s in `as()` and `is()` (issue #1256) -* Added `JsonVariant` as an input type for `deserializeXxx()` - For example, you can do: `deserializeJson(doc2, doc1["payload"])` -* Break the build if using 64-bit integers with ARDUINOJSON_USE_LONG_LONG==0 - -v6.15.1 (2020-04-08) -------- - -* Fixed "maybe-uninitialized" warning (issue #1217) -* Fixed "statement is unreachable" warning on IAR (issue #1233) -* Fixed "pointless integer comparison" warning on IAR (issue #1233) -* Added CMake "install" target (issue #1209) -* Disabled alignment on AVR (issue #1231) - -v6.15.0 (2020-03-22) -------- - -* Added `DeserializationOption::Filter` (issue #959) -* Added example `JsonFilterExample.ino` -* Changed the array subscript operator to automatically add missing elements -* Fixed "deprecated-copy" warning on GCC 9 (fixes #1184) -* Fixed `MemberProxy::set(char[])` not duplicating the string (issue #1191) -* Fixed enums serialized as booleans (issue #1197) -* Fixed incorrect string comparison on some platforms (issue #1198) -* Added move-constructor and move-assignment to `BasicJsonDocument` -* Added `BasicJsonDocument::garbageCollect()` (issue #1195) -* Added `StaticJsonDocument::garbageCollect()` -* Changed copy-constructor of `BasicJsonDocument` to preserve the capacity of the source. -* Removed copy-constructor of `JsonDocument` (issue #1189) - -> ### BREAKING CHANGES -> -> #### Copy-constructor of `BasicJsonDocument` -> -> In previous versions, the copy constructor of `BasicJsonDocument` looked at the source's `memoryUsage()` to choose its capacity. -> Now, the copy constructor of `BasicJsonDocument` uses the same capacity as the source. -> -> Example: -> -> ```c++ -> DynamicJsonDocument doc1(64); -> doc1.set(String("example")); -> -> DynamicJsonDocument doc2 = doc1; -> Serial.print(doc2.capacity()); // 8 with ArduinoJson 6.14 -> // 64 with ArduinoJson 6.15 -> ``` -> -> I made this change to get consistent results between copy-constructor and move-constructor, and whether RVO applies or not. -> -> If you use the copy-constructor to optimize your documents, you can use `garbageCollect()` or `shrinkToFit()` instead. -> -> #### Copy-constructor of `JsonDocument` -> -> In previous versions, it was possible to create a function that take a `JsonDocument` by value. +> In ArduinoJson 6, `JsonDocument` had a fixed capacity; in ArduinoJson 7, it has an elastic capacity that grows as needed. +> Therefore, you don't need to specify the capacity anymore, so the macros `JSON_ARRAY_SIZE()`, `JSON_OBJECT_SIZE()`, and `JSON_STRING_SIZE()` have been removed. > > ```c++ -> void myFunction(JsonDocument doc) {} -> ``` -> -> This function gives the wrong clues because it doesn't receive a copy of the `JsonDocument`, only a sliced version. -> It worked because the copy constructor copied the internal pointers, but it was an accident. -> -> From now, if you need to pass a `JsonDocument` to a function, you must use a reference: -> -> ```c++ -> void myFunction(JsonDocument& doc) {} -> ``` - -v6.14.1 (2020-01-27) -------- - -* Fixed regression in UTF16 decoding (issue #1173) -* Fixed `containsKey()` on `JsonVariantConst` -* Added `getElement()` and `getMember()` to `JsonVariantConst` - -v6.14.0 (2020-01-16) -------- - -* Added `BasicJsonDocument::shrinkToFit()` -* Added support of `uint8_t` for `serializeJson()`, `serializeJsonPretty()`, and `serializeMsgPack()` (issue #1142) -* Added `ARDUINOJSON_ENABLE_COMMENTS` to enable support for comments (defaults to 0) -* Auto enable support for `std::string` and `std::stream` on modern compilers (issue #1156) - (No need to define `ARDUINOJSON_ENABLE_STD_STRING` and `ARDUINOJSON_ENABLE_STD_STREAM` anymore) -* Improved decoding of UTF-16 surrogate pairs (PR #1157 by @kaysievers) - (ArduinoJson now produces standard UTF-8 instead of CESU-8) -* Added `measureJson`, `measureJsonPretty`, and `measureMsgPack` to `keywords.txt` - (This file is used for syntax highlighting in the Arduino IDE) -* Fixed `variant.is()` -* Fixed value returned by `serializeJson()`, `serializeJsonPretty()`, and `serializeMsgPack()` when writing to a `String` -* Improved speed of `serializeJson()`, `serializeJsonPretty()`, and `serializeMsgPack()` when writing to a `String` - -> ### BREAKING CHANGES +> // ArduinoJson 6 +> StaticJsonDocument<256> doc; +> // or +> DynamicJsonDocument doc(256); > -> #### Comments -> -> Support for comments in input is now optional and disabled by default. -> -> If you need support for comments, you must defined `ARDUINOJSON_ENABLE_COMMENTS` to `1`; otherwise, you'll receive `InvalidInput` errors. -> -> ```c++ -> #define ARDUINOJSON_ENABLE_COMMENTS 1 -> #include +> // ArduinoJson 7 +> JsonDocument doc; > ``` - -v6.13.0 (2019-11-01) -------- - -* Added support for custom writer/reader classes (issue #1088) -* Added conversion from `JsonArray` and `JsonObject` to `bool`, to be consistent with `JsonVariant` -* Fixed `deserializeJson()` when input contains duplicate keys (issue #1095) -* Improved `deserializeMsgPack()` speed by reading several bytes at once -* Added detection of Atmel AVR8/GNU C Compiler (issue #1112) -* Fixed deserializer that stopped reading at the first `0xFF` (PR #1118 by @mikee47) -* Fixed dangling reference in copies of `MemberProxy` and `ElementProxy` (issue #1120) - -v6.12.0 (2019-09-05) -------- - -* Use absolute instead of relative includes (issue #1072) -* Changed `JsonVariant::as()` to return `true` for any non-null value (issue #1005) -* Moved ancillary files to `extras/` (issue #1011) - -v6.11.5 (2019-08-23) -------- - -* Added fallback implementations of `strlen_P()`, `strncmp_P()`, `strcmp_P()`, and `memcpy_P()` (issue #1073) - -v6.11.4 (2019-08-12) -------- - -* Added `measureJson()` to the `ArduinoJson` namespace (PR #1069 by @nomis) -* Added support for `basic_string` (issue #1045) -* Fixed example `JsonConfigFile.ino` for ESP8266 -* Include `Arduino.h` if `ARDUINO` is defined (PR #1071 by @nomis) - -v6.11.3 (2019-07-22) -------- - -* Added operators `==` and `!=` for `JsonDocument`, `ElementProxy`, and `MemberProxy` -* Fixed comparison of `JsonVariant` when one contains a linked string and the other contains an owned string (issue #1051) - -v6.11.2 (2019-07-08) -------- - -* Fixed assignment of `JsonDocument` to `JsonVariant` (issue #1023) -* Fix invalid conversion error on Particle Argon (issue #1035) - -v6.11.1 (2019-06-21) -------- - -* Fixed `serialized()` not working with Flash strings (issue #1030) - -v6.11.0 (2019-05-26) -------- - -* Fixed `deserializeJson()` silently accepting a `Stream*` (issue #978) -* Fixed invalid result from `operator|` (issue #981) -* Made `deserializeJson()` more picky about trailing characters (issue #980) -* Added `ARDUINOJSON_ENABLE_NAN` (default=0) to enable NaN in JSON (issue #973) -* Added `ARDUINOJSON_ENABLE_INFINITY` (default=0) to enable Infinity in JSON -* Removed implicit conversion in comparison operators (issue #998) -* Added lexicographical comparison for `JsonVariant` -* Added support for `nullptr` (issue #998) - -> ### BREAKING CHANGES -> -> #### NaN and Infinity -> -> The JSON specification allows neither NaN not Infinity, but previous -> versions of ArduinoJson supported it. Now, ArduinoJson behaves like most -> other libraries: a NaN or and Infinity in the `JsonDocument`, becomes -> a `null` in the output JSON. Also, `deserializeJson()` returns -> `InvalidInput` if the JSON document contains NaN or Infinity. -> -> This version still supports NaN and Infinity in JSON documents, but -> it's disabled by default to be compatible with other JSON parsers. -> If you need the old behavior back, define `ARDUINOJSON_ENABLE_NAN` and -> `ARDUINOJSON_ENABLE_INFINITY` to `1`;: -> -> ```c++ -> #define ARDUINOJSON_ENABLE_NAN 1 -> #define ARDUINOJSON_ENABLE_INFINITY 1 -> #include -> ``` -> -> #### The "or" operator -> -> This version slightly changes the behavior of the | operator when the -> variant contains a float and the user requests an integer. -> -> Older versions returned the floating point value truncated. -> Now, it returns the default value. -> -> ```c++ -> // suppose variant contains 1.2 -> int value = variant | 3; -> -> // old behavior: -> value == 1 -> -> // new behavior -> value == 3 -> ``` -> -> If you need the old behavior, you must add `if (variant.is())`. - -v6.10.1 (2019-04-23) -------- - -* Fixed error "attributes are not allowed on a function-definition" -* Fixed `deserializeJson()` not being picky enough (issue #969) -* Fixed error "no matching function for call to write(uint8_t)" (issue #972) - -v6.10.0 (2019-03-22) -------- - -* Fixed an integer overflow in the JSON deserializer -* Added overflow handling in `JsonVariant::as()` and `JsonVariant::is()`. - - `as()` returns `0` if the integer `T` overflows - - `is()` returns `false` if the integer `T` overflows -* Added `BasicJsonDocument` to support custom allocator (issue #876) -* Added `JsonDocument::containsKey()` (issue #938) -* Added `JsonVariant::containsKey()` - -v6.9.1 (2019-03-01) ------- - -* Fixed warning "unused variable" with GCC 4.4 (issue #912) -* Fixed warning "cast increases required alignment" (issue #914) -* Fixed warning "conversion may alter value" (issue #914) -* Fixed naming conflict with "CAPACITY" (issue #839) -* Muted warning "will change in GCC 7.1" (issue #914) -* Added a clear error message for `StaticJsonBuffer` and `DynamicJsonBuffer` -* Marked ArduinoJson.h as a "system header" - -v6.9.0 (2019-02-26) ------- - -* Decode escaped Unicode characters like \u00DE (issue #304, PR #791) - Many thanks to Daniel Schulte (aka @trilader) who implemented this feature. -* Added option ARDUINOJSON_DECODE_UNICODE to enable it -* Converted `JsonArray::copyFrom()/copyTo()` to free functions `copyArray()` -* Renamed `JsonArray::copyFrom()` and `JsonObject::copyFrom()` to `set()` -* Renamed `JsonArray::get()` to `getElement()` -* Renamed `JsonArray::add()` (without arg) to `addElement()` -* Renamed `JsonObject::get()` to `getMember()` -* Renamed `JsonObject::getOrCreate()` to `getOrAddMember()` -* Fixed `JsonVariant::isNull()` not returning `true` after `set((char*)0)` -* Fixed segfault after `variant.set(serialized((char*)0))` -* Detect `IncompleteInput` in `false`, `true`, and `null` -* Added `JsonDocument::size()` -* Added `JsonDocument::remove()` -* Added `JsonVariant::clear()` -* Added `JsonVariant::remove()` - -v6.8.0-beta (2019-01-30) ------------ - -* Import functions in the ArduinoJson namespace to get clearer errors -* Improved syntax highlighting in Arduino IDE -* Removed default capacity of `DynamicJsonDocument` -* `JsonArray::copyFrom()` accepts `JsonArrayConst` -* `JsonVariant::set()` accepts `JsonArrayConst` and `JsonObjectConst` -* `JsonDocument` was missing in the ArduinoJson namespace -* Added `memoryUsage()` to `JsonArray`, `JsonObject`, and `JsonVariant` -* Added `nesting()` to `JsonArray`, `JsonDocument`, `JsonObject`, and `JsonVariant` -* Replaced `JsonDocument::nestingLimit` with an additional parameter - to `deserializeJson()` and `deserializeMsgPack()` -* Fixed uninitialized variant in `JsonDocument` -* Fixed `StaticJsonDocument` copy constructor and copy assignment -* The copy constructor of `DynamicJsonDocument` chooses the capacity according to the memory usage of the source, not from the capacity of the source. -* Added the ability to create/assign a `StaticJsonDocument`/`DynamicJsonDocument` from a `JsonArray`/`JsonObject`/`JsonVariant` -* Added `JsonDocument::isNull()` -* Added `JsonDocument::operator[]` -* Added `ARDUINOJSON_TAB` to configure the indentation character -* Reduced the size of the pretty JSON serializer -* Added `add()`, `createNestedArray()` and `createNestedObject()` to `JsonVariant` -* `JsonVariant` automatically promotes to `JsonObject` or `JsonArray` on write. - Calling `JsonVariant::to()` is not required anymore. -* `JsonDocument` now support the same operations as `JsonVariant`. - Calling `JsonDocument::as()` is not required anymore. -* Fixed example `JsonHttpClient.ino` -* User can now use a `JsonString` as a key or a value - -> ### BREAKING CHANGES -> -> #### `DynamicJsonDocument`'s constructor -> -> The parameter to the constructor of `DynamicJsonDocument` is now mandatory -> -> Old code: > -> ```c++ -> DynamicJsonDocument doc; -> ``` +> In ArduinoJson 7, `JsonDocument` reuses released memory, so `garbageCollect()` has been removed. +> `shrinkToFit()` is still available and releases the over-allocated memory. > -> New code: -> -> ```c++ -> DynamicJsonDocument doc(1024); -> ``` -> -> #### Nesting limit -> -> `JsonDocument::nestingLimit` was replaced with a new parameter to `deserializeJson()` and `deserializeMsgPack()`. -> -> Old code: -> -> ```c++ -> doc.nestingLimit = 15; -> deserializeJson(doc, input); -> ``` -> -> New code: +> Due to a change in the implementation, it's not possible to store a pointer to a variant from another `JsonDocument`, so `shallowCopy()` has been removed. > -> ```c++ -> deserializeJson(doc, input, DeserializationOption::NestingLimit(15)); -> ``` - -v6.7.0-beta (2018-12-07) ------------ - -* Removed the automatic expansion of `DynamicJsonDocument`, it now has a fixed capacity. -* Restored the monotonic allocator because the code was getting too big -* Reduced the memory usage -* Reduced the code size -* Renamed `JsonKey` to `JsonString` -* Removed spurious files in the Particle library - -v6.6.0-beta (2018-11-13) ------------ - -* Removed `JsonArray::is(i)` and `JsonArray::set(i,v)` -* Removed `JsonObject::is(k)` and `JsonObject::set(k,v)` -* Replaced `T JsonArray::get(i)` with `JsonVariant JsonArray::get(i)` -* Replaced `T JsonObject::get(k)` with `JsonVariant JsonObject::get(k)` -* Added `JSON_STRING_SIZE()` -* ~~Replacing or removing a value now releases the memory~~ -* Added `DeserializationError::code()` to be used in switch statements (issue #846) - -v6.5.0-beta (2018-10-13) ------------ - -* Added implicit conversion from `JsonArray` and `JsonObject` to `JsonVariant` -* Allow mixed configuration in compilation units (issue #809) -* Fixed object keys not being duplicated -* `JsonPair::key()` now returns a `JsonKey` -* Increased the default capacity of `DynamicJsonDocument` -* Fixed `JsonVariant::is()` (closes #763) -* Added `JsonArrayConst`, `JsonObjectConst`, and `JsonVariantConst` -* Added copy-constructor and copy-assignment-operator for `JsonDocument` (issue #827) - -v6.4.0-beta (2018-09-11) ------------ - -* Copy `JsonArray` and `JsonObject`, instead of storing pointers (issue #780) -* Added `JsonVariant::to()` and `JsonVariant::to()` - -v6.3.0-beta (2018-08-31) ------------ - -* Implemented reference semantics for `JsonVariant` -* Replaced `JsonPair`'s `key` and `value` with `key()` and `value()` -* Fixed `serializeJson(obj[key], dst)` (issue #794) - -> ### BREAKING CHANGES +> In ArduinoJson 6, the meaning of `memoryUsage()` was clear: it returned the number of bytes used in the memory pool. +> In ArduinoJson 7, the meaning of `memoryUsage()` would be ambiguous, so it has been removed. > -> #### JsonVariant -> -> `JsonVariant` now has a semantic similar to `JsonObject` and `JsonArray`. -> It's a reference to a value stored in the `JsonDocument`. -> As a consequence, a `JsonVariant` cannot be used as a standalone variable anymore. +> #### Custom allocators > -> Old code: +> In ArduinoJson 6, you could specify a custom allocator class as a template parameter of `BasicJsonDocument`. +> In ArduinoJson 7, you must inherit from `ArduinoJson::Allocator` and pass a pointer to an instance of your class to the constructor of `JsonDocument`. > > ```c++ -> JsonVariant myValue = 42; -> ``` -> -> New code: +> // ArduinoJson 6 +> class MyAllocator { +> // ... +> }; +> BasicJsonDocument doc(256); > -> ```c++ -> DynamicJsonDocument doc; -> JsonVariant myValue = doc.to(); -> myValue.set(42); +> // ArduinoJson 7 +> class MyAllocator : public ArduinoJson::Allocator { +> // ... +> }; +> MyAllocator myAllocator; +> JsonDocument doc(&myAllocator); > ``` > -> #### JsonPair -> -> Old code: +> #### `createNestedArray()` and `createNestedObject()` > -> ```c++ -> for(JsonPair p : myObject) { -> Serial.println(p.key); -> Serial.println(p.value.as()); -> } -> ``` +> In ArduinoJson 6, you could create a nested array or object with `createNestedArray()` and `createNestedObject()`. +> In ArduinoJson 7, you must use `add()` or `to()` instead. > -> New code: +> For example, to create `[[],{}]`, you would write: > > ```c++ -> for(JsonPair p : myObject) { -> Serial.println(p.key()); -> Serial.println(p.value().as()); -> } -> ``` +> // ArduinoJson 6 +> arr.createNestedArray(); +> arr.createNestedObject(); > -> CAUTION: the key is now read only! - -v6.2.3-beta (2018-07-19) ------------ - -* Fixed exception when using Flash strings as object keys (issue #784) - -v6.2.2-beta (2018-07-18) ------------ - -* Fixed `invalid application of 'sizeof' to incomplete type '__FlashStringHelper'` (issue #783) -* Fixed `char[]` not duplicated when passed to `JsonVariant::operator[]` - -v6.2.1-beta (2018-07-17) ------------ - -* Fixed `JsonObject` not inserting keys of type `String` (issue #782) - -v6.2.0-beta (2018-07-12) ------------ - -* Disabled lazy number deserialization (issue #772) -* Fixed `JsonVariant::is()` that returned true for empty strings -* Improved float serialization when `-fsingle-precision-constant` is used -* Renamed function `RawJson()` to `serialized()` -* `serializeMsgPack()` now supports values marked with `serialized()` - -> ### BREAKING CHANGES -> -> #### Non quoted strings -> -> Non quoted strings are now forbidden in values, but they are still allowed in keys. -> For example, `{key:"value"}` is accepted, but `{key:value}` is not. -> -> #### Preformatted values +> // ArduinoJson 7 +> arr.add(); +> arr.add(); +> ``` > -> Old code: +> And to create `{"array":[],"object":{}}`, you would write: > > ```c++ -> object["values"] = RawJson("[1,2,3,4]"); -> ``` -> -> New code: -> -> ```c++ -> object["values"] = serialized("[1,2,3,4]"); -> ``` - -v6.1.0-beta (2018-07-02) ------------ - -* Return `JsonArray` and `JsonObject` by value instead of reference (issue #309) -* Replaced `success()` with `isNull()` - -> ### BREAKING CHANGES -> -> Old code: +> // ArduinoJson 6 +> obj.createNestedArray("array"); +> obj.createNestedObject("object"); > -> ```c++ -> JsonObject& obj = doc.to(); -> JsonArray& arr = obj.createNestedArray("key"); -> if (!arr.success()) { -> Serial.println("Not enough memory"); -> return; -> } -> ``` -> -> New code: -> -> ```c++ -> JsonObject obj = doc.to(); -> JsonArray arr = obj.createNestedArray("key"); -> if (arr.isNull()) { -> Serial.println("Not enough memory"); -> return; -> } -> ``` - -v6.0.1-beta (2018-06-11) ------------ - -* Fixed conflicts with `isnan()` and `isinf()` macros (issue #752) - -v6.0.0-beta (2018-06-07) ------------ - -* Added `DynamicJsonDocument` and `StaticJsonDocument` -* Added `deserializeJson()` -* Added `serializeJson()` and `serializeJsonPretty()` -* Added `measureJson()` and `measureJsonPretty()` -* Added `serializeMsgPack()`, `deserializeMsgPack()` and `measureMsgPack()` (issue #358) -* Added example `MsgPackParser.ino` (issue #358) -* Added support for non zero-terminated strings (issue #704) -* Removed `JsonBuffer::parseArray()`, `parseObject()` and `parse()` -* Removed `JsonBuffer::createArray()` and `createObject()` -* Removed `printTo()` and `prettyPrintTo()` -* Removed `measureLength()` and `measurePrettyLength()` -* Removed all deprecated features - -> ### BREAKING CHANGES -> -> #### Deserialization -> -> Old code: -> -> ```c++ -> DynamicJsonBuffer jb; -> JsonObject& obj = jb.parseObject(json); -> if (obj.success()) { -> -> } -> ``` -> -> New code: -> -> ```c++ -> DynamicJsonDocument doc; -> DeserializationError error = deserializeJson(doc, json); -> if (error) { -> -> } -> JsonObject& obj = doc.as(); -> ``` -> -> #### Serialization -> -> Old code: -> -> ```c++ -> DynamicJsonBuffer jb; -> JsonObject& obj = jb.createObject(); -> obj["key"] = "value"; -> obj.printTo(Serial); -> ``` -> -> New code: -> -> ```c++ -> DynamicJsonDocument obj; -> JsonObject& obj = doc.to(); -> obj["key"] = "value"; -> serializeJson(doc, Serial); +> // ArduinoJson 7 +> obj["array"].to(); +> obj["object"].to(); > ``` diff --git a/lib/ArduinoJson/CONTRIBUTING.md b/lib/ArduinoJson/CONTRIBUTING.md new file mode 100644 index 000000000..d32a04ff1 --- /dev/null +++ b/lib/ArduinoJson/CONTRIBUTING.md @@ -0,0 +1,10 @@ +# Contribution to ArduinoJson + +First, thank you for taking the time to contribute to this project. + +You can submit changes via GitHub Pull Requests. + +Please: + +1. Update the test suite for any change of behavior +2. Use clang-format in "file" mode to format the code diff --git a/lib/ArduinoJson/LICENSE.txt b/lib/ArduinoJson/LICENSE.txt index 15f1b9fbb..56bb92b7f 100644 --- a/lib/ArduinoJson/LICENSE.txt +++ b/lib/ArduinoJson/LICENSE.txt @@ -1,7 +1,7 @@ The MIT License (MIT) --------------------- -Copyright © 2014-2023, Benoit BLANCHON +Copyright © 2014-2024, Benoit BLANCHON Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/lib/ArduinoJson/README.md b/lib/ArduinoJson/README.md index 16d93a3a6..a490af33f 100644 --- a/lib/ArduinoJson/README.md +++ b/lib/ArduinoJson/README.md @@ -4,13 +4,10 @@ --- -[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/bblanchon/ArduinoJson/ci.yml?branch=6.x&logo=github)](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A6.x) -[![Continuous Integration](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/6.x?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x) +[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/bblanchon/ArduinoJson/ci.yml?branch=7.x&logo=github)](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A7.x) +[![Continuous Integration](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/7.x?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/7.x) [![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/arduinojson.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson) -[![Coveralls branch](https://img.shields.io/coveralls/github/bblanchon/ArduinoJson/6.x?logo=coveralls)](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x) -[![Arduino Library Manager](https://img.shields.io/static/v1?label=Arduino&message=v6.21.3&logo=arduino&logoColor=white&color=blue)](https://www.ardu-badge.com/ArduinoJson/6.21.3) -[![PlatformIO Registry](https://badges.registry.platformio.org/packages/bblanchon/library/ArduinoJson.svg?version=6.21.3)](https://registry.platformio.org/packages/libraries/bblanchon/ArduinoJson?version=6.21.3) -[![ESP IDF](https://img.shields.io/static/v1?label=ESP+IDF&message=v6.21.3&logo=cpu&logoColor=white&color=blue)](https://components.espressif.com/components/bblanchon/arduinojson) +[![Coveralls branch](https://img.shields.io/coveralls/github/bblanchon/ArduinoJson/7.x?logo=coveralls)](https://coveralls.io/github/bblanchon/ArduinoJson?branch=7.x) [![GitHub stars](https://img.shields.io/github/stars/bblanchon/ArduinoJson?style=flat&logo=github&color=orange)](https://github.com/bblanchon/ArduinoJson/stargazers) [![GitHub Sponsors](https://img.shields.io/github/sponsors/bblanchon?logo=github&color=orange)](https://github.com/sponsors/bblanchon) @@ -18,31 +15,28 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things). ## Features -* [JSON deserialization](https://arduinojson.org/v6/api/json/deserializejson/) - * [Optionally decodes UTF-16 escape sequences to UTF-8](https://arduinojson.org/v6/api/config/decode_unicode/) - * [Optionally stores links to the input buffer (zero-copy)](https://arduinojson.org/v6/api/json/deserializejson/) - * [Optionally supports comments in the input](https://arduinojson.org/v6/api/config/enable_comments/) - * [Optionally filters the input to keep only desired values](https://arduinojson.org/v6/api/json/deserializejson/#filtering) +* [JSON deserialization](https://arduinojson.org/v7/api/json/deserializejson/) + * [Optionally decodes UTF-16 escape sequences to UTF-8](https://arduinojson.org/v7/api/config/decode_unicode/) + * [Optionally supports comments in the input](https://arduinojson.org/v7/api/config/enable_comments/) + * [Optionally filters the input to keep only desired values](https://arduinojson.org/v7/api/json/deserializejson/#filtering) * Supports single quotes as a string delimiter * Compatible with [NDJSON](http://ndjson.org/) and [JSON Lines](https://jsonlines.org/) -* [JSON serialization](https://arduinojson.org/v6/api/json/serializejson/) - * [Can write to a buffer or a stream](https://arduinojson.org/v6/api/json/serializejson/) - * [Optionally indents the document (prettified JSON)](https://arduinojson.org/v6/api/json/serializejsonpretty/) -* [MessagePack serialization](https://arduinojson.org/v6/api/msgpack/serializemsgpack/) -* [MessagePack deserialization](https://arduinojson.org/v6/api/msgpack/deserializemsgpack/) +* [JSON serialization](https://arduinojson.org/v7/api/json/serializejson/) + * [Can write to a buffer or a stream](https://arduinojson.org/v7/api/json/serializejson/) + * [Optionally indents the document (prettified JSON)](https://arduinojson.org/v7/api/json/serializejsonpretty/) +* [MessagePack serialization](https://arduinojson.org/v7/api/msgpack/serializemsgpack/) +* [MessagePack deserialization](https://arduinojson.org/v7/api/msgpack/deserializemsgpack/) * Efficient * [Twice smaller than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/) * [Almost 10% faster than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/) * [Consumes roughly 10% less RAM than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/) - * [Fixed memory allocation, no heap fragmentation](https://arduinojson.org/v6/api/jsondocument/) - * [Optionally works without heap memory (zero malloc)](https://arduinojson.org/v6/api/staticjsondocument/) * [Deduplicates strings](https://arduinojson.org/news/2020/08/01/version-6-16-0/) * Versatile - * Supports [custom allocators (to use external RAM chip, for example)](https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/) - * Supports [`String`](https://arduinojson.org/v6/api/config/enable_arduino_string/), [`std::string`](https://arduinojson.org/v6/api/config/enable_std_string/), and [`std::string_view`](https://arduinojson.org/v6/api/config/enable_string_view/) - * Supports [`Stream`](https://arduinojson.org/v6/api/config/enable_arduino_stream/) and [`std::istream`/`std::ostream`](https://arduinojson.org/v6/api/config/enable_std_stream/) - * Supports [Flash strings](https://arduinojson.org/v6/api/config/enable_progmem/) - * Supports [custom readers](https://arduinojson.org/v6/api/json/deserializejson/#custom-reader) and [custom writers](https://arduinojson.org/v6/api/json/serializejson/#custom-writer) + * Supports [custom allocators (to use external RAM chip, for example)](https://arduinojson.org/v7/how-to/use-external-ram-on-esp32/) + * Supports [`String`](https://arduinojson.org/v7/api/config/enable_arduino_string/), [`std::string`](https://arduinojson.org/v7/api/config/enable_std_string/), and [`std::string_view`](https://arduinojson.org/v7/api/config/enable_string_view/) + * Supports [`Stream`](https://arduinojson.org/v7/api/config/enable_arduino_stream/) and [`std::istream`/`std::ostream`](https://arduinojson.org/v7/api/config/enable_std_stream/) + * Supports [Flash strings](https://arduinojson.org/v7/api/config/enable_progmem/) + * Supports [custom readers](https://arduinojson.org/v7/api/json/deserializejson/#custom-reader) and [custom writers](https://arduinojson.org/v7/api/json/serializejson/#custom-writer) * Supports [custom converters](https://arduinojson.org/news/2021/05/04/version-6-18-0/) * Portable * Usable on any C++ project (not limited to Arduino) @@ -72,29 +66,29 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things). * [Visual Micro](http://www.visualmicro.com/) * [Visual Studio](https://www.visualstudio.com/) * [Even works with online compilers like wandbox.org](https://wandbox.org/permlink/RlZSKy17DjJ6HcdN) - * [CMake friendly](https://arduinojson.org/v6/how-to/use-arduinojson-with-cmake/) + * [CMake friendly](https://arduinojson.org/v7/how-to/use-arduinojson-with-cmake/) * Well designed - * [Elegant API](http://arduinojson.org/v6/example/) + * [Elegant API](http://arduinojson.org/v7/example/) * [Thread-safe](https://en.wikipedia.org/wiki/Thread_safety) * Self-contained (no external dependency) * `const` friendly - * [`for` friendly](https://arduinojson.org/v6/api/jsonobject/begin_end/) + * [`for` friendly](https://arduinojson.org/v7/api/jsonobject/begin_end/) * [TMP friendly](https://en.wikipedia.org/wiki/Template_metaprogramming) - * Handles [integer overflows](https://arduinojson.org/v6/api/jsonvariant/as/#integer-overflows) + * Handles [integer overflows](https://arduinojson.org/v7/api/jsonvariant/as/#integer-overflows) * Well tested - * [Unit test coverage close to 100%](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x) + * [Unit test coverage close to 100%](https://coveralls.io/github/bblanchon/ArduinoJson?branch=7.x) * Continuously tested on - * [Visual Studio 2017, 2019, 2022](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x) - * [GCC 5, 6, 7, 8, 9, 10, 11](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22) - * [Clang 3.8, 3.9, 4.0, 5.0, 6.0, 7, 8, 9, 10](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22) + * [Visual Studio 2017, 2019, 2022](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/7.x) + * [GCC 5, 6, 7, 8, 9, 10, 11, 12](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22) + * [Clang 3.9, 4.0, 5.0, 6.0, 7, 8, 9, 10, 11, 12, 13, 14, 15](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22) * [Continuously fuzzed with Google OSS Fuzz](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson) * Passes all default checks of [clang-tidy](https://releases.llvm.org/10.0.0/tools/clang/tools/extra/docs/clang-tidy/) * Well documented - * [Tutorials](https://arduinojson.org/v6/doc/deserialization/) - * [Examples](https://arduinojson.org/v6/example/) - * [How-tos](https://arduinojson.org/v6/example/) - * [FAQ](https://arduinojson.org/v6/faq/) - * [Troubleshooter](https://arduinojson.org/v6/troubleshooter/) + * [Tutorials](https://arduinojson.org/v7/doc/deserialization/) + * [Examples](https://arduinojson.org/v7/example/) + * [How-tos](https://arduinojson.org/v7/example/) + * [FAQ](https://arduinojson.org/v7/faq/) + * [Troubleshooter](https://arduinojson.org/v7/troubleshooter/) * [Book](https://arduinojson.org/book/) * [Changelog](CHANGELOG.md) * Vibrant user community @@ -109,9 +103,9 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things). Here is a program that parses a JSON document with ArduinoJson. ```c++ -char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; +const char* json = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; -DynamicJsonDocument doc(1024); +JsonDocument doc; deserializeJson(doc, json); const char* sensor = doc["sensor"]; @@ -120,14 +114,14 @@ double latitude = doc["data"][0]; double longitude = doc["data"][1]; ``` -See the [tutorial on arduinojson.org](https://arduinojson.org/v6/doc/deserialization/) +See the [tutorial on arduinojson.org](https://arduinojson.org/v7/doc/deserialization/) ### Serialization Here is a program that generates a JSON document with ArduinoJson: ```c++ -DynamicJsonDocument doc(1024); +JsonDocument doc; doc["sensor"] = "gps"; doc["time"] = 1351824120; @@ -139,7 +133,7 @@ serializeJson(doc, Serial); // {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]} ``` -See the [tutorial on arduinojson.org](https://arduinojson.org/v6/doc/serialization/) +See the [tutorial on arduinojson.org](https://arduinojson.org/v7/doc/serialization/) ## Sponsors diff --git a/lib/ArduinoJson/SUPPORT.md b/lib/ArduinoJson/SUPPORT.md new file mode 100644 index 000000000..c47e1b1ba --- /dev/null +++ b/lib/ArduinoJson/SUPPORT.md @@ -0,0 +1,27 @@ +# ArduinoJson Support + +First off, thank you very much for using ArduinoJson. + +We'll be very happy to help you, but first please read the following. + +## Before asking for help + +1. Read the [FAQ](https://arduinojson.org/faq/?utm_source=github&utm_medium=support) +2. Search in the [API Reference](https://arduinojson.org/api/?utm_source=github&utm_medium=support) + +If you did not find the answer, please create a [new issue on GitHub](https://github.com/bblanchon/ArduinoJson/issues/new). + +It is OK to add a comment to a currently opened issue, but please avoid adding comments to a closed issue. + +## Before hitting the Submit button + +Please provide all the relevant information: + +* Good title +* Short description of the problem +* Target platform +* Compiler model and version +* [MVCE](https://stackoverflow.com/help/mcve) +* Compiler output + +Good questions get fast answers! diff --git a/lib/ArduinoJson/keywords.txt b/lib/ArduinoJson/keywords.txt deleted file mode 100644 index 3dff06bfc..000000000 --- a/lib/ArduinoJson/keywords.txt +++ /dev/null @@ -1,40 +0,0 @@ -# Macros -JSON_ARRAY_SIZE KEYWORD2 -JSON_OBJECT_SIZE KEYWORD2 -JSON_STRING_SIZE KEYWORD2 - -# Free functions -deserializeJson KEYWORD2 -deserializeMsgPack KEYWORD2 -serialized KEYWORD2 -serializeJson KEYWORD2 -serializeJsonPretty KEYWORD2 -serializeMsgPack KEYWORD2 -measureJson KEYWORD2 -measureJsonPretty KEYWORD2 -measureMsgPack KEYWORD2 - -# Methods -add KEYWORD2 -as KEYWORD2 -createNestedArray KEYWORD2 -createNestedObject KEYWORD2 -get KEYWORD2 -set KEYWORD2 -to KEYWORD2 - -# Type names -DeserializationError KEYWORD1 DATA_TYPE -DynamicJsonDocument KEYWORD1 DATA_TYPE -JsonArray KEYWORD1 DATA_TYPE -JsonArrayConst KEYWORD1 DATA_TYPE -JsonDocument KEYWORD1 DATA_TYPE -JsonFloat KEYWORD1 DATA_TYPE -JsonInteger KEYWORD1 DATA_TYPE -JsonObject KEYWORD1 DATA_TYPE -JsonObjectConst KEYWORD1 DATA_TYPE -JsonString KEYWORD1 DATA_TYPE -JsonUInt KEYWORD1 DATA_TYPE -JsonVariant KEYWORD1 DATA_TYPE -JsonVariantConst KEYWORD1 DATA_TYPE -StaticJsonDocument KEYWORD1 DATA_TYPE diff --git a/lib/ArduinoJson/library.properties b/lib/ArduinoJson/library.properties deleted file mode 100644 index 6a285cf0d..000000000 --- a/lib/ArduinoJson/library.properties +++ /dev/null @@ -1,11 +0,0 @@ -name=ArduinoJson -version=6.21.3 -author=Benoit Blanchon -maintainer=Benoit Blanchon -sentence=A simple and efficient JSON library for embedded C++. -paragraph=ArduinoJson supports ✔ serialization, ✔ deserialization, ✔ MessagePack, ✔ fixed allocation, ✔ zero-copy, ✔ streams, ✔ filtering, and more. It is the most popular Arduino library on GitHub ❤❤❤❤❤. Check out arduinojson.org for a comprehensive documentation. -category=Data Processing -url=https://arduinojson.org/?utm_source=meta&utm_medium=library.properties -architectures=* -repository=https://github.com/bblanchon/ArduinoJson.git -license=MIT diff --git a/lib/ArduinoJson/src/ArduinoJson.h b/lib/ArduinoJson/src/ArduinoJson.h index c9ac0ca64..fec64c3d1 100644 --- a/lib/ArduinoJson/src/ArduinoJson.h +++ b/lib/ArduinoJson/src/ArduinoJson.h @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once diff --git a/lib/ArduinoJson/src/ArduinoJson.hpp b/lib/ArduinoJson/src/ArduinoJson.hpp index 2d1b0be13..c210ed266 100644 --- a/lib/ArduinoJson/src/ArduinoJson.hpp +++ b/lib/ArduinoJson/src/ArduinoJson.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once @@ -30,18 +30,19 @@ #include "ArduinoJson/Object/JsonObject.hpp" #include "ArduinoJson/Variant/JsonVariantConst.hpp" -#include "ArduinoJson/Document/DynamicJsonDocument.hpp" -#include "ArduinoJson/Document/StaticJsonDocument.hpp" +#include "ArduinoJson/Document/JsonDocument.hpp" +#include "ArduinoJson/Array/ArrayImpl.hpp" #include "ArduinoJson/Array/ElementProxy.hpp" -#include "ArduinoJson/Array/JsonArrayImpl.hpp" #include "ArduinoJson/Array/Utilities.hpp" #include "ArduinoJson/Collection/CollectionImpl.hpp" -#include "ArduinoJson/Object/JsonObjectImpl.hpp" +#include "ArduinoJson/Memory/VariantPoolImpl.hpp" #include "ArduinoJson/Object/MemberProxy.hpp" +#include "ArduinoJson/Object/ObjectImpl.hpp" #include "ArduinoJson/Variant/ConverterImpl.hpp" +#include "ArduinoJson/Variant/JsonVariantCopier.hpp" #include "ArduinoJson/Variant/VariantCompare.hpp" -#include "ArduinoJson/Variant/VariantImpl.hpp" +#include "ArduinoJson/Variant/VariantRefBaseImpl.hpp" #include "ArduinoJson/Json/JsonDeserializer.hpp" #include "ArduinoJson/Json/JsonSerializer.hpp" diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/ArrayData.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayData.hpp new file mode 100644 index 000000000..93a65d543 --- /dev/null +++ b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayData.hpp @@ -0,0 +1,57 @@ +// ArduinoJson - https://arduinojson.org +// Copyright © 2014-2024, Benoit BLANCHON +// MIT License + +#pragma once + +#include + +ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE + +class ArrayData : public CollectionData { + public: + VariantData* addElement(ResourceManager* resources) { + return addSlot(resources).data(); + } + + static VariantData* addElement(ArrayData* array, ResourceManager* resources) { + if (!array) + return nullptr; + return array->addElement(resources); + } + + VariantData* getOrAddElement(size_t index, ResourceManager* resources); + + VariantData* getElement(size_t index, const ResourceManager* resources) const; + + static VariantData* getElement(const ArrayData* array, size_t index, + const ResourceManager* resources) { + if (!array) + return nullptr; + return array->getElement(index, resources); + } + + void removeElement(size_t index, ResourceManager* resources); + + static void removeElement(ArrayData* array, size_t index, + ResourceManager* resources) { + if (!array) + return; + array->removeElement(index, resources); + } + + bool copyFrom(const ArrayData& src, ResourceManager* resources); + + static bool copy(ArrayData* dst, const ArrayData* src, + ResourceManager* resources) { + if (!dst || !src) + return false; + + return dst->copyFrom(*src, resources); + } + + private: + iterator at(size_t index, const ResourceManager* resources) const; +}; + +ARDUINOJSON_END_PRIVATE_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/ArrayImpl.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayImpl.hpp new file mode 100644 index 000000000..595e847b3 --- /dev/null +++ b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayImpl.hpp @@ -0,0 +1,50 @@ +// ArduinoJson - https://arduinojson.org +// Copyright © 2014-2024, Benoit BLANCHON +// MIT License + +#pragma once + +#include +#include + +ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE + +inline ArrayData::iterator ArrayData::at( + size_t index, const ResourceManager* resources) const { + auto it = createIterator(resources); + while (!it.done() && index) { + it.next(resources); + --index; + } + return it; +} + +inline VariantData* ArrayData::getOrAddElement(size_t index, + ResourceManager* resources) { + auto it = createIterator(resources); + while (!it.done() && index > 0) { + it.next(resources); + index--; + } + if (it.done()) + index++; + VariantData* element = it.data(); + while (index > 0) { + element = addElement(resources); + if (!element) + return nullptr; + index--; + } + return element; +} + +inline VariantData* ArrayData::getElement( + size_t index, const ResourceManager* resources) const { + return at(index, resources).data(); +} + +inline void ArrayData::removeElement(size_t index, ResourceManager* resources) { + remove(at(index, resources), resources); +} + +ARDUINOJSON_END_PRIVATE_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/ElementProxy.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/ElementProxy.hpp index d6e9aa5d1..2ae26624a 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Array/ElementProxy.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/ElementProxy.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once @@ -9,7 +9,7 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE // A proxy class to get or set an element of an array. -// https://arduinojson.org/v6/api/jsonarray/subscript/ +// https://arduinojson.org/v7/api/jsonarray/subscript/ template class ElementProxy : public VariantRefBase>, public VariantOperators> { @@ -40,17 +40,22 @@ class ElementProxy : public VariantRefBase>, } private: - FORCE_INLINE MemoryPool* getPool() const { - return VariantAttorney::getPool(upstream_); + FORCE_INLINE ResourceManager* getResourceManager() const { + return VariantAttorney::getResourceManager(upstream_); } FORCE_INLINE VariantData* getData() const { - return variantGetElement(VariantAttorney::getData(upstream_), index_); + return VariantData::getElement( + VariantAttorney::getData(upstream_), index_, + VariantAttorney::getResourceManager(upstream_)); } FORCE_INLINE VariantData* getOrCreateData() const { - return variantGetOrAddElement(VariantAttorney::getOrCreateData(upstream_), - index_, VariantAttorney::getPool(upstream_)); + auto data = VariantAttorney::getOrCreateData(upstream_); + if (!data) + return nullptr; + return data->getOrAddElement( + index_, VariantAttorney::getResourceManager(upstream_)); } TUpstream upstream_; diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/JsonArray.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/JsonArray.hpp index d208e4175..069c353de 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Array/JsonArray.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/JsonArray.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once @@ -12,7 +12,7 @@ ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE class JsonObject; // A reference to an array in a JsonDocument -// https://arduinojson.org/v6/api/jsonarray/ +// https://arduinojson.org/v7/api/jsonarray/ class JsonArray : public detail::VariantOperators { friend class detail::VariantAttorney; @@ -20,192 +20,178 @@ class JsonArray : public detail::VariantOperators { typedef JsonArrayIterator iterator; // Constructs an unbound reference. - FORCE_INLINE JsonArray() : data_(0), pool_(0) {} + FORCE_INLINE JsonArray() : data_(0), resources_(0) {} // INTERNAL USE ONLY - FORCE_INLINE JsonArray(detail::MemoryPool* pool, detail::CollectionData* data) - : data_(data), pool_(pool) {} + FORCE_INLINE JsonArray(detail::ArrayData* data, + detail::ResourceManager* resources) + : data_(data), resources_(resources) {} // Returns a JsonVariant pointing to the array. - // https://arduinojson.org/v6/api/jsonvariant/ + // https://arduinojson.org/v7/api/jsonvariant/ operator JsonVariant() { void* data = data_; // prevent warning cast-align - return JsonVariant(pool_, reinterpret_cast(data)); + return JsonVariant(reinterpret_cast(data), + resources_); } // Returns a read-only reference to the array. - // https://arduinojson.org/v6/api/jsonarrayconst/ + // https://arduinojson.org/v7/api/jsonarrayconst/ operator JsonArrayConst() const { - return JsonArrayConst(data_); + return JsonArrayConst(data_, resources_); + } + + // Appends a new (empty) element to the array. + // Returns a reference to the new element. + // https://arduinojson.org/v7/api/jsonarray/add/ + template + typename detail::enable_if::value, T>::type + add() const { + return add().to(); } // Appends a new (null) element to the array. // Returns a reference to the new element. - // https://arduinojson.org/v6/api/jsonarray/add/ - JsonVariant add() const { - if (!data_) - return JsonVariant(); - return JsonVariant(pool_, data_->addElement(pool_)); + // https://arduinojson.org/v7/api/jsonarray/add/ + template + typename detail::enable_if::value, T>::type + add() const { + return JsonVariant(detail::ArrayData::addElement(data_, resources_), + resources_); } // Appends a value to the array. - // https://arduinojson.org/v6/api/jsonarray/add/ + // https://arduinojson.org/v7/api/jsonarray/add/ template FORCE_INLINE bool add(const T& value) const { - return add().set(value); + return add().set(value); } // Appends a value to the array. - // https://arduinojson.org/v6/api/jsonarray/add/ + // https://arduinojson.org/v7/api/jsonarray/add/ template FORCE_INLINE bool add(T* value) const { - return add().set(value); + return add().set(value); } // Returns an iterator to the first element of the array. - // https://arduinojson.org/v6/api/jsonarray/begin/ + // https://arduinojson.org/v7/api/jsonarray/begin/ FORCE_INLINE iterator begin() const { if (!data_) return iterator(); - return iterator(pool_, data_->head()); + return iterator(data_->createIterator(resources_), resources_); } // Returns an iterator following the last element of the array. - // https://arduinojson.org/v6/api/jsonarray/end/ + // https://arduinojson.org/v7/api/jsonarray/end/ FORCE_INLINE iterator end() const { return iterator(); } // Copies an array. - // https://arduinojson.org/v6/api/jsonarray/set/ + // https://arduinojson.org/v7/api/jsonarray/set/ FORCE_INLINE bool set(JsonArrayConst src) const { - if (!data_ || !src.data_) + if (!data_) return false; - return data_->copyFrom(*src.data_, pool_); - } - // Compares the content of two arrays. - FORCE_INLINE bool operator==(JsonArray rhs) const { - return JsonArrayConst(data_) == JsonArrayConst(rhs.data_); + clear(); + for (auto element : src) { + if (!add(element)) + return false; + } + + return true; } // Removes the element at the specified iterator. - // ⚠️ Doesn't release the memory associated with the removed element. - // https://arduinojson.org/v6/api/jsonarray/remove/ + // https://arduinojson.org/v7/api/jsonarray/remove/ FORCE_INLINE void remove(iterator it) const { - if (!data_) - return; - data_->removeSlot(it.slot_); + detail::ArrayData::remove(data_, it.iterator_, resources_); } // Removes the element at the specified index. - // ⚠️ Doesn't release the memory associated with the removed element. - // https://arduinojson.org/v6/api/jsonarray/remove/ + // https://arduinojson.org/v7/api/jsonarray/remove/ FORCE_INLINE void remove(size_t index) const { - if (!data_) - return; - data_->removeElement(index); + detail::ArrayData::removeElement(data_, index, resources_); } // Removes all the elements of the array. - // ⚠️ Doesn't release the memory associated with the removed elements. - // https://arduinojson.org/v6/api/jsonarray/clear/ + // https://arduinojson.org/v7/api/jsonarray/clear/ void clear() const { - if (!data_) - return; - data_->clear(); + detail::ArrayData::clear(data_, resources_); } // Gets or sets the element at the specified index. - // https://arduinojson.org/v6/api/jsonarray/subscript/ + // https://arduinojson.org/v7/api/jsonarray/subscript/ FORCE_INLINE detail::ElementProxy operator[](size_t index) const { return {*this, index}; } - // Creates an object and appends it to the array. - // https://arduinojson.org/v6/api/jsonarray/createnestedobject/ - FORCE_INLINE JsonObject createNestedObject() const; - - // Creates an array and appends it to the array. - // https://arduinojson.org/v6/api/jsonarray/createnestedarray/ - FORCE_INLINE JsonArray createNestedArray() const { - return add().to(); - } - operator JsonVariantConst() const { - return JsonVariantConst(collectionToVariant(data_)); + return JsonVariantConst(collectionToVariant(data_), resources_); } // Returns true if the reference is unbound. - // https://arduinojson.org/v6/api/jsonarray/isnull/ + // https://arduinojson.org/v7/api/jsonarray/isnull/ FORCE_INLINE bool isNull() const { return data_ == 0; } // Returns true if the reference is bound. - // https://arduinojson.org/v6/api/jsonarray/isnull/ + // https://arduinojson.org/v7/api/jsonarray/isnull/ FORCE_INLINE operator bool() const { return data_ != 0; } - // Returns the number of bytes occupied by the array. - // https://arduinojson.org/v6/api/jsonarray/memoryusage/ - FORCE_INLINE size_t memoryUsage() const { - return data_ ? data_->memoryUsage() : 0; - } - // Returns the depth (nesting level) of the array. - // https://arduinojson.org/v6/api/jsonarray/nesting/ + // https://arduinojson.org/v7/api/jsonarray/nesting/ FORCE_INLINE size_t nesting() const { - return variantNesting(collectionToVariant(data_)); + return detail::VariantData::nesting(collectionToVariant(data_), resources_); } // Returns the number of elements in the array. - // https://arduinojson.org/v6/api/jsonarray/size/ + // https://arduinojson.org/v7/api/jsonarray/size/ FORCE_INLINE size_t size() const { - return data_ ? data_->size() : 0; + return data_ ? data_->size(resources_) : 0; } - private: - detail::MemoryPool* getPool() const { - return pool_; + // DEPRECATED: use add() instead + ARDUINOJSON_DEPRECATED("use add() instead") + JsonVariant add() const { + return add(); } - detail::VariantData* getData() const { - return collectionToVariant(data_); + // DEPRECATED: use add() instead + ARDUINOJSON_DEPRECATED("use add() instead") + JsonArray createNestedArray() const { + return add(); } - detail::VariantData* getOrCreateData() const { - return collectionToVariant(data_); - } + // DEPRECATED: use add() instead + ARDUINOJSON_DEPRECATED("use add() instead") + JsonObject createNestedObject() const; - detail::CollectionData* data_; - detail::MemoryPool* pool_; -}; - -template <> -struct Converter : private detail::VariantAttorney { - static void toJson(JsonVariantConst src, JsonVariant dst) { - variantCopyFrom(getData(dst), getData(src), getPool(dst)); + // DEPRECATED: always returns zero + ARDUINOJSON_DEPRECATED("always returns zero") + size_t memoryUsage() const { + return 0; } - static JsonArray fromJson(JsonVariant src) { - auto data = getData(src); - auto pool = getPool(src); - return JsonArray(pool, data != 0 ? data->asArray() : 0); + private: + detail::ResourceManager* getResourceManager() const { + return resources_; } - static detail::InvalidConversion fromJson( - JsonVariantConst); - - static bool checkJson(JsonVariantConst) { - return false; + detail::VariantData* getData() const { + return collectionToVariant(data_); } - static bool checkJson(JsonVariant src) { - auto data = getData(src); - return data && data->isArray(); + detail::VariantData* getOrCreateData() const { + return collectionToVariant(data_); } + + detail::ArrayData* data_; + detail::ResourceManager* resources_; }; ARDUINOJSON_END_PUBLIC_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayConst.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayConst.hpp index 6a6463c8c..e988e8621 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayConst.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayConst.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once @@ -13,7 +13,7 @@ ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE class JsonObject; // A read-only reference to an array in a JsonDocument -// https://arduinojson.org/v6/api/jsonarrayconst/ +// https://arduinojson.org/v7/api/jsonarrayconst/ class JsonArrayConst : public detail::VariantOperators { friend class JsonArray; friend class detail::VariantAttorney; @@ -22,15 +22,15 @@ class JsonArrayConst : public detail::VariantOperators { typedef JsonArrayConstIterator iterator; // Returns an iterator to the first element of the array. - // https://arduinojson.org/v6/api/jsonarrayconst/begin/ + // https://arduinojson.org/v7/api/jsonarrayconst/begin/ FORCE_INLINE iterator begin() const { if (!data_) return iterator(); - return iterator(data_->head()); + return iterator(data_->createIterator(resources_), resources_); } // Returns an iterator to the element following the last element of the array. - // https://arduinojson.org/v6/api/jsonarrayconst/end/ + // https://arduinojson.org/v7/api/jsonarrayconst/end/ FORCE_INLINE iterator end() const { return iterator(); } @@ -39,72 +39,49 @@ class JsonArrayConst : public detail::VariantOperators { FORCE_INLINE JsonArrayConst() : data_(0) {} // INTERNAL USE ONLY - FORCE_INLINE JsonArrayConst(const detail::CollectionData* data) - : data_(data) {} - - // Compares the content of two arrays. - // Returns true if the two arrays are equal. - FORCE_INLINE bool operator==(JsonArrayConst rhs) const { - if (data_ == rhs.data_) - return true; - if (!data_ || !rhs.data_) - return false; - - iterator it1 = begin(); - iterator it2 = rhs.begin(); - - for (;;) { - bool end1 = it1 == end(); - bool end2 = it2 == rhs.end(); - if (end1 && end2) - return true; - if (end1 || end2) - return false; - if (*it1 != *it2) - return false; - ++it1; - ++it2; - } - } + FORCE_INLINE JsonArrayConst(const detail::ArrayData* data, + const detail::ResourceManager* resources) + : data_(data), resources_(resources) {} // Returns the element at the specified index. - // https://arduinojson.org/v6/api/jsonarrayconst/subscript/ + // https://arduinojson.org/v7/api/jsonarrayconst/subscript/ FORCE_INLINE JsonVariantConst operator[](size_t index) const { - return JsonVariantConst(data_ ? data_->getElement(index) : 0); + return JsonVariantConst( + detail::ArrayData::getElement(data_, index, resources_), resources_); } operator JsonVariantConst() const { - return JsonVariantConst(collectionToVariant(data_)); + return JsonVariantConst(collectionToVariant(data_), resources_); } // Returns true if the reference is unbound. - // https://arduinojson.org/v6/api/jsonarrayconst/isnull/ + // https://arduinojson.org/v7/api/jsonarrayconst/isnull/ FORCE_INLINE bool isNull() const { return data_ == 0; } // Returns true if the reference is bound. - // https://arduinojson.org/v6/api/jsonarrayconst/isnull/ + // https://arduinojson.org/v7/api/jsonarrayconst/isnull/ FORCE_INLINE operator bool() const { return data_ != 0; } - // Returns the number of bytes occupied by the array. - // https://arduinojson.org/v6/api/jsonarrayconst/memoryusage/ - FORCE_INLINE size_t memoryUsage() const { - return data_ ? data_->memoryUsage() : 0; - } - // Returns the depth (nesting level) of the array. - // https://arduinojson.org/v6/api/jsonarrayconst/nesting/ + // https://arduinojson.org/v7/api/jsonarrayconst/nesting/ FORCE_INLINE size_t nesting() const { - return variantNesting(collectionToVariant(data_)); + return detail::VariantData::nesting(collectionToVariant(data_), resources_); } // Returns the number of elements in the array. - // https://arduinojson.org/v6/api/jsonarrayconst/size/ + // https://arduinojson.org/v7/api/jsonarrayconst/size/ FORCE_INLINE size_t size() const { - return data_ ? data_->size() : 0; + return data_ ? data_->size(resources_) : 0; + } + + // DEPRECATED: always returns zero + ARDUINOJSON_DEPRECATED("always returns zero") + size_t memoryUsage() const { + return 0; } private: @@ -112,24 +89,31 @@ class JsonArrayConst : public detail::VariantOperators { return collectionToVariant(data_); } - const detail::CollectionData* data_; + const detail::ArrayData* data_; + const detail::ResourceManager* resources_; }; -template <> -struct Converter : private detail::VariantAttorney { - static void toJson(JsonVariantConst src, JsonVariant dst) { - variantCopyFrom(getData(dst), getData(src), getPool(dst)); - } +// Compares the content of two arrays. +// Returns true if the two arrays are equal. +inline bool operator==(JsonArrayConst lhs, JsonArrayConst rhs) { + if (!lhs && !rhs) + return true; + if (!lhs || !rhs) + return false; - static JsonArrayConst fromJson(JsonVariantConst src) { - auto data = getData(src); - return data ? data->asArray() : 0; - } + auto a = lhs.begin(); + auto b = rhs.begin(); - static bool checkJson(JsonVariantConst src) { - auto data = getData(src); - return data && data->isArray(); + for (;;) { + if (a == b) // same pointer or both null + return true; + if (a == lhs.end() || b == rhs.end()) + return false; + if (*a != *b) + return false; + ++a; + ++b; } -}; +} ARDUINOJSON_END_PUBLIC_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayImpl.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayImpl.hpp deleted file mode 100644 index dc0487af8..000000000 --- a/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayImpl.hpp +++ /dev/null @@ -1,36 +0,0 @@ -// ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON -// MIT License - -#pragma once - -#include -#include - -ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE - -inline JsonObject JsonArray::createNestedObject() const { - return add().to(); -} - -ARDUINOJSON_END_PUBLIC_NAMESPACE - -ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE - -template -inline JsonArray VariantRefBase::createNestedArray() const { - return add().template to(); -} - -template -inline JsonObject VariantRefBase::createNestedObject() const { - return add().template to(); -} - -template -inline ElementProxy VariantRefBase::operator[]( - size_t index) const { - return ElementProxy(derived(), index); -} - -ARDUINOJSON_END_PRIVATE_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayIterator.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayIterator.hpp index d9048b28c..70bb28f4a 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayIterator.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayIterator.hpp @@ -1,121 +1,96 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once #include -#include ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE -class VariantPtr { +template +class Ptr { public: - VariantPtr(detail::MemoryPool* pool, detail::VariantData* data) - : variant_(pool, data) {} + Ptr(T value) : value_(value) {} - JsonVariant* operator->() { - return &variant_; + T* operator->() { + return &value_; } - JsonVariant& operator*() { - return variant_; + T& operator*() { + return value_; } private: - JsonVariant variant_; + T value_; }; class JsonArrayIterator { friend class JsonArray; public: - JsonArrayIterator() : slot_(0) {} - explicit JsonArrayIterator(detail::MemoryPool* pool, - detail::VariantSlot* slot) - : pool_(pool), slot_(slot) {} + JsonArrayIterator() {} + explicit JsonArrayIterator(detail::ArrayData::iterator iterator, + detail::ResourceManager* resources) + : iterator_(iterator), resources_(resources) {} - JsonVariant operator*() const { - return JsonVariant(pool_, slot_->data()); + JsonVariant operator*() { + return JsonVariant(iterator_.data(), resources_); } - VariantPtr operator->() { - return VariantPtr(pool_, slot_->data()); + Ptr operator->() { + return operator*(); } bool operator==(const JsonArrayIterator& other) const { - return slot_ == other.slot_; + return iterator_ == other.iterator_; } bool operator!=(const JsonArrayIterator& other) const { - return slot_ != other.slot_; + return iterator_ != other.iterator_; } JsonArrayIterator& operator++() { - slot_ = slot_->next(); - return *this; - } - - JsonArrayIterator& operator+=(size_t distance) { - slot_ = slot_->next(distance); + iterator_.next(resources_); return *this; } private: - detail::MemoryPool* pool_; - detail::VariantSlot* slot_; -}; - -class VariantConstPtr { - public: - VariantConstPtr(const detail::VariantData* data) : variant_(data) {} - - JsonVariantConst* operator->() { - return &variant_; - } - - JsonVariantConst& operator*() { - return variant_; - } - - private: - JsonVariantConst variant_; + detail::ArrayData::iterator iterator_; + detail::ResourceManager* resources_; }; class JsonArrayConstIterator { friend class JsonArray; public: - JsonArrayConstIterator() : slot_(0) {} - explicit JsonArrayConstIterator(const detail::VariantSlot* slot) - : slot_(slot) {} + JsonArrayConstIterator() {} + explicit JsonArrayConstIterator(detail::ArrayData::iterator iterator, + const detail::ResourceManager* resources) + : iterator_(iterator), resources_(resources) {} JsonVariantConst operator*() const { - return JsonVariantConst(slot_->data()); + return JsonVariantConst(iterator_.data(), resources_); } - VariantConstPtr operator->() { - return VariantConstPtr(slot_->data()); + Ptr operator->() { + return operator*(); } bool operator==(const JsonArrayConstIterator& other) const { - return slot_ == other.slot_; + return iterator_ == other.iterator_; } bool operator!=(const JsonArrayConstIterator& other) const { - return slot_ != other.slot_; + return iterator_ != other.iterator_; } JsonArrayConstIterator& operator++() { - slot_ = slot_->next(); - return *this; - } - - JsonArrayConstIterator& operator+=(size_t distance) { - slot_ = slot_->next(distance); + iterator_.next(resources_); return *this; } private: - const detail::VariantSlot* slot_; + detail::ArrayData::iterator iterator_; + const detail::ResourceManager* resources_; }; ARDUINOJSON_END_PUBLIC_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/Utilities.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/Utilities.hpp index 398e11d45..ff589cea8 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Array/Utilities.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/Utilities.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once @@ -18,7 +18,7 @@ copyArray(const T& src, JsonVariant dst) { } // Copies values from an array to a JsonArray or a JsonVariant. -// https://arduinojson.org/v6/api/misc/copyarray/ +// https://arduinojson.org/v7/api/misc/copyarray/ template inline typename detail::enable_if< !detail::is_base_of::value, bool>::type @@ -27,14 +27,14 @@ copyArray(T (&src)[N], const TDestination& dst) { } // Copies values from an array to a JsonArray or a JsonVariant. -// https://arduinojson.org/v6/api/misc/copyarray/ +// https://arduinojson.org/v7/api/misc/copyarray/ template inline typename detail::enable_if< !detail::is_base_of::value, bool>::type copyArray(const T* src, size_t len, const TDestination& dst) { bool ok = true; for (size_t i = 0; i < len; i++) { - ok &= copyArray(src[i], dst.add()); + ok &= copyArray(src[i], dst.template add()); } return ok; } @@ -47,14 +47,14 @@ inline bool copyArray(const char* src, size_t, const TDestination& dst) { } // Copies values from an array to a JsonDocument. -// https://arduinojson.org/v6/api/misc/copyarray/ +// https://arduinojson.org/v7/api/misc/copyarray/ template inline bool copyArray(const T& src, JsonDocument& dst) { return copyArray(src, dst.to()); } // Copies an array to a JsonDocument. -// https://arduinojson.org/v6/api/misc/copyarray/ +// https://arduinojson.org/v7/api/misc/copyarray/ template inline bool copyArray(const T* src, size_t len, JsonDocument& dst) { return copyArray(src, len, dst.to()); @@ -70,14 +70,14 @@ copyArray(JsonVariantConst src, T& dst) { } // Copies values from a JsonArray or JsonVariant to an array. -// https://arduinojson.org/v6/api/misc/copyarray/ +// https://arduinojson.org/v7/api/misc/copyarray/ template inline size_t copyArray(JsonArrayConst src, T (&dst)[N]) { return copyArray(src, dst, N); } // Copies values from a JsonArray or JsonVariant to an array. -// https://arduinojson.org/v6/api/misc/copyarray/ +// https://arduinojson.org/v7/api/misc/copyarray/ template inline size_t copyArray(JsonArrayConst src, T* dst, size_t len) { size_t i = 0; @@ -101,7 +101,7 @@ inline size_t copyArray(JsonVariantConst src, char (&dst)[N]) { } // Copies values from a JsonDocument to an array. -// https://arduinojson.org/v6/api/misc/copyarray/ +// https://arduinojson.org/v7/api/misc/copyarray/ template inline typename detail::enable_if< detail::is_array::value && diff --git a/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionData.hpp b/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionData.hpp index 090c98b9e..1010795ce 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionData.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionData.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once @@ -11,74 +11,108 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE -class MemoryPool; class VariantData; class VariantSlot; -class CollectionData { - VariantSlot* head_; - VariantSlot* tail_; +class CollectionIterator { + friend class CollectionData; public: - // Must be a POD! - // - no constructor - // - no destructor - // - no virtual - // - no inheritance + CollectionIterator() : slot_(nullptr), currentId_(NULL_SLOT) {} + + void next(const ResourceManager* resources); + + bool done() const { + return slot_ == nullptr; + } + + bool operator==(const CollectionIterator& other) const { + return slot_ == other.slot_; + } - // Array only + bool operator!=(const CollectionIterator& other) const { + return slot_ != other.slot_; + } + + VariantData* operator->() { + ARDUINOJSON_ASSERT(slot_ != nullptr); + return data(); + } + + VariantData& operator*() { + ARDUINOJSON_ASSERT(slot_ != nullptr); + return *data(); + } - VariantData* addElement(MemoryPool* pool); + const VariantData& operator*() const { + ARDUINOJSON_ASSERT(slot_ != nullptr); + return *data(); + } - VariantData* getElement(size_t index) const; + const char* key() const; + bool ownsKey() const; - VariantData* getOrAddElement(size_t index, MemoryPool* pool); + void setKey(StringNode*); + void setKey(const char*); - void removeElement(size_t index); + VariantData* data() { + return reinterpret_cast(slot_); + } - // Object only + const VariantData* data() const { + return reinterpret_cast(slot_); + } - template - VariantData* addMember(TAdaptedString key, MemoryPool* pool); + private: + CollectionIterator(VariantSlot* slot, SlotId slotId); - template - VariantData* getMember(TAdaptedString key) const; + VariantSlot* slot_; + SlotId currentId_, nextId_; +}; - template - VariantData* getOrAddMember(TAdaptedString key, MemoryPool* pool); +class CollectionData { + SlotId head_ = NULL_SLOT; + SlotId tail_ = NULL_SLOT; - template - void removeMember(TAdaptedString key) { - removeSlot(getSlot(key)); + public: + // Placement new + static void* operator new(size_t, void* p) noexcept { + return p; } - template - bool containsKey(const TAdaptedString& key) const; + static void operator delete(void*, void*) noexcept {} - // Generic + using iterator = CollectionIterator; - void clear(); - size_t memoryUsage() const; - size_t size() const; + iterator createIterator(const ResourceManager* resources) const { + return iterator(resources->getSlot(head_), head_); + } - VariantSlot* addSlot(MemoryPool*); - void removeSlot(VariantSlot* slot); + size_t size(const ResourceManager*) const; + size_t nesting(const ResourceManager*) const; - bool copyFrom(const CollectionData& src, MemoryPool* pool); + void clear(ResourceManager* resources); - VariantSlot* head() const { - return head_; + static void clear(CollectionData* collection, ResourceManager* resources) { + if (!collection) + return; + collection->clear(resources); } - void movePointers(ptrdiff_t stringDistance, ptrdiff_t variantDistance); + void remove(iterator it, ResourceManager* resources); - private: - VariantSlot* getSlot(size_t index) const; + static void remove(CollectionData* collection, iterator it, + ResourceManager* resources) { + if (collection) + return collection->remove(it, resources); + } - template - VariantSlot* getSlot(TAdaptedString key) const; + protected: + iterator addSlot(ResourceManager*); - VariantSlot* getPreviousSlot(VariantSlot*) const; + private: + SlotWithId getPreviousSlot(VariantSlot*, const ResourceManager*) const; + void releaseSlot(SlotWithId, ResourceManager*); }; inline const VariantData* collectionToVariant( diff --git a/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionImpl.hpp b/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionImpl.hpp index 134d5bd64..79d9ac72b 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionImpl.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionImpl.hpp @@ -1,197 +1,133 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once #include -#include +#include #include +#include #include ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE -inline VariantSlot* CollectionData::addSlot(MemoryPool* pool) { - VariantSlot* slot = pool->allocVariant(); - if (!slot) - return 0; - - if (tail_) { - ARDUINOJSON_ASSERT(pool->owns(tail_)); // Can't alter a linked array/object - tail_->setNextNotNull(slot); - tail_ = slot; - } else { - head_ = slot; - tail_ = slot; - } - - slot->clear(); - return slot; +inline CollectionIterator::CollectionIterator(VariantSlot* slot, SlotId slotId) + : slot_(slot), currentId_(slotId) { + nextId_ = slot_ ? slot_->next() : NULL_SLOT; } -inline VariantData* CollectionData::addElement(MemoryPool* pool) { - return slotData(addSlot(pool)); +inline const char* CollectionIterator::key() const { + ARDUINOJSON_ASSERT(slot_ != nullptr); + return slot_->key(); } -template -inline VariantData* CollectionData::addMember(TAdaptedString key, - MemoryPool* pool) { - VariantSlot* slot = addSlot(pool); - if (!slotSetKey(slot, key, pool)) { - removeSlot(slot); - return 0; - } - return slot->data(); +inline void CollectionIterator::setKey(const char* s) { + ARDUINOJSON_ASSERT(slot_ != nullptr); + ARDUINOJSON_ASSERT(s != nullptr); + return slot_->setKey(s); } -inline void CollectionData::clear() { - head_ = 0; - tail_ = 0; +inline void CollectionIterator::setKey(StringNode* s) { + ARDUINOJSON_ASSERT(slot_ != nullptr); + ARDUINOJSON_ASSERT(s != nullptr); + return slot_->setKey(s); } -template -inline bool CollectionData::containsKey(const TAdaptedString& key) const { - return getSlot(key) != 0; +inline bool CollectionIterator::ownsKey() const { + ARDUINOJSON_ASSERT(slot_ != nullptr); + return slot_->ownsKey(); } -inline bool CollectionData::copyFrom(const CollectionData& src, - MemoryPool* pool) { - clear(); - for (VariantSlot* s = src.head_; s; s = s->next()) { - VariantData* var; - if (s->key() != 0) { - JsonString key(s->key(), - s->ownsKey() ? JsonString::Copied : JsonString::Linked); - var = addMember(adaptString(key), pool); - } else { - var = addElement(pool); - } - if (!var) - return false; - if (!var->copyFrom(*s->data(), pool)) - return false; - } - return true; +inline void CollectionIterator::next(const ResourceManager* resources) { + ARDUINOJSON_ASSERT(currentId_ != NULL_SLOT); + slot_ = resources->getSlot(nextId_); + currentId_ = nextId_; + if (slot_) + nextId_ = slot_->next(); } -template -inline VariantSlot* CollectionData::getSlot(TAdaptedString key) const { - if (key.isNull()) - return 0; - VariantSlot* slot = head_; - while (slot) { - if (stringEquals(key, adaptString(slot->key()))) - break; - slot = slot->next(); +inline CollectionData::iterator CollectionData::addSlot( + ResourceManager* resources) { + auto slot = resources->allocSlot(); + if (!slot) + return {}; + if (tail_ != NULL_SLOT) { + auto tail = resources->getSlot(tail_); + tail->setNext(slot.id()); + tail_ = slot.id(); + } else { + head_ = slot.id(); + tail_ = slot.id(); } - return slot; -} - -inline VariantSlot* CollectionData::getSlot(size_t index) const { - if (!head_) - return 0; - return head_->next(index); + return iterator(slot, slot.id()); } -inline VariantSlot* CollectionData::getPreviousSlot(VariantSlot* target) const { - VariantSlot* current = head_; - while (current) { - VariantSlot* next = current->next(); - if (next == target) - return current; - current = next; +inline void CollectionData::clear(ResourceManager* resources) { + auto next = head_; + while (next != NULL_SLOT) { + auto currId = next; + auto slot = resources->getSlot(next); + next = slot->next(); + releaseSlot(SlotWithId(slot, currId), resources); } - return 0; -} - -template -inline VariantData* CollectionData::getMember(TAdaptedString key) const { - VariantSlot* slot = getSlot(key); - return slot ? slot->data() : 0; -} - -template -inline VariantData* CollectionData::getOrAddMember(TAdaptedString key, - MemoryPool* pool) { - // ignore null key - if (key.isNull()) - return 0; - // search a matching key - VariantSlot* slot = getSlot(key); - if (slot) - return slot->data(); - - return addMember(key, pool); + head_ = NULL_SLOT; + tail_ = NULL_SLOT; } -inline VariantData* CollectionData::getElement(size_t index) const { - VariantSlot* slot = getSlot(index); - return slot ? slot->data() : 0; -} - -inline VariantData* CollectionData::getOrAddElement(size_t index, - MemoryPool* pool) { - VariantSlot* slot = head_; - while (slot && index > 0) { - slot = slot->next(); - index--; - } - if (!slot) - index++; - while (index > 0) { - slot = addSlot(pool); - index--; +inline SlotWithId CollectionData::getPreviousSlot( + VariantSlot* target, const ResourceManager* resources) const { + auto prev = SlotWithId(); + auto currentId = head_; + while (currentId != NULL_SLOT) { + auto currentSlot = resources->getSlot(currentId); + if (currentSlot == target) + return prev; + prev = SlotWithId(currentSlot, currentId); + currentId = currentSlot->next(); } - return slotData(slot); + return SlotWithId(); } -inline void CollectionData::removeSlot(VariantSlot* slot) { - if (!slot) +inline void CollectionData::remove(iterator it, ResourceManager* resources) { + if (it.done()) return; - VariantSlot* prev = getPreviousSlot(slot); - VariantSlot* next = slot->next(); + auto curr = it.slot_; + auto prev = getPreviousSlot(curr, resources); + auto next = curr->next(); if (prev) prev->setNext(next); else head_ = next; - if (!next) - tail_ = prev; -} - -inline void CollectionData::removeElement(size_t index) { - removeSlot(getSlot(index)); + if (next == NULL_SLOT) + tail_ = prev.id(); + releaseSlot({it.slot_, it.currentId_}, resources); } -inline size_t CollectionData::memoryUsage() const { - size_t total = 0; - for (VariantSlot* s = head_; s; s = s->next()) { - total += sizeof(VariantSlot) + s->data()->memoryUsage(); - if (s->ownsKey()) - total += strlen(s->key()) + 1; +inline size_t CollectionData::nesting(const ResourceManager* resources) const { + size_t maxChildNesting = 0; + for (auto it = createIterator(resources); !it.done(); it.next(resources)) { + size_t childNesting = it->nesting(resources); + if (childNesting > maxChildNesting) + maxChildNesting = childNesting; } - return total; + return maxChildNesting + 1; } -inline size_t CollectionData::size() const { - return slotSize(head_); -} - -template -inline void movePointer(T*& p, ptrdiff_t offset) { - if (!p) - return; - p = reinterpret_cast( - reinterpret_cast(reinterpret_cast(p) + offset)); - ARDUINOJSON_ASSERT(isAligned(p)); +inline size_t CollectionData::size(const ResourceManager* resources) const { + size_t count = 0; + for (auto it = createIterator(resources); !it.done(); it.next(resources)) + count++; + return count; } -inline void CollectionData::movePointers(ptrdiff_t stringDistance, - ptrdiff_t variantDistance) { - movePointer(head_, variantDistance); - movePointer(tail_, variantDistance); - for (VariantSlot* slot = head_; slot; slot = slot->next()) - slot->movePointers(stringDistance, variantDistance); +inline void CollectionData::releaseSlot(SlotWithId slot, + ResourceManager* resources) { + if (slot->ownsKey()) + resources->dereferenceString(slot->key()); + slot->data()->setNull(resources); + resources->freeSlot(slot); } ARDUINOJSON_END_PRIVATE_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Configuration.hpp b/lib/ArduinoJson/src/ArduinoJson/Configuration.hpp index ac0ea660a..12d60688a 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Configuration.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Configuration.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once @@ -59,35 +59,75 @@ # define ARDUINOJSON_USE_DOUBLE 1 #endif +// Pointer size: a heuristic to set sensible defaults +#ifndef ARDUINOJSON_SIZEOF_POINTER +# if defined(__SIZEOF_POINTER__) +# define ARDUINOJSON_SIZEOF_POINTER __SIZEOF_POINTER__ +# elif defined(_WIN64) && _WIN64 +# define ARDUINOJSON_SIZEOF_POINTER 8 // 64 bits +# else +# define ARDUINOJSON_SIZEOF_POINTER 4 // assume 32 bits otherwise +# endif +#endif + // Store integral values with long (0) or long long (1) #ifndef ARDUINOJSON_USE_LONG_LONG -# if defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ >= 4 || \ - defined(_MSC_VER) +# if ARDUINOJSON_SIZEOF_POINTER >= 4 // 32 & 64 bits systems # define ARDUINOJSON_USE_LONG_LONG 1 +# else +# define ARDUINOJSON_USE_LONG_LONG 0 # endif #endif -#ifndef ARDUINOJSON_USE_LONG_LONG -# define ARDUINOJSON_USE_LONG_LONG 0 -#endif // Limit nesting as the stack is likely to be small #ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT # define ARDUINOJSON_DEFAULT_NESTING_LIMIT 10 #endif -// Number of bits to store the pointer to next node -// (saves RAM but limits the number of values in a document) -#ifndef ARDUINOJSON_SLOT_OFFSET_SIZE -# if defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ <= 2 -// Address space == 16-bit => max 127 values -# define ARDUINOJSON_SLOT_OFFSET_SIZE 1 -# elif defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ >= 8 || \ - defined(_WIN64) && _WIN64 -// Address space == 64-bit => max 2147483647 values -# define ARDUINOJSON_SLOT_OFFSET_SIZE 4 +// Number of bytes to store the variant identifier +#ifndef ARDUINOJSON_SLOT_ID_SIZE +# if ARDUINOJSON_SIZEOF_POINTER <= 2 +# define ARDUINOJSON_SLOT_ID_SIZE 1 // up to 255 slots +# elif ARDUINOJSON_SIZEOF_POINTER == 4 +# define ARDUINOJSON_SLOT_ID_SIZE 2 // up to 65535 slots +# else +# define ARDUINOJSON_SLOT_ID_SIZE 4 // up to 4294967295 slots +# endif +#endif + +// Capacity of each variant pool (in slots) +#ifndef ARDUINOJSON_POOL_CAPACITY +# if ARDUINOJSON_SIZEOF_POINTER <= 2 +# define ARDUINOJSON_POOL_CAPACITY 16 // 128 bytes +# elif ARDUINOJSON_SIZEOF_POINTER == 4 +# define ARDUINOJSON_POOL_CAPACITY 64 // 1024 bytes # else -// Address space == 32-bit => max 32767 values -# define ARDUINOJSON_SLOT_OFFSET_SIZE 2 +# define ARDUINOJSON_POOL_CAPACITY 128 // 3072 bytes +# endif +#endif + +// Initial capacity of the pool list +#ifndef ARDUINOJSON_INITIAL_POOL_COUNT +# define ARDUINOJSON_INITIAL_POOL_COUNT 4 +#endif + +// Automatically call shrinkToFit() from deserializeXxx() +// Disabled by default on 8-bit platforms because it's not worth the increase in +// code size +#ifndef ARDUINOJSON_AUTO_SHRINK +# if ARDUINOJSON_SIZEOF_POINTER <= 2 +# define ARDUINOJSON_AUTO_SHRINK 0 +# else +# define ARDUINOJSON_AUTO_SHRINK 1 +# endif +#endif + +// Number of bytes to store the length of a string +#ifndef ARDUINOJSON_STRING_LENGTH_SIZE +# if ARDUINOJSON_SIZEOF_POINTER <= 2 +# define ARDUINOJSON_STRING_LENGTH_SIZE 1 // up to 255 characters +# else +# define ARDUINOJSON_STRING_LENGTH_SIZE 2 // up to 65535 characters # endif #endif @@ -195,10 +235,6 @@ # define ARDUINOJSON_TAB " " #endif -#ifndef ARDUINOJSON_ENABLE_STRING_DEDUPLICATION -# define ARDUINOJSON_ENABLE_STRING_DEDUPLICATION 1 -#endif - #ifndef ARDUINOJSON_STRING_BUFFER_SIZE # define ARDUINOJSON_STRING_BUFFER_SIZE 32 #endif diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationError.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationError.hpp index 1bfc39392..fd32a55e9 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationError.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationError.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationOptions.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationOptions.hpp index 8400cc0b2..4c73934fc 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationOptions.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationOptions.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Filter.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Filter.hpp index 39883027d..76705560b 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Filter.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Filter.hpp @@ -1,17 +1,24 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once -#include +#include +#include ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE namespace DeserializationOption { class Filter { public: - explicit Filter(JsonVariantConst v) : variant_(v) {} +#if ARDUINOJSON_AUTO_SHRINK + explicit Filter(JsonDocument& doc) : variant_(doc) { + doc.shrinkToFit(); + } +#endif + + explicit Filter(JsonVariantConst variant) : variant_(variant) {} bool allow() const { return variant_; diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/NestingLimit.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/NestingLimit.hpp index 6434275be..d30402b4b 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/NestingLimit.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/NestingLimit.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp index 44437686a..c4b5edb74 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once @@ -19,7 +19,7 @@ struct Reader { int read() { // clang-format off - return source_->read(); // Error here? See https://arduinojson.org/v6/invalid-input/ + return source_->read(); // Error here? See https://arduinojson.org/v7/invalid-input/ // clang-format on } diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp index 8a8738858..43c5a432b 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once @@ -15,7 +15,7 @@ struct Readerread() as it ignores the timeout char c; return stream_->readBytes(&c, 1) ? static_cast(c) : -1; } diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp index 14491f44a..4730be016 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp index 97714afb1..fa8ff23d7 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/IteratorReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/IteratorReader.hpp index c0ca4a771..1ca46c852 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/IteratorReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/IteratorReader.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/RamReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/RamReader.hpp index eff67bac3..8603bb138 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/RamReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/RamReader.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp index 41e0c00aa..25ba63645 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/VariantReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/VariantReader.hpp index b60f1cec8..ddb07b8b2 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/VariantReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/VariantReader.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp index 9f4d78e85..21d187640 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once @@ -8,7 +8,6 @@ #include #include #include -#include ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE @@ -23,44 +22,62 @@ struct first_or_void { using type = T; }; -template