Merge pull request #350 from toblum/develop

v2.2.1
This commit is contained in:
Debashish Sahu 2019-03-07 12:15:53 -05:00 committed by GitHub
commit c0329ef01e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 16297 additions and 233 deletions

View file

@ -53,8 +53,8 @@
#endif #endif
#ifdef ARDUINOJSON_VERSION #ifdef ARDUINOJSON_VERSION
#if !(ARDUINOJSON_VERSION_MAJOR == 6 and ARDUINOJSON_VERSION_MINOR == 7) #if !(ARDUINOJSON_VERSION_MAJOR == 6 and ARDUINOJSON_VERSION_MINOR == 8)
#error "Install ArduinoJson v6.7.0-beta" #error "Install ArduinoJson v6.8.0-beta"
#endif #endif
#endif #endif
@ -64,6 +64,9 @@
ESPAsyncE131 e131(END_UNIVERSE - START_UNIVERSE + 1); ESPAsyncE131 e131(END_UNIVERSE - START_UNIVERSE + 1);
#endif #endif
#ifdef USE_HTML_MIN_GZ
#include "html_gz.h"
#endif
// *************************************************************************** // ***************************************************************************
// Instanciate HTTP(80) / WebSockets(81) Server // Instanciate HTTP(80) / WebSockets(81) Server
@ -81,39 +84,41 @@ ESP8266HTTPUpdateServer httpUpdater;
// *************************************************************************** // ***************************************************************************
// https://github.com/kitesurfer1404/WS2812FX // https://github.com/kitesurfer1404/WS2812FX
#include <WS2812FX.h> #include <WS2812FX.h>
WS2812FX strip = WS2812FX(NUMLEDS, PIN, NEO_GRB + NEO_KHZ800); // WS2812FX strip = WS2812FX(NUMLEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
WS2812FX* strip;
// Parameter 1 = number of pixels in strip #if defined(USE_WS2812FX_DMA) or defined(USE_WS2812FX_UART1) or defined(USE_WS2812FX_UART2)
// Parameter 2 = Arduino pin number (most are valid) #include <NeoPixelBus.h>
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
#ifdef USE_WS2812FX_DMA // Uses GPIO3/RXD0/RX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods #ifdef USE_WS2812FX_DMA // Uses GPIO3/RXD0/RX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
#include <NeoPixelBus.h> NeoEsp8266Dma800KbpsMethod* dma;
NeoEsp8266Dma800KbpsMethod dma = NeoEsp8266Dma800KbpsMethod(NUMLEDS, 3); //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) #endif
#ifdef USE_WS2812FX_UART1 // Uses UART1: GPIO1/TXD0/TX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
NeoEsp8266Uart0800KbpsMethod* dma;
#endif
#ifdef USE_WS2812FX_UART2 // Uses UART2: GPIO2/TXD1/D4, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
NeoEsp8266Uart1800KbpsMethod* dma;
#endif
void initDMA(uint16_t stripSize = NUMLEDS){
if (dma) delete dma;
#ifdef USE_WS2812FX_DMA // Uses GPIO3/RXD0/RX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
dma = new NeoEsp8266Dma800KbpsMethod(stripSize, 3); //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//NeoEsp8266Dma400KbpsMethod dma = NeoEsp8266Dma400KbpsMethod(NUMLEDS, 3); //400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) //NeoEsp8266Dma400KbpsMethod dma = NeoEsp8266Dma400KbpsMethod(NUMLEDS, 3); //400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
#endif #endif
#ifdef USE_WS2812FX_UART1 // Uses UART1: GPIO1/TXD0/TX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods #ifdef USE_WS2812FX_UART1 // Uses UART1: GPIO1/TXD0/TX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
#include <NeoPixelBus.h> dma = new NeoEsp8266Uart0800KbpsMethod(stripSize, 3);
NeoEsp8266Uart0800KbpsMethod dma = NeoEsp8266Uart0800KbpsMethod(NUMLEDS, 3);
#endif #endif
#ifdef USE_WS2812FX_UART2 // Uses UART2: GPIO2/TXD1/D4, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods #ifdef USE_WS2812FX_UART2 // Uses UART2: GPIO2/TXD1/D4, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
#include <NeoPixelBus.h> dma = new NeoEsp8266Uart1800KbpsMethod(stripSize, 3);
NeoEsp8266Uart1800KbpsMethod dma = NeoEsp8266Uart1800KbpsMethod(NUMLEDS, 3);
#endif #endif
#if defined(USE_WS2812FX_DMA) or defined(USE_WS2812FX_UART) dma->Initialize();
}
void DMA_Show(void) { void DMA_Show(void) {
if(dma.IsReadyToUpdate()) { if(dma->IsReadyToUpdate()) {
memcpy(dma.getPixels(), strip.getPixels(), dma.getPixelsSize()); memcpy(dma->getPixels(), strip->getPixels(), dma->getPixelsSize());
dma.Update(); dma->Update();
} }
} }
#endif #endif
@ -202,10 +207,10 @@ void configModeCallback (WiFiManager *myWiFiManager) {
ticker.attach(0.2, tick); ticker.attach(0.2, tick);
uint16_t i; uint16_t i;
for (i = 0; i < strip.numPixels(); i++) { for (i = 0; i < strip->numPixels(); i++) {
strip.setPixelColor(i, 0, 0, 255); strip->setPixelColor(i, 0, 0, 255);
} }
strip.show(); strip->show();
} }
//callback notifying us of the need to save config //callback notifying us of the need to save config
@ -224,6 +229,50 @@ void saveConfigCallback () {
// *************************************************************************** // ***************************************************************************
#include "request_handlers.h" #include "request_handlers.h"
#ifdef CUSTOM_WS2812FX_ANIMATIONS
#include "custom_ws2812fx_animations.h" // Add animations in this file
#endif
// function to Initialize the strip
void initStrip(uint16_t stripSize = WS2812FXStripSettings.stripSize, neoPixelType RGBOrder = WS2812FXStripSettings.RGBOrder, uint8_t pin = WS2812FXStripSettings.pin){
if (strip) {
delete strip;
WS2812FXStripSettings.stripSize = stripSize;
WS2812FXStripSettings.RGBOrder = RGBOrder;
WS2812FXStripSettings.pin = pin;
}
strip = new WS2812FX(stripSize, pin, RGBOrder + NEO_KHZ800);
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
strip->init();
#if defined(USE_WS2812FX_DMA) or defined(USE_WS2812FX_UART1) or defined(USE_WS2812FX_UART2)
initDMA(stripSize);
strip->setCustomShow(DMA_Show);
#endif
strip->setBrightness(brightness);
strip->setSpeed(convertSpeed(ws2812fx_speed));
//strip->setMode(ws2812fx_mode);
strip->setColor(main_color.red, main_color.green, main_color.blue);
strip->setOptions(0, GAMMA); // We only have one WS2812FX segment, set color to human readable GAMMA correction
#ifdef CUSTOM_WS2812FX_ANIMATIONS
strip->setCustomMode(F("Fire 2012"), myCustomEffect);
#endif
strip->start();
if(mode != HOLD) mode = SET_MODE;
saveWS2812FXStripSettings.once(3, writeStripConfigFS);
}
// *************************************************************************** // ***************************************************************************
// Include: Color modes // Include: Color modes
// *************************************************************************** // ***************************************************************************
@ -271,16 +320,8 @@ void setup() {
// *************************************************************************** // ***************************************************************************
// Setup: Neopixel // Setup: Neopixel
// *************************************************************************** // ***************************************************************************
strip.init(); readStripConfigFS(); // Read config from FS first
#if defined(USE_WS2812FX_DMA) or defined(USE_WS2812FX_UART) initStrip();
dma.Initialize();
strip.setCustomShow(DMA_Show);
#endif
strip.setBrightness(brightness);
strip.setSpeed(convertSpeed(ws2812fx_speed));
//strip.setMode(FX_MODE_RAINBOW_CYCLE);
strip.setColor(main_color.red, main_color.green, main_color.blue);
strip.start();
// *************************************************************************** // ***************************************************************************
// Setup: WiFiManager // Setup: WiFiManager
@ -306,10 +347,16 @@ void setup() {
#endif #endif
WiFiManagerParameter custom_mqtt_host("host", "MQTT hostname", mqtt_host, 64); WiFiManagerParameter custom_mqtt_host("host", "MQTT hostname", mqtt_host, 64);
WiFiManagerParameter custom_mqtt_port("port", "MQTT port", mqtt_port, 6); WiFiManagerParameter custom_mqtt_port("port", "MQTT port", mqtt_port, 6);
WiFiManagerParameter custom_mqtt_user("user", "MQTT user", mqtt_user, 32); WiFiManagerParameter custom_mqtt_user("user", "MQTT user", mqtt_user, 32, " maxlength=31");
WiFiManagerParameter custom_mqtt_pass("pass", "MQTT pass", mqtt_pass, 32); WiFiManagerParameter custom_mqtt_pass("pass", "MQTT pass", mqtt_pass, 32, " maxlength=31 type='password'");
#endif #endif
sprintf(strip_size, "%d", WS2812FXStripSettings.stripSize);
sprintf(led_pin, "%d", WS2812FXStripSettings.pin);
WiFiManagerParameter custom_strip_size("strip_size", "Number of LEDs", strip_size, 3);
WiFiManagerParameter custom_led_pin("led_pin", "LED GPIO", led_pin, 2);
//Local intialization. Once its business is done, there is no need to keep it around //Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wifiManager; WiFiManager wifiManager;
//reset settings - for testing //reset settings - for testing
@ -329,6 +376,9 @@ void setup() {
wifiManager.addParameter(&custom_mqtt_pass); wifiManager.addParameter(&custom_mqtt_pass);
#endif #endif
wifiManager.addParameter(&custom_strip_size);
wifiManager.addParameter(&custom_led_pin);
WiFi.setSleepMode(WIFI_NONE_SLEEP); WiFi.setSleepMode(WIFI_NONE_SLEEP);
// Uncomment if you want to restart ESP8266 if it cannot connect to WiFi. // Uncomment if you want to restart ESP8266 if it cannot connect to WiFi.
@ -361,6 +411,16 @@ 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());
strcpy(strip_size, custom_strip_size.getValue());
strcpy(led_pin, custom_led_pin.getValue());
if(atoi(strip_size) != WS2812FXStripSettings.stripSize)
WS2812FXStripSettings.stripSize = atoi(strip_size);
uint8_t pin = atoi(led_pin);
if ((pin == 16 or pin == 5 or pin == 4 or pin == 0 or pin == 2 or pin == 14 or pin == 12 or pin == 13 or pin == 15 or pin == 3 or pin == 1) and (pin != WS2812FXStripSettings.pin) )
WS2812FXStripSettings.pin = pin;
initStrip();
//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!");
@ -441,9 +501,6 @@ void setup() {
#ifdef ENABLE_MQTT #ifdef ENABLE_MQTT
if (mqtt_host != "" && atoi(mqtt_port) > 0) { if (mqtt_host != "" && atoi(mqtt_port) > 0) {
snprintf(mqtt_intopic, sizeof mqtt_intopic, "%s/in", HOSTNAME);
snprintf(mqtt_outtopic, sizeof mqtt_outtopic, "%s/out", HOSTNAME);
DBG_OUTPUT_PORT.printf("MQTT active: %s:%d\n", mqtt_host, String(mqtt_port).toInt()); DBG_OUTPUT_PORT.printf("MQTT active: %s:%d\n", mqtt_host, String(mqtt_port).toInt());
mqtt_client.setServer(mqtt_host, atoi(mqtt_port)); mqtt_client.setServer(mqtt_host, atoi(mqtt_port));
@ -459,6 +516,7 @@ void setup() {
amqttClient.setServer(mqtt_host, atoi(mqtt_port)); amqttClient.setServer(mqtt_host, atoi(mqtt_port));
if (mqtt_user != "" or mqtt_pass != "") amqttClient.setCredentials(mqtt_user, mqtt_pass); if (mqtt_user != "" or mqtt_pass != "") amqttClient.setCredentials(mqtt_user, mqtt_pass);
amqttClient.setClientId(mqtt_clientid); amqttClient.setClientId(mqtt_clientid);
amqttClient.setWill(mqtt_will_topic, 2, true, mqtt_will_payload, 0);
connectToMqtt(); connectToMqtt();
} }
@ -515,7 +573,7 @@ void setup() {
}, handleFileUpload); }, handleFileUpload);
//get heap status, analog input value and all GPIO statuses in one json call //get heap status, analog input value and all GPIO statuses in one json call
server.on("/esp_status", HTTP_GET, []() { server.on("/esp_status", HTTP_GET, []() {
DynamicJsonDocument jsonBuffer; DynamicJsonDocument jsonBuffer(JSON_OBJECT_SIZE(21) + 1500);
JsonObject json = jsonBuffer.to<JsonObject>(); JsonObject json = jsonBuffer.to<JsonObject>();
json["HOSTNAME"] = HOSTNAME; json["HOSTNAME"] = HOSTNAME;
@ -533,12 +591,15 @@ void setup() {
#if defined(USE_WS2812FX_DMA) #if defined(USE_WS2812FX_DMA)
json["animation_lib"] = "WS2812FX_DMA"; json["animation_lib"] = "WS2812FX_DMA";
json["pin"] = 3; json["pin"] = 3;
#elif defined(USE_WS2812FX_UART) #elif defined(USE_WS2812FX_UART1)
json["animation_lib"] = "WS2812FX_UART"; json["animation_lib"] = "WS2812FX_UART1";
json["pin"] = 1;
#elif defined(USE_WS2812FX_UART2)
json["animation_lib"] = "WS2812FX_UART2";
json["pin"] = 2; json["pin"] = 2;
#else #else
json["animation_lib"] = "WS2812FX"; json["animation_lib"] = "WS2812FX";
json["pin"] = PIN; json["pin"] = LED_PIN;
#endif #endif
json["number_leds"] = NUMLEDS; json["number_leds"] = NUMLEDS;
#ifdef ENABLE_BUTTON #ifdef ENABLE_BUTTON
@ -581,6 +642,25 @@ void setup() {
server.send(200, "application/json", json_str); server.send(200, "application/json", json_str);
}); });
server.on("/", HTTP_GET, [&](){
#ifdef USE_HTML_MIN_GZ
server.sendHeader("Content-Encoding", "gzip", true);
server.send_P(200, PSTR("text/html"), index_htm_gz, index_htm_gz_len);
#else
if (!handleFileRead(server.uri()))
handleNotFound();
#endif
});
server.on("/edit", HTTP_GET, [&](){
#ifdef USE_HTML_MIN_GZ
server.sendHeader("Content-Encoding", "gzip", true);
server.send_P(200, PSTR("text/html"), edit_htm_gz, edit_htm_gz_len);
#else
if (!handleFileRead(server.uri()))
handleNotFound();
#endif
});
//called when the url is not defined here //called when the url is not defined here
//use it to load content from SPIFFS //use it to load content from SPIFFS
@ -626,7 +706,7 @@ void setup() {
mqtt_client.publish(mqtt_outtopic, String(String("OK %") + String(brightness)).c_str()); mqtt_client.publish(mqtt_outtopic, String(String("OK %") + String(brightness)).c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK %") + String(brightness)).c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String(String("OK %") + String(brightness)).c_str());
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = true; stateOn = true;
@ -650,12 +730,12 @@ void setup() {
if (server.arg("d").toInt() >= 0) { if (server.arg("d").toInt() >= 0) {
ws2812fx_speed = server.arg("d").toInt(); ws2812fx_speed = server.arg("d").toInt();
ws2812fx_speed = constrain(ws2812fx_speed, 0, 255); ws2812fx_speed = constrain(ws2812fx_speed, 0, 255);
strip.setSpeed(convertSpeed(ws2812fx_speed)); strip->setSpeed(convertSpeed(ws2812fx_speed));
#ifdef ENABLE_MQTT #ifdef ENABLE_MQTT
mqtt_client.publish(mqtt_outtopic, String(String("OK ?") + String(ws2812fx_speed)).c_str()); mqtt_client.publish(mqtt_outtopic, String(String("OK ?") + String(ws2812fx_speed)).c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK ?") + String(ws2812fx_speed)).c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String(String("OK ?") + String(ws2812fx_speed)).c_str());
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState); if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
@ -692,6 +772,105 @@ void setup() {
getStatusJSON(); getStatusJSON();
}); });
server.on("/pixelconf", []() {
/*
// This will be used later when web-interface is ready and HTTP_GET will not be allowed to update the Strip Settings
if(server.args() == 0 and server.method() != HTTP_POST)
{
server.sendHeader("Access-Control-Allow-Origin", "*");
server.send(200, "text/plain", "Only HTTP POST method is allowed and check the number of arguments!");
return;
}
*/
bool updateStrip = false;
if(server.hasArg("ct")){
uint16_t pixelCt = server.arg("ct").toInt();
if (pixelCt > 0) {
WS2812FXStripSettings.stripSize = pixelCt;
updateStrip = true;
DBG_OUTPUT_PORT.printf("/pixels: Count# %d\n", pixelCt);
}
}
if(server.hasArg("rgbo")){
String RGBOrder = server.arg("rgbo");
DBG_OUTPUT_PORT.print("/pixels: RGB Order# ");
if (RGBOrder == "grb") {
WS2812FXStripSettings.RGBOrder = NEO_GRB;
updateStrip = true;
DBG_OUTPUT_PORT.println(RGBOrder);
} else if (RGBOrder == "gbr") {
WS2812FXStripSettings.RGBOrder = NEO_GBR;
updateStrip = true;
DBG_OUTPUT_PORT.println(RGBOrder);
} else if (RGBOrder == "rgb") {
WS2812FXStripSettings.RGBOrder = NEO_RGB;
updateStrip = true;
DBG_OUTPUT_PORT.println(RGBOrder);
} else if (RGBOrder == "rbg") {
WS2812FXStripSettings.RGBOrder = NEO_RBG;
updateStrip = true;
DBG_OUTPUT_PORT.println(RGBOrder);
} else if (RGBOrder == "brg") {
WS2812FXStripSettings.RGBOrder = NEO_BRG;
updateStrip = true;
DBG_OUTPUT_PORT.println(RGBOrder);
} else if (RGBOrder == "bgr") {
WS2812FXStripSettings.RGBOrder = NEO_BGR;
updateStrip = true;
DBG_OUTPUT_PORT.println(RGBOrder);
} else {
DBG_OUTPUT_PORT.println("invalid input!");
}
}
if(server.hasArg("pin")){
uint8_t pin = server.arg("pin").toInt();
DBG_OUTPUT_PORT.print("/pixels: GPIO used# ");
#if defined(USE_WS2812FX_DMA) or defined(USE_WS2812FX_UART1) or defined(USE_WS2812FX_UART2)
#ifdef USE_WS2812FX_DMA
DBG_OUTPUT_PORT.println("3");
#endif
#ifdef USE_WS2812FX_UART1
DBG_OUTPUT_PORT.println("2");
#endif
#ifdef USE_WS2812FX_UART2
DBG_OUTPUT_PORT.println("1");
#endif
#else
if (pin == 16 or pin == 5 or pin == 4 or pin == 0 or pin == 2 or pin == 14 or pin == 12 or pin == 13 or pin == 15 or pin == 3 or pin == 1) {
WS2812FXStripSettings.pin = pin;
updateStrip = true;
DBG_OUTPUT_PORT.println(pin);
} else {
DBG_OUTPUT_PORT.println("invalid input!");
}
#endif
}
if(updateStrip)
{
ws2812fx_mode = strip->getMode();
if(strip->isRunning()) strip->stop();
initStrip();
strip->setMode(ws2812fx_mode);
strip->trigger();
}
DynamicJsonDocument jsonBuffer(200);
JsonObject json = jsonBuffer.to<JsonObject>();
json["pixel_pount"] = WS2812FXStripSettings.stripSize;
json["rgb_order"] = WS2812FXStripSettings.RGBOrder;
json["pin"] = WS2812FXStripSettings.pin;
String json_str;
serializeJson(json, json_str);
server.sendHeader("Access-Control-Allow-Origin", "*");
server.send(200, "application/json", json_str);
});
server.on("/off", []() { server.on("/off", []() {
#ifdef ENABLE_LEGACY_ANIMATIONS #ifdef ENABLE_LEGACY_ANIMATIONS
exit_func = true; exit_func = true;
@ -703,7 +882,7 @@ void setup() {
mqtt_client.publish(mqtt_outtopic, String("OK =off").c_str()); mqtt_client.publish(mqtt_outtopic, String("OK =off").c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =off").c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String("OK =off").c_str());
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = false; stateOn = false;
@ -726,7 +905,7 @@ void setup() {
mqtt_client.publish(mqtt_outtopic, String("OK =all").c_str()); mqtt_client.publish(mqtt_outtopic, String("OK =all").c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =all").c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String("OK =all").c_str());
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = true; stateOn = true;
@ -746,7 +925,7 @@ void setup() {
mqtt_client.publish(mqtt_outtopic, String("OK =wipe").c_str()); mqtt_client.publish(mqtt_outtopic, String("OK =wipe").c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =wipe").c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String("OK =wipe").c_str());
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = true; stateOn = true;
@ -765,7 +944,7 @@ void setup() {
mqtt_client.publish(mqtt_outtopic, String("OK =rainbow").c_str()); mqtt_client.publish(mqtt_outtopic, String("OK =rainbow").c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =rainbow").c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String("OK =rainbow").c_str());
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = true; stateOn = true;
@ -784,7 +963,7 @@ void setup() {
mqtt_client.publish(mqtt_outtopic, String("OK =rainbowCycle").c_str()); mqtt_client.publish(mqtt_outtopic, String("OK =rainbowCycle").c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =rainbowCycle").c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String("OK =rainbowCycle").c_str());
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = true; stateOn = true;
@ -803,7 +982,7 @@ void setup() {
mqtt_client.publish(mqtt_outtopic, String("OK =theaterchase").c_str()); mqtt_client.publish(mqtt_outtopic, String("OK =theaterchase").c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =theaterchase").c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String("OK =theaterchase").c_str());
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = true; stateOn = true;
@ -822,7 +1001,7 @@ void setup() {
mqtt_client.publish(mqtt_outtopic, String("OK =twinkleRandom").c_str()); mqtt_client.publish(mqtt_outtopic, String("OK =twinkleRandom").c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =twinkleRandom").c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String("OK =twinkleRandom").c_str());
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = true; stateOn = true;
@ -841,7 +1020,7 @@ void setup() {
mqtt_client.publish(mqtt_outtopic, String("OK =theaterchaseRainbow").c_str()); mqtt_client.publish(mqtt_outtopic, String("OK =theaterchaseRainbow").c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =theaterchaseRainbow").c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String("OK =theaterchaseRainbow").c_str());
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = true; stateOn = true;
@ -860,7 +1039,7 @@ void setup() {
mqtt_client.publish(mqtt_outtopic, String("OK =e131").c_str()); mqtt_client.publish(mqtt_outtopic, String("OK =e131").c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =131").c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String("OK =131").c_str());
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = true; stateOn = true;
@ -880,7 +1059,7 @@ void setup() {
mqtt_client.publish(mqtt_outtopic, String("OK =tv").c_str()); mqtt_client.publish(mqtt_outtopic, String("OK =tv").c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =tv").c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String("OK =tv").c_str());
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = true; stateOn = true;
@ -904,7 +1083,7 @@ void setup() {
mqtt_client.publish(mqtt_outtopic, String(String("OK /") + String(ws2812fx_mode)).c_str()); mqtt_client.publish(mqtt_outtopic, String(String("OK /") + String(ws2812fx_mode)).c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK /") + String(ws2812fx_mode)).c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String(String("OK /") + String(ws2812fx_mode)).c_str());
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = true; stateOn = true;
@ -930,7 +1109,7 @@ void setup() {
// Choose one to begin listening for E1.31 data // Choose one to begin listening for E1.31 data
// if (e131.begin(E131_UNICAST)) // Listen via Unicast // if (e131.begin(E131_UNICAST)) // Listen via Unicast
if (e131.begin(E131_MULTICAST, START_UNIVERSE, END_UNIVERSE)) // Listen via Multicast if (e131.begin(E131_MULTICAST, START_UNIVERSE, END_UNIVERSE)) // Listen via Multicast
Serial.println(F("Listening for data...")); Serial.println(F("E1.31 mode setup complete."));
else else
Serial.println(F("*** e131.begin failed ***")); Serial.println(F("*** e131.begin failed ***"));
#endif #endif
@ -993,63 +1172,63 @@ void loop() {
// Simple statemachine that handles the different modes // Simple statemachine that handles the different modes
if (mode == SET_MODE) { if (mode == SET_MODE) {
DBG_OUTPUT_PORT.printf("SET_MODE: %d %d\n", ws2812fx_mode, mode); DBG_OUTPUT_PORT.printf("SET_MODE: %d %d\n", ws2812fx_mode, mode);
strip.setMode(ws2812fx_mode); strip->setMode(ws2812fx_mode);
strip.trigger(); strip->trigger();
prevmode = SET_MODE; prevmode = SET_MODE;
mode = SETCOLOR; mode = SETCOLOR;
} }
if (mode == OFF) { if (mode == OFF) {
if(strip.isRunning()) strip.stop(); //should clear memory if(strip->isRunning()) strip->stop(); //should clear memory
// mode = HOLD; // mode = HOLD;
} }
if (mode == SETCOLOR) { if (mode == SETCOLOR) {
strip.setColor(main_color.red, main_color.green, main_color.blue); strip->setColor(main_color.red, main_color.green, main_color.blue);
strip.trigger(); strip->trigger();
mode = (prevmode == SET_MODE) ? SETSPEED : HOLD; mode = (prevmode == SET_MODE) ? SETSPEED : HOLD;
} }
if (mode == SETSPEED) { if (mode == SETSPEED) {
strip.setSpeed(convertSpeed(ws2812fx_speed)); strip->setSpeed(convertSpeed(ws2812fx_speed));
strip.trigger(); strip->trigger();
mode = (prevmode == SET_MODE) ? BRIGHTNESS : HOLD; mode = (prevmode == SET_MODE) ? BRIGHTNESS : HOLD;
} }
if (mode == BRIGHTNESS) { if (mode == BRIGHTNESS) {
strip.setBrightness(brightness); strip->setBrightness(brightness);
strip.trigger(); strip->trigger();
if (prevmode == SET_MODE) prevmode = HOLD; if (prevmode == SET_MODE) prevmode = HOLD;
mode = HOLD; mode = HOLD;
} }
#ifdef ENABLE_LEGACY_ANIMATIONS #ifdef ENABLE_LEGACY_ANIMATIONS
if (mode == WIPE) { if (mode == WIPE) {
strip.setColor(main_color.red, main_color.green, main_color.blue); strip->setColor(main_color.red, main_color.green, main_color.blue);
strip.setMode(FX_MODE_COLOR_WIPE); strip->setMode(FX_MODE_COLOR_WIPE);
strip.trigger(); strip->trigger();
mode = HOLD; mode = HOLD;
} }
if (mode == RAINBOW) { if (mode == RAINBOW) {
strip.setMode(FX_MODE_RAINBOW); strip->setMode(FX_MODE_RAINBOW);
strip.trigger(); strip->trigger();
mode = HOLD; mode = HOLD;
} }
if (mode == RAINBOWCYCLE) { if (mode == RAINBOWCYCLE) {
strip.setMode(FX_MODE_RAINBOW_CYCLE); strip->setMode(FX_MODE_RAINBOW_CYCLE);
strip.trigger(); strip->trigger();
mode = HOLD; mode = HOLD;
} }
if (mode == THEATERCHASE) { if (mode == THEATERCHASE) {
strip.setColor(main_color.red, main_color.green, main_color.blue); strip->setColor(main_color.red, main_color.green, main_color.blue);
strip.setMode(FX_MODE_THEATER_CHASE); strip->setMode(FX_MODE_THEATER_CHASE);
strip.trigger(); strip->trigger();
mode = HOLD; mode = HOLD;
} }
if (mode == TWINKLERANDOM) { if (mode == TWINKLERANDOM) {
strip.setColor(main_color.red, main_color.green, main_color.blue); strip->setColor(main_color.red, main_color.green, main_color.blue);
strip.setMode(FX_MODE_TWINKLE_RANDOM); strip->setMode(FX_MODE_TWINKLE_RANDOM);
strip.trigger(); strip->trigger();
mode = HOLD; mode = HOLD;
} }
if (mode == THEATERCHASERAINBOW) { if (mode == THEATERCHASERAINBOW) {
strip.setMode(FX_MODE_THEATER_CHASE_RAINBOW); strip->setMode(FX_MODE_THEATER_CHASE_RAINBOW);
strip.trigger(); strip->trigger();
mode = HOLD; mode = HOLD;
} }
#ifdef ENABLE_E131 #ifdef ENABLE_E131
@ -1059,7 +1238,7 @@ void loop() {
#endif #endif
#endif #endif
if (mode == HOLD || mode == CUSTOM) { if (mode == HOLD || mode == CUSTOM) {
if(!strip.isRunning()) strip.start(); if(!strip->isRunning()) strip->start();
#ifdef ENABLE_LEGACY_ANIMATIONS #ifdef ENABLE_LEGACY_ANIMATIONS
if (exit_func) { if (exit_func) {
exit_func = false; exit_func = false;
@ -1069,7 +1248,7 @@ void loop() {
} }
#ifdef ENABLE_LEGACY_ANIMATIONS #ifdef ENABLE_LEGACY_ANIMATIONS
if (mode == TV) { if (mode == TV) {
if(!strip.isRunning()) strip.start(); if(!strip->isRunning()) strip->start();
tv(); tv();
} }
#endif #endif
@ -1080,7 +1259,7 @@ void loop() {
#else #else
if (mode != CUSTOM) { if (mode != CUSTOM) {
#endif #endif
strip.service(); strip->service();
} }
#ifdef ENABLE_STATE_SAVE_SPIFFS #ifdef ENABLE_STATE_SAVE_SPIFFS
@ -1091,7 +1270,7 @@ void loop() {
#ifdef ENABLE_STATE_SAVE_EEPROM #ifdef ENABLE_STATE_SAVE_EEPROM
// Check for state changes // Check for state changes
sprintf(current_state, "STA|%2d|%3d|%3d|%3d|%3d|%3d|%3d", mode, strip.getMode(), ws2812fx_speed, brightness, main_color.red, main_color.green, main_color.blue); sprintf(current_state, "STA|%2d|%3d|%3d|%3d|%3d|%3d|%3d", mode, strip->getMode(), ws2812fx_speed, brightness, main_color.red, main_color.green, main_color.blue);
if (strcmp(current_state, last_state) != 0) { if (strcmp(current_state, last_state) != 0) {
// DBG_OUTPUT_PORT.printf("STATE CHANGED: %s / %s\n", last_state, current_state); // DBG_OUTPUT_PORT.printf("STATE CHANGED: %s / %s\n", last_state, current_state);

View file

@ -25,7 +25,7 @@ void hsb2rgbAN1(uint16_t index, uint8_t sat, uint8_t bright, uint8_t myled) {
temp[1] = temp[4] = (uint8_t)((((( (index & 255) * sat) / 255) + (sat ^ 255)) * bright) / 255); temp[1] = temp[4] = (uint8_t)((((( (index & 255) * sat) / 255) + (sat ^ 255)) * bright) / 255);
temp[2] = (uint8_t)(((((((index & 255) ^ 255) * sat) / 255) + (sat ^ 255)) * bright) / 255); temp[2] = (uint8_t)(((((((index & 255) ^ 255) * sat) / 255) + (sat ^ 255)) * bright) / 255);
strip.setPixelColor(myled, temp[n + 2], temp[n + 1], temp[n]); strip->setPixelColor(myled, temp[n + 2], temp[n + 1], temp[n]);
} }
@ -37,7 +37,7 @@ void updateLed (int led, int brightness) {
uint16_t index = (i%3 == 0) ? 400 : random(0,767); uint16_t index = (i%3 == 0) ? 400 : random(0,767);
hsb2rgbAN1(index, 200, ledStates[i], i); hsb2rgbAN1(index, 200, ledStates[i], i);
} }
strip.show(); strip->show();
} }
@ -61,7 +61,7 @@ void tv() {
} }
if(currentMillis-previousMillis<twitch) if(currentMillis-previousMillis<twitch)
{ {
led=random(0, (strip.numPixels()-1)); led=random(0, (strip->numPixels()-1));
analogLevel=random(50,255);// set the range of the 3 pwm leds analogLevel=random(50,255);// set the range of the 3 pwm leds
ledState = ledState == LOW ? HIGH: LOW; // if the LED is off turn it on and vice-versa: ledState = ledState == LOW ? HIGH: LOW; // if the LED is off turn it on and vice-versa:
@ -76,7 +76,7 @@ void tv() {
darkTime = random(50,150); darkTime = random(50,150);
dipInterval = random(5,250);// cycles of flicker dipInterval = random(5,250);// cycles of flicker
} }
//strip.show(); //strip->show();
} }
} }
else else
@ -85,7 +85,7 @@ void tv() {
currentDipTime = millis(); currentDipTime = millis();
if (currentDipTime - dipStartTime < darkTime) if (currentDipTime - dipStartTime < darkTime)
{ {
for (int i=3; i<strip.numPixels(); i++) for (int i=3; i<strip->numPixels(); i++)
{ {
updateLed(i, 0); updateLed(i, 0);
} }
@ -94,6 +94,6 @@ void tv() {
{ {
timeToDip = false; timeToDip = false;
} }
strip.show(); strip->show();
} }
} }

View file

@ -0,0 +1,97 @@
/*
Example of adding the example: https://github.com/kitesurfer1404/WS2812FX/blob/master/examples/ws2812fx_custom_FastLED/ws2812fx_custom_FastLED.ino
as a custom effect
More info on how to create custom aniamtions for WS2812FX: https://github.com/kitesurfer1404/WS2812FX/blob/master/extras/WS2812FX%20Users%20Guide.md#custom-effects
*/
#include <FastLED.h> //https://github.com/FastLED/FastLED
/*
* paste in the Fire2012 code with a small edit at the end which uses the
* setPixelColor() function to copy the color data to the ws2812fx instance.
*/
// Fire2012 by Mark Kriegsman, July 2012
// as part of "Five Elements" shown here: http://youtu.be/knWiGsmgycY
////
// This basic one-dimensional 'fire' simulation works roughly as follows:
// There's a underlying array of 'heat' cells, that model the temperature
// at each point along the line. Every cycle through the simulation,
// four steps are performed:
// 1) All cells cool down a little bit, losing heat to the air
// 2) The heat from each cell drifts 'up' and diffuses a little
// 3) Sometimes randomly new 'sparks' of heat are added at the bottom
// 4) The heat from each cell is rendered as a color into the leds array
// The heat-to-color mapping uses a black-body radiation approximation.
//
// Temperature is in arbitrary units from 0 (cold black) to 255 (white hot).
//
// This simulation scales it self a bit depending on NUM_LEDS; it should look
// "OK" on anywhere from 20 to 100 LEDs without too much tweaking.
//
// I recommend running this simulation at anywhere from 30-100 frames per second,
// meaning an interframe delay of about 10-35 milliseconds.
//
// Looks best on a high-density LED setup (60+ pixels/meter).
//
//
// There are two main parameters you can play with to control the look and
// feel of your fire: COOLING (used in step 1 above), and SPARKING (used
// in step 3 above).
//
// COOLING: How much does the air cool as it rises?
// Less cooling = taller flames. More cooling = shorter flames.
// Default 50, suggested range 20-100
#define COOLING 55
// SPARKING: What chance (out of 255) is there that a new spark will be lit?
// Higher chance = more roaring fire. Lower chance = more flickery fire.
// Default 120, suggested range 50-200.
#define SPARKING 120
bool gReverseDirection = false;
void Fire2012()
{
// Array of temperature readings at each simulation cell
byte heat[WS2812FXStripSettings.stripSize];
// Step 1. Cool down every cell a little
for( int i = 0; i < WS2812FXStripSettings.stripSize; i++) {
heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / WS2812FXStripSettings.stripSize) + 2));
}
// Step 2. Heat from each cell drifts 'up' and diffuses a little
for( int k= WS2812FXStripSettings.stripSize- 1; k >= 2; k--) {
heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
}
// Step 3. Randomly ignite new 'sparks' of heat near the bottom
if( random8() < SPARKING ) {
int y = random8(7);
heat[y] = qadd8( heat[y], random8(160,255) );
}
// Step 4. Map from heat cells to LED colors
for( int j = 0; j < WS2812FXStripSettings.stripSize; j++) {
CRGB color = HeatColor( heat[j]);
int pixelnumber;
if( gReverseDirection ) {
pixelnumber = (WS2812FXStripSettings.stripSize-1) - j;
} else {
pixelnumber = j;
}
strip->setPixelColor(pixelnumber, color.red, color.green, color.blue);
}
}
uint16_t myCustomEffect() {
Fire2012();
return (strip->getSpeed() / WS2812FXStripSettings.stripSize);
}

Binary file not shown.

View file

@ -1,14 +1,14 @@
//#define USE_WS2812FX_DMA // Uses PIN is ignored & set to RX/GPIO3 Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX //#define USE_WS2812FX_DMA // LED_PIN is ignored & set to RX/GPIO3 Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX
//#define USE_WS2812FX_UART1 // Uses PIN is ignored & set to D4/GPIO2 Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX //#define USE_WS2812FX_UART1 // LED_PIN is ignored & set to D4/GPIO2 Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX
//#define USE_WS2812FX_UART2 // Uses PIN is ignored & set to TX/GPIO1 Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX //#define USE_WS2812FX_UART2 // LED_PIN is ignored & set to TX/GPIO1 Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX
// Neopixel // Neopixel
#define PIN 14 // PIN (14 / D5) where neopixel / WS2811 strip is attached #define LED_PIN 14 // LED_PIN (14 / D5) where neopixel / WS2811 strip is attached
#define NUMLEDS 24 // Number of leds in the strip #define NUMLEDS 24 // Number of leds in the strip
#define BUILTIN_LED 2 // ESP-12F has the built in LED on GPIO2, see https://github.com/esp8266/Arduino/issues/2192 #define BUILTIN_LED 2 // ESP-12F has the built in LED on GPIO2, see https://github.com/esp8266/Arduino/issues/2192
#define BUTTON 4 // Input pin (4 / D2) for switching the LED strip on / off, connect this PIN to ground to trigger button. #define BUTTON 4 // Input pin (4 / D2) for switching the LED strip on / off, connect this PIN to ground to trigger button.
const char HOSTNAME[] = "McLighting01"; // Friedly hostname #define HOSTNAME "McLighting01" // Friedly hostname
#define HTTP_OTA // If defined, enable ESP8266HTTPUpdateServer OTA code. #define HTTP_OTA // If defined, enable ESP8266HTTPUpdateServer OTA code.
//#define ENABLE_OTA // If defined, enable Arduino OTA code. //#define ENABLE_OTA // If defined, enable Arduino OTA code.
@ -19,10 +19,13 @@ const char HOSTNAME[] = "McLighting01"; // Friedly hostname
//#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 // Dont disbale this for now #define ENABLE_LEGACY_ANIMATIONS // Dont disbale this for now
#define ENABLE_E131 // E1.31 implementation #define ENABLE_E131 // E1.31 implementation
#define USE_HTML_MIN_GZ //comment for using index.htm & edit.htm from SPIFFs instead of PROGMEM
//#define CUSTOM_WS2812FX_ANIMATIONS //uncomment and put animations in "custom_ws2812fx_animations.h"
#ifdef ENABLE_E131 #ifdef ENABLE_E131
#define START_UNIVERSE 1 // First DMX Universe to listen for #define START_UNIVERSE 1 // First DMX Universe to listen for
#define END_UNIVERSE 2 // Total number of Universes to listen for, starting at UNIVERSE #define END_UNIVERSE 2 // Last Universe to listen for, starting at UNIVERSE
// MUST: END_UNIVERSE >= START_UNIVERSE
#endif #endif
//#define WIFIMGR_PORTAL_TIMEOUT 180 //#define WIFIMGR_PORTAL_TIMEOUT 180
@ -35,7 +38,7 @@ const char HOSTNAME[] = "McLighting01"; // Friedly hostname
#endif #endif
#ifdef MQTT_HOME_ASSISTANT_SUPPORT #ifdef MQTT_HOME_ASSISTANT_SUPPORT
#define MQTT_HOME_ASSISTANT_0_84_SUPPORT // Comment if using HA version < 0.84 #define MQTT_HOME_ASSISTANT_0_87_SUPPORT // Comment if using HA version < 0.87
#endif #endif
#if defined(USE_WS2812FX_DMA) and defined(USE_WS2812FX_UART) #if defined(USE_WS2812FX_DMA) and defined(USE_WS2812FX_UART)
@ -52,35 +55,36 @@ const char HOSTNAME[] = "McLighting01"; // Friedly hostname
#endif #endif
// parameters for automatically cycling favorite patterns // parameters for automatically cycling favorite patterns
uint32_t autoParams[][4] = { // color, speed, mode, duration (seconds) uint32_t autoParams[][4] = { // color, speed, mode, duration (milliseconds)
{0xff0000, 200, 1, 5.0}, // blink red for 5 seconds {0xff0000, 200, 1, 5000}, // blink red for 5 seconds
{0x00ff00, 200, 3, 10.0}, // wipe green for 10 seconds {0x00ff00, 200, 3, 10000}, // wipe green for 10 seconds
{0x0000ff, 200, 11, 5.0}, // dual scan blue for 5 seconds {0x0000ff, 200, 14, 5000}, // dual scan blue for 5 seconds
{0x0000ff, 200, 42, 15.0} // fireworks for 15 seconds {0x0000ff, 200, 45, 15000} // fireworks for 15 seconds
}; };
#if defined(ENABLE_MQTT) or defined(ENABLE_AMQTT) #if defined(ENABLE_MQTT) or defined(ENABLE_AMQTT)
const char mqtt_will_topic[] = HOSTNAME "/status";
const char mqtt_will_payload[] = "ONLINE";
const char mqtt_intopic[] = HOSTNAME "/in";
const char mqtt_outtopic[] = HOSTNAME "/out";
#ifdef ENABLE_MQTT #ifdef ENABLE_MQTT
#define MQTT_MAX_PACKET_SIZE 2048 #define MQTT_MAX_PACKET_SIZE 512
#define MQTT_MAX_RECONNECT_TRIES 4 #define MQTT_MAX_RECONNECT_TRIES 4
int mqtt_reconnect_retries = 0; int mqtt_reconnect_retries = 0;
char mqtt_intopic[strlen(HOSTNAME) + 4 + 5]; // Topic in will be: <HOSTNAME>/in
char mqtt_outtopic[strlen(HOSTNAME) + 5 + 5]; // Topic out will be: <HOSTNAME>/out
uint8_t qossub = 0; // PubSubClient can sub qos 0 or 1 uint8_t qossub = 0; // PubSubClient can sub qos 0 or 1
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
String mqtt_intopic = String(HOSTNAME) + "/in";
String mqtt_outtopic = String(HOSTNAME) + "/out";
uint8_t qossub = 0; // AMQTT can sub qos 0 or 1 or 2 uint8_t qossub = 0; // AMQTT can sub qos 0 or 1 or 2
uint8_t qospub = 0; // AMQTT can pub qos 0 or 1 or 2 uint8_t qospub = 0; // AMQTT can pub qos 0 or 1 or 2
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
String mqtt_ha = "home/" + String(HOSTNAME) + "_ha/"; const char mqtt_ha_state_in[] = "home/" HOSTNAME "_ha/state/in";
String mqtt_ha_state_in = mqtt_ha + "state/in"; const char mqtt_ha_state_out[] = "home/" HOSTNAME "_ha/state/out";
String mqtt_ha_state_out = mqtt_ha + "state/out";
const char* on_cmd = "ON"; const char* on_cmd = "ON";
const char* off_cmd = "OFF"; const char* off_cmd = "OFF";
@ -94,7 +98,7 @@ uint32_t autoParams[][4] = { // color, speed, mode, duration (seconds)
#ifdef ENABLE_MQTT_HOSTNAME_CHIPID #ifdef ENABLE_MQTT_HOSTNAME_CHIPID
char mqtt_clientid[64]; char mqtt_clientid[64];
#else #else
const char* mqtt_clientid = HOSTNAME; const char mqtt_clientid[] = HOSTNAME;
#endif #endif
char mqtt_host[64] = ""; char mqtt_host[64] = "";

15646
Arduino/McLighting/html_gz.h Normal file

File diff suppressed because it is too large Load diff

View file

@ -27,9 +27,9 @@ void handleE131(){
uint16_t len = (170 + multipacketOffset > NUMLEDS) ? (NUMLEDS - multipacketOffset) : 170; uint16_t len = (170 + multipacketOffset > NUMLEDS) ? (NUMLEDS - multipacketOffset) : 170;
for (uint16_t i = 0; i < len; i++){ for (uint16_t i = 0; i < len; i++){
uint16_t j = i * 3; uint16_t j = i * 3;
strip.setPixelColor(i + multipacketOffset, data[j], data[j + 1], data[j + 2]); strip->setPixelColor(i + multipacketOffset, data[j], data[j + 1], data[j + 2]);
} }
strip.show(); strip->show();
checkForRequests(); checkForRequests();
} }
} }
@ -63,7 +63,7 @@ void getArgs() {
} }
if (server.arg("m") != "") { if (server.arg("m") != "") {
ws2812fx_mode = constrain(server.arg("m").toInt(), 0, strip.getModeCount() - 1); ws2812fx_mode = constrain(server.arg("m").toInt(), 0, strip->getModeCount() - 1);
} }
if (server.arg("c").toInt() > 0) { if (server.arg("c").toInt() > 0) {
@ -114,7 +114,7 @@ void handleSetMainColor(uint8_t * mypayload) {
main_color.red = ((rgb >> 16) & 0xFF); main_color.red = ((rgb >> 16) & 0xFF);
main_color.green = ((rgb >> 8) & 0xFF); main_color.green = ((rgb >> 8) & 0xFF);
main_color.blue = ((rgb >> 0) & 0xFF); main_color.blue = ((rgb >> 0) & 0xFF);
// strip.setColor(main_color.red, main_color.green, main_color.blue); // strip->setColor(main_color.red, main_color.green, main_color.blue);
mode = SETCOLOR; mode = SETCOLOR;
} }
@ -140,14 +140,17 @@ void handleSetSingleLED(uint8_t * mypayload, uint8_t firstChar = 0) {
strncpy (templed, (const char *) &mypayload[firstChar], 2 ); strncpy (templed, (const char *) &mypayload[firstChar], 2 );
uint8_t led = atoi(templed); uint8_t led = atoi(templed);
DBG_OUTPUT_PORT.printf("led value: [%i]. Entry threshold: <= [%i] (=> %s)\n", led, strip.numPixels(), mypayload ); DBG_OUTPUT_PORT.printf("led value: [%i]. Entry threshold: <= [%i] (=> %s)\n", led, strip->numPixels(), mypayload );
if (led <= strip.numPixels()) { if (led <= strip->numPixels()) {
char redhex[3]; char redhex[3];
char greenhex[3]; char greenhex[3];
char bluehex[3]; char bluehex[3];
strncpy (redhex, (const char *) &mypayload[2 + firstChar], 2 ); strncpy (redhex, (const char *) &mypayload[2 + firstChar], 2 );
strncpy (greenhex, (const char *) &mypayload[4 + firstChar], 2 ); strncpy (greenhex, (const char *) &mypayload[4 + firstChar], 2 );
strncpy (bluehex, (const char *) &mypayload[6 + firstChar], 2 ); strncpy (bluehex, (const char *) &mypayload[6 + firstChar], 2 );
redhex[2] = 0x00;
greenhex[2] = 0x00;
bluehex[2] = 0x00;
ledstates[led].red = strtol(redhex, NULL, 16); ledstates[led].red = strtol(redhex, NULL, 16);
ledstates[led].green = strtol(greenhex, NULL, 16); ledstates[led].green = strtol(greenhex, NULL, 16);
ledstates[led].blue = strtol(bluehex, NULL, 16); ledstates[led].blue = strtol(bluehex, NULL, 16);
@ -156,8 +159,8 @@ void handleSetSingleLED(uint8_t * mypayload, uint8_t firstChar = 0) {
DBG_OUTPUT_PORT.printf("WS: Set single led [%i] to [%i] [%i] [%i] (%s)!\n", led, ledstates[led].red, ledstates[led].green, ledstates[led].blue, mypayload); DBG_OUTPUT_PORT.printf("WS: Set single led [%i] to [%i] [%i] [%i] (%s)!\n", led, ledstates[led].red, ledstates[led].green, ledstates[led].blue, mypayload);
strip.setPixelColor(led, ledstates[led].red, ledstates[led].green, ledstates[led].blue); strip->setPixelColor(led, ledstates[led].red, ledstates[led].green, ledstates[led].blue);
strip.show(); strip->show();
} }
#ifdef ENABLE_LEGACY_ANIMATIONS #ifdef ENABLE_LEGACY_ANIMATIONS
exit_func = true; exit_func = true;
@ -234,10 +237,10 @@ void setModeByStateString(String saved_state_string) {
DBG_OUTPUT_PORT.printf("main_color.green: %d\n", main_color.green); DBG_OUTPUT_PORT.printf("main_color.green: %d\n", main_color.green);
DBG_OUTPUT_PORT.printf("main_color.blue: %d\n", main_color.blue); DBG_OUTPUT_PORT.printf("main_color.blue: %d\n", main_color.blue);
strip.setMode(ws2812fx_mode); strip->setMode(ws2812fx_mode);
strip.setSpeed(convertSpeed(ws2812fx_speed)); strip->setSpeed(convertSpeed(ws2812fx_speed));
strip.setBrightness(brightness); strip->setBrightness(brightness);
strip.setColor(main_color.red, main_color.green, main_color.blue); strip->setColor(main_color.red, main_color.green, main_color.blue);
} }
#ifdef ENABLE_LEGACY_ANIMATIONS #ifdef ENABLE_LEGACY_ANIMATIONS
@ -306,7 +309,7 @@ void setModeByStateString(String saved_state_string) {
void handleE131NamedMode(String str_mode) { void handleE131NamedMode(String str_mode) {
exit_func = true; exit_func = true;
if (str_mode.startsWith("=e131") or str_mode.startsWith("/e131")) { if (str_mode.startsWith("=e131") or str_mode.startsWith("/e131")) {
if(strip.isRunning()) strip.stop(); if(strip->isRunning()) strip->stop();
mode = E131; mode = E131;
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = true; stateOn = true;
@ -318,18 +321,18 @@ void setModeByStateString(String saved_state_string) {
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);
ws2812fx_mode = constrain(ws2812fx_mode_tmp, 0, strip.getModeCount() - 1); ws2812fx_mode = constrain(ws2812fx_mode_tmp, 0, strip->getModeCount() - 1);
} }
String listStatusJSON(void) { String listStatusJSON(void) {
uint8_t tmp_mode = (mode == SET_MODE) ? (uint8_t) ws2812fx_mode : strip.getMode(); uint8_t tmp_mode = (mode == SET_MODE) ? (uint8_t) ws2812fx_mode : strip->getMode();
const size_t bufferSize = JSON_ARRAY_SIZE(3) + JSON_OBJECT_SIZE(6) + 500; const size_t bufferSize = JSON_ARRAY_SIZE(3) + JSON_OBJECT_SIZE(6) + 500;
DynamicJsonDocument jsonBuffer(bufferSize); DynamicJsonDocument jsonBuffer(bufferSize);
JsonObject root = jsonBuffer.to<JsonObject>(); JsonObject root = jsonBuffer.to<JsonObject>();
root["mode"] = (uint8_t) mode; root["mode"] = (uint8_t) mode;
root["ws2812fx_mode"] = tmp_mode; root["ws2812fx_mode"] = tmp_mode;
root["ws2812fx_mode_name"] = strip.getModeName(tmp_mode); root["ws2812fx_mode_name"] = strip->getModeName(tmp_mode);
root["speed"] = ws2812fx_speed; root["speed"] = ws2812fx_speed;
root["brightness"] = brightness; root["brightness"] = brightness;
JsonArray color = root.createNestedArray("color"); JsonArray color = root.createNestedArray("color");
@ -349,7 +352,7 @@ void getStatusJSON() {
} }
String listModesJSON(void) { String listModesJSON(void) {
const size_t bufferSize = JSON_ARRAY_SIZE(strip.getModeCount()+1) + strip.getModeCount()*JSON_OBJECT_SIZE(2) + 1000; const size_t bufferSize = JSON_ARRAY_SIZE(strip->getModeCount()+1) + strip->getModeCount()*JSON_OBJECT_SIZE(2) + 1000;
DynamicJsonDocument jsonBuffer(bufferSize); DynamicJsonDocument jsonBuffer(bufferSize);
JsonArray json = jsonBuffer.to<JsonArray>(); JsonArray json = jsonBuffer.to<JsonArray>();
#ifdef ENABLE_E131 #ifdef ENABLE_E131
@ -357,10 +360,10 @@ String listModesJSON(void) {
objecte131["mode"] = "e131"; objecte131["mode"] = "e131";
objecte131["name"] = "E131"; objecte131["name"] = "E131";
#endif #endif
for (uint8_t i = 0; i < strip.getModeCount(); i++) { for (uint8_t i = 0; i < strip->getModeCount(); i++) {
JsonObject object = json.createNestedObject(); JsonObject object = json.createNestedObject();
object["mode"] = i; object["mode"] = i;
object["name"] = strip.getModeName(i); object["name"] = strip->getModeName(i);
} }
JsonObject object = json.createNestedObject(); JsonObject object = json.createNestedObject();
@ -422,12 +425,11 @@ Ticker autoTicker;
int autoCount = 0; int autoCount = 0;
void autoTick() { void autoTick() {
strip.setColor(autoParams[autoCount][0]); strip->setColor(autoParams[autoCount][0]);
strip.setSpeed(convertSpeed((uint8_t)autoParams[autoCount][1])); strip->setSpeed(convertSpeed((uint8_t)autoParams[autoCount][1]));
strip.setMode((uint8_t)autoParams[autoCount][2]); strip->setMode((uint8_t)autoParams[autoCount][2]);
autoTicker.once((float)autoParams[autoCount][3], autoTick); autoTicker.once_ms((uint32_t)autoParams[autoCount][3], autoTick);
DBG_OUTPUT_PORT.print("autoTick "); DBG_OUTPUT_PORT.printf("autoTick[%d]: {0x%06x, %d, %d, %d}\n", autoCount, autoParams[autoCount][0], (uint8_t)autoParams[autoCount][1], (uint8_t)autoParams[autoCount][2], (uint32_t)autoParams[autoCount][3]);
DBG_OUTPUT_PORT.println(autoCount);
autoCount++; autoCount++;
if (autoCount >= (sizeof(autoParams) / sizeof(autoParams[0]))) autoCount = 0; if (autoCount >= (sizeof(autoParams) / sizeof(autoParams[0]))) autoCount = 0;
@ -436,12 +438,12 @@ void autoTick() {
void handleAutoStart() { void handleAutoStart() {
autoCount = 0; autoCount = 0;
autoTick(); autoTick();
strip.start(); strip->start();
} }
void handleAutoStop() { void handleAutoStop() {
autoTicker.detach(); autoTicker.detach();
strip.stop(); strip->stop();
} }
void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) { void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
@ -459,7 +461,7 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str()); mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK ") + String((char *)payload)).c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String(String("OK ") + String((char *)payload)).c_str());
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = true; stateOn = true;
@ -490,7 +492,7 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str()); mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK ") + String((char *)payload)).c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String(String("OK ") + String((char *)payload)).c_str());
#endif #endif
} }
@ -510,7 +512,7 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str()); mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK ") + String((char *)payload)).c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String(String("OK ") + String((char *)payload)).c_str());
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = true; stateOn = true;
@ -535,7 +537,7 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str()); mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK ") + String((char *)payload)).c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String(String("OK ") + String((char *)payload)).c_str());
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = true; stateOn = true;
@ -560,7 +562,7 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str()); mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK ") + String((char *)payload)).c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String(String("OK ") + String((char *)payload)).c_str());
#endif #endif
} }
@ -578,7 +580,7 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str()); mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK ") + String((char *)payload)).c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String(String("OK ") + String((char *)payload)).c_str());
#endif #endif
} }
@ -597,7 +599,7 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str()); mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK ") + String((char *)payload)).c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String(String("OK ") + String((char *)payload)).c_str());
#endif #endif
} }
@ -622,7 +624,7 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str()); mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK ") + String((char *)payload)).c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String(String("OK ") + String((char *)payload)).c_str());
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState); if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
@ -642,7 +644,7 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
mqtt_client.publish(mqtt_outtopic, json.c_str()); mqtt_client.publish(mqtt_outtopic, json.c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, json.c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, json.c_str());
#endif #endif
} else { } else {
DBG_OUTPUT_PORT.print("WS: "); DBG_OUTPUT_PORT.print("WS: ");
@ -669,7 +671,7 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
//DBG_OUTPUT_PORT.printf("Result: %d / %d", res, json_modes.length()); //DBG_OUTPUT_PORT.printf("Result: %d / %d", res, json_modes.length());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, json.c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, json.c_str());
#endif #endif
} else { } else {
DBG_OUTPUT_PORT.print("WS: "); DBG_OUTPUT_PORT.print("WS: ");
@ -698,7 +700,7 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str()); mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK ") + String((char *)payload)).c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String(String("OK ") + String((char *)payload)).c_str());
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = true; stateOn = true;
@ -748,7 +750,6 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
} }
} }
#ifdef ENABLE_LEGACY_ANIMATIONS
void checkForRequests() { void checkForRequests() {
webSocket.loop(); webSocket.loop();
server.handleClient(); server.handleClient();
@ -756,7 +757,6 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
mqtt_client.loop(); mqtt_client.loop();
#endif #endif
} }
#endif
// *************************************************************************** // ***************************************************************************
@ -841,26 +841,26 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
root["speed"] = ws2812fx_speed; root["speed"] = ws2812fx_speed;
//char modeName[30]; //char modeName[30];
//strncpy_P(modeName, (PGM_P)strip.getModeName(strip.getMode()), sizeof(modeName)); // copy from progmem //strncpy_P(modeName, (PGM_P)strip->getModeName(strip->getMode()), sizeof(modeName)); // copy from progmem
#if defined(ENABLE_E131) and defined(ENABLE_HOMEASSISTANT) #if defined(ENABLE_E131) and defined(ENABLE_HOMEASSISTANT)
if (mode == E131) if (mode == E131)
root["effect"] = "E131"; root["effect"] = "E131";
else else
root["effect"] = strip.getModeName(strip.getMode()); root["effect"] = strip->getModeName(strip->getMode());
#else #else
root["effect"] = strip.getModeName(strip.getMode()); root["effect"] = strip->getModeName(strip->getMode());
#endif #endif
char buffer[measureJson(root) + 1]; char buffer[measureJson(root) + 1];
serializeJson(root, buffer, sizeof(buffer)); serializeJson(root, buffer, sizeof(buffer));
#ifdef ENABLE_MQTT #ifdef ENABLE_MQTT
mqtt_client.publish(mqtt_ha_state_out.c_str(), buffer, true); mqtt_client.publish(mqtt_ha_state_out, buffer, true);
DBG_OUTPUT_PORT.printf("MQTT: Send [%s]: %s\n", mqtt_ha_state_out.c_str(), buffer); DBG_OUTPUT_PORT.printf("MQTT: Send [%s]: %s\n", mqtt_ha_state_out, buffer);
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_ha_state_out.c_str(), 1, true, buffer); amqttClient.publish(mqtt_ha_state_out, 1, true, buffer);
DBG_OUTPUT_PORT.printf("MQTT: Send [%s]: %s\n", mqtt_ha_state_out.c_str(), buffer); DBG_OUTPUT_PORT.printf("MQTT: Send [%s]: %s\n", mqtt_ha_state_out, buffer);
#endif #endif
new_ha_mqtt_msg = false; new_ha_mqtt_msg = false;
ha_send_data.detach(); ha_send_data.detach();
@ -927,15 +927,15 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
animation_on = true; animation_on = true;
String effectString = root["effect"].as<String>(); String effectString = root["effect"].as<String>();
for (uint8_t i = 0; i < strip.getModeCount(); i++) { for (uint8_t i = 0; i < strip->getModeCount(); i++) {
#if defined(ENABLE_E131) and defined(ENABLE_HOMEASSISTANT) #if defined(ENABLE_E131) and defined(ENABLE_HOMEASSISTANT)
if(effectString == "E131"){ if(effectString == "E131"){
if(strip.isRunning()) strip.stop(); if(strip->isRunning()) strip->stop();
mode = E131; mode = E131;
break; break;
} }
#endif #endif
if(String(strip.getModeName(i)) == effectString) { if(String(strip->getModeName(i)) == effectString) {
mode = SET_MODE; mode = SET_MODE;
ws2812fx_mode = i; ws2812fx_mode = i;
break; break;
@ -965,7 +965,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
DBG_OUTPUT_PORT.printf("MQTT: Message arrived [%s]\n", payload); DBG_OUTPUT_PORT.printf("MQTT: Message arrived [%s]\n", payload);
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
if (strcmp(topic, mqtt_ha_state_in.c_str()) == 0) { if (strcmp(topic, mqtt_ha_state_in) == 0) {
if (!processJson((char*)payload)) { if (!processJson((char*)payload)) {
return; return;
} }
@ -977,7 +977,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
} else if (strcmp(topic, (char *)mqtt_intopic) == 0) { } else if (strcmp(topic, (char *)mqtt_intopic) == 0) {
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
} else if (strcmp(topic, mqtt_intopic.c_str()) == 0) { } else if (strcmp(topic, mqtt_intopic) == 0) {
#endif #endif
#endif #endif
@ -996,7 +996,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
mqtt_reconnect_retries++; mqtt_reconnect_retries++;
DBG_OUTPUT_PORT.printf("Attempting MQTT connection %d / %d ...\n", mqtt_reconnect_retries, MQTT_MAX_RECONNECT_TRIES); DBG_OUTPUT_PORT.printf("Attempting MQTT connection %d / %d ...\n", mqtt_reconnect_retries, MQTT_MAX_RECONNECT_TRIES);
// Attempt to connect // Attempt to connect
if (mqtt_client.connect(mqtt_clientid, mqtt_user, mqtt_pass)) { if (mqtt_client.connect(mqtt_clientid, mqtt_user, mqtt_pass, mqtt_will_topic.c_str(), 2, true, mqtt_will_payload, true)) {
DBG_OUTPUT_PORT.println("MQTT connected!"); DBG_OUTPUT_PORT.println("MQTT connected!");
// Once connected, publish an announcement... // Once connected, publish an announcement...
char * message = new char[18 + strlen(HOSTNAME) + 1]; char * message = new char[18 + strlen(HOSTNAME) + 1];
@ -1007,34 +1007,46 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
mqtt_client.subscribe(mqtt_intopic, qossub); mqtt_client.subscribe(mqtt_intopic, qossub);
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
ha_send_data.detach(); ha_send_data.detach();
mqtt_client.subscribe(mqtt_ha_state_in.c_str(), qossub); mqtt_client.subscribe(mqtt_ha_state_in, qossub);
ha_send_data.once(5, tickerSendState);
#ifdef MQTT_HOME_ASSISTANT_SUPPORT #ifdef MQTT_HOME_ASSISTANT_SUPPORT
DynamicJsonDocument jsonBuffer(JSON_ARRAY_SIZE(strip.getModeCount()) + JSON_OBJECT_SIZE(12) + 1500); DynamicJsonDocument jsonBuffer(JSON_ARRAY_SIZE(strip->getModeCount()) + JSON_OBJECT_SIZE(12) + 1500);
JsonObject json = jsonBuffer.to<JsonObject>(); JsonObject json = jsonBuffer.to<JsonObject>();
json["name"] = HOSTNAME; json["name"] = HOSTNAME;
#ifdef MQTT_HOME_ASSISTANT_0_84_SUPPORT #ifdef MQTT_HOME_ASSISTANT_0_87_SUPPORT
json["schema"] = "json"; json["schema"] = "json";
#else #else
json["platform"] = "mqtt_json"; json["platform"] = "mqtt_json";
#endif #endif
json["state_topic"] = mqtt_ha_state_out; json["state_topic"] = mqtt_ha_state_out;
json["command_topic"] = mqtt_ha_state_in; json["command_topic"] = mqtt_ha_state_in;
#ifndef MQTT_HOME_ASSISTANT_0_87_SUPPORT
json["on_command_type"] = "first"; json["on_command_type"] = "first";
#endif
json["brightness"] = "true"; json["brightness"] = "true";
json["rgb"] = "true"; json["rgb"] = "true";
json["optimistic"] = "false"; json["optimistic"] = "false";
json["color_temp"] = "true"; json["color_temp"] = "true";
json["effect"] = "true"; json["effect"] = "true";
JsonArray effect_list = json.createNestedArray("effect_list"); JsonArray effect_list = json.createNestedArray("effect_list");
for (uint8_t i = 0; i < strip.getModeCount(); i++) { for (uint8_t i = 0; i < strip->getModeCount(); i++) {
effect_list.add(strip.getModeName(i)); effect_list.add(strip->getModeName(i));
} }
#if defined(ENABLE_E131) and defined(MQTT_HOME_ASSISTANT_SUPPORT) #if defined(ENABLE_E131) and defined(MQTT_HOME_ASSISTANT_SUPPORT)
effect_list.add("E131"); effect_list.add("E131");
#endif #endif
char buffer[measureJson(json) + 1]; // Following will never work for PubSubClient as message size > 1.6kB
// char buffer[measureJson(json) + 1];
// serializeJson(json, buffer, sizeof(buffer));
// mqtt_client.publish(String("homeassistant/light/" + String(HOSTNAME) + "/config").c_str(), buffer, true);
// Alternate way to publish large messages using PubSubClient
unsigned int msg_len = measureJson(json) + 1;
char buffer[msg_len];
serializeJson(json, buffer, sizeof(buffer)); serializeJson(json, buffer, sizeof(buffer));
mqtt_client.publish(String("homeassistant/light/" + String(HOSTNAME) + "/config").c_str(), buffer, true); mqtt->beginPublish(String("homeassistant/light/" + String(HOSTNAME) + "/config").c_str(), msg_len, true);
mqtt->write((const uint8_t*)buffer, msg_len);
mqtt->endPublish();
#endif #endif
#endif #endif
@ -1087,34 +1099,37 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
char * message = new char[18 + strlen(HOSTNAME) + 1]; char * message = new char[18 + strlen(HOSTNAME) + 1];
strcpy(message, "McLighting ready: "); strcpy(message, "McLighting ready: ");
strcat(message, HOSTNAME); strcat(message, HOSTNAME);
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, message); amqttClient.publish(mqtt_outtopic, qospub, false, message);
//Subscribe //Subscribe
uint16_t packetIdSub1 = amqttClient.subscribe((char *)mqtt_intopic.c_str(), qossub); uint16_t packetIdSub1 = amqttClient.subscribe((char *)mqtt_intopic, qossub);
DBG_OUTPUT_PORT.printf("Subscribing at QoS %d, packetId: ", qossub); DBG_OUTPUT_PORT.println(packetIdSub1); DBG_OUTPUT_PORT.printf("Subscribing at QoS %d, packetId: ", qossub); DBG_OUTPUT_PORT.println(packetIdSub1);
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
ha_send_data.detach(); ha_send_data.detach();
uint16_t packetIdSub2 = amqttClient.subscribe((char *)mqtt_ha_state_in.c_str(), qossub); uint16_t packetIdSub2 = amqttClient.subscribe((char *)mqtt_ha_state_in, qossub);
DBG_OUTPUT_PORT.printf("Subscribing at QoS %d, packetId: ", qossub); DBG_OUTPUT_PORT.println(packetIdSub2); DBG_OUTPUT_PORT.printf("Subscribing at QoS %d, packetId: ", qossub); DBG_OUTPUT_PORT.println(packetIdSub2);
ha_send_data.once(5, tickerSendState);
#ifdef MQTT_HOME_ASSISTANT_SUPPORT #ifdef MQTT_HOME_ASSISTANT_SUPPORT
DynamicJsonDocument jsonBuffer(JSON_ARRAY_SIZE(strip.getModeCount()) + JSON_OBJECT_SIZE(12) + 1500); DynamicJsonDocument jsonBuffer(JSON_ARRAY_SIZE(strip->getModeCount()) + JSON_OBJECT_SIZE(12) + 1500);
JsonObject json = jsonBuffer.to<JsonObject>(); JsonObject json = jsonBuffer.to<JsonObject>();
json["name"] = HOSTNAME; json["name"] = HOSTNAME;
#ifdef MQTT_HOME_ASSISTANT_0_84_SUPPORT #ifdef MQTT_HOME_ASSISTANT_0_87_SUPPORT
json["schema"] = "json"; json["schema"] = "json";
#else #else
json["platform"] = "mqtt_json"; json["platform"] = "mqtt_json";
#endif #endif
json["state_topic"] = mqtt_ha_state_out; json["state_topic"] = mqtt_ha_state_out;
json["command_topic"] = mqtt_ha_state_in; json["command_topic"] = mqtt_ha_state_in;
#ifndef MQTT_HOME_ASSISTANT_0_87_SUPPORT
json["on_command_type"] = "first"; json["on_command_type"] = "first";
#endif
json["brightness"] = "true"; json["brightness"] = "true";
json["rgb"] = "true"; json["rgb"] = "true";
json["optimistic"] = "false"; json["optimistic"] = "false";
json["color_temp"] = "true"; json["color_temp"] = "true";
json["effect"] = "true"; json["effect"] = "true";
JsonArray effect_list = json.createNestedArray("effect_list"); JsonArray effect_list = json.createNestedArray("effect_list");
for (uint8_t i = 0; i < strip.getModeCount(); i++) { for (uint8_t i = 0; i < strip->getModeCount(); i++) {
effect_list.add(strip.getModeName(i)); effect_list.add(strip->getModeName(i));
} }
#if defined(ENABLE_E131) and defined(MQTT_HOME_ASSISTANT_SUPPORT) #if defined(ENABLE_E131) and defined(MQTT_HOME_ASSISTANT_SUPPORT)
effect_list.add("E131"); effect_list.add("E131");
@ -1167,7 +1182,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
mqtt_client.publish(mqtt_outtopic, String("OK =static white").c_str()); mqtt_client.publish(mqtt_outtopic, String("OK =static white").c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =static white").c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String("OK =static white").c_str());
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = true; stateOn = true;
@ -1183,7 +1198,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
mqtt_client.publish(mqtt_outtopic, String("OK =off").c_str()); mqtt_client.publish(mqtt_outtopic, String("OK =off").c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =off").c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String("OK =off").c_str());
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = false; stateOn = false;
@ -1203,7 +1218,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
mqtt_client.publish(mqtt_outtopic, String("OK =fire flicker").c_str()); mqtt_client.publish(mqtt_outtopic, String("OK =fire flicker").c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =fire flicker").c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String("OK =fire flicker").c_str());
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = true; stateOn = true;
@ -1222,7 +1237,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
mqtt_client.publish(mqtt_outtopic, String("OK =fireworks random").c_str()); mqtt_client.publish(mqtt_outtopic, String("OK =fireworks random").c_str());
#endif #endif
#ifdef ENABLE_AMQTT #ifdef ENABLE_AMQTT
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =fireworks random").c_str()); amqttClient.publish(mqtt_outtopic, qospub, false, String("OK =fireworks random").c_str());
#endif #endif
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = true; stateOn = true;
@ -1273,7 +1288,7 @@ bool writeConfigFS(bool saveConfig){
//FS save //FS save
updateFS = true; updateFS = true;
DBG_OUTPUT_PORT.print("Saving config: "); DBG_OUTPUT_PORT.print("Saving config: ");
DynamicJsonDocument jsonBuffer; DynamicJsonDocument jsonBuffer(200);
JsonObject json = jsonBuffer.to<JsonObject>(); JsonObject json = jsonBuffer.to<JsonObject>();
json["mqtt_host"] = mqtt_host; json["mqtt_host"] = mqtt_host;
json["mqtt_port"] = mqtt_port; json["mqtt_port"] = mqtt_port;
@ -1342,10 +1357,10 @@ bool writeStateFS(){
updateFS = true; updateFS = true;
//save the strip state to FS JSON //save the strip state to FS JSON
DBG_OUTPUT_PORT.print("Saving cfg: "); DBG_OUTPUT_PORT.print("Saving cfg: ");
DynamicJsonDocument jsonBuffer; DynamicJsonDocument jsonBuffer(JSON_OBJECT_SIZE(7)+200);
JsonObject json = jsonBuffer.to<JsonObject>(); JsonObject json = jsonBuffer.to<JsonObject>();
json["mode"] = static_cast<int>(mode); json["mode"] = static_cast<int>(mode);
json["strip_mode"] = (int) strip.getMode(); json["strip_mode"] = (int) strip->getMode();
json["brightness"] = brightness; json["brightness"] = brightness;
json["speed"] = ws2812fx_speed; json["speed"] = ws2812fx_speed;
json["red"] = main_color.red; json["red"] = main_color.red;
@ -1397,14 +1412,15 @@ bool readStateFS() {
main_color.green = json["green"]; main_color.green = json["green"];
main_color.blue = json["blue"]; main_color.blue = json["blue"];
strip.setMode(ws2812fx_mode); if(mode != OFF) stateOn = true;
strip.setSpeed(convertSpeed(ws2812fx_speed)); strip->setMode(ws2812fx_mode);
strip.setBrightness(brightness); strip->setSpeed(convertSpeed(ws2812fx_speed));
strip.setColor(main_color.red, main_color.green, main_color.blue); strip->setBrightness(brightness);
strip->setColor(main_color.red, main_color.green, main_color.blue);
#ifdef ENABLE_E131 #ifdef ENABLE_E131
if (mode == E131) { if (mode == E131) {
strip.stop(); strip->stop();
} }
#endif #endif
@ -1424,3 +1440,90 @@ bool readStateFS() {
return false; return false;
} }
#endif #endif
//Strip Config
char strip_size[3], led_pin[2]; //needed for WiFiManager Settings
struct
{
uint16_t stripSize = NUMLEDS;
uint8_t RGBOrder = NEO_GRB;
#if defined(USE_WS2812FX_DMA) or defined(USE_WS2812FX_UART1) or defined(USE_WS2812FX_UART2)
#ifdef USE_WS2812FX_DMA
uint8_t pin = 3;
#endif
#ifdef USE_WS2812FX_UART1
uint8_t pin = 2;
#endif
#ifdef USE_WS2812FX_UART2
uint8_t pin = 1;
#endif
#else
uint8_t pin = LED_PIN;
#endif
} WS2812FXStripSettings;
Ticker saveWS2812FXStripSettings;
bool readStripConfigFS(void) {
//read stripconfiguration from FS JSON
updateFS = true;
if (SPIFFS.exists("/neoconfig.json")) {
//file exists, reading and loading
DBG_OUTPUT_PORT.print("Reading neoconfig file... ");
File configFile = SPIFFS.open("/neoconfig.json", "r");
if (configFile) {
DBG_OUTPUT_PORT.println("Opened!");
size_t size = configFile.size();
std::unique_ptr<char[]> buf(new char[size]);
configFile.readBytes(buf.get(), size);
DynamicJsonDocument jsonBuffer(JSON_OBJECT_SIZE(4)+300);
DeserializationError error = deserializeJson(jsonBuffer, buf.get());
DBG_OUTPUT_PORT.print("Config: ");
if (!error) {
DBG_OUTPUT_PORT.println(" Parsed!");
JsonObject json = jsonBuffer.as<JsonObject>();
serializeJson(json, DBG_OUTPUT_PORT);
WS2812FXStripSettings.stripSize = json["pixel_pount"];
WS2812FXStripSettings.RGBOrder = json["rgb_order"];
WS2812FXStripSettings.pin = json["pin"];
updateFS = false;
return true;
} else {
DBG_OUTPUT_PORT.print("Failed to load json config: ");
DBG_OUTPUT_PORT.println(error.c_str());
}
} else {
DBG_OUTPUT_PORT.println("Failed to open /config.json");
}
} else {
DBG_OUTPUT_PORT.println("Coudnt find config.json");
}
//end read
updateFS = false;
return false;
}
void writeStripConfigFS(void){
updateFS = true;
//save the strip config to FS JSON
DBG_OUTPUT_PORT.print("Saving Strip cfg: ");
DynamicJsonDocument jsonBuffer(JSON_OBJECT_SIZE(4)+300);
JsonObject json = jsonBuffer.to<JsonObject>();
json["pixel_pount"] = WS2812FXStripSettings.stripSize;
json["rgb_order"] = WS2812FXStripSettings.RGBOrder;
json["pin"] = WS2812FXStripSettings.pin;
//SPIFFS.remove("/neoconfig.json") ? DBG_OUTPUT_PORT.println("removed file") : DBG_OUTPUT_PORT.println("failed removing file");
File configFile = SPIFFS.open("/neoconfig.json", "w");
if (!configFile) {
DBG_OUTPUT_PORT.println("Failed!");
updateFS = false;
}
serializeJson(json, DBG_OUTPUT_PORT);
serializeJson(json, configFile);
DBG_OUTPUT_PORT.println();
configFile.close();
updateFS = false;
//end save
}

View file

@ -1 +1 @@
#define SKETCH_VERSION "2.2.0" #define SKETCH_VERSION "2.2.1"

View file

@ -59,4 +59,23 @@
* 6 Jan 2018 v 2.2.0 * 6 Jan 2018 v 2.2.0
* - fix webserver not responding when E1.31 is mode is acivated: do a webserver.loop() for every 1.31 packet * - fix webserver not responding when E1.31 is mode is acivated: do a webserver.loop() for every 1.31 packet
* - HA E1.31 mode added * - HA E1.31 mode added
*
* 24 Jan 2018 v 2.2.1
* - checkForRequests() is vital for e131 mode, remove from #ifdef ENABLE_LEGACY_ANIMATIONS
* - Minor fixes related to NeoPixelBus UART methods
* - Modify platformio.ini for future bump to esp8266-arduino v2.5.0 (shamelessly stolen settings from espurna project)
* - Gzipped index2.htm & edit.htm.gz(untouched), convereted to hex format using xxd -i abcd.gz > html_gz.h
* - Pointers added for WS2812FX & NeoPixelBus
* - new "REST API": /pixelconf?ct=xxx to change length of LED strip
* - new "REST API": /pixelconf?rgbo=xxx to change RGB order
* - new "REST API": /pixelconf?pin=GPIO_NO to change PIN# (Allowed GPIO values: 16/5/4/0/2/14/12/13/15/3/1)
* - added HA 0.87 version support https://github.com/toblum/McLighting/issues/327
* - Added alternative way to send large messages using PubSubClient
* - Bump PIO core to 2.0.4
* - Send HA state on MQTT connect, address https://github.com/toblum/McLighting/issues/349
* - Add LWT for MQTT and AMQTT, address https://github.com/toblum/McLighting/issues/340
* - Added file for custom WS2812FX animations in custom slots
* - Rename varaibles to be char instead of String
* - Added LED pixel count and PIN settings to WiFiManager
* - Gamma correction to LEDs
*/ */

View file

@ -1,6 +1,6 @@
# McLighting v2 - The ESP8266 based multi-client lighting gadget # McLighting v2 - The ESP8266 based multi-client lighting gadget
[![Gitter](https://badges.gitter.im/mclighting/Lobby.svg)](https://gitter.im/mclighting/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![Build Status](https://travis-ci.com/toblum/McLighting.svg?branch=master)](https://travis-ci.com/toblum/McLighting) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![version](https://img.shields.io/badge/version-v2.2.0-blue.svg)](https://github.com/toblum/McLighting/blob/master/Arduino/McLighting/version.h) [![Gitter](https://badges.gitter.im/mclighting/Lobby.svg)](https://gitter.im/mclighting/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![Build Status](https://travis-ci.com/toblum/McLighting.svg?branch=master)](https://travis-ci.com/toblum/McLighting) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![version](https://img.shields.io/badge/version-v2.2.1-blue.svg)](https://github.com/toblum/McLighting/blob/master/Arduino/McLighting/version.h)
McLighting (the multi-client lighting gadget) is a very cheap internet-controllable lighting solution based on the famous ESP8266 microcontroller and WS2811/2812 led strips. It features among other things a web-interface, a REST-API and a websocket connector. McLighting (the multi-client lighting gadget) is a very cheap internet-controllable lighting solution based on the famous ESP8266 microcontroller and WS2811/2812 led strips. It features among other things a web-interface, a REST-API and a websocket connector.
@ -61,17 +61,19 @@ I hope I didn't miss any sources and mentioned every author. In case I forgot so
## Todos ## Todos
- [ ] Support multiple strips and control them separately or together [Issue](https://github.com/toblum/McLighting/issues/118) - [ ] Support multiple strips and control them separately or together [Issue](https://github.com/toblum/McLighting/issues/118)
- [ ] Make number of pixels, MQTT and PIN configurable via front end [Issue](https://github.com/toblum/McLighting/issues/93) and [Issue](https://github.com/toblum/McLighting/issues/93)
- [ ] Bundle webpages instead of SPIFFS [Issue](https://github.com/toblum/McLighting/issues/93)
- [ ] Remove old / wrong EEPROM settings completely [Issue] - [ ] Remove old / wrong EEPROM settings completely [Issue]
- [ ] Customer profile to define segments of (in)active areas on the strip [Issue](https://github.com/toblum/McLighting/issues/37) - [ ] Customer profile to define segments of (in)active areas on the strip [Issue](https://github.com/toblum/McLighting/issues/37)
- [ ] Additional clients - [ ] Additional clients
- [ ] If no wifi, at least enable button mode. - [ ] If no wifi, at least enable button mode.
- [ ] Also enable McLighting in Wifi AP mode. - [ ] Also enable McLighting in Wifi AP mode.
- [ ] IR remote support [issue](https://github.com/toblum/McLightingUI/issues/3)
- [ ] Multiple buttons/GPIO Inputs. [Issue](https://github.com/toblum/McLighting/issues/119) - [ ] Multiple buttons/GPIO Inputs. [Issue](https://github.com/toblum/McLighting/issues/119)
- [ ] Music visualizer / Bring back ArtNet [Issue](https://github.com/toblum/McLighting/issues/111) - [ ] IR remote support [issue](https://github.com/toblum/McLightingUI/issues/3)
- [ ] Display version and parameters (Number of LEDs, definition settings, ..) in the web UI [Issue](https://github.com/toblum/McLighting/issues/150) - [ ] Make number of pixels, MQTT and PIN configurable via front end [Issue](https://github.com/toblum/McLighting/issues/93) and [Issue](https://github.com/toblum/McLighting/issues/272)
- [ ] Make switching between methods: Adafruit NeoPixel, NeoPixelBus's DMA, NeoPixelBus's UART1 and NeoPixelBus's UART2 via REST API
- [x] Make number of pixels, RGB Order and PIN configurable via REST API
- [x] Bundle webpages instead of SPIFFS [Issue](https://github.com/toblum/McLighting/issues/93)
- [x] Music visualizer / Bring back ArtNet [Issue](https://github.com/toblum/McLighting/issues/111)
- [x] Display version and parameters (Number of LEDs, definition settings, ..) in the web UI [Issue](https://github.com/toblum/McLighting/issues/150)
- [x] MQTT support - [x] MQTT support
- [x] Save favourite effects? [Issue](https://github.com/toblum/McLighting/issues/35)(https://github.com/toblum/McLighting/issues/101) - [x] Save favourite effects? [Issue](https://github.com/toblum/McLighting/issues/35)(https://github.com/toblum/McLighting/issues/101)
- [x] OTA update [Issue](https://github.com/toblum/McLighting/issues/92) - [x] OTA update [Issue](https://github.com/toblum/McLighting/issues/92)

View file

@ -4,7 +4,6 @@ light:
name: "NeoPixel LEDs" name: "NeoPixel LEDs"
state_topic: "home/McLighting01_ha/state/out" state_topic: "home/McLighting01_ha/state/out"
command_topic: "home/McLighting01_ha/state/in" command_topic: "home/McLighting01_ha/state/in"
on_command_type: 'first'
effect: true effect: true
effect_list: effect_list:
###### ######

View file

@ -1,13 +1,3 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[platformio] [platformio]
src_dir = ./Arduino/McLighting/ src_dir = ./Arduino/McLighting/
data_dir = ./Arduino/McLighting/data/ data_dir = ./Arduino/McLighting/data/
@ -15,14 +5,32 @@ env_default = nodemcuv2
description = The ESP8266 based multi-client lighting gadget description = The ESP8266 based multi-client lighting gadget
[common] [common]
# ------------------------------------------------------------------------------
# PLATFORM:
# !! DO NOT confuse platformio's ESP8266 development platform with Arduino core for ESP8266
# We use Arduino Core 2.5.0 (platformIO 2.0.4) as default
#
# arduino core 2.3.0 = platformIO 1.5.0
# arduino core 2.4.0 = platformIO 1.6.0
# arduino core 2.4.1 = platformIO 1.7.3
# arduino core 2.4.2 = platformIO 1.8.0
# arduino core 2.5.0 = platformIO 2.0.4
# arduino core stage = platformIO feature#stage
# ------------------------------------------------------------------------------
arduino_core_2_3_0 = espressif8266@1.5.0
arduino_core_2_4_0 = espressif8266@1.6.0
arduino_core_2_4_1 = espressif8266@1.7.3
arduino_core_2_4_2 = espressif8266@1.8.0
arduino_core_2_5_0 = espressif8266@2.0.4
arduino_core_stage = https://github.com/platformio/platform-espressif8266.git#feature/stage
framework = arduino framework = arduino
platform = espressif8266@1.8.0 ; platform = ${common.arduino_core_2_4_2}
; platform = https://github.com/platformio/platform-espressif8266.git platform = ${common.arduino_core_2_5_0}
; platform = https://github.com/platformio/platform-espressif8266.git#feature/stage
; platform = https://github.com/platformio/platform-espressif8266.git#develop
build_flags = build_flags =
-DPIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH -DPIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH
-DMQTT_MAX_PACKET_SIZE=2048 ; PubSubClient Specific flags -DMQTT_MAX_PACKET_SIZE=512 ; PubSubClient Specific flags
-w ; supress all warnings -w ; supress all warnings
monitor_speed = 115200 monitor_speed = 115200
board_build.flash_mode = dout board_build.flash_mode = dout
@ -31,12 +39,16 @@ upload_resetmethod = nodemcu
lib_deps = lib_deps =
WiFiManager@0.14 WiFiManager@0.14
AsyncMqttClient AsyncMqttClient
https://github.com/bblanchon/ArduinoJson.git#v6.7.0-beta https://github.com/bblanchon/ArduinoJson.git#v6.8.0-beta
WS2812FX WS2812FX
NeoPixelBus@2.4.1 NeoPixelBus@2.4.2
WebSockets WebSockets
ESPAsyncE131 ESPAsyncE131
ESPAsyncUDP ESPAsyncUDP
;PubSubClient ;neede for #define ENABLE_MQTT
;FastLED ;needed for #define CUSTOM_WS2812FX_ANIMATIONS
targets_eum = erase, upload, monitor
targets_um = upload, monitor
[env:esp01_1m] [env:esp01_1m]
board = esp01_1m board = esp01_1m
@ -53,8 +65,11 @@ lib_deps = ${common.lib_deps}
board = nodemcuv2 board = nodemcuv2
framework = ${common.framework} framework = ${common.framework}
platform = ${common.platform} platform = ${common.platform}
build_flags = ${common.build_flags} build_flags =
${common.build_flags}
-Wl,-Teagle.flash.4m3m.ld ;;;; Required for core > v2.5.0 or staging version
monitor_speed = ${common.monitor_speed} monitor_speed = ${common.monitor_speed}
upload_speed = ${common.upload_speed} upload_speed = ${common.upload_speed}
upload_resetmethod = ${common.upload_resetmethod} upload_resetmethod = ${common.upload_resetmethod}
lib_deps = ${common.lib_deps} lib_deps = ${common.lib_deps}
; targets = ${common.targets_um}