diff --git a/Makefile b/Makefile index e311dab9d..bf03a0f72 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ CXX_STANDARD := -std=gnu++14 # Defined Symbols #---------------------------------------------------------------------- DEFINES += -DARDUINOJSON_ENABLE -DARDUINOJSON_ENABLE_ARDUINO_STRING -DARDUINOJSON_USE_DOUBLE=0 -DEFINES += -DEMSESP_STANDALONE -DEMSESP_TEST -DEMC_RX_BUFFER_SIZE=1500 +DEFINES += -DEMSESP_STANDALONE -DEMSESP_TEST -DEMSESP_DEBUG -DEMC_RX_BUFFER_SIZE=1500 DEFINES += $(ARGS) DEFAULTS = -DEMSESP_DEFAULT_LOCALE=\"en\" -DEMSESP_DEFAULT_TX_MODE=8 -DEMSESP_DEFAULT_VERSION=\"3.7.0-dev\" -DEMSESP_DEFAULT_BOARD_PROFILE=\"S32\" diff --git a/mock-api/api_test.http b/mock-api/api_test.http index 71012060a..e52b2898d 100755 --- a/mock-api/api_test.http +++ b/mock-api/api_test.http @@ -4,7 +4,7 @@ # The response will be shown in the right panel @host = http://ems-esp.local -@host_dev = http://10.10.10.173 +@host_dev = http://10.10.10.175 @host_standalone = http://localhost:3080 @host_standalone2 = http://localhost:3082 @@ -84,6 +84,11 @@ GET {{host_dev}}/api/system/info ### +GET {{host_dev}}/api/system/restart +Authorization: Bearer {{token}} + +### + GET {{host_dev}}/api?device=system&cmd=test&data=general ### @@ -150,7 +155,7 @@ Content-Type: application/json # https://developers.home-assistant.io/docs/api/rest/#post-apiservicesdomainservice POST {{host_standalone}}/api -# HA +# HA tests @ha = http://192.168.1.42:8123 @ha_token = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIwMzMyZjU1MjhlZmM0NGIyOTgyMjIxNThiODU1NDkyNSIsImlhdCI6MTcyMTMwNDg2NSwiZXhwIjoyMDM2NjY0ODY1fQ.Q-Y7E_i7clH3ff4Ma-OMmhZfbN7aMi_CahKwmoar diff --git a/mock-api/rest_server.ts b/mock-api/rest_server.ts index 3e5b5f105..2d07b583b 100644 --- a/mock-api/rest_server.ts +++ b/mock-api/rest_server.ts @@ -30,6 +30,7 @@ const headers = { // GLOBAL VARIABLES let countWifiScanPoll = 0; // wifi network scan +let countHardwarePoll = 0; // for during an upload function updateMask(entity: any, de: any, dd: any) { const current_mask = parseInt(entity.slice(0, 2), 16); @@ -359,9 +360,6 @@ const ACTIVITY_ENDPOINT = REST_ENDPOINT_ROOT + 'activity'; // SETTINGS const HARDWARE_STATUS_ENDPOINT = REST_ENDPOINT_ROOT + 'hardwareStatus'; const SECURITY_SETTINGS_ENDPOINT = REST_ENDPOINT_ROOT + 'securitySettings'; -const RESTART_ENDPOINT = REST_ENDPOINT_ROOT + 'restart'; -const RESTART_PARTITION_ENDPOINT = REST_ENDPOINT_ROOT + 'partition'; -const FACTORY_RESET_ENDPOINT = REST_ENDPOINT_ROOT + 'factoryReset'; // SYSTEM SIGNIN const VERIFY_AUTHORIZATION_ENDPOINT = REST_ENDPOINT_ROOT + 'verifyAuthorization'; @@ -371,7 +369,7 @@ const GENERATE_TOKEN_ENDPOINT = REST_ENDPOINT_ROOT + 'generateToken'; const VERSION = '3.7.0-dev.0'; // const VERSION = '3.6.4'; -const hardware_status = { +let hardware_status = { emsesp_version: VERSION, esp_platform: 'ESP32S3', build_flags: 'DEMO', @@ -396,7 +394,8 @@ const hardware_status = { free_psram: 8166, has_loader: true, // model: '' - model: 'BBQKees Electronics EMS Gateway E32 V2 (E32 V2.0 P3/2024011)' + model: 'BBQKees Electronics EMS Gateway E32 V2 (E32 V2.0 P3/2024011)', + status: 'downloading' }; const system_status = { @@ -4212,7 +4211,21 @@ router router .get(SYSTEM_STATUS_ENDPOINT, () => system_status) .get(ACTIVITY_ENDPOINT, () => activity) - .get(HARDWARE_STATUS_ENDPOINT, () => hardware_status) + .get(HARDWARE_STATUS_ENDPOINT, () => { + if (countHardwarePoll === 0) { + console.log('Reseting hardware count...'); + } + + if (countHardwarePoll >= 2) { + countHardwarePoll = 0; + hardware_status.status = 'ready'; + } + + console.log('Hardware count ' + countHardwarePoll + ' of 2'); + countHardwarePoll++; + + return hardware_status; + }) .get(SECURITY_SETTINGS_ENDPOINT, () => security_settings) .post(SECURITY_SETTINGS_ENDPOINT, async (request: any) => { security_settings = await request.json(); @@ -4220,15 +4233,6 @@ router return status(200); }) .get(VERIFY_AUTHORIZATION_ENDPOINT, () => verify_authentication) - .post(RESTART_ENDPOINT, () => { - console.log('restarting...'); - return status(200); - }) - .post(RESTART_PARTITION_ENDPOINT, () => { - console.log('restarting.from partition...'); - return status(200); - }) - .post(FACTORY_RESET_ENDPOINT, () => status(200)) .post(SIGN_IN_ENDPOINT, () => signin) .get(GENERATE_TOKEN_ENDPOINT, () => generate_token); @@ -4695,13 +4699,33 @@ router .get(EMSESP_SYSTEM_INFO_ENDPOINT, () => emsesp_info) .post(API_ENDPOINT_ROOT, async (request: any) => { const data = await request.json(); + // check if the json data has key called cmd + let cmd = ''; + if (data.hasOwnProperty('cmd')) { + cmd = data.cmd; + } else if (data.hasOwnProperty('entity')) { + cmd = data.entity; + } else { + return status(400); // bad request + } + if (data.device === 'system') { - if (data.entity === 'info') { + if (cmd === 'info') { return emsesp_info; } - if (data.entity === 'allvalues') { + if (cmd === 'allvalues') { return emsesp_allvalues; } + if (cmd === 'format') { + console.log('formatting...'); + return status(200); + } + if (cmd === 'restart') { + console.log('restarting...'); + hardware_status.status = 'restarting'; + countHardwarePoll = 0; + return status(200); + } } return status(404); // not found }); diff --git a/src/test/test.cpp b/src/test/test.cpp index c13c8c349..dbfbd55cb 100644 --- a/src/test/test.cpp +++ b/src/test/test.cpp @@ -417,7 +417,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const if (command == "upload") { // S3 has 16MB flash - EMSESP::system_.uploadFirmwareURL("https://github.com/emsesp/EMS-ESP32/releases/download/latest/EMS-ESP-3_7_0-dev_31-ESP32S3-16MB+.bin"); // TODO remove + EMSESP::system_.uploadFirmwareURL("https://github.com/emsesp/EMS-ESP32/releases/download/latest/EMS-ESP-3_7_0-dev_31-ESP32S3-16MB+.bin"); ok = true; } #endif @@ -958,8 +958,8 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const bool single; - // single = true; - single = false; + single = true; + // single = false; AsyncWebServerRequest request; JsonDocument doc; @@ -972,19 +972,33 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const if (single) { // run dedicated tests only - EMSESP::webCustomEntityService.test(); // custom entities - EMSESP::webCustomizationService.test(); // set customizations - this will overwrite any settings in the FS - EMSESP::temperaturesensor_.test(); // add temperature sensors - EMSESP::webSchedulerService.test(); // run scheduler tests, and conditions + + // EMSESP::webCustomEntityService.test(); // custom entities + // EMSESP::webCustomizationService.test(); // set customizations - this will overwrite any settings in the FS + // EMSESP::temperaturesensor_.test(); // add temperature sensors + // EMSESP::webSchedulerService.test(); // run scheduler tests, and conditions // shell.invoke_command("call system fetch"); // request.url("/api/system/fetch"); // EMSESP::webAPIService.webAPIService(&request); - request.url("/api/thermostat"); - EMSESP::webAPIService.webAPIService(&request); - request.url("/api/thermostat/hc1"); - EMSESP::webAPIService.webAPIService(&request); + // request.url("/api/system/restart"); + // EMSESP::webAPIService.webAPIService(&request); + + // request.url("/api/system/format"); + // EMSESP::webAPIService.webAPIService(&request); + + request.method(HTTP_POST); + char data_api[] = "{\"device\":\"system\", \"cmd\":\"restart\",\"id\":-1}"; + deserializeJson(doc, data_api); + json = doc.as(); + request.url("/api"); + EMSESP::webAPIService.webAPIService(&request, json); + + // request.url("/api/thermostat"); + // EMSESP::webAPIService.webAPIService(&request); + // request.url("/api/thermostat/hc1"); + // EMSESP::webAPIService.webAPIService(&request); } else { EMSESP::webCustomEntityService.test(); // custom entities diff --git a/src/test/test.h b/src/test/test.h index d44a9b9c7..62c95373c 100644 --- a/src/test/test.h +++ b/src/test/test.h @@ -59,7 +59,7 @@ namespace emsesp { // #define EMSESP_DEBUG_DEFAULT "scheduler" // #define EMSESP_DEBUG_DEFAULT "heat_exchange" // #define EMSESP_DEBUG_DEFAULT "ls" -#define EMSESP_DEBUG_DEFAULT "upload" +// #define EMSESP_DEBUG_DEFAULT "upload" #ifndef EMSESP_DEBUG_DEFAULT #define EMSESP_DEBUG_DEFAULT "general"