diff --git a/ESPixelStick.h b/ESPixelStick.h index 67a78952d..f248c77fd 100644 --- a/ESPixelStick.h +++ b/ESPixelStick.h @@ -27,13 +27,13 @@ #endif /* Name and version */ -const char VERSION[] = "3.0-rc1 (20170729)"; +const char VERSION[] = "3.0-rc2 (20170804)"; #define HTTP_PORT 80 /* Default web server port */ #define MQTT_PORT 1883 /* Default MQTT port */ #define DATA_PIN 2 /* Pixel output - GPIO2 */ #define EEPROM_BASE 0 /* EEPROM configuration base address */ -#define UNIVERSE_LIMIT 512 /* Universe boundary - 512 Channels */ +#define UNIVERSE_MAX 512 /* Max channels in a DMX Universe */ #define PIXEL_LIMIT 1360 /* Total pixel limit - 40.85ms for 8 universes */ #define RENARD_LIMIT 2048 /* Channel limit for serial outputs */ #define E131_TIMEOUT 1000 /* Force refresh every second an E1.31 packet is not seen */ @@ -101,6 +101,7 @@ typedef struct { /* E131 */ uint16_t universe; /* Universe to listen for */ + uint16_t universe_limit; /* Universe boundary limit */ uint16_t channel_start; /* Channel to start listening at - 1 based */ uint16_t channel_count; /* Number of channels */ bool multicast; /* Enable multicast listener */ diff --git a/ESPixelStick.ino b/ESPixelStick.ino index 35b986e07..f8181f85b 100644 --- a/ESPixelStick.ino +++ b/ESPixelStick.ino @@ -274,8 +274,24 @@ void onWiFiDisconnect(const WiFiEventStationModeDisconnected &event) { wifiTicker.once(2, connectWifi); } +// Subscribe to "n" universes, starting at "universe" +void multiSub() { + uint8_t count; + ip_addr_t ifaddr; + ip_addr_t multicast_addr; + + count = uniLast - config.universe + 1; + ifaddr.addr = static_cast(WiFi.localIP()); + for (uint8_t i = 0; i < count; i++) { + multicast_addr.addr = static_cast(IPAddress(239, 255, + (((config.universe + i) >> 8) & 0xff), + (((config.universe + i) >> 0) & 0xff))); + igmp_joingroup(&ifaddr, &multicast_addr); + } +} + ///////////////////////////////////////////////////////// -// +// // MQTT Section // ///////////////////////////////////////////////////////// @@ -457,10 +473,13 @@ void validateConfig() { if (config.universe < 1) config.universe = 1; + if (config.universe_limit > UNIVERSE_MAX || config.universe_limit < 1) + config.universe_limit = UNIVERSE_MAX; + if (config.channel_start < 1) config.channel_start = 1; - else if (config.channel_start > UNIVERSE_LIMIT) - config.channel_start = UNIVERSE_LIMIT; + else if (config.channel_start > config.universe_limit) + config.channel_start = config.universe_limit; // Set default MQTT port if missing if (config.mqtt_port == 0) @@ -504,8 +523,8 @@ void validateConfig() { else if (config.channel_count < 1) config.channel_count = 1; - if (config.serial_type == SerialType::DMX512 && config.channel_count > UNIVERSE_LIMIT) - config.channel_count = UNIVERSE_LIMIT; + if (config.serial_type == SerialType::DMX512 && config.channel_count > UNIVERSE_MAX) + config.channel_count = UNIVERSE_MAX; // Baud rate check if (config.baudrate > BaudRate::BR_460800) @@ -521,10 +540,10 @@ void updateConfig() { /* Find the last universe we should listen for */ uint16_t span = config.channel_start + config.channel_count - 1; - if (span % UNIVERSE_LIMIT) - uniLast = config.universe + span / UNIVERSE_LIMIT; + if (span % config.universe_limit) + uniLast = config.universe + span / config.universe_limit; else - uniLast = config.universe + span / UNIVERSE_LIMIT - 1; + uniLast = config.universe + span / config.universe_limit - 1; /* Setup the sequence error tracker */ uint8_t uniTotal = (uniLast + 1) - config.universe; @@ -553,6 +572,10 @@ void updateConfig() { LOG_PORT.print(config.universe); LOG_PORT.print(F(" to ")); LOG_PORT.println(uniLast); + + // Setup IGMP subscriptions if multicast is enabled + if (config.multicast) + multiSub(); } // De-Serialize Network config @@ -591,6 +614,7 @@ void dsDeviceConfig(JsonObject &json) { // E131 config.universe = json["e131"]["universe"]; + config.universe_limit = json["e131"]["universe_limit"]; config.channel_start = json["e131"]["channel_start"]; config.channel_count = json["e131"]["channel_count"]; config.multicast = json["e131"]["multicast"]; @@ -696,6 +720,7 @@ void serializeConfig(String &jsonString, bool pretty, bool creds) { // E131 JsonObject &e131 = json.createNestedObject("e131"); e131["universe"] = config.universe; + e131["universe_limit"] = config.universe_limit; e131["channel_start"] = config.channel_start; e131["channel_count"] = config.channel_count; e131["multicast"] = config.multicast; @@ -796,12 +821,12 @@ void loop() { offset = config.channel_start - 1; // Find start of data based off the Universe - int16_t dataStart = uniOffset * UNIVERSE_LIMIT - offset; + int16_t dataStart = uniOffset * config.universe_limit - offset; // Calculate how much data we need for this buffer uint16_t dataStop = config.channel_count; - if ((dataStart + UNIVERSE_LIMIT) < dataStop) - dataStop = dataStart + UNIVERSE_LIMIT; + if ((dataStart + config.universe_limit) < dataStop) + dataStop = dataStart + config.universe_limit; // Set the data uint16_t buffloc = 0; diff --git a/data/config.json b/data/config.json index a8cc474f8..5c2088d27 100644 --- a/data/config.json +++ b/data/config.json @@ -30,6 +30,7 @@ "e131": { "universe": 1, + "universe_limit": 512, "channel_start": 1, "channel_count": 512, "multicast": false diff --git a/html/index.html b/html/index.html index 9cec46c43..40ae2c42f 100644 --- a/html/index.html +++ b/html/index.html @@ -133,6 +133,11 @@
+
+ +
+
+
diff --git a/html/script.js b/html/script.js index 32f53836d..a12730d2a 100644 --- a/html/script.js +++ b/html/script.js @@ -412,6 +412,7 @@ function getConfig(data) { // E1.31 Config $('#universe').val(config.e131.universe); + $('#universe_limit').val(config.e131.universe_limit); $('#channel_start').val(config.e131.channel_start); $('#multicast').prop('checked', config.e131.multicast); @@ -571,6 +572,7 @@ function submitConfig() { }, 'e131': { 'universe': parseInt($('#universe').val()), + 'universe_limit': parseInt($('#universe_limit').val()), 'channel_start': parseInt($('#channel_start').val()), 'channel_count': channels, 'multicast': $('#multicast').prop('checked') diff --git a/wshandler.h b/wshandler.h index 10fd00b95..6e838d240 100644 --- a/wshandler.h +++ b/wshandler.h @@ -162,23 +162,22 @@ void procS(uint8_t *data, AsyncWebSocketClient *client) { client->text("S1"); break; case '2': // Set Device Config + // Reboot if MQTT changed + bool reboot = false; + if (config.mqtt != json["mqtt"]["enabled"]) + reboot = true; + dsDeviceConfig(json); saveConfig(); - client->text("S2"); + + if (reboot) + client->text("S1"); + else + client->text("S2"); break; } } -/* -enum class TestMode : uint8_t { - DISABLED, - STATIC, - CHASE, - RAINBOW, - VIEW_STREAM -}; -*/ - void procT(uint8_t *data, AsyncWebSocketClient *client) { switch (data[1]) { case '0':