Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
build/
build/
BLLEDController.code-workspace
.python-version

# generated .h files from html
src/www/setuppage.h
38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,48 @@ The BL Led Controller is an ESP8266 / ESP32 based device that connects to your B
- Connects to Bambulab X1,X1C,P1P Or P1S
- Controls LED strip based on printer state

### Development Environment

To contribute to the BL Led Controller project, you'll need the following tools:

### Tools & Libraries Used

- [Visual Studio Code](https://code.visualstudio.com/): A lightweight and powerful source code editor.
- [PlatformIO](https://platformio.org/): An open-source ecosystem for IoT development.
- [Python](https://www.python.org/): A programming language used for scripting and automation.
- [qpdf](https://qpdf.sourceforge.io/): A command-line tool and library of compression tools (`gzip`)

### Building and Running the Project
1. Clone the repository to your local machine.
2. Open the project folder in Visual Studio Code.
3. Ensure that PlatformIO is installed and configured in your Visual Studio Code environment.
4. Connect your BLLED device (ESP8266 or ESP32) to your computer.
6. Build the project by clicking on the PlatformIO icon in the sidebar and selecting "Build" from the available options.
7. Once the build process is complete, upload the firmware to your device using the "Upload" option in PlatformIO.
8. After uploading the firmware, your BL Led Controller device should be ready to use.

### Setup Instructions
Once you have uploaded the firmware to your device, please visit the [dutchdevelop.com/bl-led-controller](https://dutchdevelop.com/bl-led-controller) website for detailed setup instructions.


### Development Notes

#### Generating .h Files for Compressed HTML

In embedded applications, HTML content is efficiently stored in PROGMEM memory. To achieve this, .h files are generated from compressed HTML files for webpages (i.e., `src/www/setuppage.html`) that are run on the device.

For detailed setup instructions, please visit the [dutchdevelop.com/bl-led-controller](https://dutchdevelop.com/bl-led-controller) website.
- The `compress_html.py` is used to compress HTML files and generate corresponding .h files and is integrated into the build process and executed as a pre-build step in `platform.ini`
- The generated .h files should not be checked into git (see `.gitignore`)

### License

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/BLLEDController/blob/main/LICENSE) file for more details.

### Credits
[DutchDeveloper]: Lead programmer
[Modbot]: Tester: X1C, P1P & P1S
[xps3riments]: Inspiration for foundation of the code
- **[DutchDeveloper](https://dutchdevelop.com/)**: Lead programmer
- **[Modbot](https://github.com/Modbot)**: Tester for X1C, P1P & P1S
- **[xps3riments](https://github.com/xps3riments)**: Inspiration for the foundation of the code
- **[longrackslabs](https://github.com/longrackslabs)**: Build process, documentation, developer & community support

### Author

Expand Down
66 changes: 66 additions & 0 deletions compress_html.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import sys
import gzip
import subprocess
import os

def should_compress(html_file, header_file):
if not os.path.exists(header_file):
return True

html_modified_time = os.path.getmtime(html_file)
header_modified_time = os.path.getmtime(header_file)

return html_modified_time > header_modified_time

def compress_html(html_file):
# Check if compression is necessary
header_file = os.path.splitext(html_file)[0] + ".h"
if not should_compress(html_file, header_file):
print("No need to compress:", html_file)
return

# Compress HTML file
compressed_file = html_file + ".gz"
with open(html_file, "rb") as input_file:
with gzip.open(compressed_file, "wb", compresslevel=6) as output_file:
output_file.write(input_file.read())

# Check if .h file exists and if HTML file is newer
if os.path.exists(header_file):
header_modified_time = os.path.getmtime(header_file)
html_modified_time = os.path.getmtime(html_file)
if html_modified_time < header_modified_time:
print("No need to generate header file. HTML file is not modified.")
os.remove(compressed_file)
return

# Generate header file
print("Header file path:", header_file) # Debug print
result = subprocess.run(["xxd", "-i", compressed_file], stdout=open(header_file, "w"))
if result.returncode != 0:
print("Error: xxd failed to generate the header file")
return

# Modify the generated header file to include PROGMEM attribute
with open(header_file, "r") as file:
content = file.read()

with open(header_file, "w") as file:
# Add PROGMEM attribute after the array declaration
content = content.replace("unsigned char ", "const uint8_t ")
# Remove "__" prefix from the length variable
content = content.replace("unsigned int ", "unsigned int ")
# Add PROGMEM attribute after the variable name
content = content.replace("const uint8_t ", "const uint8_t ", 1).replace("{", "PROGMEM {")
file.write(content)

# Clean up
os.remove(compressed_file)

if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python compress_html.py <html_file>")
sys.exit(1)

html_file = sys.argv[1]
compress_html(html_file)
6 changes: 4 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ framework = arduino
monitor_speed = 115200
board_build.filesystem = littlefs
extra_scripts =
pre:pre_build.py
merge_firmware.py
lib_deps =
https://github.com/bblanchon/ArduinoJson.git @ 7.0.4
https://github.com/knolleary/pubsubclient.git
https://github.com/bblanchon/ArduinoJson.git @ 7.0.4
https://github.com/knolleary/pubsubclient.git

[platformio]
build_dir = build

14 changes: 14 additions & 0 deletions pre_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import subprocess
import os

def compress_html_files():
# Change the working directory to the location of the compression script
os.chdir("src/www")

# List of HTML files to compress
html_files = ["setuppage.html"]
for html_file in html_files:
print("Compressing file:", html_file)
subprocess.run(["python", "../../compress_html.py", html_file])

compress_html_files()
4 changes: 2 additions & 2 deletions src/web-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ WebServer webServer(80);



#include "www/setupPage.h"
#include "www/setuppage.h"

bool isAuthorized() {
return true; //webServer.authenticate("BLLC", printerConfig.webpagePassword);
Expand Down Expand Up @@ -271,4 +271,4 @@ void webserverloop(){
delay(10);
}

#endif
#endif
Loading