mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
Compare commits
16 Commits
9f467ecec1
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64058b0f61 | ||
|
|
d7b5c81b0e | ||
|
|
02e8dba971 | ||
|
|
59878fb190 | ||
|
|
9ff0f83af9 | ||
|
|
e6f825371e | ||
|
|
45f3f23033 | ||
|
|
ffd27db208 | ||
|
|
a452d6131b | ||
|
|
03ef981765 | ||
|
|
9ca9f25fd3 | ||
|
|
41122dddb2 | ||
|
|
1e0c94d007 | ||
|
|
3e42a7fb4c | ||
|
|
a8fcc1fb44 | ||
|
|
e43416019d |
24
.github/workflows/dev_release.yml
vendored
24
.github/workflows/dev_release.yml
vendored
@@ -64,29 +64,7 @@ jobs:
|
|||||||
- name: Commit the generated files
|
- name: Commit the generated files
|
||||||
uses: stefanzweifel/git-auto-commit-action@v5
|
uses: stefanzweifel/git-auto-commit-action@v5
|
||||||
with:
|
with:
|
||||||
commit_message: "chore: update generated files"
|
commit_message: "chore: update generated files for v${{steps.build_info.outputs.VERSION}}"
|
||||||
|
|
||||||
- name: Configure Git
|
|
||||||
run: |
|
|
||||||
git config --local user.email "action@github.com"
|
|
||||||
git config --local user.name "GitHub Action"
|
|
||||||
|
|
||||||
- name: Check for changes and commit
|
|
||||||
run: |
|
|
||||||
if [ -n "$(git status --porcelain)" ]; then
|
|
||||||
echo "Changes detected, committing..."
|
|
||||||
git add .
|
|
||||||
git commit -m "Auto-commit build artifacts and configuration updates
|
|
||||||
|
|
||||||
- Updated build configurations
|
|
||||||
- Generated build artifacts
|
|
||||||
- Version: ${{steps.build_info.outputs.VERSION}}"
|
|
||||||
|
|
||||||
echo "Pushing changes to repository..."
|
|
||||||
git push origin dev
|
|
||||||
else
|
|
||||||
echo "No changes to commit"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Create GitHub Release
|
- name: Create GitHub Release
|
||||||
id: 'automatic_releases'
|
id: 'automatic_releases'
|
||||||
|
|||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,7 +2,6 @@
|
|||||||
.vscode/c_cpp_properties.json
|
.vscode/c_cpp_properties.json
|
||||||
.vscode/extensions.json
|
.vscode/extensions.json
|
||||||
.vscode/launch.json
|
.vscode/launch.json
|
||||||
.vscode/settings.json
|
|
||||||
|
|
||||||
# c++ compiling
|
# c++ compiling
|
||||||
.clang_complete
|
.clang_complete
|
||||||
@@ -73,7 +72,6 @@ logs/*
|
|||||||
sdkconfig.*
|
sdkconfig.*
|
||||||
sdkconfig_tasmota_esp32
|
sdkconfig_tasmota_esp32
|
||||||
pnpm-lock.yaml
|
pnpm-lock.yaml
|
||||||
package.json
|
|
||||||
.cache/
|
.cache/
|
||||||
interface/.tsbuildinfo
|
interface/.tsbuildinfo
|
||||||
test/test_api/package-lock.json
|
test/test_api/package-lock.json
|
||||||
|
|||||||
5
Makefile
5
Makefile
@@ -21,13 +21,14 @@ endif
|
|||||||
|
|
||||||
# Optimize parallel build configuration
|
# Optimize parallel build configuration
|
||||||
UNAME_S := $(shell uname -s)
|
UNAME_S := $(shell uname -s)
|
||||||
|
JOBS ?= 1
|
||||||
ifeq ($(UNAME_S),Linux)
|
ifeq ($(UNAME_S),Linux)
|
||||||
EXTRA_CPPFLAGS = -D LINUX
|
EXTRA_CPPFLAGS = -D LINUX
|
||||||
JOBS ?= $(shell nproc)
|
JOBS := $(shell nproc)
|
||||||
endif
|
endif
|
||||||
ifeq ($(UNAME_S),Darwin)
|
ifeq ($(UNAME_S),Darwin)
|
||||||
EXTRA_CPPFLAGS = -D OSX -Wno-tautological-constant-out-of-range-compare
|
EXTRA_CPPFLAGS = -D OSX -Wno-tautological-constant-out-of-range-compare
|
||||||
JOBS ?= $(shell sysctl -n hw.ncpu)
|
JOBS := $(shell sysctl -n hw.ncpu)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Set optimal parallel build settings
|
# Set optimal parallel build settings
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
"upload": {
|
"upload": {
|
||||||
"flash_size": "32MB",
|
"flash_size": "32MB",
|
||||||
"maximum_ram_size": 327680,
|
"maximum_ram_size": 327680,
|
||||||
"maximum_size": 16777216,
|
"maximum_size": 33554432,
|
||||||
"require_upload_port": true,
|
"require_upload_port": true,
|
||||||
"speed": 460800
|
"speed": 460800
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -26,8 +26,8 @@
|
|||||||
"@alova/adapter-xhr": "2.3.0",
|
"@alova/adapter-xhr": "2.3.0",
|
||||||
"@emotion/react": "^11.14.0",
|
"@emotion/react": "^11.14.0",
|
||||||
"@emotion/styled": "^11.14.1",
|
"@emotion/styled": "^11.14.1",
|
||||||
"@mui/icons-material": "^7.3.5",
|
"@mui/icons-material": "^7.3.6",
|
||||||
"@mui/material": "^7.3.5",
|
"@mui/material": "^7.3.6",
|
||||||
"@preact/compat": "^18.3.1",
|
"@preact/compat": "^18.3.1",
|
||||||
"@table-library/react-table-library": "4.1.15",
|
"@table-library/react-table-library": "4.1.15",
|
||||||
"alova": "3.4.0",
|
"alova": "3.4.0",
|
||||||
@@ -37,11 +37,11 @@
|
|||||||
"jwt-decode": "^4.0.0",
|
"jwt-decode": "^4.0.0",
|
||||||
"magic-string": "^0.30.21",
|
"magic-string": "^0.30.21",
|
||||||
"mime-types": "^3.0.2",
|
"mime-types": "^3.0.2",
|
||||||
"preact": "^10.27.2",
|
"preact": "^10.28.0",
|
||||||
"react": "^19.2.0",
|
"react": "^19.2.1",
|
||||||
"react-dom": "^19.2.0",
|
"react-dom": "^19.2.1",
|
||||||
"react-icons": "^5.5.0",
|
"react-icons": "^5.5.0",
|
||||||
"react-router": "^7.9.6",
|
"react-router": "^7.10.1",
|
||||||
"react-toastify": "^11.0.5",
|
"react-toastify": "^11.0.5",
|
||||||
"typesafe-i18n": "^5.26.2",
|
"typesafe-i18n": "^5.26.2",
|
||||||
"typescript": "^5.9.3"
|
"typescript": "^5.9.3"
|
||||||
@@ -59,11 +59,11 @@
|
|||||||
"concurrently": "^9.2.1",
|
"concurrently": "^9.2.1",
|
||||||
"eslint": "^9.39.1",
|
"eslint": "^9.39.1",
|
||||||
"eslint-config-prettier": "^10.1.8",
|
"eslint-config-prettier": "^10.1.8",
|
||||||
"prettier": "^3.7.3",
|
"prettier": "^3.7.4",
|
||||||
"rollup-plugin-visualizer": "^6.0.5",
|
"rollup-plugin-visualizer": "^6.0.5",
|
||||||
"terser": "^5.44.1",
|
"terser": "^5.44.1",
|
||||||
"typescript-eslint": "^8.48.0",
|
"typescript-eslint": "^8.48.1",
|
||||||
"vite": "^7.2.4",
|
"vite": "^7.2.6",
|
||||||
"vite-plugin-imagemin": "^0.6.1",
|
"vite-plugin-imagemin": "^0.6.1",
|
||||||
"vite-tsconfig-paths": "^5.1.4"
|
"vite-tsconfig-paths": "^5.1.4"
|
||||||
},
|
},
|
||||||
|
|||||||
476
interface/pnpm-lock.yaml
generated
476
interface/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -13,7 +13,7 @@
|
|||||||
"@trivago/prettier-plugin-sort-imports": "^6.0.0",
|
"@trivago/prettier-plugin-sort-imports": "^6.0.0",
|
||||||
"formidable": "^3.5.4",
|
"formidable": "^3.5.4",
|
||||||
"itty-router": "^5.0.22",
|
"itty-router": "^5.0.22",
|
||||||
"prettier": "^3.7.3"
|
"prettier": "^3.7.4"
|
||||||
},
|
},
|
||||||
"packageManager": "pnpm@10.24.0+sha512.01ff8ae71b4419903b65c60fb2dc9d34cf8bb6e06d03bde112ef38f7a34d6904c424ba66bea5cdcf12890230bf39f9580473140ed9c946fef328b6e5238a345a"
|
"packageManager": "pnpm@10.24.0+sha512.01ff8ae71b4419903b65c60fb2dc9d34cf8bb6e06d03bde112ef38f7a34d6904c424ba66bea5cdcf12890230bf39f9580473140ed9c946fef328b6e5238a345a"
|
||||||
}
|
}
|
||||||
|
|||||||
16
mock-api/pnpm-lock.yaml
generated
16
mock-api/pnpm-lock.yaml
generated
@@ -13,7 +13,7 @@ importers:
|
|||||||
version: 3.1.2
|
version: 3.1.2
|
||||||
'@trivago/prettier-plugin-sort-imports':
|
'@trivago/prettier-plugin-sort-imports':
|
||||||
specifier: ^6.0.0
|
specifier: ^6.0.0
|
||||||
version: 6.0.0(prettier@3.7.3)
|
version: 6.0.0(prettier@3.7.4)
|
||||||
formidable:
|
formidable:
|
||||||
specifier: ^3.5.4
|
specifier: ^3.5.4
|
||||||
version: 3.5.4
|
version: 3.5.4
|
||||||
@@ -21,8 +21,8 @@ importers:
|
|||||||
specifier: ^5.0.22
|
specifier: ^5.0.22
|
||||||
version: 5.0.22
|
version: 5.0.22
|
||||||
prettier:
|
prettier:
|
||||||
specifier: ^3.7.3
|
specifier: ^3.7.4
|
||||||
version: 3.7.3
|
version: 3.7.4
|
||||||
|
|
||||||
packages:
|
packages:
|
||||||
|
|
||||||
@@ -167,8 +167,8 @@ packages:
|
|||||||
picocolors@1.1.1:
|
picocolors@1.1.1:
|
||||||
resolution: {integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==}
|
resolution: {integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==}
|
||||||
|
|
||||||
prettier@3.7.3:
|
prettier@3.7.4:
|
||||||
resolution: {integrity: sha512-QgODejq9K3OzoBbuyobZlUhznP5SKwPqp+6Q6xw6o8gnhr4O85L2U915iM2IDcfF2NPXVaM9zlo9tdwipnYwzg==}
|
resolution: {integrity: sha512-v6UNi1+3hSlVvv8fSaoUbggEM5VErKmmpGA7Pl3HF8V6uKY7rvClBOJlH6yNwQtfTueNkGVpOv/mtWL9L4bgRA==}
|
||||||
engines: {node: '>=14'}
|
engines: {node: '>=14'}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
|
||||||
@@ -246,7 +246,7 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
'@noble/hashes': 1.8.0
|
'@noble/hashes': 1.8.0
|
||||||
|
|
||||||
'@trivago/prettier-plugin-sort-imports@6.0.0(prettier@3.7.3)':
|
'@trivago/prettier-plugin-sort-imports@6.0.0(prettier@3.7.4)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@babel/generator': 7.28.5
|
'@babel/generator': 7.28.5
|
||||||
'@babel/parser': 7.28.5
|
'@babel/parser': 7.28.5
|
||||||
@@ -256,7 +256,7 @@ snapshots:
|
|||||||
lodash-es: 4.17.21
|
lodash-es: 4.17.21
|
||||||
minimatch: 9.0.5
|
minimatch: 9.0.5
|
||||||
parse-imports-exports: 0.2.4
|
parse-imports-exports: 0.2.4
|
||||||
prettier: 3.7.3
|
prettier: 3.7.4
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- supports-color
|
- supports-color
|
||||||
|
|
||||||
@@ -311,6 +311,6 @@ snapshots:
|
|||||||
|
|
||||||
picocolors@1.1.1: {}
|
picocolors@1.1.1: {}
|
||||||
|
|
||||||
prettier@3.7.3: {}
|
prettier@3.7.4: {}
|
||||||
|
|
||||||
wrappy@1.0.2: {}
|
wrappy@1.0.2: {}
|
||||||
|
|||||||
@@ -632,9 +632,6 @@ void EMSdevice::add_device_value(int8_t tag, // to b
|
|||||||
devicevalues_.emplace_back(
|
devicevalues_.emplace_back(
|
||||||
device_type_, tag, value_p, type, options, options_single, numeric_operator, short_name, fullname, custom_fullname, uom, has_cmd, min, max, state);
|
device_type_, tag, value_p, type, options, options_single, numeric_operator, short_name, fullname, custom_fullname, uom, has_cmd, min, max, state);
|
||||||
|
|
||||||
// add to index for fast lookup by (tag, short_name)
|
|
||||||
devicevalue_index_[{static_cast<uint8_t>(tag), short_name}] = devicevalues_.size() - 1;
|
|
||||||
|
|
||||||
// add a new command if it has a function attached
|
// add a new command if it has a function attached
|
||||||
if (has_cmd) {
|
if (has_cmd) {
|
||||||
uint8_t flags = CommandFlag::ADMIN_ONLY; // executing commands require admin privileges
|
uint8_t flags = CommandFlag::ADMIN_ONLY; // executing commands require admin privileges
|
||||||
@@ -2212,13 +2209,14 @@ std::string EMSdevice::name() {
|
|||||||
// copy a raw value (i.e. without applying the numeric_operator) to the output buffer.
|
// copy a raw value (i.e. without applying the numeric_operator) to the output buffer.
|
||||||
// returns true on success.
|
// returns true on success.
|
||||||
int EMSdevice::get_modbus_value(uint8_t tag, const std::string & shortname, std::vector<uint16_t> & result) {
|
int EMSdevice::get_modbus_value(uint8_t tag, const std::string & shortname, std::vector<uint16_t> & result) {
|
||||||
// find device value by shortname using hash map index
|
// find device value by shortname
|
||||||
auto index_it = devicevalue_index_.find({tag, shortname});
|
// TODO replace linear search which is inefficient
|
||||||
if (index_it == devicevalue_index_.end()) {
|
const auto & it = std::find_if(devicevalues_.begin(), devicevalues_.end(), [&](const DeviceValue & x) { return x.tag == tag && x.short_name == shortname; });
|
||||||
|
if (it == devicevalues_.end() && (it->short_name != shortname || it->tag != tag)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto & dv = devicevalues_[index_it->second];
|
auto & dv = *it;
|
||||||
|
|
||||||
// check if it exists, there is a value for the entity. Set the flag to ACTIVE
|
// check if it exists, there is a value for the entity. Set the flag to ACTIVE
|
||||||
// not that this will override any previously removed states
|
// not that this will override any previously removed states
|
||||||
@@ -2299,13 +2297,13 @@ int EMSdevice::get_modbus_value(uint8_t tag, const std::string & shortname, std:
|
|||||||
int EMSdevice::modbus_value_to_json(uint8_t tag, const std::string & shortname, const std::vector<uint8_t> & modbus_data, JsonObject jsonValue) {
|
int EMSdevice::modbus_value_to_json(uint8_t tag, const std::string & shortname, const std::vector<uint8_t> & modbus_data, JsonObject jsonValue) {
|
||||||
// LOG_DEBUG("modbus_value_to_json(%d,%s,[%d bytes])\n", tag, shortname.c_str(), modbus_data.size());
|
// LOG_DEBUG("modbus_value_to_json(%d,%s,[%d bytes])\n", tag, shortname.c_str(), modbus_data.size());
|
||||||
|
|
||||||
// find device value by shortname using hash map index
|
// find device value by shortname
|
||||||
auto index_it = devicevalue_index_.find({tag, shortname});
|
const auto & it = std::find_if(devicevalues_.begin(), devicevalues_.end(), [&](const DeviceValue & x) { return x.tag == tag && x.short_name == shortname; });
|
||||||
if (index_it == devicevalue_index_.end()) {
|
if (it == devicevalues_.end() && (it->short_name != shortname || it->tag != tag)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto & dv = devicevalues_[index_it->second];
|
auto & dv = *it;
|
||||||
|
|
||||||
// handle Booleans
|
// handle Booleans
|
||||||
if (dv.type == DeviceValueType::BOOL) {
|
if (dv.type == DeviceValueType::BOOL) {
|
||||||
|
|||||||
@@ -556,26 +556,6 @@ class EMSdevice {
|
|||||||
#endif
|
#endif
|
||||||
std::vector<TelegramFunction> telegram_functions_; // each EMS device has its own set of registered telegram types
|
std::vector<TelegramFunction> telegram_functions_; // each EMS device has its own set of registered telegram types
|
||||||
std::vector<DeviceValue> devicevalues_; // all the device values
|
std::vector<DeviceValue> devicevalues_; // all the device values
|
||||||
|
|
||||||
// added for modbus
|
|
||||||
// Hash map for O(1) lookup of device values by (tag, short_name) key
|
|
||||||
struct DeviceValueKey {
|
|
||||||
uint8_t tag;
|
|
||||||
std::string short_name;
|
|
||||||
|
|
||||||
bool operator==(const DeviceValueKey & other) const {
|
|
||||||
return tag == other.tag && short_name == other.short_name;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DeviceValueKeyHash {
|
|
||||||
std::size_t operator()(const DeviceValueKey & key) const {
|
|
||||||
// Combine hash of tag and short_name
|
|
||||||
return std::hash<uint8_t>()(key.tag) ^ (std::hash<std::string>()(key.short_name) << 1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
std::unordered_map<DeviceValueKey, size_t, DeviceValueKeyHash> devicevalue_index_; // index: key -> devicevalues_ position
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace emsesp
|
} // namespace emsesp
|
||||||
|
|||||||
@@ -964,17 +964,17 @@ Boiler::Boiler(uint8_t device_type, int8_t device_id, uint8_t product_id, const
|
|||||||
48,
|
48,
|
||||||
63);
|
63);
|
||||||
register_device_value(
|
register_device_value(
|
||||||
DeviceValueTAG::TAG_DHW1, &wwComfDiffTemp_, DeviceValueType::UINT8, FL_(wwComfDiffTemp), DeviceValueUOM::K, MAKE_CF_CB(set_wwComfDiffTemp), 4, 12);
|
DeviceValueTAG::TAG_DHW1, &wwComfDiffTemp_, DeviceValueType::UINT8, FL_(wwComfDiffTemp), DeviceValueUOM::K, MAKE_CF_CB(set_wwComfDiffTemp), 4, 15);
|
||||||
register_device_value(
|
register_device_value(
|
||||||
DeviceValueTAG::TAG_DHW1, &wwEcoDiffTemp_, DeviceValueType::UINT8, FL_(wwEcoDiffTemp), DeviceValueUOM::K, MAKE_CF_CB(set_wwEcoDiffTemp), 4, 12);
|
DeviceValueTAG::TAG_DHW1, &wwEcoDiffTemp_, DeviceValueType::UINT8, FL_(wwEcoDiffTemp), DeviceValueUOM::K, MAKE_CF_CB(set_wwEcoDiffTemp), 4, 15);
|
||||||
register_device_value(DeviceValueTAG::TAG_DHW1,
|
register_device_value(DeviceValueTAG::TAG_DHW1,
|
||||||
&wwEcoPlusDiffTemp_,
|
&wwEcoPlusDiffTemp_,
|
||||||
DeviceValueType::UINT8,
|
DeviceValueType::UINT8,
|
||||||
FL_(wwEcoPlusDiffTemp),
|
FL_(wwEcoPlusDiffTemp),
|
||||||
DeviceValueUOM::K,
|
DeviceValueUOM::K,
|
||||||
MAKE_CF_CB(set_wwEcoPlusDiffTemp),
|
MAKE_CF_CB(set_wwEcoPlusDiffTemp),
|
||||||
6,
|
4,
|
||||||
12);
|
15);
|
||||||
register_device_value(DeviceValueTAG::TAG_DHW1,
|
register_device_value(DeviceValueTAG::TAG_DHW1,
|
||||||
&wwComfStopTemp_,
|
&wwComfStopTemp_,
|
||||||
DeviceValueType::UINT8,
|
DeviceValueType::UINT8,
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
#define EMSESP_APP_VERSION "3.7.3-dev.33"
|
#define EMSESP_APP_VERSION "3.7.3-dev.34"
|
||||||
|
|||||||
@@ -3,48 +3,50 @@
|
|||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
|
||||||
async function testAPI(ip = "ems-esp.local", apiPath = "system", loopCount = 1, delayMs = 1000) {
|
async function testAPI(ip = "ems-esp.local", apiPath = "system", loopCount = 1, delayMs = 1000) {
|
||||||
const baseUrl = `http://${ip}/api`;
|
const baseUrl = `http://${ip}`;
|
||||||
const url = `${baseUrl}/${apiPath}`;
|
const url = `${baseUrl}/${apiPath}`;
|
||||||
const results = [];
|
const results = [];
|
||||||
|
const testStartTime = Date.now();
|
||||||
|
|
||||||
for (let i = 0; i < loopCount; i++) {
|
for (let i = 0; i < loopCount; i++) {
|
||||||
let logMessage = '';
|
let logMessage = '';
|
||||||
if (loopCount > 1) {
|
if (loopCount > 1) {
|
||||||
logMessage = `--- Request ${i + 1} of ${loopCount} ---`;
|
const totalElapsed = ((Date.now() - testStartTime) / 1000).toFixed(1);
|
||||||
|
logMessage = `[${totalElapsed}s] Request: ${i + 1}/${loopCount},`;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const startTime = Date.now();
|
||||||
const response = await axios.get(url, {
|
const response = await axios.get(url, {
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
logMessage += (logMessage ? ' ' : '') + `URL: ${url}, Status: ${response.status}`;
|
||||||
// console.log('Status:', response.status);
|
|
||||||
// console.log('Data:', JSON.stringify(response.data, null, 2));
|
|
||||||
|
|
||||||
// Extract and print freeMem
|
|
||||||
const freeMem = response.data?.freeMem || response.data?.system?.freeMem;
|
|
||||||
if (freeMem !== undefined) {
|
|
||||||
logMessage += (logMessage ? ' ' : '') + `System Free Memory: ${freeMem}`;
|
|
||||||
} else {
|
|
||||||
logMessage += (logMessage ? ' ' : '') + 'freeMem not found in response';
|
|
||||||
}
|
|
||||||
console.log(logMessage);
|
|
||||||
|
|
||||||
// Delay before next request (except for the last one)
|
|
||||||
if (i < loopCount - 1) {
|
|
||||||
await new Promise(resolve => setTimeout(resolve, delayMs));
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error:', error.message);
|
console.error('Error:', error.message);
|
||||||
if (error.response) {
|
// if (error.response) {
|
||||||
console.error('Response status:', error.response.status);
|
// console.error('Response status:', error.response.status);
|
||||||
console.error('Response data:', error.response.data);
|
// console.error('Response data:', error.response.data);
|
||||||
}
|
// }
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if successful make another request to the /api/system/info endpoint to fetch the freeMem
|
||||||
|
const response = await axios.get(`${baseUrl}/api/system/info`);
|
||||||
|
const freeMem = response.data?.freeMem || response.data?.system?.freeMem;
|
||||||
|
if (freeMem !== undefined) {
|
||||||
|
logMessage += `, freeMem: ${freeMem}`;
|
||||||
|
} else {
|
||||||
|
logMessage += 'freeMem not found in response';
|
||||||
|
}
|
||||||
|
console.log(logMessage);
|
||||||
|
|
||||||
|
// Delay before next request (except for the last one)
|
||||||
|
if (i < loopCount - 1) {
|
||||||
|
await new Promise(resolve => setTimeout(resolve, delayMs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return loopCount === 1 ? results[0] : results;
|
return loopCount === 1 ? results[0] : results;
|
||||||
@@ -52,10 +54,11 @@ async function testAPI(ip = "ems-esp.local", apiPath = "system", loopCount = 1,
|
|||||||
|
|
||||||
// Run the test
|
// Run the test
|
||||||
// Examples:
|
// Examples:
|
||||||
// testAPI("192.168.1.65", "system") - single call
|
// testAPI("192.168.1.65", "api/system") - single call
|
||||||
// testAPI("192.168.1.65", "system", 5) - 5 calls with 1000ms delay
|
// testAPI("192.168.1.65", "api/system", 5) - 5 calls with 1000ms delay
|
||||||
// testAPI("192.168.1.65", "system", 10, 2000) - 10 calls with 2000ms delay
|
// testAPI("192.168.1.65", "api/system", 10, 2000) - 10 calls with 2000ms delay
|
||||||
testAPI("192.168.1.65", "system", 20000, 5)
|
// testAPI("192.168.1.65", "status", 20000, 5)
|
||||||
|
testAPI("192.168.1.65", "api/custom/test_custom", 1000, 5)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log('Test completed successfully');
|
console.log('Test completed successfully');
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
|
|||||||
5
test/test_api/package.json
Normal file
5
test/test_api/package.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"axios": "^1.13.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user