Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define DEBUG_ETHERNET_WEBSERVER_PORT Serial
- #define UNIQUE_SUBARTNET
- #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3
- #define NB_CHANNEL_PER_LED 3 //Should be 4 if your sending tool is sending RGBW
- #define UNIVERSE_SIZE_IN_CHANNEL 510 //here we define a universe of 170 pixels each pixel is composed of 3 channels
- #include <Preferences.h>
- #include "WebServer_ESP32_W5500.h"
- #include "I2SClocklessLedDriver.h"
- #include "artnetESP32V2.h"
- WebServer server(80);
- Preferences preferences;
- // Default configuration values
- int numledsperstrip = 680;
- int numstrips = 3;
- int startuniverse = 0;
- int pins[3] = { 2, 15, 0 };
- String colororder = "GRB"; // Default color order
- String nodename = "Artnet Node esp32";
- artnetESP32V2 artnet = artnetESP32V2();
- I2SClocklessLedDriver driver;
- void displayfunction(void *param) {
- subArtnet *subartnet = (subArtnet *)param;
- driver.showPixels(NO_WAIT, subartnet->data);
- }
- void handleRoot() {
- String content = "<!DOCTYPE html><html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">";
- content += "<link rel=\"icon\" href=\"data:,\">"; // Empty favicon
- content += "<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}";
- content += ".button { background-color: #4CAF50; border: none; color: white; padding: 16px 40px; text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}";
- content += ".button2 { background-color: #555555; }</style></head>";
- content += "<body><h1>" + nodename + " Configuration</h1><form method='get' action='/config'>";
- content += "Number of LEDs per strip: <input type='text' name='numledsperstrip' value='" + String(numledsperstrip) + "'><br>";
- content += "Number of strips: <input type='text' name='numstrips' value='" + String(numstrips) + "'><br>";
- content += "Startuniverse: <input type='text' name='startuniverse' value='" + String(startuniverse) + "'><br>";
- content += "Color order (e.g., RGB, GRB): <input type='text' name='colororder' value='" + colororder + "'><br>";
- content += "Arnet Node name: <input type='text' name='nodename' value='" + nodename + "'><br>";
- content += "<input type='submit' value='Save'></form></body></html>";
- server.send(200, "text/html", content);
- }
- void handleConfig() {
- if (server.args() > 0) {
- for (uint8_t i = 0; i < server.args(); i++) {
- if (server.argName(i) == "numledsperstrip") {
- numledsperstrip = server.arg(i).toInt();
- } else if (server.argName(i) == "numstrips") {
- numstrips = server.arg(i).toInt();
- } else if (server.argName(i) == "startuniverse") {
- startuniverse = server.arg(i).toInt();
- } else if (server.argName(i) == "colororder") {
- colororder = server.arg(i);
- } else if (server.argName(i) == "nodename") {
- nodename = server.arg(i);
- }
- }
- // Store updated configuration in Preferences
- preferences.begin("esp32config", false);
- preferences.putInt("numledsperstrip", numledsperstrip);
- preferences.putInt("numstrips", numstrips);
- preferences.putInt("startuniverse", startuniverse);
- preferences.putString("colororder", colororder);
- preferences.putString("nodename", nodename);
- preferences.end();
- }
- handleRoot();
- }
- void setup() {
- Serial.begin(115200);
- // Initialize Preferences
- preferences.begin("esp32config", true);
- numledsperstrip = preferences.getInt("numledsperstrip", numledsperstrip);
- numstrips = preferences.getInt("numstrips", numstrips);
- colororder = preferences.getString("colororder", colororder);
- nodename = preferences.getString("nodename", nodename);
- startuniverse = preferences.getInt("startuniverse", startuniverse);
- preferences.end();
- while (!Serial && (millis() < 5000))
- ;
- driver.initled(NULL, pins, numstrips, numledsperstrip);
- driver.setBrightness(20);
- // Initialize Ethernet
- ESP32_W5500_onEvent();
- ETH.begin(MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST);
- //Output
- //addSubArtnet(Output universe start, #bits 680*1*3 = 2040, universe size = 510, callbackfunction )
- artnet.addSubArtnet(startuniverse, numledsperstrip * numstrips * NB_CHANNEL_PER_LED, UNIVERSE_SIZE_IN_CHANNEL, &displayfunction);
- artnet.setNodeName("Arnet Node esp32");
- if (artnet.listen(ETH.localIP(), 6454)) {
- Serial.print("artnet Listening on IP: ");
- Serial.println(ETH.localIP());
- }
- // Initialize Web Server
- server.on("/", HTTP_GET, handleRoot);
- server.on("/config", HTTP_GET, handleConfig);
- server.begin();
- ESP32_W5500_waitForConnect();
- Serial.println("");
- Serial.println("Ethernet connected.");
- Serial.println("IP address: ");
- Serial.println(ETH.localIP());
- Serial.println("HTTP server started");
- }
- void loop() {
- server.handleClient();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement