├── .DS_Store ├── .gitattributes ├── .theia └── launch.json ├── .vscode ├── arduino.json ├── c_cpp_properties.json └── settings.json ├── BambulabLedController.ino ├── LICENSE ├── README.md ├── build ├── .DS_Store ├── esp8266.esp8266.d1_mini │ └── .DS_Store ├── firmware │ ├── blledcontroller_v095.bin │ ├── blledcontroller_v100.bin │ ├── blledcontroller_v101.bin │ ├── blledcontroller_v102.bin │ ├── blledcontroller_v103.bin │ ├── blledcontroller_v104.bin │ ├── blledcontroller_v105.bin │ └── blledcontroller_v106.bin └── manifest.json ├── eeprom_utils.cpp ├── eeprom_utils.h ├── html.h ├── led_utils.cpp ├── led_utils.h └── variables.h /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DutchDevelop/BambulabLedController/130f0924acb4f01b7e8e9aaf05902d26e4033da6/.DS_Store -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.theia/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | "version": "0.2.0", 5 | "configurations": [ 6 | 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /.vscode/arduino.json: -------------------------------------------------------------------------------- 1 | { 2 | "configuration": "xtal=80,vt=flash,exception=disabled,stacksmash=disabled,ssl=all,mmu=3232,non32xfer=fast,eesz=4M2M,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=921600", 3 | "board": "esp8266:esp8266:d1_mini" 4 | } -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Win32", 5 | "includePath": [ 6 | "${workspaceFolder}/**", 7 | "C:\\Users\\DutchDeveloper\\AppData\\Local\\Arduino15\\**", 8 | "C:\\Users\\DutchDeveloper\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\3.1.1\\libraries\\**", 9 | "C:\\Users\\DutchDeveloper\\AppData\\Local\\Arduino15\\staging\\libraries\\**", 10 | "C:\\Users\\DutchDeveloper\\Documents\\Arduino\\libraries\\**" 11 | ], 12 | "defines": [ 13 | "_DEBUG", 14 | "UNICODE", 15 | "_UNICODE" 16 | ], 17 | "compilerPath": "C:\\Strawberry\\c\\bin\\gcc.exe", 18 | "cStandard": "c17", 19 | "cppStandard": "gnu++14", 20 | "intelliSenseMode": "windows-gcc-x64" 21 | } 22 | ], 23 | "version": 4 24 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp.errorSquiggles": "disabled", 3 | "files.associations": { 4 | "string": "cpp", 5 | "*.tcc": "cpp", 6 | "optional": "cpp", 7 | "istream": "cpp", 8 | "ostream": "cpp", 9 | "ratio": "cpp", 10 | "system_error": "cpp", 11 | "array": "cpp", 12 | "functional": "cpp", 13 | "regex": "cpp", 14 | "tuple": "cpp", 15 | "type_traits": "cpp", 16 | "utility": "cpp", 17 | "variant": "cpp" 18 | } 19 | } -------------------------------------------------------------------------------- /BambulabLedController.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "eeprom_utils.h" 10 | #include "led_utils.h" 11 | #include "variables.h" 12 | #include "html.h" 13 | 14 | const char* wifiname = "Bambulab Led controller"; 15 | const char* setuppage = html_setuppage; 16 | const char* finishedpage = html_finishpage; 17 | 18 | char Printerip[Max_ipLength+1] = ""; 19 | char Printercode[Max_accessCode+1] = ""; 20 | char PrinterID[Max_DeviceId+1] = ""; 21 | char EspPassword[Max_EspPassword+1] = ""; 22 | char DeviceName[20]; 23 | 24 | int CurrentStage = -1; 25 | bool hasHMSerror = false; 26 | bool ledstate = false; 27 | unsigned long finishstartms; 28 | unsigned long lastmqttconnectionattempt; 29 | 30 | ESP8266WebServer server(80); 31 | IPAddress apIP(192, 168, 1, 1); 32 | 33 | WiFiClientSecure WiFiClient; 34 | WiFiManager wifiManager; 35 | PubSubClient mqttClient(WiFiClient); 36 | 37 | char* generateRandomString(int length) { 38 | static const char charset[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 39 | int charsetLength = strlen(charset); 40 | 41 | char* randomString = new char[length + 1]; 42 | for (int i = 0; i < length; i++) { 43 | int randomIndex = random(0, charsetLength); 44 | randomString[i] = charset[randomIndex]; 45 | } 46 | randomString[length] = '\0'; 47 | 48 | return randomString; 49 | } 50 | 51 | void handleLed(){ //Function to handle ledstatus eg if the X1C has an error then make the ledstrip red, or when its scanning turn off the light until its starts printing 52 | if (ledstate == 1){ 53 | if (CurrentStage == 6 || CurrentStage == 17 || CurrentStage == 20 || CurrentStage == 21 || hasHMSerror){ 54 | setLedColor(255,0,0,0,0); 55 | return; 56 | }; 57 | if (finishstartms > 0 && millis() - finishstartms <= 300000){ 58 | setLedColor(0,255,0,0,0); 59 | return; 60 | }else if(millis() - finishstartms > 300000){ 61 | finishstartms; 62 | } 63 | if (CurrentStage == 0 || CurrentStage == -1 || CurrentStage == 2){ 64 | setLedColor(0,0,0,255,255); 65 | return; 66 | }; 67 | if (CurrentStage == 14 || CurrentStage == 9){ 68 | setLedColor(0,0,0,0,0); 69 | return; 70 | }; 71 | }else{ 72 | setLedColor(0,0,0,0,0); 73 | }; 74 | } 75 | 76 | void replaceSubstring(char* string, const char* substring, const char* newSubstring) { 77 | char* substringStart = strstr(string, substring); 78 | if (substringStart) { 79 | char* substringEnd = substringStart + strlen(substring); 80 | memmove(substringStart + strlen(newSubstring), substringEnd, strlen(substringEnd) + 1); 81 | memcpy(substringStart, newSubstring, strlen(newSubstring)); 82 | } 83 | } 84 | 85 | void handleSetTemperature() { 86 | if (!server.hasArg("api_key")) { 87 | return server.send(400, "text/plain", "Missing API key parameter."); 88 | }; 89 | char shortened_key[7]; 90 | strncpy(shortened_key, EspPassword, 7); 91 | shortened_key[7] = '\0'; 92 | char received_api_key[8]; 93 | 94 | server.arg("api_key").toCharArray(received_api_key, 8); 95 | if (!strcmp(received_api_key, shortened_key) == 0) { 96 | return server.send(401, "text/plain", "Unauthorized access."); 97 | } 98 | char mqttTopic[50]; 99 | strcpy(mqttTopic, "device/"); 100 | strcat(mqttTopic, PrinterID); 101 | strcat(mqttTopic, "/request"); 102 | if (server.hasArg("bedtemp")) { 103 | float bedtemp = server.arg("bedtemp").toFloat(); 104 | String message = "{\"print\":{\"sequence_id\":\"2026\",\"command\":\"gcode_line\",\"param\":\"M140 S" + String(bedtemp) + "\\n\"}}"; 105 | mqttClient.publish(mqttTopic, message.c_str()); 106 | } 107 | if (server.hasArg("nozzletemp")) { 108 | float bedtemp = server.arg("nozzletemp").toFloat(); 109 | String message = "{\"print\":{\"sequence_id\":\"2026\",\"command\":\"gcode_line\",\"param\":\"M104 S" + String(bedtemp) + "\\n\"}}"; 110 | mqttClient.publish(mqttTopic, message.c_str()); 111 | } 112 | return server.send(200, "text/plain", "Ok"); 113 | } 114 | 115 | void handleSetupRoot() { //Function to handle the setuppage 116 | if (!server.authenticate("BLLC", EspPassword)) { 117 | return server.requestAuthentication(); 118 | } 119 | replaceSubstring((char*)setuppage, "ipinputvalue", Printerip); 120 | replaceSubstring((char*)setuppage, "idinputvalue", PrinterID); 121 | replaceSubstring((char*)setuppage, "codeinputvalue", Printercode); 122 | server.send(200, "text/html", setuppage); 123 | } 124 | 125 | void SetupWebpage(){ //Function to start webpage system 126 | Serial.println(F("Starting Web server")); 127 | server.on("/", handleSetupRoot); 128 | server.on("/setupmqtt", savemqttdata); 129 | // server.on("/settemp", handleSetTemperature); 130 | server.begin(); 131 | Serial.println(F("Web server started")); 132 | } 133 | 134 | void savemqttdata() { 135 | char iparg[Max_ipLength + 1]; 136 | char codearg[Max_accessCode + 1]; 137 | char idarg[Max_DeviceId + 1]; 138 | 139 | // Copy the arguments from server to char arrays 140 | server.arg("ip").toCharArray(iparg, Max_ipLength + 1); 141 | server.arg("code").toCharArray(codearg, Max_accessCode + 1); 142 | server.arg("id").toCharArray(idarg, Max_DeviceId + 1); 143 | 144 | if (strlen(iparg) == 0 || strlen(codearg) == 0 || strlen(idarg) == 0) { 145 | return handleSetupRoot(); 146 | } 147 | 148 | server.send(200, "text/html", finishedpage); 149 | 150 | Serial.println(F("Printer IP:")); 151 | Serial.println(iparg); 152 | Serial.println(F("Printer Code:")); 153 | Serial.println(codearg); 154 | Serial.println(F("Printer Id:")); 155 | Serial.println(idarg); 156 | 157 | writeToEEPROM(iparg, codearg, idarg, EspPassword); 158 | delay(1000); //wait for page to load 159 | ESP.restart(); 160 | } 161 | 162 | 163 | void PrinterCallback(char* topic, byte* payload, unsigned int length){ //Function to handle the MQTT Data from the mqtt broker 164 | Serial.print(F("Message arrived in topic: ")); 165 | Serial.println(topic); 166 | Serial.print(F("Message Length: ")); 167 | Serial.println(length); 168 | Serial.print(F("Message:")); 169 | 170 | StaticJsonDocument<10000> doc; 171 | DeserializationError error = deserializeJson(doc, payload, length); 172 | 173 | if (error) { 174 | Serial.print(F("deserializeJson() failed: ")); 175 | Serial.println(error.c_str()); 176 | return; 177 | } 178 | 179 | if (!doc.containsKey("print")) { 180 | return; 181 | } 182 | 183 | Serial.println(F("===== JSON Data =====")); 184 | serializeJsonPretty(doc, Serial); 185 | Serial.println(F("======================")); 186 | 187 | if (doc["print"].containsKey("stg_cur")){ 188 | CurrentStage = doc["print"]["stg_cur"]; 189 | } 190 | 191 | Serial.print(F("stg_cur: ")); 192 | Serial.println(CurrentStage); 193 | 194 | if (doc["print"].containsKey("gcode_state")){ 195 | if (doc["print"]["gcode_state"] == "FINISH" && finishstartms <= 0){ 196 | finishstartms = millis(); 197 | }else if (doc["print"]["gcode_state"] != "FINISH" && finishstartms > 0){ 198 | finishstartms = 0; 199 | } 200 | } 201 | 202 | if (doc["print"].containsKey("hms")){ 203 | hasHMSerror = false; 204 | for (const auto& hms : doc["print"]["hms"].as()) { 205 | if (hms["code"] == 131073) { 206 | hasHMSerror = true; 207 | }; 208 | } 209 | } 210 | 211 | Serial.print(F("HMS error: ")); 212 | Serial.println(hasHMSerror); 213 | 214 | if (doc["print"].containsKey("lights_report")) { 215 | if (doc["print"]["lights_report"][0]["node"] == "chamber_light"){ 216 | ledstate = doc["print"]["lights_report"][0]["mode"] == "on"; 217 | Serial.print("Ledchanged: "); 218 | Serial.println(ledstate); 219 | } 220 | } 221 | 222 | Serial.print(F("cur_led: ")); 223 | Serial.println(ledstate); 224 | 225 | 226 | Serial.println(F(" - - - - - - - - - - - -")); 227 | 228 | handleLed(); 229 | } 230 | 231 | void setup() { // Setup function 232 | Serial.begin(115200); 233 | EEPROM.begin(512); 234 | 235 | //clearEEPROM(); 236 | 237 | setPins(0,0,0,0,0); 238 | 239 | WiFiClient.setInsecure(); 240 | mqttClient.setBufferSize(10000); 241 | 242 | if (wifiManager.getWiFiIsSaved()) wifiManager.setEnableConfigPortal(false); 243 | wifiManager.autoConnect(wifiname); 244 | 245 | WiFi.hostname("bambuledcontroller"); 246 | 247 | if (WiFi.status() != WL_CONNECTED) { 248 | Serial.println(F("Failed to connect to WiFi, creating access point...")); 249 | wifiManager.setAPCallback([](WiFiManager* mgr) { 250 | Serial.println(F("Access point created, connect to:")); 251 | Serial.print(mgr->getConfigPortalSSID()); 252 | }); 253 | wifiManager.setConfigPortalTimeout(300); 254 | wifiManager.startConfigPortal(wifiname); 255 | } 256 | 257 | while (WiFi.status() != WL_CONNECTED) { 258 | delay(10); 259 | Serial.println(F("Connecting to Wi-Fi...")); 260 | } 261 | 262 | readFromEEPROM(Printerip,Printercode,PrinterID,EspPassword); 263 | 264 | if (strchr(EspPassword, '#') == NULL) { //Isue with eeprom giving �, so adding a # to check if the eeprom is empty or not 265 | Serial.println(F("No Password has been set, Resetting")); 266 | memset(EspPassword, 0, Max_EspPassword); 267 | memset(Printercode, '_', Max_accessCode); 268 | memset(PrinterID, '_', Max_DeviceId); 269 | memset(Printerip, '_', Max_ipLength); 270 | char* newEspPassword = generateRandomString(Max_EspPassword-1); 271 | strcat(newEspPassword, "#"); 272 | strcat(EspPassword, newEspPassword); 273 | writeToEEPROM(Printerip, Printercode, PrinterID, EspPassword); 274 | readFromEEPROM(Printerip,Printercode,PrinterID,EspPassword); //This will auto clear the eeprom 275 | }; 276 | 277 | Serial.print(F("Connected to WiFi, IP address: ")); 278 | Serial.println(WiFi.localIP()); 279 | Serial.println(F("-------------------------------------")); 280 | Serial.print(F("Head over to http://")); 281 | Serial.println(WiFi.localIP()); 282 | Serial.print(F("Login Details User: BLLC, Password: ")); 283 | Serial.println(String(EspPassword)); 284 | Serial.println(F(" To configure the mqtt settings.")); 285 | Serial.println(F("-------------------------------------")); 286 | 287 | SetupWebpage(); 288 | 289 | strcpy(DeviceName, "ESP8266MQTT"); 290 | char* randomString = generateRandomString(4); 291 | strcat(DeviceName, randomString); 292 | 293 | mqttClient.setServer(Printerip, 8883); 294 | mqttClient.setCallback(PrinterCallback); 295 | } 296 | 297 | void loop() { //Loop function 298 | server.handleClient(); 299 | if (WiFi.status() != WL_CONNECTED){ 300 | Serial.println(F("Connection lost! Reconnecting...")); 301 | //wifiManager.autoConnect(wifiname); 302 | //Serial.println(F("Connected to WiFi!")); 303 | ESP.restart(); 304 | } 305 | if (WiFi.status() == WL_CONNECTED && strlen(Printerip) > 0 && (lastmqttconnectionattempt <= 0 || millis() - lastmqttconnectionattempt >= 10000)){ 306 | if (!mqttClient.connected()) { 307 | 308 | Serial.print(F("Connecting with device name:")); 309 | Serial.println(DeviceName); 310 | Serial.println(F("Connecting to mqtt")); 311 | 312 | if (mqttClient.connect(DeviceName, "bblp", Printercode)){ 313 | Serial.println(F("Connected to MQTT")); 314 | setLedColor(0,0,0,0,0); //Turn off led printer might be offline 315 | char mqttTopic[50]; 316 | strcpy(mqttTopic, "device/"); 317 | strcat(mqttTopic, PrinterID); 318 | strcat(mqttTopic, "/report"); 319 | Serial.println("Topic: "); 320 | Serial.println(mqttTopic); 321 | mqttClient.subscribe(mqttTopic); 322 | lastmqttconnectionattempt; 323 | } else { 324 | setPins(0,0,0,0,0); //Turn off led printer is offline and or the given information is wrong 325 | Serial.print("failed, rc="); 326 | Serial.print(mqttClient.state()); 327 | Serial.println(" try again in 10 seconds"); 328 | lastmqttconnectionattempt = millis(); 329 | } 330 | } 331 | } 332 | //Serial.printf("Free heap: %u\n", ESP.getFreeHeap()); 333 | mqttClient.loop(); 334 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Bambulanb Controller and Firmware License - Version 2.0 2 | 3 | This license ("License") governs the use, distribution, and modification of the Bambulanb Controller's code, firmware, forks, and firmware of forks ("Material"). By using, distributing, or modifying the Material, you agree to abide by the terms and conditions of this License. 4 | 5 | You are free to: 6 | 7 | - Share: Copy and redistribute the Material in any medium or format. 8 | - Adapt: Remix, transform, and build upon the Material. 9 | 10 | Under the following terms: 11 | 12 | - Attribution: You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. 13 | - Non-commercial: You may not use the Material for commercial purposes. 14 | - Device and DIY Non-Commercial Restriction: The Material may only be used for the "bambulanb controller" device or for non-commercial DIY projects. 15 | - Share-alike: If you remix, transform, or build upon the Material, you must distribute your contributions under the same license as the original. 16 | 17 | No additional restrictions: You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. 18 | 19 | For the full text of the CC BY-NC-SA 4.0 license, please visit: https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode 20 | 21 | This License is based on the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. The terms of that license apply to the extent they do not conflict with the terms of this License. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Please note that using this code is not advised as it has been replaced by a newer version. 2 | ## https://github.com/DutchDevelop/BLLEDController 3 | 4 | ## BL Led Controller 5 | 6 | The BL Led Controller is an ESP8266-based device that connects to your Bambulab X1 or X1C and controls the LED strip based on the state of the printer. 7 | 8 | ### Features 9 | 10 | - Connects to Bambulab X1 or X1C 11 | - Controls LED strip based on printer state 12 | 13 | ### Setup Instructions 14 | 15 | For detailed setup instructions, please visit the [dutchdevelop.com/bl-led-controller](https://dutchdevelop.com/bl-led-controller) website. 16 | 17 | ### License 18 | 19 | The BL Led Controller is released under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) license. See the [LICENSE](https://github.com/DutchDevelop/BambulabLedController/blob/main/LICENSE) file for more details. 20 | 21 | ### Credits 22 | [DutchDeveloper]: Lead programmer 23 | [Modbot]: Tester: X1C, P1P & P1S 24 | [xps3riments]: Debuging BLLab firmware 01.05.06.62 25 | 26 | ### Author 27 | 28 | This project was created by [DutchDeveloper](https://dutchdevelop.com/). 29 | -------------------------------------------------------------------------------- /build/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DutchDevelop/BambulabLedController/130f0924acb4f01b7e8e9aaf05902d26e4033da6/build/.DS_Store -------------------------------------------------------------------------------- /build/esp8266.esp8266.d1_mini/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DutchDevelop/BambulabLedController/130f0924acb4f01b7e8e9aaf05902d26e4033da6/build/esp8266.esp8266.d1_mini/.DS_Store -------------------------------------------------------------------------------- /build/firmware/blledcontroller_v095.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DutchDevelop/BambulabLedController/130f0924acb4f01b7e8e9aaf05902d26e4033da6/build/firmware/blledcontroller_v095.bin -------------------------------------------------------------------------------- /build/firmware/blledcontroller_v100.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DutchDevelop/BambulabLedController/130f0924acb4f01b7e8e9aaf05902d26e4033da6/build/firmware/blledcontroller_v100.bin -------------------------------------------------------------------------------- /build/firmware/blledcontroller_v101.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DutchDevelop/BambulabLedController/130f0924acb4f01b7e8e9aaf05902d26e4033da6/build/firmware/blledcontroller_v101.bin -------------------------------------------------------------------------------- /build/firmware/blledcontroller_v102.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DutchDevelop/BambulabLedController/130f0924acb4f01b7e8e9aaf05902d26e4033da6/build/firmware/blledcontroller_v102.bin -------------------------------------------------------------------------------- /build/firmware/blledcontroller_v103.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DutchDevelop/BambulabLedController/130f0924acb4f01b7e8e9aaf05902d26e4033da6/build/firmware/blledcontroller_v103.bin -------------------------------------------------------------------------------- /build/firmware/blledcontroller_v104.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DutchDevelop/BambulabLedController/130f0924acb4f01b7e8e9aaf05902d26e4033da6/build/firmware/blledcontroller_v104.bin -------------------------------------------------------------------------------- /build/firmware/blledcontroller_v105.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DutchDevelop/BambulabLedController/130f0924acb4f01b7e8e9aaf05902d26e4033da6/build/firmware/blledcontroller_v105.bin -------------------------------------------------------------------------------- /build/firmware/blledcontroller_v106.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DutchDevelop/BambulabLedController/130f0924acb4f01b7e8e9aaf05902d26e4033da6/build/firmware/blledcontroller_v106.bin -------------------------------------------------------------------------------- /build/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bambulabledcontroller", 3 | "version": "1.0.6", 4 | "new_install_prompt_erase": true, 5 | "builds": [ 6 | { 7 | "chipFamily": "ESP8266", 8 | "parts": [ 9 | { "path": "firmware/blledcontroller_v106.bin", "offset": 0 } 10 | ] 11 | } 12 | ] 13 | } -------------------------------------------------------------------------------- /eeprom_utils.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "eeprom_utils.h" 3 | #include "variables.h" 4 | 5 | void fillWithUnderscores(char* text, int length) { //Fills whitespace with underscores for eeprom to overwrite 6 | int textLength = strlen(text); 7 | for(int i=textLength; i 5 | 6 | void readFromEEPROM(char* Printerip, char* Printercode, char* PrinterID, char* EspPassword); 7 | 8 | void writeToEEPROM(char* Printerip, char* Printercode, char* PrinterID, char* EspPassword); 9 | 10 | void clearEEPROM(); 11 | 12 | #endif // EEPROM_UTILS_H -------------------------------------------------------------------------------- /html.h: -------------------------------------------------------------------------------- 1 | #ifndef HTML_H 2 | #define HTML_H 3 | 4 | const char* html_setuppage = "\ 5 | \ 6 | \ 7 | \ 56 | \ 57 | \ 58 |
\ 59 |
\ 60 |

BL LED Controller Setup Page

\ 61 |

\ 62 | This page allows you to set up your BL LED controller by configuring your MQTT broker, access code, and serial ID.\ 63 |

\ 64 |
\ 65 | \ 66 |
\ 67 | \ 68 |
\ 69 | \ 70 |
\ 71 | \ 72 |
\ 73 |
\ 74 |
\ 75 | "; 76 | 77 | const char* html_finishpage = "\ 78 | \ 79 | \ 80 | \ 81 | BL LED Controller Setup\ 82 | \ 120 | \ 121 | \ 122 |
\ 123 |

Successfully saved parameters

\ 124 |

Your parameters have been saved. You can now close this window and return to the main menu.

\ 125 |
\ 126 | \ 127 | "; 128 | 129 | #endif -------------------------------------------------------------------------------- /led_utils.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "led_utils.h" 3 | 4 | #define LED_PIN_R 5 // Red pin 5 | #define LED_PIN_G 14 // Green pin 6 | #define LED_PIN_B 4 // Blue pin 7 | #define LED_PIN_W 0 // White pin 8 | #define LED_PIN_WW 2 // Warm white pin 9 | 10 | int startR = 0; 11 | int startG = 0; 12 | int startB = 0; 13 | int startC = 0; 14 | int startW = 0; 15 | 16 | void setLedColor(int redValue, int greenValue, int blueValue, int coldValue, int warmValue) { //Function to change ledstrip color 17 | if (redValue == startR && greenValue == startG && blueValue == startB && coldValue == startC && warmValue == startW) { 18 | return; 19 | } 20 | transitionLedColor(redValue,greenValue,blueValue,coldValue,warmValue,100); 21 | } 22 | 23 | void pulseLedColor(int redValue, int greenValue, int blueValue, int coldValue, int warmValue) { //Function to change ledstrip color 24 | if (redValue == startR && greenValue == startG && blueValue == startB && coldValue == startC && warmValue == startW) { 25 | return; 26 | } 27 | int oldR = startR; 28 | int oldG = startG; 29 | int oldB = startB; 30 | int oldC = startC; 31 | int oldW = startW; 32 | transitionLedColor(redValue,greenValue,blueValue,coldValue,warmValue,50); 33 | transitionLedColor(oldR,oldG,oldB,oldC,oldW,50); 34 | } 35 | 36 | void setPins(int redValue, int greenValue, int blueValue, int coldValue, int warmValue) { //Function to change lestrip pins 37 | pinMode(LED_PIN_R, OUTPUT); 38 | pinMode(LED_PIN_G, OUTPUT); 39 | pinMode(LED_PIN_B, OUTPUT); 40 | pinMode(LED_PIN_W, OUTPUT); 41 | pinMode(LED_PIN_WW, OUTPUT); 42 | 43 | analogWrite(LED_PIN_R, redValue); 44 | analogWrite(LED_PIN_G, greenValue); 45 | analogWrite(LED_PIN_B, blueValue); 46 | analogWrite(LED_PIN_W, coldValue); 47 | analogWrite(LED_PIN_WW, warmValue); 48 | } 49 | 50 | void transitionLedColor(int endR, int endG, int endB, int endC, int endW, int duration) { //Function to tween color change 51 | float stepTime = (float)duration / 255.0; 52 | int rStep = (endR - startR) / 255; 53 | int gStep = (endG - startG) / 255; 54 | int bStep = (endB - startB) / 255; 55 | int cStep = (endC - startC) / 255; 56 | int wStep = (endW - startW) / 255; 57 | 58 | for (int i = 0; i < 256; i++) { 59 | int r = startR + i * rStep; 60 | int g = startG + i * gStep; 61 | int b = startB + i * bStep; 62 | int c = startC + i * cStep; 63 | int w = startW + i * wStep; 64 | 65 | setPins(r, g, b, c, w); 66 | delay(stepTime); 67 | } 68 | startR = endR; 69 | startG = endG; 70 | startB = endB; 71 | startC = endC; 72 | startW = endW; 73 | } -------------------------------------------------------------------------------- /led_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef LED_UTILS_H 2 | #define LED_UTILS_H 3 | 4 | #include 5 | 6 | void setLedColor(int redValue, int greenValue, int blueValue, int coldValue, int warmValue); 7 | void pulseLedColor(int redValue, int greenValue, int blueValue, int coldValue, int warmValue); 8 | void setPins(int redValue, int greenValue, int blueValue, int coldValue, int warmValue); 9 | void transitionLedColor(int endR, int endG, int endB, int endC, int endW, int duration); 10 | 11 | #endif -------------------------------------------------------------------------------- /variables.h: -------------------------------------------------------------------------------- 1 | #ifndef VARIABLES_H 2 | #define VARIABLES_H 3 | 4 | #include 5 | 6 | const int Max_ipLength = 15; 7 | const int Max_accessCode = 8; 8 | const int Max_DeviceId = 15; 9 | const int Max_EspPassword = 8; 10 | 11 | const int Ip_Adress = 0; 12 | const int Accesscode_Adress = 15; 13 | const int DeviceId_Adress = 23; 14 | const int EspPassword_Adress = 38; 15 | 16 | 17 | #endif --------------------------------------------------------------------------------