Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP-DASH v5 #246

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 12 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ jobs:
core: esp32:esp32
board: esp32:esp32:esp32
index_url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
- name: package_esp32_dev_index.json
core: esp32:esp32
board: esp32:esp32:esp32
index_url: https://espressif.github.io/arduino-esp32/package_esp32_dev_index.json
# Disabled due to an error coming from the package file:
# Error during install: Cannot install tool esp32:esp32-arduino-libs@idf-release_v5.3-a0f798cf: testing local archive integrity: testing archive checksum: archive hash differs from hash in index
# - name: package_esp32_dev_index.json
# core: esp32:esp32
# board: esp32:esp32:esp32
# index_url: https://espressif.github.io/arduino-esp32/package_esp32_dev_index.json
- name: package_esp8266com_index.json
core: esp8266:esp8266
board: esp8266:esp8266:huzzah
Expand Down Expand Up @@ -62,10 +64,10 @@ jobs:
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/esphome-ESPAsyncTCP#v2.0.0

- name: Install ESPAsyncWebServer
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/ESPAsyncWebServer#v3.3.14
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/ESPAsyncWebServer#v3.3.23

- name: Install ArduinoJson
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/bblanchon/ArduinoJson#v7.1.0
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/bblanchon/ArduinoJson#v7.2.1

- name: Build AccessPoint
run: arduino-cli compile --library . --warnings none -b ${{ matrix.board }} "examples/AccessPoint/AccessPoint.ino"
Expand All @@ -76,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 @@ -152,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 }}
37 changes: 20 additions & 17 deletions examples/Benchmark/Benchmark.ino
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,36 @@ 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);

Chart bar(&dashboard, BAR_CHART, "Power Usage (kWh)");

// Bar Chart Data
String XAxis[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
dash::string XAxis[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
int YAxis[] = {0, 0, 0, 0, 0, 0, 0};


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("success");
status2.update("warning");
status3.update("danger");
status4.update("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()));
}
}
4 changes: 2 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
{
"owner": "bblanchon",
"name": "ArduinoJson",
"version": "^7.1.0",
"version": "^7.2.1",
"platforms": ["espressif8266", "espressif32"]
},
{
"owner": "mathieucarbou",
"name": "ESPAsyncWebServer",
"version": "^3.3.14",
"version": "^3.3.23",
"platforms": ["espressif8266", "espressif32"]
}
]
Expand Down
17 changes: 13 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@
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.1.0
mathieucarbou/ESPAsyncWebServer@^3.3.14
bblanchon/ArduinoJson@^7.2.1
mathieucarbou/ESPAsyncWebServer@^3.3.23
upload_protocol = esptool
monitor_speed = 115200
monitor_filters = esp32_exception_decoder, log2file
Expand All @@ -26,7 +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 = esp32-s3-devkitc-1
board = esp32dev

[env:esp8266]
platform = espressif8266
Expand Down
Loading
Loading