Skip to content

Commit

Permalink
Many changes regarding Json support and memory improvement
Browse files Browse the repository at this point in the history
- Support for ArduinoJson 7
- Fixed missing `step` for slider when using short ranges or big ranges
- Supports WebSocket batching to avoid crash with the initial layout sending. Batch sizes can be controlled with `DASH_JSON_SIZE`.
- Mitigate concurrency issue with `isAsyncAccessInProgress()` to avoid updating cards while the layout is being generated
- Changed card and stat names to `const char*` to improve memory usage. This makes them immutable and require to use constants.
- Removed the ability to change a stat name (for this dynamic use case we can remove and recreate a stat)
- refreshLayout() refactoring in order to avoid too many layout refresh requests when updating components dynamically: let the caller trigger a layout refresh once.
- Removed refreshStatistics() because it it not refreshing the stats only but all the updated cards also
- Removed update calls when adding / removing cards and stats in order to avoid trigger a sequence of full layout updates: this is u to the user to call refreshLayout() when he has finished
- Support both ESPAsyncWebServer fork from ESPHome and yubox-node-org (which as a better api for sending websocket buffers and dealing with concurrency)
  • Loading branch information
mathieucarbou committed Jan 29, 2024
1 parent b677bf6 commit 7696dff
Show file tree
Hide file tree
Showing 11 changed files with 3,200 additions and 3,202 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/dep-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ cd ${HOME}/Arduino/libraries
git clone https://github.com/me-no-dev/ESPAsyncWebServer.git ESPAsyncWebServer
git clone https://github.com/me-no-dev/ESPAsyncTCP.git ESPAsyncTCP
git clone https://github.com/me-no-dev/AsyncTCP.git AsyncTCP
git clone --single-branch --branch 6.x https://github.com/bblanchon/ArduinoJson.git ArduinoJson
git clone --single-branch --branch 7.x https://github.com/bblanchon/ArduinoJson.git ArduinoJson
6 changes: 2 additions & 4 deletions library.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@
"dependencies":
[
{
"name": "ESPAsyncWebServer-esphome",
"version": "^3.1.0"
"name": "ESP Async WebServer"
},
{
"name": "ArduinoJson",
"version": "^6.17.0"
"name": "ArduinoJson"
}
]
}
3 changes: 2 additions & 1 deletion src/Card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
/*
Constructor
*/
Card::Card(ESPDash *dashboard, const int type, const char* name, const char* symbol, const int min, const int max){
Card::Card(ESPDash *dashboard, const int type, const char* name, const char* symbol, const int min, const int max, const int step){
_dashboard = dashboard;
_id = dashboard->nextId();
_type = type;
_name = name;
_symbol = symbol;
_value_min = min;
_value_max = max;
_value_step = step;
_dashboard->add(this);
}

Expand Down
5 changes: 3 additions & 2 deletions src/Card.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Card {
ESPDash *_dashboard;

uint32_t _id;
String _name;
const char* _name;
int _type;
bool _changed;
enum { INTEGER, FLOAT, STRING } _value_type;
Expand All @@ -44,11 +44,12 @@ class Card {
String _value_s;
int _value_min;
int _value_max;
int _value_step;
String _symbol;
std::function<void(int value)> _callback = nullptr;

public:
Card(ESPDash *dashboard, const int type, const char* name, const char* symbol = "", const int min = 0, const int max = 0);
Card(ESPDash *dashboard, const int type, const char* name, const char* symbol = "", const int min = 0, const int max = 0, const int step = 1);
void attachCallback(std::function<void(int)> cb);
void update(int value);
void update(int value, const char* symbol);
Expand Down
2 changes: 1 addition & 1 deletion src/Chart.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Chart {
ESPDash *_dashboard;

uint32_t _id;
String _name;
const char *_name;
int _type;
bool _changed;
GraphAxisType _x_axis_type;
Expand Down
Loading

0 comments on commit 7696dff

Please sign in to comment.