Skip to content

Commit a583a73

Browse files
committed
ESP-DASH v5
1 parent edd847e commit a583a73

21 files changed

+2031
-1034
lines changed

.clang-format

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Language: Cpp
2+
BasedOnStyle: LLVM
3+
4+
AccessModifierOffset: -2
5+
AlignConsecutiveMacros: true
6+
AllowAllArgumentsOnNextLine: false
7+
AllowAllParametersOfDeclarationOnNextLine: false
8+
AllowShortIfStatementsOnASingleLine: false
9+
AllowShortLambdasOnASingleLine: Inline
10+
BinPackArguments: false
11+
ColumnLimit: 0
12+
ContinuationIndentWidth: 2
13+
FixNamespaceComments: false
14+
IndentAccessModifiers: true
15+
IndentCaseLabels: true
16+
IndentPPDirectives: BeforeHash
17+
IndentWidth: 2
18+
NamespaceIndentation: All
19+
PointerAlignment: Left
20+
ReferenceAlignment: Left
21+
TabWidth: 2
22+
UseTab: Never

.github/workflows/ci.yml

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ jobs:
7878
- name: Build Benchmark
7979
run: arduino-cli compile --library . --warnings none -b ${{ matrix.board }} "examples/Benchmark/Benchmark.ino"
8080

81+
- name: Build Benchmark5
82+
run: arduino-cli compile --library . --warnings none -b ${{ matrix.board }} "examples/Benchmark5/Benchmark5.ino"
83+
8184
- name: Build Chart
8285
run: arduino-cli compile --library . --warnings none -b ${{ matrix.board }} "examples/Chart/Chart.ino"
8386

@@ -154,6 +157,7 @@ jobs:
154157
- run: PLATFORMIO_SRC_DIR=examples/AccessPoint PIO_BOARD=${{ matrix.board }} pio run -e ${{ matrix.env }}
155158
- run: PLATFORMIO_SRC_DIR=examples/Basic PIO_BOARD=${{ matrix.board }} pio run -e ${{ matrix.env }}
156159
- run: PLATFORMIO_SRC_DIR=examples/Benchmark PIO_BOARD=${{ matrix.board }} pio run -e ${{ matrix.env }}
160+
- run: PLATFORMIO_SRC_DIR=examples/Benchmark5 PIO_BOARD=${{ matrix.board }} pio run -e ${{ matrix.env }}
157161
- run: PLATFORMIO_SRC_DIR=examples/Chart PIO_BOARD=${{ matrix.board }} pio run -e ${{ matrix.env }}
158162
- run: PLATFORMIO_SRC_DIR=examples/Dynamic PIO_BOARD=${{ matrix.board }} pio run -e ${{ matrix.env }}
159163
- run: PLATFORMIO_SRC_DIR=examples/Interactive PIO_BOARD=${{ matrix.board }} pio run -e ${{ matrix.env }}

examples/Benchmark/Benchmark.ino

+19-16
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ ESPDash dashboard(&server);
4242
Card generic(&dashboard, GENERIC_CARD, "Generic");
4343
Card temp(&dashboard, TEMPERATURE_CARD, "Temperature", "°C");
4444
Card hum(&dashboard, HUMIDITY_CARD, "Humidity", "%");
45-
Card status1(&dashboard, STATUS_CARD, "Status 1", "success");
46-
Card status2(&dashboard, STATUS_CARD, "Status 2", "warning");
47-
Card status3(&dashboard, STATUS_CARD, "Status 3", "danger");
48-
Card status4(&dashboard, STATUS_CARD, "Status 4", "idle");
45+
Card status1(&dashboard, STATUS_CARD, "Status 1", DASH_STATUS_SUCCESS);
46+
Card status2(&dashboard, STATUS_CARD, "Status 2", DASH_STATUS_WARNING);
47+
Card status3(&dashboard, STATUS_CARD, "Status 3", DASH_STATUS_DANGER);
48+
Card status4(&dashboard, STATUS_CARD, "Status 4", DASH_STATUS_IDLE);
4949
Card progress(&dashboard, PROGRESS_CARD, "Progress", "", 0, 100);
5050
Card button(&dashboard, BUTTON_CARD, "Test Button");
5151
Card slider(&dashboard, SLIDER_CARD, "Test Slider", "", 0, 255);
@@ -61,14 +61,17 @@ void setup() {
6161
Serial.begin(115200);
6262

6363
/* Connect WiFi */
64-
WiFi.mode(WIFI_STA);
65-
WiFi.begin(ssid, password);
66-
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
67-
Serial.printf("WiFi Failed!\n");
68-
return;
69-
}
70-
Serial.print("IP Address: ");
71-
Serial.println(WiFi.localIP());
64+
// WiFi.mode(WIFI_STA);
65+
// WiFi.begin(ssid, password);
66+
// if (WiFi.waitForConnectResult() != WL_CONNECTED) {
67+
// Serial.printf("WiFi Failed!\n");
68+
// return;
69+
// }
70+
// Serial.print("IP Address: ");
71+
// Serial.println(WiFi.localIP());
72+
73+
WiFi.mode(WIFI_AP);
74+
WiFi.softAP("esp-captive");
7275

7376
bar.updateX(XAxis, 7);
7477

@@ -107,10 +110,10 @@ void loop() {
107110
generic.update((int)random(0, 100));
108111
temp.update((int)random(0, 100));
109112
hum.update((int)random(0, 100));
110-
status1.update(DASH_STATUS_SUCCESS);
111-
status2.update(DASH_STATUS_WARNING);
112-
status3.update(DASH_STATUS_DANGER);
113-
status4.update(DASH_STATUS_IDLE);
113+
status1.update("message 1", DASH_STATUS_SUCCESS);
114+
status2.update("message 2", DASH_STATUS_WARNING);
115+
status3.update("message 3", DASH_STATUS_DANGER);
116+
status4.update("message 4", DASH_STATUS_IDLE);
114117
progress.update((int)random(0, 100));
115118

116119
dashboard.sendUpdates();

examples/Benchmark5/Benchmark5.ino

+200
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
/*
2+
-----------------------------
3+
ESPDASH Pro - Benchmark Example
4+
-----------------------------
5+
Use this benchmark example to test if ESP-DASH Pro is working properly on your platform.
6+
7+
Github: https://github.com/ayushsharma82/ESP-DASH
8+
WiKi: https://docs.espdash.pro
9+
10+
Works with both ESP8266 & ESP32
11+
-------------------------------
12+
*/
13+
14+
#include <Arduino.h>
15+
#if defined(ESP8266)
16+
/* ESP8266 Dependencies */
17+
#include <ESP8266WiFi.h>
18+
#include <ESPAsyncTCP.h>
19+
#include <ESPAsyncWebServer.h>
20+
#elif defined(ESP32)
21+
/* ESP32 Dependencies */
22+
#include <AsyncTCP.h>
23+
#include <ESPAsyncWebServer.h>
24+
#include <WiFi.h>
25+
#endif
26+
27+
#include <ESPDash.h>
28+
29+
/* Your WiFi Credentials */
30+
const char* ssid = ""; // SSID
31+
const char* password = ""; // Password
32+
33+
/* Start Webserver */
34+
AsyncWebServer server(80);
35+
36+
/* Attach ESP-DASH to AsyncWebServer */
37+
ESPDash dashboard(server, true);
38+
39+
// Cards
40+
dash::FeedbackCard feedback(dashboard, "Status", dash::Status::SUCCESS);
41+
dash::GenericCard genericString(dashboard, "Generic String");
42+
dash::GenericCard<float> genericFloat(dashboard, "Generic Float");
43+
dash::GenericCard<int> genericInt(dashboard, "Generic Int");
44+
dash::HumidityCard<float, 3> hum(dashboard, "Humidity"); // set decimal precision is 3
45+
dash::ProgressCard<float, 4> progressFloat(dashboard, "Progress Float", 0, 1, "kWh");
46+
dash::ProgressCard progressInt(dashboard, "Progress Int", 0, 100, "%");
47+
dash::SliderCard<float, 4> sliderFloatP4(dashboard, "Float Slider (4)", 0, 1, 0.0001f);
48+
dash::SliderCard<float> sliderFloatP2(dashboard, "Float Slider (2)", 0, 1, 0.01f);
49+
dash::SliderCard sliderInt(dashboard, "Int Slider", 0, 255, 1, "bits");
50+
dash::SliderCard<uint32_t> updateDelay(dashboard, "Update Delay", 1000, 20000, 1000, "ms");
51+
dash::SwitchCard button(dashboard, "Button");
52+
dash::TemperatureCard temp(dashboard, "Temperature"); // default precision is 2
53+
54+
// Charts
55+
dash::BarChart<const char*, int> bar(dashboard, "Power Usage (kWh)");
56+
57+
// Custom Statistics
58+
dash::StatisticValue stat1(dashboard, "Statistic 1");
59+
dash::StatisticValue<float, 4> stat2(dashboard, "Statistic 2");
60+
dash::StatisticProvider<uint32_t> statProvider(dashboard, "Statistic Provider");
61+
62+
uint8_t test_status = 0;
63+
64+
/**
65+
* Note how we are keeping all the chart data in global scope.
66+
*/
67+
// Bar Chart Data
68+
const char* BarXAxis[] = {"1/4/22", "2/4/22", "3/4/22", "4/4/22", "5/4/22", "6/4/22", "7/4/22", "8/4/22", "9/4/22", "10/4/22", "11/4/22", "12/4/22", "13/4/22", "14/4/22", "15/4/22", "16/4/22", "17/4/22", "18/4/22", "19/4/22", "20/4/22", "21/4/22", "22/4/22", "23/4/22", "24/4/22", "25/4/22", "26/4/22", "27/4/22", "28/4/22", "29/4/22", "30/4/22"};
69+
int BarYAxis[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
70+
71+
unsigned long last_update_millis = 0;
72+
uint32_t update_delay = 2000;
73+
74+
void setup() {
75+
Serial.begin(115200);
76+
Serial.println();
77+
/* Connect WiFi */
78+
79+
// WiFi.persistent(false);
80+
// WiFi.mode(WIFI_STA);
81+
// WiFi.begin(ssid, password);
82+
// while (WiFi.status() != WL_CONNECTED) {
83+
// delay(500);
84+
// Serial.print(".");
85+
// }
86+
// Serial.print("IP Address: ");
87+
// Serial.println(WiFi.localIP());
88+
89+
WiFi.mode(WIFI_AP);
90+
WiFi.softAP("esp-captive");
91+
92+
/* Attach Button Callback */
93+
button.onChange([&](bool state) {
94+
/* Print our new button value received from dashboard */
95+
Serial.println(String("Button Triggered: ") + (state ? "true" : "false"));
96+
/* Make sure we update our button's value and send update to dashboard */
97+
button.setValue(state);
98+
dashboard.refresh(button);
99+
});
100+
101+
// Set Slider Index
102+
sliderInt.setIndex(1);
103+
104+
/* Attach Slider Callback */
105+
sliderInt.onChange([&](int value) {
106+
/* Print our new slider value received from dashboard */
107+
Serial.println("Slider Triggered: " + String(value));
108+
/* Make sure we update our slider's value and send update to dashboard */
109+
sliderInt.setValue(value);
110+
dashboard.refresh(sliderInt);
111+
});
112+
113+
sliderFloatP2.setIndex(2);
114+
sliderFloatP2.onChange([&](float value) {
115+
Serial.println("Slider Float P2 Triggered: " + String(value));
116+
sliderFloatP2.setValue(value);
117+
dashboard.refresh(sliderFloatP2);
118+
});
119+
120+
sliderFloatP4.setIndex(3);
121+
sliderFloatP4.onChange([&](float value) {
122+
Serial.println("Slider Float P4 Triggered: " + String(value, 4));
123+
sliderFloatP4.setValue(value);
124+
dashboard.refresh(sliderFloatP4);
125+
});
126+
127+
updateDelay.setValue(update_delay);
128+
updateDelay.onChange([&](uint32_t value) {
129+
update_delay = value;
130+
updateDelay.setValue(value);
131+
dashboard.refresh(updateDelay);
132+
});
133+
134+
stat1.setValue("Value 1");
135+
stat2.setValue(10.0 / 3.0);
136+
statProvider.setProvider([]() { return millis(); });
137+
138+
bar.setX(BarXAxis, 30);
139+
140+
genericFloat.setValue(10.0 / 3.0); // default rounding is 2
141+
genericString.setValue("Hello World!");
142+
143+
/* Start AsyncWebServer */
144+
server.begin();
145+
146+
server.onNotFound([](AsyncWebServerRequest* request) {
147+
request->send(404);
148+
});
149+
}
150+
151+
void loop() {
152+
// Update Everything every 2 seconds using millis if connected to WiFi
153+
if (millis() - last_update_millis > update_delay && dashboard.hasClient()) {
154+
last_update_millis = millis();
155+
156+
// Randomize Bar Chart YAxis Values ( for demonstration purposes only )
157+
for (int i = 0; i < 30; i++) {
158+
BarYAxis[i] = (int)random(0, 200);
159+
}
160+
161+
/* Update Chart Y Axis (yaxis_array, array_size) */
162+
bar.setY(BarYAxis, 30);
163+
164+
// Update all cards with random values
165+
genericInt.setSymbol(random(0, 2) ? "unit1" : "unit2");
166+
genericInt.setValue((int)random(0, 100));
167+
temp.setValue(random(0, 100) / 3.0);
168+
hum.setValue(random(0, 100) / 3.0);
169+
170+
progressInt.setValue(random(0, 200)); // if more than max, clamped to max
171+
progressFloat.setValue(random(0, 1000) / 2000.0); // if more than max, clamped to max
172+
173+
sliderInt.setValue(random(0, 200)); // clamped at 255 by max
174+
sliderFloatP2.setValue(random(0, 100) / 333.0);
175+
sliderFloatP4.setValue(random(0, 100) / 333.0);
176+
177+
// Loop through statuses
178+
if (test_status == 0) {
179+
feedback.setFeedback("Success Msg!", dash::Status::SUCCESS);
180+
test_status = 1;
181+
} else if (test_status == 1) {
182+
feedback.setFeedback("Warning Msg!", dash::Status::WARNING);
183+
test_status = 2;
184+
} else if (test_status == 2) {
185+
feedback.setFeedback("Danger Msg!", dash::Status::DANGER);
186+
test_status = 3;
187+
} else if (test_status == 3) {
188+
feedback.setFeedback("Idle Msg!", dash::Status::IDLE);
189+
test_status = 0;
190+
}
191+
192+
if (random(0, 2))
193+
button.toggle();
194+
195+
// Get Free Heap
196+
Serial.println("Free Heap (Before Update): " + String(ESP.getFreeHeap()));
197+
dashboard.sendUpdates();
198+
Serial.println("Free Heap (After Update): " + String(ESP.getFreeHeap()));
199+
}
200+
}

platformio.ini

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
lib_dir = .
33
; src_dir = examples/AccessPoint
44
; src_dir = examples/Basic
5-
src_dir = examples/Benchmark
5+
; src_dir = examples/Benchmark
6+
src_dir = examples/Benchmark5
67
; src_dir = examples/Chart
78
; src_dir = examples/Dynamic
89
; src_dir = examples/Interactive
910

1011
[env]
1112
framework = arduino
1213
build_flags =
14+
-std=c++17
15+
-std=gnu++17
1316
-Wall -Wextra
1417
-D CONFIG_ARDUHAL_LOG_COLORS
1518
-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
1619
; -D DASH_USE_LEGACY_CHART_STORAGE=1
1720
; -D DASH_USE_STL_STRING=1
21+
; -D DASH_DEBUG
22+
build_unflags =
23+
-std=gnu++11
1824
lib_deps =
1925
bblanchon/ArduinoJson@^7.2.1
2026
mathieucarbou/ESPAsyncWebServer@^3.3.23
@@ -28,8 +34,8 @@ board = esp32-s3-devkitc-1
2834

2935
[env:arduino-3]
3036
platform = https://github.com/pioarduino/platform-espressif32/releases/download/53.03.10-rc1/platform-espressif32.zip
31-
board = esp32-s3-devkitc-1
32-
; board = esp32dev
37+
; board = esp32-s3-devkitc-1
38+
board = esp32dev
3339

3440
[env:esp8266]
3541
platform = espressif8266

0 commit comments

Comments
 (0)