Skip to content

Commit

Permalink
Display widgets based on application
Browse files Browse the repository at this point in the history
  • Loading branch information
Lillifee committed Nov 27, 2020
1 parent efb9f85 commit 04109da
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 56 deletions.
134 changes: 84 additions & 50 deletions data/bundle.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions lib/WebServerHelper/WebServerHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ void WebServerHelperClass::start() {
}
});

WebServerHelper.server.on("/api/application", HTTP_GET, [this](AsyncWebServerRequest *request) {
AsyncJsonResponse *response = new AsyncJsonResponse();
response->addHeader("Server", "ESP Async Web Server");

JsonVariant &root = response->getRoot();
root["application"] = application;

response->setLength();
request->send(response);
});

server.on("/api/esp", HTTP_GET, [this](AsyncWebServerRequest *request) {
AsyncJsonResponse *response = new AsyncJsonResponse();
response->addHeader("Server", "ESP Async Web Server");
Expand Down
1 change: 1 addition & 0 deletions lib/WebServerHelper/WebServerHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class WebServerHelperClass {
void uploadFile(int command, AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);

public:
String application;
AsyncWebServer server;
WebServerHelperClass();
void start();
Expand Down
4 changes: 3 additions & 1 deletion lib/WiFiHelper/WiFiHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void WiFiHelperClass::sleep() {
esp_wifi_stop();
}

void WiFiHelperClass::server() {
void WiFiHelperClass::server(String application) {
Serial.println("Setup WiFi helper");

if (WiFiHelper.connect(true)) {
Expand All @@ -125,6 +125,8 @@ void WiFiHelperClass::server() {
WiFiHelper.setupAP();
}

WebServerHelper.application = application;

WebServerHelper.server.on("/api/wifi", HTTP_GET, [this](AsyncWebServerRequest *request) {
int args = request->args();

Expand Down
2 changes: 1 addition & 1 deletion lib/WiFiHelper/WiFiHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class WiFiHelperClass {

public:
void setup();
void server();
void server(String application);
bool connect(bool firstConnect = false);
void sleep();
};
Expand Down
2 changes: 1 addition & 1 deletion src/co2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void setup() {
Serial.begin(115200);

WiFiHelper.setup();
WiFiHelper.server();
WiFiHelper.server("co2");

Co2Helper.setup();
Co2Helper.server();
Expand Down
2 changes: 1 addition & 1 deletion src/cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void setup() {
if (wakeupReason == ESP_SLEEP_WAKEUP_UNDEFINED) {
pinMode(LED_BUILTIN, OUTPUT);

WiFiHelper.server();
WiFiHelper.server("cube");
MpuHelper.server();

WebServerHelper.onSleep(deepSleep);
Expand Down
2 changes: 1 addition & 1 deletion src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void setup() {
if (wakeupReason == ESP_SLEEP_WAKEUP_UNDEFINED) {
pinMode(LED_BUILTIN, OUTPUT);

WiFiHelper.server();
WiFiHelper.server("display");
WaveshareHelper.server();

WebServerHelper.onSleep(deepSleep);
Expand Down
2 changes: 1 addition & 1 deletion src/knob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void setup() {
wakeupReason = esp_sleep_get_wakeup_cause();

if (wakeupReason == ESP_SLEEP_WAKEUP_UNDEFINED) {
WiFiHelper.server();
WiFiHelper.server("knob");
KnobHelper.server();

WebServerHelper.onSleep(deepSleep);
Expand Down

0 comments on commit 04109da

Please sign in to comment.