forked from xiaozhi/xiaozhi-esp32
move ota headers to ota.cc
This commit is contained in:
25
main/ota.cc
25
main/ota.cc
@@ -2,6 +2,7 @@
|
||||
#include "system_info.h"
|
||||
#include "board.h"
|
||||
#include "settings.h"
|
||||
#include "assets/lang_config.h"
|
||||
|
||||
#include <cJSON.h>
|
||||
#include <esp_log.h>
|
||||
@@ -18,6 +19,7 @@
|
||||
|
||||
|
||||
Ota::Ota() {
|
||||
SetCheckVersionUrl(CONFIG_OTA_VERSION_URL);
|
||||
}
|
||||
|
||||
Ota::~Ota() {
|
||||
@@ -31,12 +33,12 @@ void Ota::SetHeader(const std::string& key, const std::string& value) {
|
||||
headers_[key] = value;
|
||||
}
|
||||
|
||||
void Ota::SetPostData(const std::string& post_data) {
|
||||
post_data_ = post_data;
|
||||
}
|
||||
|
||||
bool Ota::CheckVersion() {
|
||||
current_version_ = esp_app_get_description()->version;
|
||||
auto& board = Board::GetInstance();
|
||||
auto app_desc = esp_app_get_description();
|
||||
|
||||
// Check if there is a new firmware version available
|
||||
current_version_ = app_desc->version;
|
||||
ESP_LOGI(TAG, "Current version: %s", current_version_.c_str());
|
||||
|
||||
if (check_version_url_.length() < 10) {
|
||||
@@ -44,14 +46,21 @@ bool Ota::CheckVersion() {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto http = Board::GetInstance().CreateHttp();
|
||||
auto http = board.CreateHttp();
|
||||
for (const auto& header : headers_) {
|
||||
http->SetHeader(header.first, header.second);
|
||||
}
|
||||
|
||||
http->SetHeader("Ota-Version", "2");
|
||||
http->SetHeader("Device-Id", SystemInfo::GetMacAddress().c_str());
|
||||
http->SetHeader("Client-Id", board.GetUuid());
|
||||
http->SetHeader("User-Agent", std::string(BOARD_NAME "/") + app_desc->version);
|
||||
http->SetHeader("Accept-Language", Lang::CODE);
|
||||
http->SetHeader("Content-Type", "application/json");
|
||||
std::string method = post_data_.length() > 0 ? "POST" : "GET";
|
||||
if (!http->Open(method, check_version_url_, post_data_)) {
|
||||
|
||||
std::string post_data = board.GetJson();
|
||||
std::string method = post_data.length() > 0 ? "POST" : "GET";
|
||||
if (!http->Open(method, check_version_url_, post_data)) {
|
||||
ESP_LOGE(TAG, "Failed to open HTTP connection");
|
||||
delete http;
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user