e131 mode
Submit "=e131" via mqtt or websocket to activate
This commit is contained in:
parent
20e6bc5c57
commit
edc7c56c1a
8 changed files with 122 additions and 6 deletions
|
@ -53,11 +53,17 @@
|
|||
#endif
|
||||
|
||||
#ifdef ARDUINOJSON_VERSION
|
||||
#if !(ARDUINOJSON_VERSION_MAJOR == 6 and ARDUINOJSON_VERSION_MINOR == 6)
|
||||
#error "Install ArduinoJson v6.6.0-beta"
|
||||
#if !(ARDUINOJSON_VERSION_MAJOR == 6 and ARDUINOJSON_VERSION_MINOR == 7)
|
||||
#error "Install ArduinoJson v6.7.0-beta"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_E131
|
||||
#include <ESPAsyncUDP.h> //https://github.com/me-no-dev/ESPAsyncUDP
|
||||
#include <ESPAsyncE131.h> //https://github.com/forkineye/ESPAsyncE131
|
||||
ESPAsyncE131 e131(UNIVERSE_COUNT);
|
||||
#endif
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
// Instanciate HTTP(80) / WebSockets(81) Server
|
||||
|
@ -351,6 +357,8 @@ void setup() {
|
|||
strcpy(mqtt_user, custom_mqtt_user.getValue());
|
||||
strcpy(mqtt_pass, custom_mqtt_pass.getValue());
|
||||
|
||||
Serial.printf(">>>>>%s %s %s %s<<<<<<<<<\n", mqtt_host, mqtt_port, mqtt_user, mqtt_pass);
|
||||
|
||||
//save the custom parameters to FS
|
||||
#if defined(ENABLE_STATE_SAVE_SPIFFS) and (defined(ENABLE_MQTT) or defined(ENABLE_AMQTT))
|
||||
(writeConfigFS(shouldSaveConfig)) ? DBG_OUTPUT_PORT.println("WiFiManager config FS Save success!"): DBG_OUTPUT_PORT.println("WiFiManager config FS Save failure!");
|
||||
|
@ -840,6 +848,26 @@ void setup() {
|
|||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
|
||||
#ifdef ENABLE_E131
|
||||
server.on("/e131", []() {
|
||||
exit_func = true;
|
||||
mode = E131;
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =e131").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =131").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
#endif
|
||||
|
||||
server.on("/tv", []() {
|
||||
exit_func = true;
|
||||
|
@ -895,6 +923,15 @@ void setup() {
|
|||
if (mdns_result) {
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_E131
|
||||
// Choose one to begin listening for E1.31 data
|
||||
// if (e131.begin(E131_UNICAST)) // Listen via Unicast
|
||||
if (e131.begin(E131_MULTICAST, UNIVERSE, UNIVERSE_COUNT)) // Listen via Multicast
|
||||
Serial.println(F("Listening for data..."));
|
||||
else
|
||||
Serial.println(F("*** e131.begin failed ***"));
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
(readStateFS()) ? DBG_OUTPUT_PORT.println(" Success!") : DBG_OUTPUT_PORT.println(" Failure!");
|
||||
#endif
|
||||
|
@ -1013,6 +1050,11 @@ void loop() {
|
|||
strip.trigger();
|
||||
mode = HOLD;
|
||||
}
|
||||
#ifdef ENABLE_E131
|
||||
if (mode == E131) {
|
||||
handleE131();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
if (mode == HOLD || mode == CUSTOM) {
|
||||
if(!strip.isRunning()) strip.start();
|
||||
|
|
|
@ -16,7 +16,13 @@ const char HOSTNAME[] = "McLighting01"; // Friedly hostname
|
|||
#define ENABLE_HOMEASSISTANT // If defined, enable Homeassistant integration, ENABLE_MQTT or ENABLE_AMQTT must be active
|
||||
#define ENABLE_BUTTON // If defined, enable button handling code, see: https://github.com/toblum/McLighting/wiki/Button-control
|
||||
//#define MQTT_HOME_ASSISTANT_SUPPORT // If defined, use AMQTT and select Tools -> IwIP Variant -> Higher Bandwidth
|
||||
#define ENABLE_LEGACY_ANIMATIONS
|
||||
#define ENABLE_LEGACY_ANIMATIONS // Dont disbale this for now
|
||||
#define ENABLE_E131 // E1.31 implementation
|
||||
|
||||
#ifdef ENABLE_E131
|
||||
#define UNIVERSE 1 // First DMX Universe to listen for
|
||||
#define UNIVERSE_COUNT 7 // Total number of Universes to listen for, starting at UNIVERSE
|
||||
#endif
|
||||
|
||||
//#define WIFIMGR_PORTAL_TIMEOUT 180
|
||||
//#define WIFIMGR_SET_MANUAL_IP
|
||||
|
@ -104,7 +110,11 @@ uint32_t autoParams[][4] = { // color, speed, mode, duration (seconds)
|
|||
|
||||
// List of all color modes
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
enum MODE { SET_MODE, HOLD, OFF, SETCOLOR, SETSPEED, BRIGHTNESS, WIPE, RAINBOW, RAINBOWCYCLE, THEATERCHASE, TWINKLERANDOM, THEATERCHASERAINBOW, TV, CUSTOM };
|
||||
#ifdef ENABLE_E131
|
||||
enum MODE { SET_MODE, HOLD, OFF, SETCOLOR, SETSPEED, BRIGHTNESS, WIPE, RAINBOW, RAINBOWCYCLE, THEATERCHASE, TWINKLERANDOM, THEATERCHASERAINBOW, TV, CUSTOM, E131 };
|
||||
#else
|
||||
enum MODE { SET_MODE, HOLD, OFF, SETCOLOR, SETSPEED, BRIGHTNESS, WIPE, RAINBOW, RAINBOWCYCLE, THEATERCHASE, TWINKLERANDOM, THEATERCHASERAINBOW, TV, CUSTOM };
|
||||
#endif
|
||||
MODE mode = RAINBOW; // Standard mode that is active when software starts
|
||||
bool exit_func = false; // Global helper variable to get out of the color modes when mode changes
|
||||
#else
|
||||
|
|
|
@ -1,6 +1,38 @@
|
|||
// ***************************************************************************
|
||||
// Request handlers
|
||||
// ***************************************************************************
|
||||
#ifdef ENABLE_E131
|
||||
void handleE131(){
|
||||
if (!e131.isEmpty())
|
||||
{
|
||||
e131_packet_t packet;
|
||||
e131.pull(&packet); // Pull packet from ring buffer
|
||||
|
||||
uint16_t universe = htons(packet.universe);
|
||||
uint8_t *data = packet.property_values + 1;
|
||||
|
||||
if (!e131.stats.num_packets || universe < UNIVERSE || universe > UNIVERSE_COUNT) return;
|
||||
|
||||
// Serial.printf("Universe %u / %u Channels | Packet#: %u / Errors: %u / CH1: %u\n",
|
||||
// htons(packet.universe), // The Universe for this packet
|
||||
// htons(packet.property_value_count) - 1, // Start code is ignored, we're interested in dimmer data
|
||||
// e131.stats.num_packets, // Packet counter
|
||||
// e131.stats.packet_errors, // Packet error counter
|
||||
// packet.property_values[1]); // Dimmer data for Channel 1
|
||||
|
||||
uint16_t len = e131.stats.num_packets / 3;
|
||||
uint16_t multipacketOffset = (universe - UNIVERSE) * 170; //if more than 170 LEDs (510 channels), client will send in next higher universe
|
||||
if (NUMLEDS <= multipacketOffset) return;
|
||||
if (len + multipacketOffset > NUMLEDS) len = NUMLEDS - multipacketOffset;
|
||||
for (uint16_t i = 0; i < len; i++){
|
||||
uint16_t j = i * 3;
|
||||
strip.setPixelColor(i, data[j], data[j + 1], data[j + 2]);
|
||||
}
|
||||
strip.show();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
void tickerSendState(){
|
||||
new_ha_mqtt_msg = true;
|
||||
|
@ -268,6 +300,18 @@ void setModeByStateString(String saved_state_string) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_E131
|
||||
void handleE131NamedMode(String str_mode) {
|
||||
exit_func = true;
|
||||
if (str_mode.startsWith("=e131")) {
|
||||
mode = E131;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void handleSetWS2812FXMode(uint8_t * mypayload) {
|
||||
mode = SET_MODE;
|
||||
uint8_t ws2812fx_mode_tmp = (uint8_t) strtol((const char *) &mypayload[1], NULL, 10);
|
||||
|
@ -556,6 +600,9 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
|
|||
String str_mode = String((char *) &payload[0]);
|
||||
|
||||
handleSetNamedMode(str_mode);
|
||||
#ifdef ENABLE_E131
|
||||
handleE131NamedMode(str_mode);
|
||||
#endif
|
||||
if (mqtt == true) {
|
||||
DBG_OUTPUT_PORT.print("MQTT: ");
|
||||
} else {
|
||||
|
@ -1202,6 +1249,8 @@ bool writeConfigFS(bool saveConfig){
|
|||
json["mqtt_port"] = mqtt_port;
|
||||
json["mqtt_user"] = mqtt_user;
|
||||
json["mqtt_pass"] = mqtt_pass;
|
||||
|
||||
Serial.printf(">>>>>%s %s %s %s<<<<<<<<<\n", mqtt_host, mqtt_port, mqtt_user, mqtt_pass);
|
||||
|
||||
// SPIFFS.remove("/config.json") ? DBG_OUTPUT_PORT.println("removed file") : DBG_OUTPUT_PORT.println("failed removing file");
|
||||
File configFile = SPIFFS.open("/config.json", "w");
|
||||
|
|
|
@ -1 +1 @@
|
|||
#define SKETCH_VERSION "2.1.8"
|
||||
#define SKETCH_VERSION "2.1.9"
|
|
@ -35,4 +35,7 @@
|
|||
* 11 Dec 2018 v 2.1.8
|
||||
* - Fix Auto-Discovery for HA version >= 0.84 #286
|
||||
* - Fix #283
|
||||
*
|
||||
* 12 Dec 2018 v 2.1.9
|
||||
* - Add E1.31 mode
|
||||
*/
|
||||
|
|
|
@ -130,6 +130,11 @@
|
|||
<i class="material-icons right">send</i>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col s12 m6 l6 btn_grid">
|
||||
<a class="btn waves-effect waves-light btn_mode_static blue" name="action" data-mode="E131">E131
|
||||
<i class="material-icons right">send</i>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div id="modes">
|
||||
<div class="input-field col s12">
|
||||
|
|
|
@ -130,6 +130,11 @@
|
|||
<i class="material-icons right">send</i>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col s12 m6 l6 btn_grid">
|
||||
<a class="btn waves-effect waves-light btn_mode_static blue" name="action" data-mode="E131">E131
|
||||
<i class="material-icons right">send</i>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div id="modes">
|
||||
<div class="input-field col s12">
|
||||
|
|
|
@ -49,7 +49,9 @@ upload_resetmethod = ${common.upload_resetmethod}
|
|||
lib_deps =
|
||||
WiFiManager@0.14
|
||||
AsyncMqttClient
|
||||
https://github.com/bblanchon/ArduinoJson.git#v6.6.0-beta
|
||||
https://github.com/bblanchon/ArduinoJson.git#v6.7.0-beta
|
||||
WS2812FX
|
||||
NeoPixelBus
|
||||
WebSockets
|
||||
ESPAsyncE131
|
||||
ESPAsyncUDP
|
Loading…
Reference in a new issue