Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory consumption improvement #218

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/ESPDash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ESPDash::ESPDash(AsyncWebServer* server, const char* uri, bool enable_default_st
// Attach AsyncWebServer Routes
_server->on(uri, HTTP_GET, [this](AsyncWebServerRequest *request){
if(basic_auth){
if(!request->authenticate(username, password))
if(!request->authenticate(username.c_str(), password.c_str()))
return request->requestAuthentication();
}
// respond with the compressed frontend
Expand Down Expand Up @@ -107,11 +107,11 @@ ESPDash::ESPDash(AsyncWebServer* server, const char* uri, bool enable_default_st
}

void ESPDash::setAuthentication(const char *user, const char *pass) {
basic_auth = strlen(user) > 0 && strlen(pass) > 0;
username = user;
password = pass;
basic_auth = username.length() && password.length();
if(basic_auth) {
strncpy(username, user, sizeof(username));
strncpy(password, pass, sizeof(password));
_ws->setAuthentication(user, pass);
_ws->setAuthentication(username.c_str(), password.c_str());
}
}

Expand Down Expand Up @@ -316,7 +316,7 @@ void ESPDash::generateLayoutJSON(AsyncWebSocketClient* client, bool changes_only

doc["stats"][idx]["i"] = s->_id;
doc["stats"][idx]["k"] = s->_key;
if (changes_only || strlen(s->_value) > 0)
if (changes_only || s->_value.length() > 0)
doc["stats"][idx]["v"] = s->_value;
doc["stats"][idx]["v"] = s->_value;
idx++;
Expand Down
4 changes: 2 additions & 2 deletions src/ESPDash.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ class ESPDash{
Vector<Statistic*> statistics;
bool default_stats_enabled = false;
bool basic_auth = false;
char username[64];
char password[64];
String username;
String password;
uint32_t _idCounter = 0;
BeforeUpdateCallback _beforeUpdateCallback = nullptr;

Expand Down
7 changes: 3 additions & 4 deletions src/Statistic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ Statistic::Statistic(ESPDash *dashboard, const char *key, const char *value) {
_id = dashboard->nextId();
// Safe copy
_key = key;
strncpy(_value, value, sizeof(_value));
_value = value;
_dashboard->add(this);
}

void Statistic::set(const char *value) {
// Safe copy
_changed = strcmp(_value, value) != 0;
_changed = _value != value;
if(_changed)
strncpy(_value, value, sizeof(_value));

_value = value;
}

Statistic::~Statistic() {
Expand Down
2 changes: 1 addition & 1 deletion src/Statistic.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Statistic {
ESPDash *_dashboard;
uint32_t _id;
const char *_key;
char _value[64];
String _value;
bool _changed = false;

public:
Expand Down
Loading