diff --git a/platformio.ini b/platformio.ini index f3ceccf..3d3923f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -20,3 +20,17 @@ lib_deps = tobiasschuerg/ESP8266 Influxdb@^3.13.1 upload_port = COM3 monitor_speed = 115200 + +[env:esp32-s2-saola-1] +platform = espressif32 +board = esp32-s2-saola-1 +framework = arduino +lib_deps = + Wire + Adafruit INA219 + ESP Async WebServer + ArduinoJson + tobiasschuerg/ESP8266 Influxdb@^3.13.1 +; any port that starts with /dev/ttyUSB +#upload_port = /dev/ttyUSB* +monitor_speed = 115200 \ No newline at end of file diff --git a/src/Config.h b/src/Config.h index 988d48f..676c092 100644 --- a/src/Config.h +++ b/src/Config.h @@ -10,7 +10,11 @@ const char* INFLUXDB_ORG = "48cec24009273b5e"; const char* INFLUXDB_BUCKET = "bucket-digitalisierung"; // Other configurations +// #define RELAY_PIN 2 +// #define SECOND_RELAY_PIN 15 #define RELAY_PIN 2 -#define SECOND_RELAY_PIN 15 +#define SECOND_RELAY_PIN 1 +#define THIRD_RELAY_PIN 4 +#define FOURTH_RELAY_PIN 3 #endif // CONFIG_H diff --git a/src/WebServerModule.h b/src/WebServerModule.h index 3fccf5b..955ca54 100644 --- a/src/WebServerModule.h +++ b/src/WebServerModule.h @@ -9,13 +9,17 @@ class WebServerModule { public: - WebServerModule(INA219Module& inaModule, int relayPin, int secondRelayPin); + WebServerModule(INA219Module& inaModule, int relayPin, int secondRelayPin, int thirdRelayPin, int fourthRelayPin); void begin(); bool getRelayState() const; bool getSecondRelayState() const; + bool getThirdRelayState() const; + bool getFourthRelayState() const; void handleToggleState(bool state); void handleSecondToggleState(bool state); + void handleThirdToggleState(bool state); + void handleFourthToggleState(bool state); private: INA219Module& _inaModule; @@ -23,13 +27,19 @@ private: bool relayState; bool secondRelayState; + bool thirdrelayState; + bool fourthRelayState; int _relayPin; int _secondRelayPin; + int _thirdrelayPin; + int _fourthRelayPin; void handleRoot(AsyncWebServerRequest *request); void handleValues(AsyncWebServerRequest *request); void handleToggle(AsyncWebServerRequest *request); void handleSecondToggle(AsyncWebServerRequest *request); + void handleThirdToggle(AsyncWebServerRequest *request); + void handleFourthToggle(AsyncWebServerRequest *request); }; #endif diff --git a/src/WebserverModule.cpp b/src/WebserverModule.cpp index 8cc7a4d..d24612a 100644 --- a/src/WebserverModule.cpp +++ b/src/WebserverModule.cpp @@ -1,82 +1,114 @@ // WebServerModule.cpp #include "WebServerModule.h" -WebServerModule::WebServerModule(INA219Module& inaModule, int relayPin, int secondRelayPin) - : _inaModule(inaModule), _server(80), _relayPin(relayPin), _secondRelayPin(secondRelayPin), relayState(false), secondRelayState(false) {} +WebServerModule::WebServerModule(INA219Module& inaModule, int relayPin, int secondRelayPin, int thirdRelayPin, int fourthRelayPin) + : _inaModule(inaModule), _server(80), _relayPin(relayPin), _secondRelayPin(secondRelayPin), + _thirdrelayPin(thirdRelayPin), _fourthRelayPin(fourthRelayPin), relayState(false), secondRelayState(false), + thirdrelayState(false), fourthRelayState(false) {} void WebServerModule::begin() { - // Konfiguriere die Pins für die Relais als Ausgänge + // Configure pins for relays as outputs pinMode(_relayPin, OUTPUT); pinMode(_secondRelayPin, OUTPUT); + pinMode(_thirdrelayPin, OUTPUT); + pinMode(_fourthRelayPin, OUTPUT); - // Konfiguriere die Server-Endpunkte + // Configure server endpoints _server.on("/", HTTP_GET, std::bind(&WebServerModule::handleRoot, this, std::placeholders::_1)); _server.on("/values", HTTP_GET, std::bind(&WebServerModule::handleValues, this, std::placeholders::_1)); _server.on("/toggle1", HTTP_GET, std::bind(&WebServerModule::handleToggle, this, std::placeholders::_1)); _server.on("/toggle2", HTTP_GET, std::bind(&WebServerModule::handleSecondToggle, this, std::placeholders::_1)); + _server.on("/toggle3", HTTP_GET, std::bind(&WebServerModule::handleThirdToggle, this, std::placeholders::_1)); + _server.on("/toggle4", HTTP_GET, std::bind(&WebServerModule::handleFourthToggle, this, std::placeholders::_1)); _server.begin(); } void WebServerModule::handleRoot(AsyncWebServerRequest *request) { String html = "
"; + html += "Strom: A
"; html += "Spannung: V
"; html += "Leistung: W
"; html += "Durchschnittliche Leistung: W
"; html += "Gesamtenergie: Wh
"; - // JavaScript-Code für die Werteaktualisierung und Schaltersteuerung + // JavaScript-Code für die Werteaktualisierung und Schaltersteuerung (unchanged) html += ""; - // Schalter 1 (K1) + // Schalter 1 (K1) to Schalter 4 (K4) (unchanged) html += "