| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/WebSockets/src}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/WebSockets/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/Hash/src}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/Hash/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/ESP8266WiFi/src}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/ESP8266WiFi/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/ArduinoJson/src}""/> | |||||
| </option> | </option> | ||||
| <inputType id="io.sloeber.compiler.cpp.sketch.input.1770649762" name="CPP source files" superClass="io.sloeber.compiler.cpp.sketch.input"/> | <inputType id="io.sloeber.compiler.cpp.sketch.input.1770649762" name="CPP source files" superClass="io.sloeber.compiler.cpp.sketch.input"/> | ||||
| </tool> | </tool> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/WebSockets/src}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/WebSockets/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/Hash/src}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/Hash/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/ESP8266WiFi/src}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/ESP8266WiFi/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/ArduinoJson/src}""/> | |||||
| </option> | </option> | ||||
| <inputType id="io.sloeber.compiler.c.sketch.input.1705705" name="C Source Files" superClass="io.sloeber.compiler.c.sketch.input"/> | <inputType id="io.sloeber.compiler.c.sketch.input.1705705" name="C Source Files" superClass="io.sloeber.compiler.c.sketch.input"/> | ||||
| </tool> | </tool> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/WebSockets/src}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/WebSockets/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/Hash/src}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/Hash/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/ESP8266WiFi/src}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/ESP8266WiFi/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/ArduinoJson/src}""/> | |||||
| </option> | </option> | ||||
| <inputType id="io.sloeber.compiler.S.sketch.input.1190005390" name="Assembly source files" superClass="io.sloeber.compiler.S.sketch.input"/> | <inputType id="io.sloeber.compiler.S.sketch.input.1190005390" name="Assembly source files" superClass="io.sloeber.compiler.S.sketch.input"/> | ||||
| </tool> | </tool> |
| <type>2</type> | <type>2</type> | ||||
| <locationURI>ECLIPSE_HOME/arduinoPlugin/packages/esp8266/hardware/esp8266/3.1.2/variants/d1</locationURI> | <locationURI>ECLIPSE_HOME/arduinoPlugin/packages/esp8266/hardware/esp8266/3.1.2/variants/d1</locationURI> | ||||
| </link> | </link> | ||||
| <link> | |||||
| <name>libraries/ArduinoJson</name> | |||||
| <type>2</type> | |||||
| <locationURI>ECLIPSE_HOME/arduinoPlugin/libraries/ArduinoJson/7.0.2</locationURI> | |||||
| </link> | |||||
| <link> | <link> | ||||
| <name>libraries/DNSServer</name> | <name>libraries/DNSServer</name> | ||||
| <type>2</type> | <type>2</type> |
| /* | |||||
| * Commands.h | |||||
| * | |||||
| * Created on: 09.06.2026 | |||||
| * Author: FSmilari | |||||
| */ | |||||
| #ifndef COMMANDS_H_ | |||||
| #define COMMANDS_H_ | |||||
| enum Commands { | |||||
| CMD_UNKNOWN = -1, | |||||
| CMD_CHG_MODE, | |||||
| CMD_SWITCH_LED, | |||||
| CMD_CHG_COLOR, | |||||
| CMD_CHG_BRIGHTNESS, | |||||
| CMD_RESET_WIFI_CFG | |||||
| }; | |||||
| const char* cmdToString(Commands cmd) { | |||||
| switch (cmd) { | |||||
| case CMD_CHG_MODE: | |||||
| return "CHG_MODE"; | |||||
| case CMD_SWITCH_LED: | |||||
| return "SWITCH_LED"; | |||||
| case CMD_CHG_COLOR: | |||||
| return "CHG_COLOR"; | |||||
| case CMD_CHG_BRIGHTNESS: | |||||
| return "CHG_BRIGHTNESS"; | |||||
| case CMD_RESET_WIFI_CFG: | |||||
| return "RESET_WIFI_CFG"; | |||||
| default: | |||||
| return "UNKNOWN"; | |||||
| } | |||||
| } | |||||
| Commands strToCommand(const char *cmd) { | |||||
| if (cmd == nullptr) { | |||||
| return CMD_UNKNOWN; | |||||
| } | |||||
| if (strcmp(cmd, "CHG_MODE") == 0) | |||||
| return CMD_CHG_MODE; | |||||
| if (strcmp(cmd, "SWITCH_LED") == 0) | |||||
| return CMD_SWITCH_LED; | |||||
| if (strcmp(cmd, "CHG_COLOR") == 0) | |||||
| return CMD_CHG_COLOR; | |||||
| if (strcmp(cmd, "CHG_BRIGHTNESS") == 0) | |||||
| return CMD_CHG_BRIGHTNESS; | |||||
| if (strcmp(cmd, "RESET_WIFI_CFG") == 0) | |||||
| return CMD_RESET_WIFI_CFG; | |||||
| return CMD_UNKNOWN; | |||||
| } | |||||
| #endif /* COMMANDS_H_ */ |
| function ledOn() { | function ledOn() { | ||||
| if (ws && ws.readyState === 1) { | if (ws && ws.readyState === 1) { | ||||
| ws.send("/ledOn"); | |||||
| ws.send("{\"cmd\":\"SWITCH_LED\",\"val\":\"on\"}"); | |||||
| } | } | ||||
| } | } | ||||
| function ledOff() { | function ledOff() { | ||||
| if (ws && ws.readyState === 1) { | if (ws && ws.readyState === 1) { | ||||
| ws.send("/ledOff"); | |||||
| ws.send("{\"cmd\":\"SWITCH_LED\",\"val\":\"off\"}"); | |||||
| } | } | ||||
| } | } | ||||
| function resetWifiCfg() { | function resetWifiCfg() { | ||||
| if (ws && ws.readyState === 1) { | if (ws && ws.readyState === 1) { | ||||
| ws.send("/resetWifiCfg"); | |||||
| ws.send("{\"cmd\":\"RESET_WIFI_CFG\",\"val\":\"\"}"); | |||||
| } | } | ||||
| } | } | ||||
| #include <EEPROM.h> | #include <EEPROM.h> | ||||
| #include <DNSServer.h> | #include <DNSServer.h> | ||||
| #include "States.h" | #include "States.h" | ||||
| #include "Commands.h" | |||||
| #include "HtmlPages.h" | #include "HtmlPages.h" | ||||
| #include <ArduinoJson.h> | |||||
| AppState state = STATE_BOOT; | AppState state = STATE_BOOT; | ||||
| unsigned long connectStart = 0; | unsigned long connectStart = 0; | ||||
| Serial.print("WS empfangen: "); | Serial.print("WS empfangen: "); | ||||
| Serial.println(msg); | Serial.println(msg); | ||||
| if (msg == "/ledOn") { | |||||
| digitalWrite(ledPin, LOW); | |||||
| delay(10); | |||||
| if (digitalRead(ledPin) == LOW) { | |||||
| webSocket.sendTXT(num, "LED ON"); | |||||
| JsonDocument doc; | |||||
| deserializeJson(doc, msg); | |||||
| const char *cmd = doc["cmd"]; | |||||
| if (strToCommand(cmd) == CMD_SWITCH_LED) { | |||||
| const char *value = doc["val"]; | |||||
| if (strcmp(value, "on") == 0) { | |||||
| digitalWrite(ledPin, LOW); | |||||
| delay(10); | |||||
| if (digitalRead(ledPin) == LOW) { | |||||
| webSocket.sendTXT(num, "LED ON"); | |||||
| } | |||||
| } else if (strcmp(value, "off") == 0) { | |||||
| digitalWrite(ledPin, HIGH); | |||||
| delay(10); | |||||
| if (digitalRead(ledPin) == HIGH) { | |||||
| webSocket.sendTXT(num, "LED OFF"); | |||||
| } | |||||
| } | } | ||||
| } else if (msg == "/ledOff") { | |||||
| digitalWrite(ledPin, HIGH); | |||||
| delay(10); | |||||
| if (digitalRead(ledPin) == HIGH) { | |||||
| webSocket.sendTXT(num, "LED OFF"); | |||||
| } | |||||
| } else if (msg == "/resetWifiCfg") { | |||||
| } else if (strToCommand(cmd) == CMD_RESET_WIFI_CFG) { | |||||
| resetWifiConfiguration(num); | resetWifiConfiguration(num); | ||||
| } else { | } else { | ||||
| String s = "ACK: " + msg; | |||||
| String s = "ACK UNKNOWN: " + msg; | |||||
| webSocket.sendTXT(num, s); | webSocket.sendTXT(num, s); | ||||
| } | } | ||||
| //This is a automatic generated file | //This is a automatic generated file | ||||
| //Please do not modify this file | //Please do not modify this file | ||||
| //If you touch this file your change will be overwritten during the next build | //If you touch this file your change will be overwritten during the next build | ||||
| //This file has been generated on 2026-06-09 21:27:43 | |||||
| //This file has been generated on 2026-06-09 22:24:35 | |||||
| #include "Arduino.h" | #include "Arduino.h" | ||||
| #include "Arduino.h" | #include "Arduino.h" | ||||
| #include <EEPROM.h> | #include <EEPROM.h> | ||||
| #include <DNSServer.h> | #include <DNSServer.h> | ||||
| #include "States.h" | #include "States.h" | ||||
| #include "Commands.h" | |||||
| #include "HtmlPages.h" | #include "HtmlPages.h" | ||||
| #include <ArduinoJson.h> | |||||
| void saveConfig() ; | void saveConfig() ; | ||||
| void loadConfig() ; | void loadConfig() ; |