mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +03:00
Merge remote-tracking branch 'origin/tech-upgrade' into dev
This commit is contained in:
@@ -25,6 +25,7 @@ ESP8266React::ESP8266React(AsyncWebServer * server, FS * fs)
|
||||
ArRequestHandlerFunction requestHandler = [contentType, content, len](AsyncWebServerRequest * request) {
|
||||
AsyncWebServerResponse * response = request->beginResponse_P(200, contentType, content, len);
|
||||
response->addHeader("Content-Encoding", "gzip");
|
||||
// response->addHeader("Content-Encoding", "br"); // only works over HTTPS
|
||||
request->send(response);
|
||||
};
|
||||
server->on(uri.c_str(), HTTP_GET, requestHandler);
|
||||
|
||||
@@ -31,16 +31,6 @@ class FSPersistence {
|
||||
DeserializationError error = deserializeJson(jsonDocument, settingsFile);
|
||||
if (error == DeserializationError::Ok && jsonDocument.is<JsonObject>()) {
|
||||
JsonObject jsonObject = jsonDocument.as<JsonObject>();
|
||||
|
||||
// debug added by Proddy
|
||||
#if defined(EMSESP_DEBUG)
|
||||
#if defined(EMSESP_USE_SERIAL)
|
||||
Serial.println();
|
||||
Serial.printf("Reading file: %s: ", _filePath);
|
||||
serializeJson(jsonDocument, Serial);
|
||||
Serial.println();
|
||||
#endif
|
||||
#endif
|
||||
_statefulService->updateWithoutPropagation(jsonObject, _stateUpdater);
|
||||
settingsFile.close();
|
||||
return;
|
||||
@@ -48,15 +38,8 @@ class FSPersistence {
|
||||
settingsFile.close();
|
||||
}
|
||||
|
||||
// If we reach here we have not been successful in loading the config,
|
||||
// hard-coded emergency defaults are now applied.
|
||||
#if defined(EMSESP_DEBUG)
|
||||
#if defined(EMSESP_USE_SERIAL)
|
||||
Serial.println();
|
||||
Serial.printf("Applying defaults for %s: ", _filePath);
|
||||
Serial.println();
|
||||
#endif
|
||||
#endif
|
||||
// If we reach here we have not been successful in loading the config,
|
||||
// hard-coded emergency defaults are now applied.
|
||||
applyDefaults();
|
||||
writeToFS(); // added to make sure the initial file is created
|
||||
}
|
||||
@@ -82,26 +65,9 @@ class FSPersistence {
|
||||
|
||||
// failed to open file, return false
|
||||
if (!settingsFile || !jsonObject.size()) {
|
||||
#if defined(EMSESP_DEBUG)
|
||||
#if defined(EMSESP_USE_SERIAL)
|
||||
Serial.println();
|
||||
Serial.printf("Cannot write to file system.");
|
||||
Serial.println();
|
||||
#endif
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
// debug added by Proddy
|
||||
#if defined(EMSESP_DEBUG)
|
||||
#if defined(EMSESP_USE_SERIAL)
|
||||
Serial.println();
|
||||
Serial.printf("Writing to file: %s: ", _filePath);
|
||||
serializeJson(jsonDocument, Serial);
|
||||
Serial.println();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// serialize the data to the file
|
||||
serializeJson(jsonDocument, settingsFile);
|
||||
settingsFile.close();
|
||||
|
||||
@@ -169,6 +169,7 @@ void MqttSettings::read(MqttSettings & settings, JsonObject & root) {
|
||||
root["ha_enabled"] = settings.ha_enabled;
|
||||
root["nested_format"] = settings.nested_format;
|
||||
root["discovery_prefix"] = settings.discovery_prefix;
|
||||
root["discovery_type"] = settings.discovery_type;
|
||||
root["publish_single"] = settings.publish_single;
|
||||
root["publish_single2cmd"] = settings.publish_single2cmd;
|
||||
root["send_response"] = settings.send_response;
|
||||
@@ -201,6 +202,7 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
|
||||
newSettings.ha_enabled = root["ha_enabled"] | EMSESP_DEFAULT_HA_ENABLED;
|
||||
newSettings.nested_format = root["nested_format"] | EMSESP_DEFAULT_NESTED_FORMAT;
|
||||
newSettings.discovery_prefix = root["discovery_prefix"] | EMSESP_DEFAULT_DISCOVERY_PREFIX;
|
||||
newSettings.discovery_type = root["discovery_type"] | EMSESP_DEFAULT_DISCOVERY_TYPE;
|
||||
newSettings.publish_single = root["publish_single"] | EMSESP_DEFAULT_PUBLISH_SINGLE;
|
||||
newSettings.publish_single2cmd = root["publish_single2cmd"] | EMSESP_DEFAULT_PUBLISH_SINGLE2CMD;
|
||||
newSettings.send_response = root["send_response"] | EMSESP_DEFAULT_SEND_RESPONSE;
|
||||
@@ -223,6 +225,10 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (newSettings.discovery_type != settings.discovery_type) {
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (newSettings.entity_format != settings.entity_format) {
|
||||
changed = true;
|
||||
}
|
||||
|
||||
@@ -89,6 +89,7 @@ class MqttSettings {
|
||||
bool ha_enabled;
|
||||
uint8_t nested_format;
|
||||
String discovery_prefix;
|
||||
uint8_t discovery_type;
|
||||
bool publish_single;
|
||||
bool publish_single2cmd;
|
||||
bool send_response;
|
||||
|
||||
@@ -49,7 +49,7 @@ void NTPSettingsService::WiFiEvent(WiFiEvent_t event) {
|
||||
void NTPSettingsService::configureNTP() {
|
||||
emsesp::EMSESP::system_.ntp_connected(false);
|
||||
if (connected_ && _state.enabled) {
|
||||
emsesp::EMSESP::logger().info("Starting NTP");
|
||||
emsesp::EMSESP::logger().info("Starting NTP service");
|
||||
sntp_set_sync_interval(3600000); // one hour
|
||||
sntp_set_time_sync_notification_cb(ntp_received);
|
||||
configTzTime(_state.tzFormat.c_str(), _state.server.c_str());
|
||||
|
||||
@@ -39,12 +39,11 @@ void OTASettingsService::configureArduinoOTA() {
|
||||
_arduinoOTA->onEnd([]() { emsesp::EMSESP::system_.upload_status(false); });
|
||||
|
||||
_arduinoOTA->onProgress([](unsigned int progress, unsigned int total) {
|
||||
#if defined(EMSESP_USE_SERIAL)
|
||||
Serial.printf("Progress: %u%%\r\n", (progress / (total / 100)));
|
||||
#endif
|
||||
// Serial.printf("Progress: %u%%\r\n", (progress / (total / 100)));
|
||||
});
|
||||
_arduinoOTA->onError([](ota_error_t error) {
|
||||
#if defined(EMSESP_USE_SERIAL)
|
||||
/*
|
||||
#if defined(EMSESP_DEBUG)
|
||||
Serial.printf("Error[%u]: ", error);
|
||||
if (error == OTA_AUTH_ERROR)
|
||||
Serial.println("Auth Failed");
|
||||
@@ -57,6 +56,7 @@ void OTASettingsService::configureArduinoOTA() {
|
||||
else if (error == OTA_END_ERROR)
|
||||
Serial.println("End Failed");
|
||||
#endif
|
||||
*/
|
||||
});
|
||||
|
||||
_arduinoOTA->setMdnsEnabled(false); // disable as handled in NetworkSettingsService.cpp. https://github.com/emsesp/EMS-ESP32/issues/161
|
||||
|
||||
@@ -31,7 +31,7 @@ void RestartService::partition(AsyncWebServerRequest * request) {
|
||||
uint64_t buffer;
|
||||
esp_partition_read(ota_partition, 0, &buffer, 8);
|
||||
if (buffer == 0xFFFFFFFFFFFFFFFF) { // partition empty
|
||||
request->send(400); // bad request
|
||||
request->send(400); // bad request
|
||||
return;
|
||||
}
|
||||
esp_ota_set_boot_partition(ota_partition);
|
||||
|
||||
@@ -12,13 +12,16 @@ SystemStatus::SystemStatus(AsyncWebServer * server, SecurityManager * securityMa
|
||||
}
|
||||
|
||||
void SystemStatus::systemStatus(AsyncWebServerRequest * request) {
|
||||
emsesp::EMSESP::system_.refreshHeapMem(); // refresh free heap and max alloc heap
|
||||
|
||||
AsyncJsonResponse * response = new AsyncJsonResponse(false, MAX_ESP_STATUS_SIZE);
|
||||
JsonObject root = response->getRoot();
|
||||
|
||||
root["emsesp_version"] = EMSESP_APP_VERSION;
|
||||
root["esp_platform"] = EMSESP_PLATFORM;
|
||||
root["cpu_freq_mhz"] = ESP.getCpuFreqMHz();
|
||||
root["max_alloc_heap"] = ESP.getMaxAllocHeap() / 1024;
|
||||
root["free_heap"] = ESP.getFreeHeap() / 1024;
|
||||
root["max_alloc_heap"] = emsesp::EMSESP::system_.getMaxAllocMem();
|
||||
root["free_heap"] = emsesp::EMSESP::system_.getHeapMem();
|
||||
root["sdk_version"] = ESP.getSdkVersion();
|
||||
root["flash_chip_size"] = ESP.getFlashChipSize() / 1024;
|
||||
root["flash_chip_speed"] = ESP.getFlashChipSpeed();
|
||||
@@ -28,6 +31,7 @@ void SystemStatus::systemStatus(AsyncWebServerRequest * request) {
|
||||
root["fs_used"] = FSused;
|
||||
root["fs_free"] = emsesp::EMSESP::system_.FStotal() - FSused;
|
||||
root["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3);
|
||||
|
||||
if (emsesp::EMSESP::system_.PSram()) {
|
||||
root["psram_size"] = emsesp::EMSESP::system_.PSram();
|
||||
root["free_psram"] = ESP.getFreePsram() / 1024;
|
||||
@@ -41,7 +45,7 @@ void SystemStatus::systemStatus(AsyncWebServerRequest * request) {
|
||||
uint64_t buffer;
|
||||
esp_partition_read(partition, 0, &buffer, 8);
|
||||
const esp_partition_t * running = esp_ota_get_running_partition();
|
||||
root["has_loader"] = (buffer != 0xFFFFFFFFFFFFFFFF && running->size != partition->size);
|
||||
root["has_loader"] = (buffer != 0xFFFFFFFFFFFFFFFF && running->size != partition->size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,14 +29,6 @@ void UploadFileService::handleUpload(AsyncWebServerRequest * request, const Stri
|
||||
std::string extension = fname.substr(position + 1);
|
||||
size_t fsize = request->contentLength();
|
||||
|
||||
#ifdef EMSESP_DEBUG
|
||||
#if defined(EMSESP_USE_SERIAL)
|
||||
Serial.println();
|
||||
Serial.printf("Received filename: %s, len: %d, index: %d, ext: %s, fsize: %d", filename.c_str(), len, index, extension.c_str(), fsize);
|
||||
Serial.println();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
is_firmware = false;
|
||||
if ((extension == "bin") && (fsize > 1000000)) {
|
||||
is_firmware = true;
|
||||
@@ -77,16 +69,13 @@ void UploadFileService::handleUpload(AsyncWebServerRequest * request, const Stri
|
||||
}
|
||||
#endif
|
||||
// it's firmware - initialize the ArduinoOTA updater
|
||||
if (Update.begin(fsize)) {
|
||||
if (Update.begin()) {
|
||||
if (strlen(md5) == 32) {
|
||||
Update.setMD5(md5);
|
||||
md5[0] = '\0';
|
||||
}
|
||||
request->onDisconnect(UploadFileService::handleEarlyDisconnect); // success, let's make sure we end the update if the client hangs up
|
||||
} else {
|
||||
#if defined(EMSESP_USE_SERIAL)
|
||||
Update.printError(Serial);
|
||||
#endif
|
||||
handleError(request, 507); // failed to begin, send an error response Insufficient Storage
|
||||
return;
|
||||
}
|
||||
@@ -104,16 +93,10 @@ void UploadFileService::handleUpload(AsyncWebServerRequest * request, const Stri
|
||||
// if we haven't delt with an error, continue with the firmware update
|
||||
if (!request->_tempObject) {
|
||||
if (Update.write(data, len) != len) {
|
||||
#if defined(EMSESP_USE_SERIAL)
|
||||
Update.printError(Serial);
|
||||
#endif
|
||||
handleError(request, 500);
|
||||
}
|
||||
if (final) {
|
||||
if (!Update.end(true)) {
|
||||
#if defined(EMSESP_USE_SERIAL)
|
||||
Update.printError(Serial);
|
||||
#endif
|
||||
handleError(request, 500);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user