From 6c699e9b95c308c2d3bbc0a9d236f5e729f16441 Mon Sep 17 00:00:00 2001 From: Christian Baars Date: Sat, 12 Jul 2025 11:43:42 +0200 Subject: [PATCH] add hostedOTA and info messages (#23675) --- tasmota/include/i18n.h | 1 + tasmota/tasmota_support/support_command.ino | 19 +++++++ .../tasmota_support/support_hosted_mcu.ino | 57 +++++++++++++++++++ .../xdrv_01_9_webserver.ino | 5 ++ 4 files changed, 82 insertions(+) create mode 100644 tasmota/tasmota_support/support_hosted_mcu.ino diff --git a/tasmota/include/i18n.h b/tasmota/include/i18n.h index 027ebeaee..21192b751 100644 --- a/tasmota/include/i18n.h +++ b/tasmota/include/i18n.h @@ -333,6 +333,7 @@ #define D_CMND_UPGRADE "Upgrade" #define D_JSON_ONE_OR_GT "1 or >%s to upgrade" #define D_CMND_OTAURL "OtaUrl" +#define D_CMND_HOSTEDOTA "HostedOta" #define D_CMND_SERIALLOG "SerialLog" #define D_CMND_SYSLOG "SysLog" #define D_CMND_FILELOG "FileLog" diff --git a/tasmota/tasmota_support/support_command.ino b/tasmota/tasmota_support/support_command.ino index dbd75a8fd..68491613c 100644 --- a/tasmota/tasmota_support/support_command.ino +++ b/tasmota/tasmota_support/support_command.ino @@ -62,6 +62,9 @@ const char kTasmotaCommands[] PROGMEM = "|" // No prefix #endif // ESP32 D_CMND_SETSENSOR "|" D_CMND_SENSOR "|" D_CMND_DRIVER "|" D_CMND_JSON "|" D_CMND_JSON_PP +#ifdef CONFIG_ESP_WIFI_REMOTE_ENABLED +"|" D_CMND_HOSTEDOTA +#endif //CONFIG_ESP_WIFI_REMOTE_ENABLED #endif //FIRMWARE_MINIMAL ; @@ -111,6 +114,9 @@ void (* const TasmotaCommand[])(void) PROGMEM = { #endif // ESP32 &CmndSetSensor, &CmndSensor, &CmndDriver, &CmndJson, &CmndJsonPP +#ifdef CONFIG_ESP_WIFI_REMOTE_ENABLED + , &CmdHostedOta +#endif //CONFIG_ESP_WIFI_REMOTE_ENABLED #endif //FIRMWARE_MINIMAL }; @@ -980,6 +986,9 @@ void CmndStatus(void) #endif ",\"" D_JSON_COREVERSION "\":\"" ARDUINO_CORE_RELEASE "\",\"" D_JSON_SDKVERSION "\":\"%s\"," "\"CpuFrequency\":%d,\"Hardware\":\"%s\"" +#ifdef CONFIG_ESP_WIFI_REMOTE_ENABLED + ",\"HostedMCU\":{\"Hardware\":\"" CONFIG_ESP_HOSTED_IDF_SLAVE_TARGET"\",\"Version\":\"%s\"}" +#endif "%s}}"), TasmotaGlobal.version, TasmotaGlobal.image_name, GetCodeCores().c_str(), GetBuildDateAndTime().c_str() #ifdef ESP8266 @@ -987,6 +996,9 @@ void CmndStatus(void) #endif , ESP.getSdkVersion(), ESP.getCpuFreqMHz(), GetDeviceHardwareRevision().c_str(), +#ifdef CONFIG_ESP_WIFI_REMOTE_ENABLED + GetHostedMCUFwVersion().c_str(), +#endif GetStatistics().c_str()); CmndStatusResponse(2); } @@ -3097,4 +3109,11 @@ void CmndTouchThres(void) { } #endif // ESP32 SOC_TOUCH_VERSION_1 or SOC_TOUCH_VERSION_2 +void CmdHostedOta() { + if (XdrvMailbox.data_len > 0) { + OTAHostedMCU(XdrvMailbox.data); + } + ResponseCmndDone(); +} + #endif // ESP32 diff --git a/tasmota/tasmota_support/support_hosted_mcu.ino b/tasmota/tasmota_support/support_hosted_mcu.ino new file mode 100644 index 000000000..b6b952ee9 --- /dev/null +++ b/tasmota/tasmota_support/support_hosted_mcu.ino @@ -0,0 +1,57 @@ +/* + support_hosted_mcu.ino - eeprom support for Tasmota + + Copyright (C) 2025 Theo Arends & Christian Baars + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + + +#ifdef CONFIG_ESP_WIFI_REMOTE_ENABLED + +#include "esp_hosted.h" +#include "esp_hosted_api_types.h" +#include "esp_hosted_ota.h" + +String GetHostedMCUFwVersion() +{ + if(!esp_hosted_is_config_valid()) { + return String(""); + } + esp_hosted_coprocessor_fwver_t ver_info; + esp_err_t err = esp_hosted_get_coprocessor_fwversion(&ver_info); + if (err == ESP_OK) { + char data[40]; + snprintf_P(data, sizeof(data), PSTR("%d.%d.%d"), ver_info.major1,ver_info.minor1,ver_info.patch1); + // AddLog(LOG_LEVEL_DEBUG, PSTR("Fw: %d.%d.%d"), ver_info.major1, ver_info.minor1, ver_info.patch1); + return String(data); + } + AddLog(LOG_LEVEL_DEBUG, PSTR("Err: %d, version 0.0..6 or older"), err); + return String(PSTR("0.0.6")); // we can not know exactly, but API was added after 0.0.6 +} + +void OTAHostedMCU(const char* image_url) { + AddLog(LOG_LEVEL_INFO, PSTR("OTA: co-processor OTA update started from %s"), image_url); + esp_err_t ret = esp_hosted_slave_ota(image_url); + // next lines are questionable, because ATM the system will reboot immediately - maybe we would see the failure + if (ret == ESP_OK) { + AddLog(LOG_LEVEL_INFO, PSTR("OTA: co-processor OTA update successful !!")); + } else { + AddLog(LOG_LEVEL_INFO, PSTR("OTA: co-processor OTA update failed: %d"), ret); + } +} + + +#endif // CONFIG_ESP_WIFI_REMOTE_ENABLED \ No newline at end of file diff --git a/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino b/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino index ba05d0e59..afe1c8432 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino @@ -2977,6 +2977,11 @@ void HandleInformation(void) { WSContentSend_P(PSTR("}1" D_FRIENDLY_NAME " %d}2%s"), i +1, SettingsTextEscaped(SET_FRIENDLYNAME1 +i).c_str()); } WSContentSeparatorIFat(); +#ifdef CONFIG_ESP_WIFI_REMOTE_ENABLED + WSContentSend_P(PSTR("}1 Hosted MCU }2 " CONFIG_ESP_HOSTED_IDF_SLAVE_TARGET "")); + WSContentSend_P(PSTR("}1 Hosted Remote Fw }2%s"), GetHostedMCUFwVersion().c_str()); + WSContentSeparatorIFat(); +#endif //CONFIG_ESP_WIFI_REMOTE_ENABLED bool show_hr = false; if ((WiFi.getMode() >= WIFI_AP) && (static_cast(WiFi.softAPIP()) != 0)) { WSContentSend_P(PSTR("}1" D_MAC_ADDRESS "}2%s"), WiFi.softAPmacAddress().c_str());