diff --git a/code/espurna/config/dependencies.h b/code/espurna/config/dependencies.h index f3f52d83b5..ad5bde8634 100644 --- a/code/espurna/config/dependencies.h +++ b/code/espurna/config/dependencies.h @@ -102,6 +102,11 @@ #define TELNET_SERVER_ASYNC_BUFFERED 1 // enable buffered telnet by default on latest Cores #endif +#if LIGHT_PROVIDER == LIGHT_PROVIDER_NONE +#undef E131_SUPPORT +#define E131_SUPPORT 0 // E1.31 needs light provider to work +#endif + #if LIGHT_PROVIDER == LIGHT_PROVIDER_TUYA #undef TUYA_SUPPORT #define TUYA_SUPPORT 1 // Need base Tuya module for this to work diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index fe1ecc3420..bcee7da905 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -1388,6 +1388,14 @@ #define DOMOTICZ_OUT_TOPIC "domoticz/out" // Default publication topic #endif +// ----------------------------------------------------------------------------- +// E1.31 +// ----------------------------------------------------------------------------- + +#ifndef E131_SUPPORT +#define E131_SUPPORT 1 // Enable E1.31 by default +#endif + // ----------------------------------------------------------------------------- // HOME ASSISTANT // ----------------------------------------------------------------------------- diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index 74edc2d295..7285ecb6e1 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -60,6 +60,7 @@ #define DEBUG_TELNET_SUPPORT 0 #define DEBUG_WEB_SUPPORT 0 #define DOMOTICZ_SUPPORT 0 + #define E131_SUPPORT 0 #define HOMEASSISTANT_SUPPORT 0 #define I2C_SUPPORT 0 #define MQTT_SUPPORT 0 @@ -96,6 +97,7 @@ #define DEBUG_SERIAL_SUPPORT 0 //#define DEBUG_TELNET_SUPPORT 0 //#define DEBUG_WEB_SUPPORT 0 + #define E131_SUPPORT 0 #define HOMEASSISTANT_SUPPORT 0 #define I2C_SUPPORT 0 #define MQTT_SUPPORT 0 diff --git a/code/espurna/e131.cpp b/code/espurna/e131.cpp new file mode 100644 index 0000000000..a6bdd9f621 --- /dev/null +++ b/code/espurna/e131.cpp @@ -0,0 +1,178 @@ +/* + +E1.31 MODULE + +Copyright (C) 2020 by Adam Honse + +*/ + +#include "e131.h" + +#if E131_SUPPORT + +#if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE + +// ----------------------------------------------------------------------------- + +#include "light.h" +#include "wifi.h" +#include "web.h" +#include "ws.h" + +#include + +bool _e131_wifi_connected = false; +bool _e131_enabled = false; +bool _e131_multicast = false; +unsigned int _e131_universe = 1; +bool _e131_light_0_enabled = false; +unsigned int _e131_light_0_channel = 1; +bool _e131_light_1_enabled = false; +unsigned int _e131_light_1_channel = 2; +bool _e131_light_2_enabled = false; +unsigned int _e131_light_2_channel = 3; +bool _e131_light_3_enabled = false; +unsigned int _e131_light_3_channel = 4; +bool _e131_light_4_enabled = false; +unsigned int _e131_light_4_channel = 5; +bool _e131_initialized = false; + +ESPAsyncE131 e131(2); + +// ----------------------------------------------------------------------------- +// E1.31 +// ----------------------------------------------------------------------------- + +#if WEB_SUPPORT + +bool _e131WebSocketOnKeyCheck(const char * key, JsonVariant& value) { + return (strncmp(key, "e131", 4) == 0); +} + +void _e131WebSocketOnVisible(JsonObject& root) { + root["e131Visible"] = 1; +} + +void _e131WebSocketOnData(JsonObject& root) { + +} + +void _e131WebSocketOnConnected(JsonObject& root) { + root["e131Enabled"] = getSetting("e131Enabled", false); + root["e131Multicast"] = getSetting("e131Multicast", false); + root["e131Universe"] = getSetting("e131Universe", 1); + root["e131Light0Enabled"] = getSetting("e131Light0Enabled", false); + root["e131Light0Channel"] = getSetting("e131Light0Channel", 1); + root["e131Light1Enabled"] = getSetting("e131Light1Enabled", false); + root["e131Light1Channel"] = getSetting("e131Light1Channel", 2); + root["e131Light2Enabled"] = getSetting("e131Light2Enabled", false); + root["e131Light2Channel"] = getSetting("e131Light2Channel", 3); + root["e131Light3Enabled"] = getSetting("e131Light3Enabled", false); + root["e131Light3Channel"] = getSetting("e131Light3Channel", 4); + root["e131Light4Enabled"] = getSetting("e131Light4Enabled", false); + root["e131Light4Channel"] = getSetting("e131Light4Channel", 5); +} + +#endif // WEB_SUPPORT + +void _e131WifiCallback(justwifi_messages_t code, char * parameter) { + + if (MESSAGE_CONNECTED == code) { + _e131_wifi_connected = true; + return; + } + + if (MESSAGE_DISCONNECTED == code) { + _e131_wifi_connected = false; + return; + } +} + +void _e131Loop() { + if (!_e131_enabled) return; + + //* Initializing multicast mode must be done when the WiFi is connected, so + //* set a flag to track when WiFi is connected and disconnected + if (_e131_wifi_connected) { + if(_e131_initialized == 0) { + if(_e131_multicast) { + e131.begin(E131_MULTICAST, _e131_universe, 1); + } + else { + e131.begin(E131_UNICAST); + } + + _e131_initialized = 1; + } + } + else { + _e131_initialized = 0; + } + + if(!e131.isEmpty()) + { + e131_packet_t pkt; + e131.pull(&pkt); + + if(_e131_light_0_enabled) { + lightChannel(0, pkt.property_values[_e131_light_0_channel]); + } + + if(_e131_light_1_enabled) { + lightChannel(1, pkt.property_values[_e131_light_1_channel]); + } + + if(_e131_light_2_enabled) { + lightChannel(2, pkt.property_values[_e131_light_2_channel]); + } + + if(_e131_light_3_enabled) { + lightChannel(3, pkt.property_values[_e131_light_3_channel]); + } + + if(_e131_light_4_enabled) { + lightChannel(4, pkt.property_values[_e131_light_4_channel]); + } + + lightUpdate(false, false, false); + } +} + +bool e131Enabled() { + return _e131_enabled; +} + +void e131Setup() { + _e131_initialized = 0; + _e131_enabled = getSetting("e131Enabled", false); + _e131_multicast = getSetting("e131Multicast", false); + _e131_universe = getSetting("e131Universe", 1); + _e131_light_0_enabled = getSetting("e131Light0Enabled", false); + _e131_light_0_channel = getSetting("e131Light0Channel", 1); + _e131_light_1_enabled = getSetting("e131Light1Enabled", false); + _e131_light_1_channel = getSetting("e131Light1Channel", 2); + _e131_light_2_enabled = getSetting("e131Light2Enabled", false); + _e131_light_2_channel = getSetting("e131Light2Channel", 3); + _e131_light_3_enabled = getSetting("e131Light3Enabled", false); + _e131_light_3_channel = getSetting("e131Light3Channel", 4); + _e131_light_4_enabled = getSetting("e131Light4Enabled", false); + _e131_light_4_channel = getSetting("e131Light4Channel", 5); + + espurnaRegisterLoop(_e131Loop); + + #if WEB_SUPPORT + wsRegister() + .onVisible(_e131WebSocketOnVisible) + .onConnected(_e131WebSocketOnConnected) + .onData(_e131WebSocketOnData) + .onKeyCheck(_e131WebSocketOnKeyCheck); + #endif + + jw.subscribe(_e131WifiCallback); + + DEBUG_MSG_P(PSTR("[E131] E131 setup code finished \n")); +} + +#endif // LIGHT_PROVIDER != LIGHT_PROVIDER_NONE + +#endif // E131_SUPPORT \ No newline at end of file diff --git a/code/espurna/e131.h b/code/espurna/e131.h new file mode 100644 index 0000000000..bf203834bb --- /dev/null +++ b/code/espurna/e131.h @@ -0,0 +1,18 @@ +/* + +E1.31 MODULE + +Copyright (C) 2020 by Adam Honse + +*/ + +#pragma once + +#include "espurna.h" + +#if E131_SUPPORT + +void e131Setup(); +bool e131Enabled(); + +#endif // E131_SUPPORT == 1 \ No newline at end of file diff --git a/code/espurna/main.cpp b/code/espurna/main.cpp index d7bb1583c3..2317523b26 100644 --- a/code/espurna/main.cpp +++ b/code/espurna/main.cpp @@ -29,6 +29,7 @@ along with this program. If not, see . #include "curtain_kingart.h" #include "debug.h" #include "domoticz.h" +#include "e131.h" #include "encoder.h" #include "homeassistant.h" #include "i2c.h" @@ -301,7 +302,10 @@ void setup() { #if KINGART_CURTAIN_SUPPORT kingartCurtainSetup(); #endif - + #if E131_SUPPORT + e131Setup(); + #endif + // 3rd party code hook #if USE_EXTRA extraSetup(); diff --git a/code/html/index.html b/code/html/index.html index 3590ef5f58..67528c4006 100644 --- a/code/html/index.html +++ b/code/html/index.html @@ -186,6 +186,10 @@

Before using this device you have to change the default password for the use THINGSPEAK +
  • + E1.31 +
  • +
  • WIFI
  • @@ -349,6 +353,101 @@

    Current configuration

    +
    +
    + +
    +

    E1.31

    +

    + E1.31 (Streaming ACN) Protocol Settings. +

    +
    + +
    +
    + General + +
    + +
    +
    + +
    + +
    +
    + +
    + + +
    + + Light 0 + +
    + +
    +
    + +
    + + +
    + + Light 1 + +
    + +
    +
    + +
    + + +
    + + Light 2 + +
    + +
    +
    + +
    + + +
    + + Light 3 + +
    + +
    +
    + +
    + + +
    + + Light 4 + +
    + +
    +
    + +
    + + +
    + +
    +
    + +
    +
    +
    diff --git a/code/platformio.ini b/code/platformio.ini index 21b3423574..8836244135 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -153,6 +153,8 @@ lib_deps = https://github.com/ThingPulse/esp8266-oled-ssd1306#3398c97 Adafruit SI1145 Library@~1.1.1 https://github.com/BoschSensortec/BSEC-Arduino-library.git#c5503e0 + https://github.com/me-no-dev/ESPAsyncUDP.git#master + https://github.com/forkineye/ESPAsyncE131.git#master # ------------------------------------------------------------------------------ # COMMON ENVIRONMENT SETTINGS: