Skip to content

Commit

Permalink
Reducing payload size
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Dec 15, 2023
1 parent 462d162 commit b6579b6
Show file tree
Hide file tree
Showing 4 changed files with 3,040 additions and 3,028 deletions.
31 changes: 18 additions & 13 deletions src/ESPDash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ESPDash::ESPDash(AsyncWebServer* server, const char* uri, bool enable_default_st
}
// respond with the compressed frontend
AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", DASH_HTML, sizeof(DASH_HTML));
response->addHeader("Content-Encoding","gzip");
response->addHeader("Content-Encoding", "gzip");
response->addHeader("Cache-Control", "public, max-age=900");
request->send(response);
});
Expand Down Expand Up @@ -315,6 +315,8 @@ size_t ESPDash::generateLayoutJSON(AsyncWebSocketClient *client, bool changes_on
}
obj["i"] = s->_id;
obj["k"] = s->_key;
if(changes_only || strlen(s->_value) > 0)
obj["v"] = s->_value;
obj["v"] = s->_value;
serializeJson(obj, buf);
obj.clear();
Expand Down Expand Up @@ -349,22 +351,25 @@ size_t ESPDash::generateLayoutJSON(AsyncWebSocketClient *client, bool changes_on
void ESPDash::generateComponentJSON(JsonObject& doc, Card* card, bool change_only){
doc["id"] = card->_id;
if(!change_only){
doc["name"] = card->_name;
doc["type"] = cardTags[card->_type].type;
doc["value_min"] = card->_value_min;
doc["value_max"] = card->_value_max;
doc["n"] = card->_name.c_str();
doc["t"] = cardTags[card->_type].type;
doc["min"] = card->_value_min;
doc["max"] = card->_value_max;
}
doc["symbol"] = card->_symbol;
if(change_only || !card->_symbol.isEmpty())
doc["s"] = card->_symbol;

switch (card->_value_type) {
case Card::INTEGER:
doc["value"] = card->_value_i;
doc["v"] = card->_value_i;
break;
case Card::FLOAT:
doc["value"] = String(card->_value_f, 2);
doc["v"] = String(card->_value_f, 2);
break;
case Card::STRING:
doc["value"] = card->_value_s;
if(change_only || !card->_value_s.isEmpty()) {
doc["v"] = card->_value_s;
}
break;
default:
// blank value
Expand All @@ -379,11 +384,11 @@ void ESPDash::generateComponentJSON(JsonObject& doc, Card* card, bool change_onl
void ESPDash::generateComponentJSON(JsonObject& doc, Chart* chart, bool change_only){
doc["id"] = chart->_id;
if(!change_only){
doc["name"] = chart->_name;
doc["type"] = chartTags[chart->_type].type;
doc["n"] = chart->_name.c_str();
doc["t"] = chartTags[chart->_type].type;
}

JsonArray xAxis = doc["x_axis"].to<JsonArray>();
JsonArray xAxis = doc["x"].to<JsonArray>();
switch (chart->_x_axis_type) {
case GraphAxisType::INTEGER:
#if DASH_USE_LEGACY_CHART_STORAGE == 1
Expand Down Expand Up @@ -434,7 +439,7 @@ void ESPDash::generateComponentJSON(JsonObject& doc, Chart* chart, bool change_o
break;
}

JsonArray yAxis = doc["y_axis"].to<JsonArray>();
JsonArray yAxis = doc["y"].to<JsonArray>();
switch (chart->_y_axis_type) {
case GraphAxisType::INTEGER:
#if DASH_USE_LEGACY_CHART_STORAGE == 1
Expand Down
6 changes: 6 additions & 0 deletions src/ESPDash.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ Github URL: https://github.com/ayushsharma82/ESP-DASH
#include "AsyncTCP.h"
#endif

#define DASH_STATUS_IDLE "i"
#define DASH_STATUS_SUCCESS "s"
#define DASH_STATUS_WARNING "w"
#define DASH_STATUS_DANGER "d"

#include "ESPAsyncWebServer.h"
#include "ArduinoJson.h"
#include "Card.h"
Expand Down Expand Up @@ -122,6 +127,7 @@ class ESPDash{
void sendUpdates(bool force = false);

void refreshStatistics();

void refreshCard(Card *card);

uint32_t nextId();
Expand Down
Loading

0 comments on commit b6579b6

Please sign in to comment.