| <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}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/ArduinoJson/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/Adafruit_NeoPixel}""/> | |||||
| </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/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}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/ArduinoJson/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/Adafruit_NeoPixel}""/> | |||||
| </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/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}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/ArduinoJson/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/Adafruit_NeoPixel}""/> | |||||
| </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/Adafruit_NeoPixel</name> | |||||
| <type>2</type> | |||||
| <locationURI>ECLIPSE_HOME/arduinoPlugin/libraries/Adafruit_NeoPixel/1.15.5</locationURI> | |||||
| </link> | |||||
| <link> | <link> | ||||
| <name>libraries/ArduinoJson</name> | <name>libraries/ArduinoJson</name> | ||||
| <type>2</type> | <type>2</type> |
| <project> | <project> | ||||
| <configuration id="io.sloeber.core.sketch.0" name="Release"> | <configuration id="io.sloeber.core.sketch.0" name="Release"> | ||||
| <extension point="org.eclipse.cdt.core.LanguageSettingsProvider"> | <extension point="org.eclipse.cdt.core.LanguageSettingsProvider"> | ||||
| <provider class="io.sloeber.core.toolchain.ArduinoLanguageProvider" console="false" env-hash="-1642491514133985484" id="io.sloeber.languageSettingsProvider" keep-relative-paths="false" name="Arduino Compiler Settings" parameter="${COMMAND} -E -P -v -dD -D__IN_ECLIPSE__ "${INPUTS}"" prefer-non-shared="true"> | |||||
| <provider class="io.sloeber.core.toolchain.ArduinoLanguageProvider" console="false" env-hash="-1662652105763046092" id="io.sloeber.languageSettingsProvider" keep-relative-paths="false" name="Arduino Compiler Settings" parameter="${COMMAND} -E -P -v -dD -D__IN_ECLIPSE__ "${INPUTS}"" prefer-non-shared="true"> | |||||
| <language-scope id="org.eclipse.cdt.core.gcc"/> | <language-scope id="org.eclipse.cdt.core.gcc"/> | ||||
| <language-scope id="org.eclipse.cdt.core.g++"/> | <language-scope id="org.eclipse.cdt.core.g++"/> | ||||
| </provider> | </provider> |
| Config.Release.board.BOARD.ID=d1 | Config.Release.board.BOARD.ID=d1 | ||||
| Config.Release.board.BOARD.MENU.baud=921600 | Config.Release.board.BOARD.MENU.baud=921600 | ||||
| Config.Release.board.BOARD.MENU.dbg=Disabled | |||||
| Config.Release.board.BOARD.MENU.eesz=4M2M | |||||
| Config.Release.board.BOARD.MENU.dbg=Serial1 | |||||
| Config.Release.board.BOARD.MENU.eesz=4M3M | |||||
| Config.Release.board.BOARD.MENU.exception=disabled | Config.Release.board.BOARD.MENU.exception=disabled | ||||
| Config.Release.board.BOARD.MENU.ip=lm2f | Config.Release.board.BOARD.MENU.ip=lm2f | ||||
| Config.Release.board.BOARD.MENU.lvl=None____ | Config.Release.board.BOARD.MENU.lvl=None____ | ||||
| Config.Release.board.BOARD.MENU.mmu=3232 | |||||
| Config.Release.board.BOARD.MENU.non32xfer=fast | |||||
| Config.Release.board.BOARD.MENU.ssl=all | |||||
| Config.Release.board.BOARD.MENU.mmu=4816 | |||||
| Config.Release.board.BOARD.MENU.non32xfer=safe | |||||
| Config.Release.board.BOARD.MENU.ssl=basic | |||||
| Config.Release.board.BOARD.MENU.stacksmash=disabled | Config.Release.board.BOARD.MENU.stacksmash=disabled | ||||
| Config.Release.board.BOARD.MENU.vt=flash | |||||
| Config.Release.board.BOARD.MENU.vt=iram | |||||
| Config.Release.board.BOARD.MENU.wipe=none | Config.Release.board.BOARD.MENU.wipe=none | ||||
| Config.Release.board.BOARD.MENU.xtal=80 | Config.Release.board.BOARD.MENU.xtal=80 | ||||
| Config.Release.board.BOARD.TXT=${SLOEBER_HOME}/arduinoPlugin/packages/esp8266/hardware/esp8266/3.1.2/boards.txt | Config.Release.board.BOARD.TXT=${SLOEBER_HOME}/arduinoPlugin/packages/esp8266/hardware/esp8266/3.1.2/boards.txt |
| #include <WebSocketsServer.h> | #include <WebSocketsServer.h> | ||||
| #include <EEPROM.h> | #include <EEPROM.h> | ||||
| #include <DNSServer.h> | #include <DNSServer.h> | ||||
| #include <ArduinoJson.h> | |||||
| #include <Adafruit_Neopixel.h> | |||||
| #include "States.h" | #include "States.h" | ||||
| #include "Commands.h" | #include "Commands.h" | ||||
| #include "HtmlPages.h" | #include "HtmlPages.h" | ||||
| #include <ArduinoJson.h> | |||||
| #include "LEDStripManager.h" | |||||
| AppState state = STATE_BOOT; | AppState state = STATE_BOOT; | ||||
| unsigned long connectStart = 0; | |||||
| #define LED_COUNT 12 // Nbr of LEDs on stripe TODO: move to eeprom, configurable over wifi | |||||
| const int ledPin = LED_BUILTIN; // The built-in LED on the Wemos D1 Mini is on GPIO2 (D4) | |||||
| unsigned long connectStart = 0; | |||||
| const byte DNS_PORT = 53; | const byte DNS_PORT = 53; | ||||
| // AP Daten | |||||
| const char *ap_ssid = "Wemos_Setup"; | |||||
| const char *ap_pass = "admin123"; | |||||
| // WLAN Config | // WLAN Config | ||||
| struct Config { | struct Config { | ||||
| char ssid[32]; | char ssid[32]; | ||||
| bool valid; | bool valid; | ||||
| }; | }; | ||||
| // AP Daten | |||||
| const char *ap_ssid = "Wemos_Setup"; | |||||
| const char *ap_pass = "admin123"; | |||||
| ESP8266WebServer webServer(80); | ESP8266WebServer webServer(80); | ||||
| WebSocketsServer webSocket(81); | WebSocketsServer webSocket(81); | ||||
| DNSServer dnsServer; | DNSServer dnsServer; | ||||
| LEDStripManager ledMngr(LED_COUNT, LED_STRIP_DATA_PIN); | |||||
| Config config; | Config config; | ||||
| // ---------- EEPROM ---------- | // ---------- EEPROM ---------- | ||||
| //TODO: move to onw class | |||||
| void saveConfig() { | void saveConfig() { | ||||
| EEPROM.begin(sizeof(Config)); | EEPROM.begin(sizeof(Config)); | ||||
| EEPROM.put(0, config); | EEPROM.put(0, config); | ||||
| IPAddress ip = webSocket.remoteIP(num); | IPAddress ip = webSocket.remoteIP(num); | ||||
| Serial.printf("WS Client %u verbunden von %d.%d.%d.%d\n", num, ip[0], ip[1], ip[2], ip[3]); | Serial.printf("WS Client %u verbunden von %d.%d.%d.%d\n", num, ip[0], ip[1], ip[2], ip[3]); | ||||
| webSocket.sendTXT(num, "Connected"); | webSocket.sendTXT(num, "Connected"); | ||||
| if (digitalRead(LED_STRIP_POWER_PIN) == HIGH) { | |||||
| webSocket.sendTXT(num, "LED ON"); | |||||
| } else { | |||||
| webSocket.sendTXT(num, "LED OFF"); | |||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| const char *value = doc["val"]; | const char *value = doc["val"]; | ||||
| if (strcmp(value, "on") == 0) { | if (strcmp(value, "on") == 0) { | ||||
| digitalWrite(ledPin, LOW); | |||||
| delay(10); | |||||
| if (digitalRead(ledPin) == LOW) { | |||||
| Serial.println("LED ON"); | |||||
| ledMngr.on(); | |||||
| delay(20); | |||||
| if (digitalRead(LED_STRIP_POWER_PIN) == HIGH) { | |||||
| webSocket.sendTXT(num, "LED ON"); | webSocket.sendTXT(num, "LED ON"); | ||||
| } | } | ||||
| } else if (strcmp(value, "off") == 0) { | } else if (strcmp(value, "off") == 0) { | ||||
| digitalWrite(ledPin, HIGH); | |||||
| delay(10); | |||||
| if (digitalRead(ledPin) == HIGH) { | |||||
| Serial.println("LED OFF"); | |||||
| ledMngr.off(); | |||||
| delay(20); | |||||
| if (digitalRead(LED_STRIP_POWER_PIN) == LOW) { | |||||
| webSocket.sendTXT(num, "LED OFF"); | webSocket.sendTXT(num, "LED OFF"); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void handleError() { | void handleError() { | ||||
| digitalWrite(ledPin, LOW); | |||||
| ledMngr.off(); | |||||
| } | } | ||||
| void startSTAWebServer() { | void startSTAWebServer() { | ||||
| // ---------- SETUP ---------- | // ---------- SETUP ---------- | ||||
| void setup() { | void setup() { | ||||
| Serial.begin(115200); | Serial.begin(115200); | ||||
| pinMode(ledPin, OUTPUT); | |||||
| digitalWrite(ledPin, HIGH); // LED zunächst AUS | |||||
| ledMngr.begin(); | |||||
| loadConfig(); | loadConfig(); | ||||
| /* | |||||
| * LEDStripManager.cpp | |||||
| * | |||||
| * Created on: 19.06.2026 | |||||
| * Author: FSmilari | |||||
| */ | |||||
| #include "LEDStripManager.h" | |||||
| /* | |||||
| * Constructor | |||||
| */ | |||||
| LEDStripManager::LEDStripManager(uint16_t numLeds, uint8_t pin) : strip(numLeds, pin, NEO_GRBW + NEO_KHZ800) { | |||||
| } | |||||
| /* | |||||
| * Destructor | |||||
| */ | |||||
| LEDStripManager::~LEDStripManager() { | |||||
| } | |||||
| void LEDStripManager::begin() { | |||||
| pinMode(LED_STRIP_POWER_PIN, OUTPUT); | |||||
| pinMode(LED_STRIP_DATA_PIN, OUTPUT); | |||||
| digitalWrite(LED_STRIP_POWER_PIN, HIGH); // LED zunächst EIN | |||||
| strip.begin(); // Initialisiert den NeoPixel-Streifen | |||||
| strip.clear(); | |||||
| strip.show(); // Setzt alle LEDs auf "aus" | |||||
| strip.setBrightness(255); // Helligkeit (0 bis 255) | |||||
| // Setzt die erste LED (Index 0) auf rotes Licht (Rot, Grün, Blau, Weiss) | |||||
| strip.setPixelColor(0, strip.Color(255, 0, 0, 0)); | |||||
| // Setzt die zweite LED auf grün | |||||
| strip.setPixelColor(1, strip.Color(0, 255, 0, 0)); | |||||
| strip.setPixelColor(2, strip.Color(0, 0, 255, 0)); | |||||
| strip.setPixelColor(3, strip.Color(0, 0, 0, 255)); | |||||
| // Schickt die Farbinformationen zum LED-Streifen | |||||
| show(); | |||||
| } | |||||
| void LEDStripManager::clear() { | |||||
| strip.clear(); | |||||
| } | |||||
| void LEDStripManager::show() { | |||||
| strip.show(); | |||||
| } | |||||
| void LEDStripManager::on() { | |||||
| Serial.println("LEDStripManager LED ON"); | |||||
| digitalWrite(LED_STRIP_POWER_PIN, HIGH); | |||||
| delay(50); | |||||
| digitalWrite(LED_STRIP_DATA_PIN, HIGH); | |||||
| delay(50); | |||||
| strip.begin(); | |||||
| strip.show(); | |||||
| // TODO: Load the state from the eeprom | |||||
| strip.setPixelColor(0, strip.Color(255, 0, 0, 0)); | |||||
| strip.setPixelColor(1, strip.Color(0, 255, 0, 0)); | |||||
| strip.setPixelColor(2, strip.Color(0, 0, 255, 0)); | |||||
| strip.setPixelColor(3, strip.Color(0, 0, 0, 255)); | |||||
| strip.show(); | |||||
| } | |||||
| void LEDStripManager::off() { | |||||
| Serial.println("LEDStripManager LED OFF"); | |||||
| clear(); | |||||
| show(); | |||||
| delay(50); | |||||
| digitalWrite(LED_STRIP_POWER_PIN, LOW); // LED zunächst AUS | |||||
| digitalWrite(LED_STRIP_DATA_PIN, LOW); | |||||
| } | |||||
| void LEDStripManager::setBrightness(uint8_t brightness) { | |||||
| strip.setBrightness(brightness); | |||||
| } | |||||
| void LEDStripManager::setPixel(uint16_t index, uint8_t red, uint8_t green, uint8_t blue) { | |||||
| if (index >= strip.numPixels()) { | |||||
| return; | |||||
| } | |||||
| strip.setPixelColor(index, strip.Color(red, green, blue)); | |||||
| } | |||||
| void LEDStripManager::setAll(uint8_t red, uint8_t green, uint8_t blue) { | |||||
| for (uint16_t i = 0; i < strip.numPixels(); i++) { | |||||
| strip.setPixelColor(i, strip.Color(red, green, blue)); | |||||
| } | |||||
| strip.show(); | |||||
| } | |||||
| uint32_t | |||||
| LEDStripManager::wheel(uint8_t pos) { | |||||
| pos = 255 - pos; | |||||
| if (pos < 85) { | |||||
| return strip.Color(255 - pos * 3, 0, pos * 3); | |||||
| } | |||||
| if (pos < 170) { | |||||
| pos -= 85; | |||||
| return strip.Color(0, pos * 3, 255 - pos * 3); | |||||
| } | |||||
| pos -= 170; | |||||
| return strip.Color(pos * 3, 255 - pos * 3, 0); | |||||
| } | |||||
| void LEDStripManager::rainbow(uint8_t wait) { | |||||
| for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256) { | |||||
| for (uint16_t i = 0; i < strip.numPixels(); i++) { | |||||
| uint32_t pixelHue = firstPixelHue + (i * 65536L / strip.numPixels()); | |||||
| strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue))); | |||||
| } | |||||
| strip.show(); | |||||
| delay(wait); | |||||
| } | |||||
| } | |||||
| #ifndef LEDSTRIPEMANAGER_H | |||||
| #define LEDSTRIPEMANAGER_H | |||||
| #include "Arduino.h" | |||||
| #include <Adafruit_NeoPixel.h> | |||||
| const int LED_STRIP_POWER_PIN = D2; // The pin to switch on / off the LED stripe | |||||
| const int LED_STRIP_DATA_PIN = D8; // The pin to switch control the LED stripe | |||||
| class LEDStripManager { | |||||
| public: | |||||
| LEDStripManager(uint16_t numLeds, uint8_t pin); | |||||
| virtual ~LEDStripManager(); | |||||
| void begin(); | |||||
| void clear(); | |||||
| void show(); | |||||
| void on(); | |||||
| void off(); | |||||
| void setBrightness(uint8_t brightness); | |||||
| void setPixel(uint16_t index, uint8_t red, uint8_t green, uint8_t blue); | |||||
| void setAll(uint8_t red, uint8_t green, uint8_t blue); | |||||
| void rainbow(uint8_t wait); | |||||
| private: | |||||
| Adafruit_NeoPixel strip; | |||||
| uint32_t wheel(uint8_t pos); | |||||
| }; | |||||
| #endif | |||||
| //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 22:24:35 | |||||
| //This file has been generated on 2026-06-19 21:07:33 | |||||
| #include "Arduino.h" | #include "Arduino.h" | ||||
| #include "Arduino.h" | #include "Arduino.h" | ||||
| #include <WebSocketsServer.h> | #include <WebSocketsServer.h> | ||||
| #include <EEPROM.h> | #include <EEPROM.h> | ||||
| #include <DNSServer.h> | #include <DNSServer.h> | ||||
| #include <ArduinoJson.h> | |||||
| #include <Adafruit_Neopixel.h> | |||||
| #include "States.h" | #include "States.h" | ||||
| #include "Commands.h" | #include "Commands.h" | ||||
| #include "HtmlPages.h" | #include "HtmlPages.h" | ||||
| #include <ArduinoJson.h> | |||||
| #include "LEDStripManager.h" | |||||
| void saveConfig() ; | void saveConfig() ; | ||||
| void loadConfig() ; | void loadConfig() ; |