Skip to content

Commit

Permalink
ESP-DASH v5
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Dec 3, 2024
1 parent edd847e commit d3b6616
Show file tree
Hide file tree
Showing 21 changed files with 2,031 additions and 1,034 deletions.
22 changes: 22 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Language: Cpp
BasedOnStyle: LLVM

AccessModifierOffset: -2
AlignConsecutiveMacros: true
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLambdasOnASingleLine: Inline
BinPackArguments: false
ColumnLimit: 0
ContinuationIndentWidth: 2
FixNamespaceComments: false
IndentAccessModifiers: true
IndentCaseLabels: true
IndentPPDirectives: BeforeHash
IndentWidth: 2
NamespaceIndentation: All
PointerAlignment: Left
ReferenceAlignment: Left
TabWidth: 2
UseTab: Never
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ jobs:
- name: Build Benchmark
run: arduino-cli compile --library . --warnings none -b ${{ matrix.board }} "examples/Benchmark/Benchmark.ino"

- name: Build Benchmark5
run: arduino-cli compile --library . --warnings none -b ${{ matrix.board }} "examples/Benchmark5/Benchmark5.ino"

- name: Build Chart
run: arduino-cli compile --library . --warnings none -b ${{ matrix.board }} "examples/Chart/Chart.ino"

Expand Down Expand Up @@ -154,6 +157,7 @@ jobs:
- run: PLATFORMIO_SRC_DIR=examples/AccessPoint PIO_BOARD=${{ matrix.board }} pio run -e ${{ matrix.env }}
- run: PLATFORMIO_SRC_DIR=examples/Basic PIO_BOARD=${{ matrix.board }} pio run -e ${{ matrix.env }}
- run: PLATFORMIO_SRC_DIR=examples/Benchmark PIO_BOARD=${{ matrix.board }} pio run -e ${{ matrix.env }}
- run: PLATFORMIO_SRC_DIR=examples/Benchmark5 PIO_BOARD=${{ matrix.board }} pio run -e ${{ matrix.env }}
- run: PLATFORMIO_SRC_DIR=examples/Chart PIO_BOARD=${{ matrix.board }} pio run -e ${{ matrix.env }}
- run: PLATFORMIO_SRC_DIR=examples/Dynamic PIO_BOARD=${{ matrix.board }} pio run -e ${{ matrix.env }}
- run: PLATFORMIO_SRC_DIR=examples/Interactive PIO_BOARD=${{ matrix.board }} pio run -e ${{ matrix.env }}
35 changes: 19 additions & 16 deletions examples/Benchmark/Benchmark.ino
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ ESPDash dashboard(&server);
Card generic(&dashboard, GENERIC_CARD, "Generic");
Card temp(&dashboard, TEMPERATURE_CARD, "Temperature", "°C");
Card hum(&dashboard, HUMIDITY_CARD, "Humidity", "%");
Card status1(&dashboard, STATUS_CARD, "Status 1", "success");
Card status2(&dashboard, STATUS_CARD, "Status 2", "warning");
Card status3(&dashboard, STATUS_CARD, "Status 3", "danger");
Card status4(&dashboard, STATUS_CARD, "Status 4", "idle");
Card status1(&dashboard, STATUS_CARD, "Status 1", DASH_STATUS_SUCCESS);
Card status2(&dashboard, STATUS_CARD, "Status 2", DASH_STATUS_WARNING);
Card status3(&dashboard, STATUS_CARD, "Status 3", DASH_STATUS_DANGER);
Card status4(&dashboard, STATUS_CARD, "Status 4", DASH_STATUS_IDLE);
Card progress(&dashboard, PROGRESS_CARD, "Progress", "", 0, 100);
Card button(&dashboard, BUTTON_CARD, "Test Button");
Card slider(&dashboard, SLIDER_CARD, "Test Slider", "", 0, 255);
Expand All @@ -61,14 +61,17 @@ void setup() {
Serial.begin(115200);

/* Connect WiFi */
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.printf("WiFi Failed!\n");
return;
}
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
// WiFi.mode(WIFI_STA);
// WiFi.begin(ssid, password);
// if (WiFi.waitForConnectResult() != WL_CONNECTED) {
// Serial.printf("WiFi Failed!\n");
// return;
// }
// Serial.print("IP Address: ");
// Serial.println(WiFi.localIP());

WiFi.mode(WIFI_AP);
WiFi.softAP("esp-captive");

bar.updateX(XAxis, 7);

Expand Down Expand Up @@ -107,10 +110,10 @@ void loop() {
generic.update((int)random(0, 100));
temp.update((int)random(0, 100));
hum.update((int)random(0, 100));
status1.update(DASH_STATUS_SUCCESS);
status2.update(DASH_STATUS_WARNING);
status3.update(DASH_STATUS_DANGER);
status4.update(DASH_STATUS_IDLE);
status1.update("message 1", DASH_STATUS_SUCCESS);
status2.update("message 2", DASH_STATUS_WARNING);
status3.update("message 3", DASH_STATUS_DANGER);
status4.update("message 4", DASH_STATUS_IDLE);
progress.update((int)random(0, 100));

dashboard.sendUpdates();
Expand Down
200 changes: 200 additions & 0 deletions examples/Benchmark5/Benchmark5.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
/*
-----------------------------
ESPDASH Pro - Benchmark Example
-----------------------------
Use this benchmark example to test if ESP-DASH Pro is working properly on your platform.
Github: https://github.com/ayushsharma82/ESP-DASH
WiKi: https://docs.espdash.pro
Works with both ESP8266 & ESP32
-------------------------------
*/

#include <Arduino.h>
#if defined(ESP8266)
/* ESP8266 Dependencies */
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#elif defined(ESP32)
/* ESP32 Dependencies */
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <WiFi.h>
#endif

#include <ESPDash.h>

/* Your WiFi Credentials */
const char* ssid = ""; // SSID
const char* password = ""; // Password

/* Start Webserver */
AsyncWebServer server(80);

/* Attach ESP-DASH to AsyncWebServer */
ESPDash dashboard(server, true);

// Cards
dash::FeedbackCard feedback(dashboard, "Status", dash::Status::SUCCESS);
dash::GenericCard genericString(dashboard, "Generic String");
dash::GenericCard<float> genericFloat(dashboard, "Generic Float");
dash::GenericCard<int> genericInt(dashboard, "Generic Int");
dash::HumidityCard<float, 3> hum(dashboard, "Humidity"); // set decimal precision is 3
dash::ProgressCard<float, 4> progressFloat(dashboard, "Progress Float", 0, 1, "kWh");
dash::ProgressCard progressInt(dashboard, "Progress Int", 0, 100, "%");
dash::SliderCard<float, 4> sliderFloatP4(dashboard, "Float Slider (4)", 0, 1, 0.0001f);
dash::SliderCard<float> sliderFloatP2(dashboard, "Float Slider (2)", 0, 1, 0.01f);
dash::SliderCard sliderInt(dashboard, "Int Slider", 0, 255, 1, "bits");
dash::SliderCard<uint32_t> updateDelay(dashboard, "Update Delay", 1000, 20000, 1000, "ms");
dash::SwitchCard button(dashboard, "Button");
dash::TemperatureCard temp(dashboard, "Temperature"); // default precision is 2

// Charts
dash::BarChart<const char*, int> bar(dashboard, "Power Usage (kWh)");

// Custom Statistics
dash::StatisticValue stat1(dashboard, "Statistic 1");
dash::StatisticValue<float, 4> stat2(dashboard, "Statistic 2");
dash::StatisticProvider<uint32_t> statProvider(dashboard, "Statistic Provider");

uint8_t test_status = 0;

/**
* Note how we are keeping all the chart data in global scope.
*/
// Bar Chart Data
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"};
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};

unsigned long last_update_millis = 0;
uint32_t update_delay = 2000;

void setup() {
Serial.begin(115200);
Serial.println();
/* Connect WiFi */

// WiFi.persistent(false);
// WiFi.mode(WIFI_STA);
// WiFi.begin(ssid, password);
// while (WiFi.status() != WL_CONNECTED) {
// delay(500);
// Serial.print(".");
// }
// Serial.print("IP Address: ");
// Serial.println(WiFi.localIP());

WiFi.mode(WIFI_AP);
WiFi.softAP("esp-captive");

/* Attach Button Callback */
button.onChange([&](bool state) {
/* Print our new button value received from dashboard */
Serial.println(String("Button Triggered: ") + (state ? "true" : "false"));
/* Make sure we update our button's value and send update to dashboard */
button.setValue(state);
dashboard.refresh(button);
});

// Set Slider Index
sliderInt.setIndex(1);

/* Attach Slider Callback */
sliderInt.onChange([&](int value) {
/* Print our new slider value received from dashboard */
Serial.println("Slider Triggered: " + String(value));
/* Make sure we update our slider's value and send update to dashboard */
sliderInt.setValue(value);
dashboard.refresh(sliderInt);
});

sliderFloatP2.setIndex(2);
sliderFloatP2.onChange([&](float value) {
Serial.println("Slider Float P2 Triggered: " + String(value));
sliderFloatP2.setValue(value);
dashboard.refresh(sliderFloatP2);
});

sliderFloatP4.setIndex(3);
sliderFloatP4.onChange([&](float value) {
Serial.println("Slider Float P4 Triggered: " + String(value, 4));
sliderFloatP4.setValue(value);
dashboard.refresh(sliderFloatP4);
});

updateDelay.setValue(update_delay);
updateDelay.onChange([&](uint32_t value) {
update_delay = value;
updateDelay.setValue(value);
dashboard.refresh(updateDelay);
});

stat1.setValue("Value 1");
stat2.setValue(10.0 / 3.0);
statProvider.setProvider([]() { return millis(); });

bar.setX(BarXAxis, 30);

genericFloat.setValue(10.0 / 3.0); // default rounding is 2
genericString.setValue("Hello World!");

/* Start AsyncWebServer */
server.begin();

server.onNotFound([](AsyncWebServerRequest* request) {
request->send(404);
});
}

void loop() {
// Update Everything every 2 seconds using millis if connected to WiFi
if (millis() - last_update_millis > update_delay && dashboard.hasClient()) {
last_update_millis = millis();

// Randomize Bar Chart YAxis Values ( for demonstration purposes only )
for (int i = 0; i < 30; i++) {
BarYAxis[i] = (int)random(0, 200);
}

/* Update Chart Y Axis (yaxis_array, array_size) */
bar.setY(BarYAxis, 30);

// Update all cards with random values
genericInt.setSymbol(random(0, 2) ? "unit1" : "unit2");
genericInt.setValue((int)random(0, 100));
temp.setValue(random(0, 100) / 3.0);
hum.setValue(random(0, 100) / 3.0);

progressInt.setValue(random(0, 200)); // if more than max, clamped to max
progressFloat.setValue(random(0, 1000) / 2000.0); // if more than max, clamped to max

sliderInt.setValue(random(0, 200)); // clamped at 255 by max
sliderFloatP2.setValue(random(0, 100) / 333.0);
sliderFloatP4.setValue(random(0, 100) / 333.0);

// Loop through statuses
if (test_status == 0) {
feedback.setFeedback("Success Msg!", dash::Status::SUCCESS);
test_status = 1;
} else if (test_status == 1) {
feedback.setFeedback("Warning Msg!", dash::Status::WARNING);
test_status = 2;
} else if (test_status == 2) {
feedback.setFeedback("Danger Msg!", dash::Status::DANGER);
test_status = 3;
} else if (test_status == 3) {
feedback.setFeedback("Idle Msg!", dash::Status::IDLE);
test_status = 0;
}

if (random(0, 2))
button.toggle();

// Get Free Heap
Serial.println("Free Heap (Before Update): " + String(ESP.getFreeHeap()));
dashboard.sendUpdates();
Serial.println("Free Heap (After Update): " + String(ESP.getFreeHeap()));
}
}
12 changes: 9 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@
lib_dir = .
; src_dir = examples/AccessPoint
; src_dir = examples/Basic
src_dir = examples/Benchmark
; src_dir = examples/Benchmark
src_dir = examples/Benchmark5
; src_dir = examples/Chart
; src_dir = examples/Dynamic
; src_dir = examples/Interactive

[env]
framework = arduino
build_flags =
-std=c++17
-std=gnu++17
-Wall -Wextra
-D CONFIG_ARDUHAL_LOG_COLORS
-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
; -D DASH_USE_LEGACY_CHART_STORAGE=1
; -D DASH_USE_STL_STRING=1
; -D DASH_DEBUG
build_unflags =
-std=gnu++11
lib_deps =
bblanchon/ArduinoJson@^7.2.1
mathieucarbou/ESPAsyncWebServer@^3.3.23
Expand All @@ -28,8 +34,8 @@ board = esp32-s3-devkitc-1

[env:arduino-3]
platform = https://github.com/pioarduino/platform-espressif32/releases/download/53.03.10-rc1/platform-espressif32.zip
board = esp32-s3-devkitc-1
; board = esp32dev
; board = esp32-s3-devkitc-1
board = esp32dev

[env:esp8266]
platform = espressif8266
Expand Down
Loading

0 comments on commit d3b6616

Please sign in to comment.