mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 10:46:31 +00:00
Unify HostedOTA with Upgrade experience
This commit is contained in:
parent
d2f7af6572
commit
fee8198e64
@ -269,6 +269,11 @@ struct TasmotaGlobal_t {
|
||||
GpioOptionABits gpio_optiona; // GPIO Option_A flags
|
||||
void *log_buffer_mutex; // Control access to log buffer
|
||||
|
||||
#ifdef CONFIG_ESP_WIFI_REMOTE_ENABLED
|
||||
char *hosted_ota_url; // ESP32-P4 hosted OTA URL
|
||||
int hosted_ota_state_flag; // ESP32-P4 hosted OTA initiated flag
|
||||
#endif // CONFIG_ESP_WIFI_REMOTE_ENABLED
|
||||
|
||||
power_t power; // Current copy of Settings->power
|
||||
power_t power_latching; // Current state of single pin latching power
|
||||
power_t rel_inverted; // Relay inverted flag (1 = (0 = On, 1 = Off))
|
||||
|
@ -1348,26 +1348,22 @@ void CmdHostedOta() {
|
||||
// As an option allow user to enter URL like:
|
||||
// HostedOta https://ota.tasmota.com/tasmota32/coprocessor/network_adapter_esp32c6.bin
|
||||
// HostedOta https://ota.tasmota.com/tasmota32/coprocessor/v2.0.14/network_adapter_esp32c6.bin
|
||||
char full_ota_url[200];
|
||||
char *hosted_ota = XdrvMailbox.data;
|
||||
if (!XdrvMailbox.data_len) {
|
||||
TasmotaGlobal.hosted_ota_url = (char*)calloc(200, sizeof(char));
|
||||
if (!TasmotaGlobal.hosted_ota_url) { return; } // Unable to allocate memory
|
||||
if (XdrvMailbox.data_len) {
|
||||
strlcpy(TasmotaGlobal.hosted_ota_url, XdrvMailbox.data, 200);
|
||||
} else {
|
||||
// Replace https://ota.tasmota.com/tasmota32/tasmota32p4.bin with https://ota.tasmota.com/tasmota32/coprocessor/network_adapter_esp32c6.bin
|
||||
char ota_url[TOPSZ];
|
||||
strlcpy(full_ota_url, GetOtaUrl(ota_url, sizeof(ota_url)), sizeof(full_ota_url));
|
||||
char *bch = strrchr(full_ota_url, '/'); // Only consider filename after last backslash
|
||||
if (bch == nullptr) { bch = full_ota_url; } // No path found so use filename only
|
||||
*bch = '\0'; // full_ota_url = https://ota.tasmota.com/tasmota32
|
||||
snprintf_P(full_ota_url, sizeof(full_ota_url), PSTR("%s/coprocessor/network_adapter_" CONFIG_ESP_HOSTED_IDF_SLAVE_TARGET ".bin"), full_ota_url);
|
||||
hosted_ota = full_ota_url;
|
||||
}
|
||||
int ret = OTAHostedMCU(hosted_ota);
|
||||
if (ret == ESP_OK) {
|
||||
// next lines are questionable, because currently the system will reboot immediately on succesful upgrade
|
||||
ResponseCmndDone();
|
||||
} else {
|
||||
snprintf_P(full_ota_url, sizeof(full_ota_url), PSTR("Upgrade failed with error %d"), ret);
|
||||
ResponseCmndChar(full_ota_url);
|
||||
strlcpy(TasmotaGlobal.hosted_ota_url, GetOtaUrl(ota_url, sizeof(ota_url)), 200);
|
||||
char *bch = strrchr(TasmotaGlobal.hosted_ota_url, '/'); // Only consider filename after last backslash
|
||||
if (bch == nullptr) { bch = TasmotaGlobal.hosted_ota_url; } // No path found so use filename only
|
||||
*bch = '\0'; // full_ota_url = https://ota.tasmota.com/tasmota32
|
||||
snprintf_P(TasmotaGlobal.hosted_ota_url, 200, PSTR("%s/coprocessor/network_adapter_" CONFIG_ESP_HOSTED_IDF_SLAVE_TARGET ".bin"), TasmotaGlobal.hosted_ota_url);
|
||||
}
|
||||
TasmotaGlobal.hosted_ota_state_flag = 1;
|
||||
Response_P(PSTR("{\"%s\":\"" D_JSON_VERSION " %s " D_JSON_FROM " %s\"}"),
|
||||
XdrvMailbox.command, GetHostedMCUFwVersion().c_str(), TasmotaGlobal.hosted_ota_url);
|
||||
}
|
||||
#endif // CONFIG_ESP_WIFI_REMOTE_ENABLED
|
||||
|
||||
|
@ -1508,6 +1508,34 @@ void Every250mSeconds(void)
|
||||
AllowInterrupts(1);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_ESP_WIFI_REMOTE_ENABLED
|
||||
if (TasmotaGlobal.hosted_ota_state_flag && CommandsReady()) {
|
||||
TasmotaGlobal.hosted_ota_state_flag--;
|
||||
/*
|
||||
if (2 == TasmotaGlobal.hosted_ota_state_flag) {
|
||||
SettingsSave(0);
|
||||
}
|
||||
*/
|
||||
if (TasmotaGlobal.hosted_ota_state_flag <= 0) {
|
||||
// Blocking
|
||||
int ret = OTAHostedMCU(TasmotaGlobal.hosted_ota_url);
|
||||
free(TasmotaGlobal.hosted_ota_url);
|
||||
TasmotaGlobal.hosted_ota_url = nullptr;
|
||||
Response_P(PSTR("{\"" D_CMND_HOSTEDOTA "\":\""));
|
||||
if (ret == ESP_OK) {
|
||||
// next lines are questionable, because currently the system will reboot immediately on succesful upgrade
|
||||
ResponseAppend_P(PSTR(D_JSON_SUCCESSFUL ". " D_JSON_RESTARTING));
|
||||
TasmotaGlobal.restart_flag = 5; // Allow time for webserver to update console
|
||||
} else {
|
||||
ResponseAppend_P(PSTR(D_JSON_FAILED " %d\"}"), ret);
|
||||
}
|
||||
ResponseAppend_P(PSTR("\"}"));
|
||||
MqttPublishPrefixTopicRulesProcess_P(STAT, PSTR(D_CMND_HOSTEDOTA));
|
||||
}
|
||||
}
|
||||
#endif // CONFIG_ESP_WIFI_REMOTE_ENABLED
|
||||
|
||||
break;
|
||||
case 1: // Every x.25 second
|
||||
if (MidnightNow()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user