e131 mode

Submit "=e131" via mqtt or websocket to activate
This commit is contained in:
Debashish Sahu 2018-12-11 22:42:15 -05:00
parent 20e6bc5c57
commit edc7c56c1a
8 changed files with 122 additions and 6 deletions

View file

@ -53,11 +53,17 @@
#endif #endif
#ifdef ARDUINOJSON_VERSION #ifdef ARDUINOJSON_VERSION
#if !(ARDUINOJSON_VERSION_MAJOR == 6 and ARDUINOJSON_VERSION_MINOR == 6) #if !(ARDUINOJSON_VERSION_MAJOR == 6 and ARDUINOJSON_VERSION_MINOR == 7)
#error "Install ArduinoJson v6.6.0-beta" #error "Install ArduinoJson v6.7.0-beta"
#endif #endif
#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 // Instanciate HTTP(80) / WebSockets(81) Server
@ -351,6 +357,8 @@ void setup() {
strcpy(mqtt_user, custom_mqtt_user.getValue()); strcpy(mqtt_user, custom_mqtt_user.getValue());
strcpy(mqtt_pass, custom_mqtt_pass.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 //save the custom parameters to FS
#if defined(ENABLE_STATE_SAVE_SPIFFS) and (defined(ENABLE_MQTT) or defined(ENABLE_AMQTT)) #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!"); (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); if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
#endif #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", []() { server.on("/tv", []() {
exit_func = true; exit_func = true;
@ -895,6 +923,15 @@ void setup() {
if (mdns_result) { if (mdns_result) {
MDNS.addService("http", "tcp", 80); 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 #ifdef ENABLE_STATE_SAVE_SPIFFS
(readStateFS()) ? DBG_OUTPUT_PORT.println(" Success!") : DBG_OUTPUT_PORT.println(" Failure!"); (readStateFS()) ? DBG_OUTPUT_PORT.println(" Success!") : DBG_OUTPUT_PORT.println(" Failure!");
#endif #endif
@ -1013,6 +1050,11 @@ void loop() {
strip.trigger(); strip.trigger();
mode = HOLD; mode = HOLD;
} }
#ifdef ENABLE_E131
if (mode == E131) {
handleE131();
}
#endif
#endif #endif
if (mode == HOLD || mode == CUSTOM) { if (mode == HOLD || mode == CUSTOM) {
if(!strip.isRunning()) strip.start(); if(!strip.isRunning()) strip.start();

View file

@ -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_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 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 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_PORTAL_TIMEOUT 180
//#define WIFIMGR_SET_MANUAL_IP //#define WIFIMGR_SET_MANUAL_IP
@ -104,7 +110,11 @@ uint32_t autoParams[][4] = { // color, speed, mode, duration (seconds)
// List of all color modes // List of all color modes
#ifdef ENABLE_LEGACY_ANIMATIONS #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 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 bool exit_func = false; // Global helper variable to get out of the color modes when mode changes
#else #else

View file

@ -1,6 +1,38 @@
// *************************************************************************** // ***************************************************************************
// Request handlers // 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 #ifdef ENABLE_HOMEASSISTANT
void tickerSendState(){ void tickerSendState(){
new_ha_mqtt_msg = true; new_ha_mqtt_msg = true;
@ -268,6 +300,18 @@ void setModeByStateString(String saved_state_string) {
} }
#endif #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) { void handleSetWS2812FXMode(uint8_t * mypayload) {
mode = SET_MODE; mode = SET_MODE;
uint8_t ws2812fx_mode_tmp = (uint8_t) strtol((const char *) &mypayload[1], NULL, 10); 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]); String str_mode = String((char *) &payload[0]);
handleSetNamedMode(str_mode); handleSetNamedMode(str_mode);
#ifdef ENABLE_E131
handleE131NamedMode(str_mode);
#endif
if (mqtt == true) { if (mqtt == true) {
DBG_OUTPUT_PORT.print("MQTT: "); DBG_OUTPUT_PORT.print("MQTT: ");
} else { } else {
@ -1202,6 +1249,8 @@ bool writeConfigFS(bool saveConfig){
json["mqtt_port"] = mqtt_port; json["mqtt_port"] = mqtt_port;
json["mqtt_user"] = mqtt_user; json["mqtt_user"] = mqtt_user;
json["mqtt_pass"] = mqtt_pass; 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"); // SPIFFS.remove("/config.json") ? DBG_OUTPUT_PORT.println("removed file") : DBG_OUTPUT_PORT.println("failed removing file");
File configFile = SPIFFS.open("/config.json", "w"); File configFile = SPIFFS.open("/config.json", "w");

View file

@ -1 +1 @@
#define SKETCH_VERSION "2.1.8" #define SKETCH_VERSION "2.1.9"

View file

@ -35,4 +35,7 @@
* 11 Dec 2018 v 2.1.8 * 11 Dec 2018 v 2.1.8
* - Fix Auto-Discovery for HA version >= 0.84 #286 * - Fix Auto-Discovery for HA version >= 0.84 #286
* - Fix #283 * - Fix #283
*
* 12 Dec 2018 v 2.1.9
* - Add E1.31 mode
*/ */

View file

@ -130,6 +130,11 @@
<i class="material-icons right">send</i> <i class="material-icons right">send</i>
</a> </a>
</div> </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 id="modes">
<div class="input-field col s12"> <div class="input-field col s12">

View file

@ -130,6 +130,11 @@
<i class="material-icons right">send</i> <i class="material-icons right">send</i>
</a> </a>
</div> </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 id="modes">
<div class="input-field col s12"> <div class="input-field col s12">

View file

@ -49,7 +49,9 @@ upload_resetmethod = ${common.upload_resetmethod}
lib_deps = lib_deps =
WiFiManager@0.14 WiFiManager@0.14
AsyncMqttClient AsyncMqttClient
https://github.com/bblanchon/ArduinoJson.git#v6.6.0-beta https://github.com/bblanchon/ArduinoJson.git#v6.7.0-beta
WS2812FX WS2812FX
NeoPixelBus NeoPixelBus
WebSockets WebSockets
ESPAsyncE131
ESPAsyncUDP