Skip to content

Commit

Permalink
perf: store static log messages in Flash
Browse files Browse the repository at this point in the history
  • Loading branch information
becem-gharbi committed Jun 21, 2024
1 parent d5fc4d7 commit 8c07d9b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
14 changes: 7 additions & 7 deletions src/HTTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace ESPAdmin
esp_http_client_handle_t client = esp_http_client_init(&config);
if (client == nullptr)
{
_logger.error("failed to init http client");
_logger.error(F("failed to init http client"));
return "";
}

Expand All @@ -40,15 +40,15 @@ namespace ESPAdmin
esp_err_t err = esp_http_client_open(client, 0);
if (err != ESP_OK)
{
_logger.error("failed to open connection");
_logger.error(F("failed to open connection"));
esp_http_client_cleanup(client);
return "";
}

int contentLength = esp_http_client_fetch_headers(client);
if (contentLength == -1)
{
_logger.error("failed to read");
_logger.error(F("failed to read"));
esp_http_client_cleanup(client);
return "";
}
Expand Down Expand Up @@ -98,7 +98,7 @@ namespace ESPAdmin
esp_http_client_handle_t client = esp_http_client_init(&config);
if (client == nullptr)
{
_logger.error("failed to init http client");
_logger.error(F("failed to init http client"));
return "";
}

Expand All @@ -108,15 +108,15 @@ namespace ESPAdmin
esp_err_t err = esp_http_client_open(client, content.length());
if (err != ESP_OK)
{
_logger.error("failed to open connection");
_logger.error(F("failed to open connection"));
esp_http_client_cleanup(client);
return "";
}

int wlen = esp_http_client_write(client, content.c_str(), content.length());
if (wlen == -1)
{
_logger.error("failed to write");
_logger.error(F("failed to write"));
esp_http_client_close(client);
esp_http_client_cleanup(client);
return "";
Expand All @@ -125,7 +125,7 @@ namespace ESPAdmin
int contentLength = esp_http_client_fetch_headers(client);
if (contentLength == -1)
{
_logger.error("failed to read");
_logger.error(F("failed to read"));
esp_http_client_close(client);
esp_http_client_cleanup(client);
return "";
Expand Down
14 changes: 7 additions & 7 deletions src/MQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace ESPAdmin

if (uriWS.length() == 0 || username.length() == 0 || password.length() == 0)
{
_logger.error("invalid MQTT configuration");
_logger.error(F("invalid MQTT configuration"));
return;
}

Expand Down Expand Up @@ -53,23 +53,23 @@ namespace ESPAdmin

if (_client == nullptr)
{
_logger.error("unable to create client");
_logger.error(F("unable to create client"));
return;
}

esp_err_t err = esp_mqtt_client_register_event(_client, MQTT_EVENT_ANY, _onEvent, _client);

if (err != ESP_OK)
{
_logger.error("unable to register event handler");
_logger.error(F("unable to register event handler"));
return;
}

err = esp_mqtt_client_start(_client);

if (err != ESP_OK)
{
_logger.error("unable to start client");
_logger.error(F("unable to start client"));
return;
}
}
Expand Down Expand Up @@ -178,7 +178,7 @@ namespace ESPAdmin
{
Store::mqttConnected = true;

_logger.info("connected");
_logger.info(F("connected"));

subscribe("device/" + String(Store::options.deviceId) + "/command/+", 1);

Expand All @@ -189,7 +189,7 @@ namespace ESPAdmin
{
Store::mqttConnected = false;

_logger.info("disconnected");
_logger.info(F("disconnected"));

Report::sendStatus("disconnected");
}
Expand All @@ -201,7 +201,7 @@ namespace ESPAdmin

void MQTT::_onSubscribed()
{
_logger.info("subscribed");
_logger.info(F("subscribed"));
}

MQTT::~MQTT()
Expand Down
6 changes: 3 additions & 3 deletions src/NVS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace ESPAdmin

if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND)
{
_logger.info("partition needs to be erased");
_logger.info(F("partition needs to be erased"));

ESP_ERROR_CHECK(nvs_flash_erase());

Expand All @@ -30,11 +30,11 @@ namespace ESPAdmin

if (err != ESP_OK)
{
_logger.error("failed to open namespace");
_logger.error(F("failed to open namespace"));
}
else
{
_logger.success("ready");
_logger.success(F("ready"));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace ESPAdmin

if (settings.length() == 0)
{
_logger.warn("could not fetch settings");
_logger.warn(F("could not fetch settings"));
return;
}

Expand All @@ -85,11 +85,11 @@ namespace ESPAdmin
set(STORE_MQTT_URI_TCP, uriTCP);
set(STORE_MQTT_URI_WS, uriWS);

_logger.success("settings saved");
_logger.success(F("settings saved"));
}
else
{
_logger.warn("failed to deserialize Json");
_logger.warn(F("failed to deserialize Json"));
}
}
}
8 changes: 4 additions & 4 deletions src/Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace ESPAdmin
}
else if (Store::updateRunning)
{
_logger.warn("already update is running");
_logger.warn(F("already update is running"));
}
else
{
Expand Down Expand Up @@ -62,7 +62,7 @@ namespace ESPAdmin

[[noreturn]] void Update::_onSuccess()
{
_logger.success("succeded");
_logger.success(F("succeded"));
Report::sendUpdateStatus(_message, "succeded");

Store::set(STORE_UPDATE_RELEASE_ID, _message.releaseId.c_str());
Expand All @@ -78,14 +78,14 @@ namespace ESPAdmin

void Update::_onFail()
{
_logger.error("failed");
_logger.error(F("failed"));

Report::sendUpdateStatus(_message, "failed");
}

void Update::_onStart()
{
_logger.info("started");
_logger.info(F("started"));

Report::sendUpdateStatus(_message, "started");
}
Expand Down

0 comments on commit 8c07d9b

Please sign in to comment.