Skip to content

Commit 6f07395

Browse files
Merge pull request #225 from ayushsharma82/dev
v4.0.5
2 parents 549aa98 + e64eb8b commit 6f07395

File tree

10 files changed

+65
-31
lines changed

10 files changed

+65
-31
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/esphome-ESPAsyncTCP#v2.0.0
6565

6666
- name: Install ESPAsyncWebServer
67-
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/ESPAsyncWebServer#v2.10.1
67+
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/ESPAsyncWebServer#v3.0.2
6868

6969
- name: Install ArduinoJson
7070
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/bblanchon/ArduinoJson#v7.0.4
@@ -97,31 +97,31 @@ jobs:
9797
- name: esp32dev|arduino
9898
board: esp32dev
9999
platform: espressif32
100-
opts:
100+
opts: "--project-option 'lib_compat_mode = strict'"
101101
- name: esp32dev|arduino-2
102102
board: esp32dev
103103
104-
opts:
104+
opts: "--project-option 'lib_compat_mode = strict'"
105105
- name: esp32dev|arduino-3
106106
board: esp32dev
107107
platform: espressif32
108-
opts: "--project-option 'platform_packages=platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.0, platform_packages=platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.0/esp32-arduino-libs-3.0.0.zip'"
108+
opts: "--project-option 'lib_compat_mode = strict' --project-option 'platform_packages=platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.2, platform_packages=platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.2/esp32-arduino-libs-3.0.2.zip'"
109109
- name: esp32-s3-devkitc-1|arduino
110110
board: esp32-s3-devkitc-1
111111
platform: espressif32
112-
opts:
112+
opts: "--project-option 'lib_compat_mode = strict'"
113113
- name: esp32-s3-devkitc-1|arduino-2
114114
board: esp32-s3-devkitc-1
115115
116-
opts:
116+
opts: "--project-option 'lib_compat_mode = strict'"
117117
- name: esp32-s3-devkitc-1|arduino-3
118118
board: esp32-s3-devkitc-1
119119
platform: espressif32
120-
opts: "--project-option 'platform_packages=platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.0, platform_packages=platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.0/esp32-arduino-libs-3.0.0.zip'"
120+
opts: "--project-option 'lib_compat_mode = strict' --project-option 'platform_packages=platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.2, platform_packages=platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.2/esp32-arduino-libs-3.0.2.zip'"
121121
- name: huzzah|espressif8266
122122
board: huzzah
123123
platform: espressif8266
124-
opts:
124+
opts: "--project-option 'lib_compat_mode = strict'"
125125
steps:
126126
- uses: actions/checkout@v4
127127
- name: Set up cache

.github/workflows/stale.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: 'Close stale issues and PR'
2+
on:
3+
schedule:
4+
- cron: '30 6 * * *'
5+
6+
jobs:
7+
stale:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/stale@v9
11+
with:
12+
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.'
13+
stale-pr-message: 'This PR is marked as stale because it has been open 45 days with no activity. You can remove stale label or comment if this PR is still valid.'
14+
close-issue-message: 'This issue was closed because it has been stalled for 5 days with no activity.'
15+
days-before-stale: 30
16+
days-before-close: 5
17+
days-before-pr-close: -1

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ ESP-DASH Pro comes with the following extended functionality:
7979

8080
<h2>License</h2>
8181

82-
ESP-DASH is licensed under General Public License v3 ( GPLv3 ). If you are intending to use ESP-DASH in a commercial project, please consider buying the [ESP-DASH Pro](https://espdash.pro) which comes with a less restrictive SCL-1.0 license ( SOFTT Commercial License 1.0 ).
82+
ESP-DASH is licensed under General Public License v3 ( GPLv3 ). If you are intending to use ESP-DASH in a commercial project, please consider buying the [ESP-DASH Pro](https://espdash.pro) which comes with a less restrictive SCL-1.1 license ( SOFTT Commercial License 1.1 ).
8383

8484
<br>
8585
<br>

library.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"maintainer": true
1616
}
1717
],
18-
"version": "4.0.4",
18+
"version": "4.0.5",
1919
"frameworks": "arduino",
2020
"platforms": ["espressif32", "espressif8266"],
2121
"dependencies": [
@@ -28,7 +28,7 @@
2828
{
2929
"owner": "mathieucarbou",
3030
"name": "ESP Async WebServer",
31-
"version": "^2.10.1",
31+
"version": "^3.0.2",
3232
"platforms": ["espressif8266", "espressif32"]
3333
}
3434
]

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ESP-DASH
2-
version=4.0.4
2+
version=4.0.5
33
author=Ayush Sharma
44
category=Communication
55
maintainer=Ayush Sharma <[email protected]>

platformio.ini

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build_flags =
77
lib_deps =
88
bblanchon/ArduinoJson @ 7.0.4
99
mathieucarbou/Async TCP @ ^3.1.4
10-
mathieucarbou/ESP Async WebServer @ 2.10.1
10+
mathieucarbou/ESP Async WebServer @ 3.0.2
1111
upload_protocol = esptool
1212
monitor_speed = 115200
1313
monitor_filters = esp32_exception_decoder, log2file
@@ -32,14 +32,14 @@ board = esp32-s3-devkitc-1
3232
[env:arduino-3]
3333
platform = espressif32
3434
platform_packages=
35-
platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.0
36-
platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.0/esp32-arduino-libs-3.0.0.zip
35+
platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.2
36+
platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.2/esp32-arduino-libs-3.0.2.zip
3737
board = esp32-s3-devkitc-1
3838

3939
[env:esp8266]
4040
platform = espressif8266
4141
board = huzzah
4242
lib_deps =
4343
bblanchon/ArduinoJson @ 7.0.4
44-
mathieucarbou/ESP Async WebServer @ 2.10.1
44+
mathieucarbou/ESP Async WebServer @ 3.0.2
4545
esphome/ESPAsyncTCP-esphome @ 2.0.0

src/ESPDash.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ ESPDash::ESPDash(AsyncWebServer* server, const char* uri, bool enable_default_st
3636
// Attach AsyncWebServer Routes
3737
_server->on(uri, HTTP_GET, [this](AsyncWebServerRequest *request){
3838
if(basic_auth){
39-
if(!request->authenticate(username, password))
39+
if(!request->authenticate(username.c_str(), password.c_str()))
4040
return request->requestAuthentication();
4141
}
4242
// respond with the compressed frontend
43-
AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", DASH_HTML, sizeof(DASH_HTML));
43+
AsyncWebServerResponse *response = request->beginResponse(200, "text/html", DASH_HTML, sizeof(DASH_HTML));
4444
response->addHeader("Content-Encoding", "gzip");
4545
response->addHeader("Cache-Control", "public, max-age=900");
4646
request->send(response);
4747
});
4848

4949
// Websocket Callback Handler
50-
_ws->onEvent([&](AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len){
50+
_ws->onEvent([&](__unused AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len){
5151
// Request Buffer
5252
#if ARDUINOJSON_VERSION_MAJOR == 7
5353
JsonDocument json;
@@ -64,6 +64,8 @@ ESPDash::ESPDash(AsyncWebServer* server, const char* uri, bool enable_default_st
6464
// client side commands parsing
6565
if (json["command"] == "get:layout") {
6666
_asyncAccessInProgress = true;
67+
if (_beforeUpdateCallback)
68+
_beforeUpdateCallback(false);
6769
generateLayoutJSON(client, false);
6870
_asyncAccessInProgress = false;
6971
} else if (json["command"] == "ping") {
@@ -105,11 +107,11 @@ ESPDash::ESPDash(AsyncWebServer* server, const char* uri, bool enable_default_st
105107
}
106108

107109
void ESPDash::setAuthentication(const char *user, const char *pass) {
108-
basic_auth = strlen(user) > 0 && strlen(pass) > 0;
110+
username = user;
111+
password = pass;
112+
basic_auth = username.length() && password.length();
109113
if(basic_auth) {
110-
strncpy(username, user, sizeof(username));
111-
strncpy(password, pass, sizeof(password));
112-
_ws->setAuthentication(user, pass);
114+
_ws->setAuthentication(username.c_str(), password.c_str());
113115
}
114116
}
115117

@@ -314,7 +316,7 @@ void ESPDash::generateLayoutJSON(AsyncWebSocketClient* client, bool changes_only
314316

315317
doc["stats"][idx]["i"] = s->_id;
316318
doc["stats"][idx]["k"] = s->_key;
317-
if (changes_only || strlen(s->_value) > 0)
319+
if (changes_only || s->_value.length() > 0)
318320
doc["stats"][idx]["v"] = s->_value;
319321
doc["stats"][idx]["v"] = s->_value;
320322
idx++;
@@ -487,6 +489,8 @@ void ESPDash::sendUpdates(bool force) {
487489
if (!hasClient()) {
488490
return;
489491
}
492+
if (_beforeUpdateCallback)
493+
_beforeUpdateCallback(!force);
490494
generateLayoutJSON(nullptr, !force);
491495
}
492496

@@ -495,6 +499,8 @@ void ESPDash::refreshCard(Card *card) {
495499
if (!hasClient()) {
496500
return;
497501
}
502+
if (_beforeUpdateCallback)
503+
_beforeUpdateCallback(true);
498504
generateLayoutJSON(nullptr, true, card);
499505
}
500506

src/ESPDash.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ class Statistic;
6868

6969
// ESPDASH Class
7070
class ESPDash{
71+
public:
72+
// changes_only: true (equivalent to sendUpdates(false)) - when sending updates to the client
73+
// changes_only: false (equivalent to sendUpdates(true)) - when sending the entire layout to the client or when forcing a full update
74+
typedef std::function<void(bool changes_only)> BeforeUpdateCallback;
75+
7176
private:
7277
AsyncWebServer* _server = nullptr;
7378
AsyncWebSocket* _ws = nullptr;
@@ -77,9 +82,10 @@ class ESPDash{
7782
Vector<Statistic*> statistics;
7883
bool default_stats_enabled = false;
7984
bool basic_auth = false;
80-
char username[64];
81-
char password[64];
85+
String username;
86+
String password;
8287
uint32_t _idCounter = 0;
88+
BeforeUpdateCallback _beforeUpdateCallback = nullptr;
8389

8490
volatile bool _asyncAccessInProgress = false;
8591

@@ -129,6 +135,12 @@ class ESPDash{
129135
// in which case you should not modify them
130136
bool isAsyncAccessInProgress() { return _asyncAccessInProgress; }
131137

138+
// Register a callback that will be called before some updates will be sent to the client.
139+
// This callback can be used for example to refresh some card values that never change after only when a full layout is request (i.e. on page reload).
140+
// This allows to avoid spending time refreshing cards that never change, but still allows them to be refreshed hen the user refresh the dashboard.
141+
// If called from the async_http task, isAsyncAccessInProgress() will return true while in this callback.
142+
void onBeforeUpdate(BeforeUpdateCallback callback) { _beforeUpdateCallback = callback; }
143+
132144
~ESPDash();
133145
};
134146

src/Statistic.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ Statistic::Statistic(ESPDash *dashboard, const char *key, const char *value) {
55
_id = dashboard->nextId();
66
// Safe copy
77
_key = key;
8-
strncpy(_value, value, sizeof(_value));
8+
_value = value;
99
_dashboard->add(this);
1010
}
1111

1212
void Statistic::set(const char *value) {
1313
// Safe copy
14-
_changed = strcmp(_value, value) != 0;
14+
_changed = _value != value;
1515
if(_changed)
16-
strncpy(_value, value, sizeof(_value));
17-
16+
_value = value;
1817
}
1918

2019
Statistic::~Statistic() {

src/Statistic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Statistic {
1616
ESPDash *_dashboard;
1717
uint32_t _id;
1818
const char *_key;
19-
char _value[64];
19+
String _value;
2020
bool _changed = false;
2121

2222
public:

0 commit comments

Comments
 (0)