Merge pull request #14 from FabLab-Luenen/development
Improvements of code
This commit is contained in:
@@ -38,7 +38,7 @@
|
|||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
WiFiClient espClient;
|
WiFiClient espClient;
|
||||||
PubSubClient mqtt_client(espClient);
|
PubSubClient * mqtt_client;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLE_MQTT == 1
|
#if ENABLE_MQTT == 1
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
#include <AsyncMqttClient.h> //https://github.com/marvinroger/async-mqtt-client
|
#include <AsyncMqttClient.h> //https://github.com/marvinroger/async-mqtt-client
|
||||||
//https://github.com/me-no-dev/ESPAsyncTCP
|
//https://github.com/me-no-dev/ESPAsyncTCP
|
||||||
AsyncMqttClient mqtt_client;
|
AsyncMqttClient * mqtt_client;
|
||||||
WiFiEventHandler wifiConnectHandler;
|
WiFiEventHandler wifiConnectHandler;
|
||||||
WiFiEventHandler wifiDisconnectHandler;
|
WiFiEventHandler wifiDisconnectHandler;
|
||||||
#endif
|
#endif
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
#include <ESPAsyncUDP.h> //https://github.com/me-no-dev/ESPAsyncUDP
|
#include <ESPAsyncUDP.h> //https://github.com/me-no-dev/ESPAsyncUDP
|
||||||
#include <ESPAsyncE131.h> //https://github.com/forkineye/ESPAsyncE131
|
#include <ESPAsyncE131.h> //https://github.com/forkineye/ESPAsyncE131
|
||||||
ESPAsyncE131* e131 = NULL; //(END_UNIVERSE - START_UNIVERSE + 1);
|
ESPAsyncE131 * e131 = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ENABLE_REMOTE)
|
#if defined(ENABLE_REMOTE)
|
||||||
@@ -107,34 +107,35 @@ WebSocketsServer webSocket = WebSocketsServer(81);
|
|||||||
// Load and instanciate WS2812FX library
|
// Load and instanciate WS2812FX library
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
#include <WS2812FX.h> // https://github.com/kitesurfer1404/WS2812FX
|
#include <WS2812FX.h> // https://github.com/kitesurfer1404/WS2812FX
|
||||||
WS2812FX* strip = NULL;
|
WS2812FX * strip = NULL;
|
||||||
|
|
||||||
#if defined(USE_WS2812FX_DMA)
|
#if defined(USE_WS2812FX_DMA)
|
||||||
#include <NeoPixelBus.h>
|
#include <NeoPixelBus.h>
|
||||||
|
|
||||||
#if USE_WS2812FX_DMA == 0 // Uses GPIO3/RXD0/RX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
|
#if USE_WS2812FX_DMA == 0 // Uses GPIO3/RXD0/RX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
|
||||||
#if !defined(LED_TYPE_WS2811)
|
#if !defined(LED_TYPE_WS2811)
|
||||||
NeoEsp8266Dma800KbpsMethod* dma = NULL ; //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
NeoEsp8266Dma800KbpsMethod * dma = NULL ; //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||||
#else
|
#else
|
||||||
NeoEsp8266Dma400KbpsMethod* dma = NULL; //400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
NeoEsp8266Dma400KbpsMethod * dma = NULL; //400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#if USE_WS2812FX_DMA == 1 // Uses UART1: GPIO1/TXD0/TX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
|
#if USE_WS2812FX_DMA == 1 // Uses UART1: GPIO1/TXD0/TX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
|
||||||
#if !defined(LED_TYPE_WS2811)
|
#if !defined(LED_TYPE_WS2811)
|
||||||
NeoEsp8266Uart0800KbpsMethod* dma = NULL; //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
NeoEsp8266Uart0800KbpsMethod * dma = NULL; //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||||
#else
|
#else
|
||||||
NeoEsp8266Uart0400KbpsMethod* dma = NULL; //400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
NeoEsp8266Uart0400KbpsMethod * dma = NULL; //400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#if USE_WS2812FX_DMA == 2 // Uses UART2: GPIO2/TXD1/D4, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
|
#if USE_WS2812FX_DMA == 2 // Uses UART2: GPIO2/TXD1/D4, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
|
||||||
#if !defined(LED_TYPE_WS2811)
|
#if !defined(LED_TYPE_WS2811)
|
||||||
NeoEsp8266Uart1800KbpsMethod* dma = NULL; //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
NeoEsp8266Uart1800KbpsMethod * dma = NULL; //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||||
#else
|
#else
|
||||||
NeoEsp8266Uart1400KbpsMethod* dma = NULL; //400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
NeoEsp8266Uart1400KbpsMethod * dma = NULL; //400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void initDMA(uint16_t stripSize = NUMLEDS){
|
void initDMA(uint16_t stripSize = NUMLEDS){
|
||||||
|
if (dma != NULL) { delete(dma); }
|
||||||
uint8_t ledcolors = 3;
|
uint8_t ledcolors = 3;
|
||||||
if (strstr(WS2812FXStripSettings.RGBOrder, "W") != NULL) {
|
if (strstr(WS2812FXStripSettings.RGBOrder, "W") != NULL) {
|
||||||
ledcolors = 4;
|
ledcolors = 4;
|
||||||
@@ -196,7 +197,6 @@ void tick() {
|
|||||||
#if defined(ENABLE_REMOTE)
|
#if defined(ENABLE_REMOTE)
|
||||||
IRrecv irrecv(ENABLE_REMOTE);
|
IRrecv irrecv(ENABLE_REMOTE);
|
||||||
decode_results results;
|
decode_results results;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Ticker settings_save_state;
|
Ticker settings_save_state;
|
||||||
@@ -269,20 +269,26 @@ void saveConfigCallback () {
|
|||||||
// function to Initialize the strip
|
// function to Initialize the strip
|
||||||
void initStrip(uint16_t stripSize = WS2812FXStripSettings.stripSize, char RGBOrder[5] = WS2812FXStripSettings.RGBOrder, uint8_t pin = WS2812FXStripSettings.pin, uint8_t fxoptions = WS2812FXStripSettings.fxoptions ){
|
void initStrip(uint16_t stripSize = WS2812FXStripSettings.stripSize, char RGBOrder[5] = WS2812FXStripSettings.RGBOrder, uint8_t pin = WS2812FXStripSettings.pin, uint8_t fxoptions = WS2812FXStripSettings.fxoptions ){
|
||||||
DBG_OUTPUT_PORT.println("Initializing strip!");
|
DBG_OUTPUT_PORT.println("Initializing strip!");
|
||||||
|
/*#if defined(USE_WS2812FX_DMA)
|
||||||
if (dma != NULL) {
|
if (dma != NULL) {
|
||||||
delete(dma);
|
delete(dma);
|
||||||
}
|
}
|
||||||
if (strip != NULL) { //second one created second to delete
|
#endif*/
|
||||||
|
if (strip != NULL) {
|
||||||
delete(strip);
|
delete(strip);
|
||||||
WS2812FXStripSettings.stripSize = stripSize;
|
WS2812FXStripSettings.stripSize = stripSize;
|
||||||
strcpy(WS2812FXStripSettings.RGBOrder, RGBOrder);
|
strcpy(WS2812FXStripSettings.RGBOrder, RGBOrder);
|
||||||
WS2812FXStripSettings.pin = pin;
|
WS2812FXStripSettings.pin = pin;
|
||||||
WS2812FXStripSettings.fxoptions = fxoptions;
|
WS2812FXStripSettings.fxoptions = fxoptions;
|
||||||
}
|
}
|
||||||
|
#if defined(ENABLE_E131)
|
||||||
|
|
||||||
|
#endif
|
||||||
if (ledstates != NULL) {
|
if (ledstates != NULL) {
|
||||||
delete(ledstates);
|
delete(ledstates);
|
||||||
}
|
}
|
||||||
ledstates = new uint8_t [WS2812FXStripSettings.stripSize];
|
ledstates = new uint8_t [WS2812FXStripSettings.stripSize];
|
||||||
|
|
||||||
#if !defined(LED_TYPE_WS2811)
|
#if !defined(LED_TYPE_WS2811)
|
||||||
strip = new WS2812FX(stripSize, pin, checkRGBOrder(RGBOrder) + NEO_KHZ800);
|
strip = new WS2812FX(stripSize, pin, checkRGBOrder(RGBOrder) + NEO_KHZ800);
|
||||||
#else
|
#else
|
||||||
@@ -314,17 +320,24 @@ void initStrip(uint16_t stripSize = WS2812FXStripSettings.stripSize, char RGBOrd
|
|||||||
gReverseDirection = (WS2812FXStripSettings.fxoptions & 128);
|
gReverseDirection = (WS2812FXStripSettings.fxoptions & 128);
|
||||||
#endif
|
#endif
|
||||||
#if defined(ENABLE_E131)
|
#if defined(ENABLE_E131)
|
||||||
/*
|
if (e131 != NULL) { delete(e131); }
|
||||||
uint8_t universe_leds = 170.0; // a universe has only 512 (0..511) channels: 3*170 or 4*128 <= 512
|
e131 = new ESPAsyncE131(END_UNIVERSE - START_UNIVERSE + 1);
|
||||||
if (strstr(WS2812FXStripSettings.RGBOrder, "W") != NULL) {
|
float universe_leds = 170.0; // a universe has only 512 (0..511) channels: 3*170 or 4*128 <= 512
|
||||||
universe_leds = 128.0;
|
if (strstr(WS2812FXStripSettings.RGBOrder, "W") != NULL) {
|
||||||
}
|
//universe_leds = 128.0;
|
||||||
*/
|
}
|
||||||
float float_enduni = stripSize/170.0;
|
float float_enduni = stripSize/universe_leds;
|
||||||
uint8_t END_UNIVERSE = stripSize/170.0;
|
uint8_t END_UNIVERSE = stripSize/universe_leds;
|
||||||
if (float_enduni > END_UNIVERSE) {
|
if (float_enduni > END_UNIVERSE) {
|
||||||
END_UNIVERSE = END_UNIVERSE +1;
|
END_UNIVERSE = END_UNIVERSE +1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if (e131.begin(E131_UNICAST)) // Listen via Unicast
|
||||||
|
if (e131->begin(E131_MULTICAST, START_UNIVERSE, END_UNIVERSE)) {// Listen via Multicast
|
||||||
|
DBG_OUTPUT_PORT.println(F("Listening for data..."));
|
||||||
|
} else {
|
||||||
|
DBG_OUTPUT_PORT.println(F("*** e131.begin failed ***"));
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,12 +347,12 @@ void initMqtt() {
|
|||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
// Configure MQTT
|
// Configure MQTT
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
/*#if ENABLE_MQTT == 0
|
#if ENABLE_MQTT == 0
|
||||||
mqtt_client = new PubSubClient(espClient);
|
mqtt_client = new PubSubClient(espClient);
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_MQTT == 1
|
#if ENABLE_MQTT == 1
|
||||||
mqtt_client = new AsyncMqttClient();
|
mqtt_client = new AsyncMqttClient();
|
||||||
#endif*/
|
#endif
|
||||||
|
|
||||||
#if defined(ENABLE_MQTT_HOSTNAME_CHIPID)
|
#if defined(ENABLE_MQTT_HOSTNAME_CHIPID)
|
||||||
snprintf(mqtt_clientid, sizeof(mqtt_clientid), "%s-%08X", HOSTNAME, ESP.getChipId());
|
snprintf(mqtt_clientid, sizeof(mqtt_clientid), "%s-%08X", HOSTNAME, ESP.getChipId());
|
||||||
@@ -357,18 +370,18 @@ void initMqtt() {
|
|||||||
if ((strlen(mqtt_host) != 0) && (mqtt_port != 0)) {
|
if ((strlen(mqtt_host) != 0) && (mqtt_port != 0)) {
|
||||||
#if ENABLE_MQTT == 0
|
#if ENABLE_MQTT == 0
|
||||||
DBG_OUTPUT_PORT.printf("MQTT active: %s:%d\r\n", mqtt_host, mqtt_port);
|
DBG_OUTPUT_PORT.printf("MQTT active: %s:%d\r\n", mqtt_host, mqtt_port);
|
||||||
mqtt_client.setServer(mqtt_host, mqtt_port);
|
mqtt_client->setServer(mqtt_host, mqtt_port);
|
||||||
mqtt_client.setCallback(mqtt_callback);
|
mqtt_client->setCallback(mqtt_callback);
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_MQTT == 1
|
#if ENABLE_MQTT == 1
|
||||||
DBG_OUTPUT_PORT.printf("AMQTT active: %s:%d\r\n", mqtt_host, mqtt_port);
|
DBG_OUTPUT_PORT.printf("AMQTT active: %s:%d\r\n", mqtt_host, mqtt_port);
|
||||||
mqtt_client.onConnect(onMqttConnect);
|
mqtt_client->onConnect(onMqttConnect);
|
||||||
mqtt_client.onDisconnect(onMqttDisconnect);
|
mqtt_client->onDisconnect(onMqttDisconnect);
|
||||||
mqtt_client.onMessage(onMqttMessage);
|
mqtt_client->onMessage(onMqttMessage);
|
||||||
if ((strlen(mqtt_user) != 0) || (strlen(mqtt_pass) != 0)) mqtt_client.setCredentials(mqtt_user, mqtt_pass);
|
if ((strlen(mqtt_user) != 0) || (strlen(mqtt_pass) != 0)) mqtt_client->setCredentials(mqtt_user, mqtt_pass);
|
||||||
mqtt_client.setClientId(mqtt_clientid);
|
mqtt_client->setClientId(mqtt_clientid);
|
||||||
mqtt_client.setWill(mqtt_will_topic, 2, true, mqtt_will_payload, 0);
|
mqtt_client->setWill(mqtt_will_topic, 2, true, mqtt_will_payload, 0);
|
||||||
mqtt_client.setServer(mqtt_host, mqtt_port);
|
mqtt_client->setServer(mqtt_host, mqtt_port);
|
||||||
connectToMqtt();
|
connectToMqtt();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -449,21 +462,21 @@ void setup() {
|
|||||||
#if defined(ENABLE_MQTT)
|
#if defined(ENABLE_MQTT)
|
||||||
char tmp_mqtt_port[6]; //needed tempararily for WiFiManager Settings
|
char tmp_mqtt_port[6]; //needed tempararily for WiFiManager Settings
|
||||||
WiFiManagerParameter custom_mqtt_host("host", "MQTT hostname", mqtt_host, 64, " maxlength=64");
|
WiFiManagerParameter custom_mqtt_host("host", "MQTT hostname", mqtt_host, 64, " maxlength=64");
|
||||||
snprintf(tmp_mqtt_port, sizeof(tmp_mqtt_port), "%d", mqtt_port);
|
sprintf(tmp_mqtt_port, "%d", mqtt_port);
|
||||||
WiFiManagerParameter custom_mqtt_port("port", "MQTT port", tmp_mqtt_port, 5, " maxlength=5 type=\"number\"");
|
WiFiManagerParameter custom_mqtt_port("port", "MQTT port", tmp_mqtt_port, 5, " maxlength=5 type=\"number\"");
|
||||||
WiFiManagerParameter custom_mqtt_user("user", "MQTT user", mqtt_user, 32, " maxlength=32");
|
WiFiManagerParameter custom_mqtt_user("user", "MQTT user", mqtt_user, 32, " maxlength=32");
|
||||||
WiFiManagerParameter custom_mqtt_pass("pass", "MQTT pass", mqtt_pass, 32, " maxlength=32 type=\"password\"");
|
WiFiManagerParameter custom_mqtt_pass("pass", "MQTT pass", mqtt_pass, 32, " maxlength=32 type=\"password\"");
|
||||||
#endif
|
#endif
|
||||||
snprintf(tmp_strip_size, sizeof(tmp_strip_size), "%d", WS2812FXStripSettings.stripSize);
|
sprintf(tmp_strip_size, "%d", WS2812FXStripSettings.stripSize);
|
||||||
WiFiManagerParameter custom_strip_size("strip_size", "Number of LEDs", tmp_strip_size, 4, " maxlength=4 type=\"number\"");
|
WiFiManagerParameter custom_strip_size("strip_size", "Number of LEDs", tmp_strip_size, 4, " maxlength=4 type=\"number\"");
|
||||||
#if !defined(USE_WS2812FX_DMA)
|
#if !defined(USE_WS2812FX_DMA)
|
||||||
char tmp_led_pin[3];
|
char tmp_led_pin[3];
|
||||||
snprintf(tmp_led_pin, sizeof(tmp_led_pin), "%d", WS2812FXStripSettings.pin);
|
sprintf(tmp_led_pin, "%d", WS2812FXStripSettings.pin);
|
||||||
WiFiManagerParameter custom_led_pin("led_pin", "LED GPIO", tmp_led_pin, 2, " maxlength=2 type=\"number\"");
|
WiFiManagerParameter custom_led_pin("led_pin", "LED GPIO", tmp_led_pin, 2, " maxlength=2 type=\"number\"");
|
||||||
#endif
|
#endif
|
||||||
snprintf(tmp_rgbOrder, sizeof(tmp_rgbOrder), "%s", WS2812FXStripSettings.RGBOrder);
|
sprintf(tmp_rgbOrder, "%s", WS2812FXStripSettings.RGBOrder);
|
||||||
WiFiManagerParameter custom_rgbOrder("rgbOrder", "RGBOrder", tmp_rgbOrder, 4, " maxlength=4");
|
WiFiManagerParameter custom_rgbOrder("rgbOrder", "RGBOrder", tmp_rgbOrder, 4, " maxlength=4");
|
||||||
snprintf(tmp_fxoptions, sizeof(tmp_fxoptions), "%d", WS2812FXStripSettings.fxoptions);
|
sprintf(tmp_fxoptions, "%d", WS2812FXStripSettings.fxoptions);
|
||||||
WiFiManagerParameter custom_fxoptions("fxoptions", "fxOptions", tmp_fxoptions, 3, " maxlength=3");
|
WiFiManagerParameter custom_fxoptions("fxoptions", "fxOptions", tmp_fxoptions, 3, " maxlength=3");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -548,6 +561,7 @@ void setup() {
|
|||||||
#else
|
#else
|
||||||
snprintf(last_conf, sizeof(last_conf), "CNF|%64s|%64s|%5d|%32s|%32s|%4d|%2d|%4s|%3d", HOSTNAME, "", "", "", "", WS2812FXStripSettings.stripSize, WS2812FXStripSettings.pin, WS2812FXStripSettings.RGBOrder, WS2812FXStripSettings.fxoptions);
|
snprintf(last_conf, sizeof(last_conf), "CNF|%64s|%64s|%5d|%32s|%32s|%4d|%2d|%4s|%3d", HOSTNAME, "", "", "", "", WS2812FXStripSettings.stripSize, WS2812FXStripSettings.pin, WS2812FXStripSettings.RGBOrder, WS2812FXStripSettings.fxoptions);
|
||||||
#endif
|
#endif
|
||||||
|
last_conf[sizeof(last_conf)]=0;
|
||||||
writeEEPROM(0, 222, last_conf);
|
writeEEPROM(0, 222, last_conf);
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
}
|
}
|
||||||
@@ -612,8 +626,6 @@ void setup() {
|
|||||||
initMqtt();
|
initMqtt();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
initStrip();
|
|
||||||
|
|
||||||
#if ENABLE_MQTT == 1
|
#if ENABLE_MQTT == 1
|
||||||
wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
|
wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
|
||||||
wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);
|
wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);
|
||||||
@@ -653,17 +665,6 @@ void setup() {
|
|||||||
MDNS.addService("http", "tcp", 80);
|
MDNS.addService("http", "tcp", 80);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(ENABLE_E131)
|
|
||||||
// Choose one to begin listening for E1.31 data
|
|
||||||
e131 = new ESPAsyncE131(END_UNIVERSE - START_UNIVERSE + 1);
|
|
||||||
// if (e131.begin(E131_UNICAST)) // Listen via Unicast
|
|
||||||
if (e131->begin(E131_MULTICAST, START_UNIVERSE, END_UNIVERSE)) {// Listen via Multicast
|
|
||||||
DBG_OUTPUT_PORT.println(F("Listening for data..."));
|
|
||||||
} else {
|
|
||||||
DBG_OUTPUT_PORT.println(F("*** e131.begin failed ***"));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
prevmode = mode;
|
prevmode = mode;
|
||||||
|
|
||||||
#if defined(ENABLE_BUTTON_GY33)
|
#if defined(ENABLE_BUTTON_GY33)
|
||||||
@@ -676,6 +677,8 @@ void setup() {
|
|||||||
snprintf(last_state, sizeof(last_state), "STA|%2d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d", mode, ws2812fx_mode, ws2812fx_speed, brightness, main_color.red, main_color.green, main_color.blue, main_color.white, back_color.red, back_color.green, back_color.blue, back_color.white, xtra_color.red, xtra_color.green, xtra_color.blue,xtra_color.white);
|
snprintf(last_state, sizeof(last_state), "STA|%2d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d|%3d", mode, ws2812fx_mode, ws2812fx_speed, brightness, main_color.red, main_color.green, main_color.blue, main_color.white, back_color.red, back_color.green, back_color.blue, back_color.white, xtra_color.red, xtra_color.green, xtra_color.blue,xtra_color.white);
|
||||||
#endif
|
#endif
|
||||||
DBG_OUTPUT_PORT.println("finished Main Setup!");
|
DBG_OUTPUT_PORT.println("finished Main Setup!");
|
||||||
|
|
||||||
|
initStrip();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
@@ -712,14 +715,14 @@ void loop() {
|
|||||||
WiFi.begin();
|
WiFi.begin();
|
||||||
} else {
|
} else {
|
||||||
if ((strlen(mqtt_host) != 0) && (mqtt_port != 0) && (mqtt_reconnect_retries < MQTT_MAX_RECONNECT_TRIES)) {
|
if ((strlen(mqtt_host) != 0) && (mqtt_port != 0) && (mqtt_reconnect_retries < MQTT_MAX_RECONNECT_TRIES)) {
|
||||||
if (!mqtt_client.connected()) {
|
if (!mqtt_client->connected()) {
|
||||||
#if defined(ENABLE_HOMEASSISTANT)
|
#if defined(ENABLE_HOMEASSISTANT)
|
||||||
ha_send_data.detach();
|
ha_send_data.detach();
|
||||||
#endif
|
#endif
|
||||||
DBG_OUTPUT_PORT.println("MQTT disconnected, reconnecting!");
|
DBG_OUTPUT_PORT.println("MQTT disconnected, reconnecting!");
|
||||||
mqtt_reconnect();
|
mqtt_reconnect();
|
||||||
} else {
|
} else {
|
||||||
mqtt_client.loop();
|
mqtt_client->loop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -863,10 +866,10 @@ void loop() {
|
|||||||
}
|
}
|
||||||
#if defined(ENABLE_MQTT)
|
#if defined(ENABLE_MQTT)
|
||||||
#if ENABLE_MQTT == 0
|
#if ENABLE_MQTT == 0
|
||||||
mqtt_client.publish(mqtt_outtopic, mqtt_buf);
|
mqtt_client->publish(mqtt_outtopic, mqtt_buf);
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_MQTT == 1
|
#if ENABLE_MQTT == 1
|
||||||
mqtt_client.publish(mqtt_outtopic, qospub, false, mqtt_buf);
|
mqtt_client->publish(mqtt_outtopic, qospub, false, mqtt_buf);
|
||||||
#endif
|
#endif
|
||||||
#if defined(ENABLE_HOMEASSISTANT)
|
#if defined(ENABLE_HOMEASSISTANT)
|
||||||
if(!ha_send_data.active()) ha_send_data.once(3, tickerSendState);
|
if(!ha_send_data.active()) ha_send_data.once(3, tickerSendState);
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
#define USE_WS2812FX_DMA 0 // 0 = Used PIN is ignored & set to RX/GPIO3; 1 = Used PIN is ignored & set to D4/GPIO2; 2 = Uses PIN is ignored & set to TX/GPIO1; Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX
|
#define USE_WS2812FX_DMA 0 // 0 = Used PIN is ignored & set to RX/GPIO3; 1 = Used PIN is ignored & set to D4/GPIO2; 2 = Uses PIN is ignored & set to TX/GPIO1; Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX
|
||||||
|
#if defined(USE_WS2812FX_DMA)
|
||||||
|
#define MAXLEDS 384 // due to memory limit of esp8266 at the moment only 384 leds are supported in DMA Mode. More can crash if mqtt is used.
|
||||||
|
#else
|
||||||
|
#define MAXLEDS 4096
|
||||||
|
#endif
|
||||||
// Neopixel
|
// Neopixel
|
||||||
#define LED_PIN 3 // PIN (15 / D8) where neopixel / WS2811 strip is attached; is configurable, if USE_WS2812FX_DMA is not defined. Just for the start
|
#define LED_PIN 3 // PIN (15 / D8) where neopixel / WS2811 strip is attached; is configurable, if USE_WS2812FX_DMA is not defined. Just for the start
|
||||||
#define NUMLEDS 50 // Number of leds in the; is configurable just for the start
|
#define NUMLEDS 50 // Number of leds in the; is configurable just for the start
|
||||||
#define MAXLEDS 700 // due to memory limit of esp8266 at the moment only 700 leds are supported.
|
|
||||||
#define RGBORDER "GRBW" // RGBOrder; is configurable just for the start
|
#define RGBORDER "GRBW" // RGBOrder; is configurable just for the start
|
||||||
#define FX_OPTIONS 56 // ws2812fx Options 56 = SIZE_SMALL + FADE_MEDIUM + GAMMA is configurable just for the start; for WS2812FX setSegment OPTIONS, see: https://github.com/kitesurfer1404/WS2812FX/blob/master/extras/WS2812FX%20Users%20Guide.md
|
#define FX_OPTIONS 56 // ws2812fx Options 56 = SIZE_SMALL + FADE_MEDIUM + GAMMA is configurable just for the start; for WS2812FX setSegment OPTIONS, see: https://github.com/kitesurfer1404/WS2812FX/blob/master/extras/WS2812FX%20Users%20Guide.md
|
||||||
//#define LED_TYPE_WS2811 // Uncomment, if LED type uses 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
//#define LED_TYPE_WS2811 // Uncomment, if LED type uses 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||||
@@ -17,7 +20,7 @@ char HOSTNAME[65] = "McLightingRGBW"; // Friedly hostname is configurable just
|
|||||||
#define ENABLE_HOMEASSISTANT // If defined, enable Homeassistant integration, ENABLE_MQTT must be active
|
#define ENABLE_HOMEASSISTANT // If defined, enable Homeassistant integration, ENABLE_MQTT must be active
|
||||||
#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_BUTTON 14 // If defined, enable button handling code, see: https://github.com/toblum/McLighting/wiki/Button-control, the value defines the input pin (14 / D5) for switching the LED strip on / off, connect this PIN to ground to trigger button.
|
#define ENABLE_BUTTON 14 // If defined, enable button handling code, see: https://github.com/toblum/McLighting/wiki/Button-control, the value defines the input pin (14 / D5) for switching the LED strip on / off, connect this PIN to ground to trigger button.
|
||||||
//#define ENABLE_BUTTON_GY33 12 // If defined, enable button handling code for GY-33 color sensor to scan color. The value defines the input pin (12 / D6) for read color data with RGB sensor, connect this PIN to ground to trigger button.
|
#define ENABLE_BUTTON_GY33 12 // If defined, enable button handling code for GY-33 color sensor to scan color. The value defines the input pin (12 / D6) for read color data with RGB sensor, connect this PIN to ground to trigger button.
|
||||||
#define ENABLE_REMOTE 13 // If defined, enable Remote Control via TSOP31238. The value defines the input pin (13 / D7) for TSOP31238 Out
|
#define ENABLE_REMOTE 13 // If defined, enable Remote Control via TSOP31238. The value defines the input pin (13 / D7) for TSOP31238 Out
|
||||||
|
|
||||||
#define ENABLE_STATE_SAVE 1 // If defined, load saved state on reboot and save state. If set to 0 from EEPROM, if set to 1 from SPIFFS
|
#define ENABLE_STATE_SAVE 1 // If defined, load saved state on reboot and save state. If set to 0 from EEPROM, if set to 1 from SPIFFS
|
||||||
@@ -26,7 +29,7 @@ char HOSTNAME[65] = "McLightingRGBW"; // Friedly hostname is configurable just
|
|||||||
#define CUSTOM_WS2812FX_ANIMATIONS //uncomment and put animations in "custom_ws2812fx_animations.h"
|
#define CUSTOM_WS2812FX_ANIMATIONS //uncomment and put animations in "custom_ws2812fx_animations.h"
|
||||||
#define ENABLE_E131 // E1.31 implementation You have to uncomment #define USE_WS2812FX_DMA and set it to 0
|
#define ENABLE_E131 // E1.31 implementation You have to uncomment #define USE_WS2812FX_DMA and set it to 0
|
||||||
#define ENABLE_TV // Enable TV Animation
|
#define ENABLE_TV // Enable TV Animation
|
||||||
#define USE_HTML_MIN_GZ //uncomment for using index.htm & edit.htm from PROGMEM instead of SPIFFs
|
bool USE_HTML_MIN_GZ = true; //uncomment for using index.htm & edit.htm from PROGMEM instead of SPIFFs -> next version i will make it customizable
|
||||||
|
|
||||||
#if defined(ENABLE_E131)
|
#if defined(ENABLE_E131)
|
||||||
#define MULTICAST false
|
#define MULTICAST false
|
||||||
|
|||||||
+1666
-1704
File diff suppressed because it is too large
Load Diff
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
// Prototypes
|
// Prototypes
|
||||||
void handleAutoStart();
|
void handleAutoStart();
|
||||||
String listStatusJSON();
|
char * listStatusJSON();
|
||||||
bool writeConfigFS(bool);
|
bool writeConfigFS(bool);
|
||||||
|
|
||||||
#if defined(ENABLE_E131)
|
#if defined(ENABLE_E131)
|
||||||
@@ -535,7 +535,7 @@ void handleSetWS2812FXMode(uint8_t * mypayload) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String listStatusJSON() {
|
char * listStatusJSON() {
|
||||||
//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(12) + JSON_OBJECT_SIZE(6) + 500;
|
const size_t bufferSize = JSON_ARRAY_SIZE(12) + JSON_OBJECT_SIZE(6) + 500;
|
||||||
DynamicJsonDocument jsonBuffer(bufferSize);
|
DynamicJsonDocument jsonBuffer(bufferSize);
|
||||||
@@ -560,13 +560,14 @@ String listStatusJSON() {
|
|||||||
color.add(xtra_color.red);
|
color.add(xtra_color.red);
|
||||||
color.add(xtra_color.green);
|
color.add(xtra_color.green);
|
||||||
color.add(xtra_color.blue);
|
color.add(xtra_color.blue);
|
||||||
String json;
|
uint16_t msg_len = measureJson(root) + 1;
|
||||||
serializeJson(root, json);
|
char * buffer = (char *) malloc(msg_len);
|
||||||
|
serializeJson(root, buffer, msg_len);
|
||||||
jsonBuffer.clear();
|
jsonBuffer.clear();
|
||||||
return json;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
String listConfigJSON() {
|
char * listConfigJSON() {
|
||||||
//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();
|
||||||
#if defined(ENABLE_MQTT)
|
#if defined(ENABLE_MQTT)
|
||||||
const size_t bufferSize = JSON_OBJECT_SIZE(9) + 500;
|
const size_t bufferSize = JSON_OBJECT_SIZE(9) + 500;
|
||||||
@@ -586,25 +587,30 @@ String listConfigJSON() {
|
|||||||
root["ws_rgbo"] = WS2812FXStripSettings.RGBOrder;
|
root["ws_rgbo"] = WS2812FXStripSettings.RGBOrder;
|
||||||
root["ws_pin"] = WS2812FXStripSettings.pin;
|
root["ws_pin"] = WS2812FXStripSettings.pin;
|
||||||
root["ws_fxopt"] = WS2812FXStripSettings.fxoptions;
|
root["ws_fxopt"] = WS2812FXStripSettings.fxoptions;
|
||||||
String json;
|
uint16_t msg_len = measureJson(root) + 1;
|
||||||
serializeJson(root, json);
|
char * buffer = (char *) malloc(msg_len);
|
||||||
|
serializeJson(root, buffer, msg_len);
|
||||||
jsonBuffer.clear();
|
jsonBuffer.clear();
|
||||||
return json;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void getStatusJSON() {
|
void getStatusJSON() {
|
||||||
|
char * buffer = listStatusJSON();
|
||||||
server.sendHeader("Access-Control-Allow-Origin", "*");
|
server.sendHeader("Access-Control-Allow-Origin", "*");
|
||||||
server.send ( 200, "application/json", listStatusJSON() );
|
server.send ( 200, "application/json", buffer);
|
||||||
|
free (buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void getConfigJSON() {
|
void getConfigJSON() {
|
||||||
|
char * buffer = listConfigJSON();
|
||||||
server.sendHeader("Access-Control-Allow-Origin", "*");
|
server.sendHeader("Access-Control-Allow-Origin", "*");
|
||||||
server.send ( 200, "application/json", listConfigJSON() );
|
server.send ( 200, "application/json", buffer);
|
||||||
|
free (buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String listModesJSON() {
|
char * listModesJSON() {
|
||||||
const size_t bufferSize = JSON_ARRAY_SIZE(strip->getModeCount() + 3) + (strip->getModeCount() + 3)*JSON_OBJECT_SIZE(2) + 2000;
|
const size_t bufferSize = JSON_ARRAY_SIZE(strip->getModeCount() + 3) + (strip->getModeCount() + 3)*JSON_OBJECT_SIZE(2) + 2000;
|
||||||
DynamicJsonDocument jsonBuffer(bufferSize);
|
DynamicJsonDocument jsonBuffer(bufferSize);
|
||||||
JsonArray root = jsonBuffer.to<JsonArray>();
|
JsonArray root = jsonBuffer.to<JsonArray>();
|
||||||
@@ -629,15 +635,18 @@ String listModesJSON() {
|
|||||||
object["mode"] = i;
|
object["mode"] = i;
|
||||||
object["name"] = strip->getModeName(i);
|
object["name"] = strip->getModeName(i);
|
||||||
}
|
}
|
||||||
String json;
|
uint16_t msg_len = measureJson(root) + 1;
|
||||||
serializeJson(root, json);
|
char * buffer = (char *) malloc(msg_len);
|
||||||
|
serializeJson(root, buffer, msg_len);
|
||||||
jsonBuffer.clear();
|
jsonBuffer.clear();
|
||||||
return json;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void getModesJSON() {
|
void getModesJSON() {
|
||||||
|
char * buffer = listModesJSON();
|
||||||
server.sendHeader("Access-Control-Allow-Origin", "*");
|
server.sendHeader("Access-Control-Allow-Origin", "*");
|
||||||
server.send ( 200, "application/json", listModesJSON() );
|
server.send ( 200, "application/json", buffer);
|
||||||
|
free (buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
@@ -810,23 +819,24 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
|
|||||||
|
|
||||||
// $ ==> Get status Info.
|
// $ ==> Get status Info.
|
||||||
if (payload[0] == '$') {
|
if (payload[0] == '$') {
|
||||||
String json = listStatusJSON();
|
char * buffer = listStatusJSON();
|
||||||
if (mqtt == true) {
|
if (mqtt == true) {
|
||||||
DBG_OUTPUT_PORT.print("MQTT: ");
|
DBG_OUTPUT_PORT.print("MQTT: ");
|
||||||
#if defined(ENABLE_MQTT)
|
#if defined(ENABLE_MQTT)
|
||||||
#if ENABLE_MQTT == 0
|
#if ENABLE_MQTT == 0
|
||||||
mqtt_client.publish(mqtt_outtopic, json.c_str());
|
mqtt_client->publish(mqtt_outtopic, buffer);
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_MQTT == 1
|
#if ENABLE_MQTT == 1
|
||||||
mqtt_client.publish(mqtt_outtopic, qospub, false, json.c_str());
|
mqtt_client->publish(mqtt_outtopic, qospub, false, buffer);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
DBG_OUTPUT_PORT.print("WS: ");
|
DBG_OUTPUT_PORT.print("WS: ");
|
||||||
webSocket.sendTXT(num, "OK");
|
webSocket.sendTXT(num, "OK");
|
||||||
webSocket.sendTXT(num, json);
|
webSocket.sendTXT(num, buffer);
|
||||||
}
|
}
|
||||||
DBG_OUTPUT_PORT.println("Get status info: " + json);
|
DBG_OUTPUT_PORT.printf("Get status info: %s\r\n", buffer);
|
||||||
|
free (buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -918,50 +928,52 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
String json = listConfigJSON();
|
char * buffer = listConfigJSON();
|
||||||
if (mqtt == true) {
|
if (mqtt == true) {
|
||||||
DBG_OUTPUT_PORT.print("MQTT: ");
|
DBG_OUTPUT_PORT.print("MQTT: ");
|
||||||
#if defined(ENABLE_MQTT)
|
#if defined(ENABLE_MQTT)
|
||||||
#if ENABLE_MQTT == 0
|
#if ENABLE_MQTT == 0
|
||||||
mqtt_client.publish(mqtt_outtopic, json.c_str());
|
mqtt_client->publish(mqtt_outtopic, buffer);
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_MQTT == 1
|
#if ENABLE_MQTT == 1
|
||||||
mqtt_client.publish(mqtt_outtopic, qospub, false, json.c_str());
|
mqtt_client->publish(mqtt_outtopic, qospub, false, buffer);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
DBG_OUTPUT_PORT.print("WS: ");
|
DBG_OUTPUT_PORT.print("WS: ");
|
||||||
webSocket.sendTXT(num, "OK");
|
webSocket.sendTXT(num, "OK");
|
||||||
webSocket.sendTXT(num, json);
|
webSocket.sendTXT(num, buffer);
|
||||||
}
|
}
|
||||||
updateStrip = false;
|
updateStrip = false;
|
||||||
updateConf = false;
|
updateConf = false;
|
||||||
DBG_OUTPUT_PORT.println("Get status info: " + json);
|
DBG_OUTPUT_PORT.printf("Get status info: %s\r\n", buffer);
|
||||||
|
free (buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ~ ==> Get WS2812 modes.
|
// ~ ==> Get WS2812 modes.
|
||||||
if (payload[0] == '~') {
|
if (payload[0] == '~') {
|
||||||
String json = listModesJSON();
|
char * buffer = listModesJSON();
|
||||||
if (mqtt == true) {
|
if (mqtt == true) {
|
||||||
DBG_OUTPUT_PORT.print("MQTT: ");
|
DBG_OUTPUT_PORT.print("MQTT: ");
|
||||||
#if defined(ENABLE_MQTT)
|
#if defined(ENABLE_MQTT)
|
||||||
#if ENABLE_MQTT == 0
|
#if ENABLE_MQTT == 0
|
||||||
uint16_t msg_len = strlen(json.c_str()) + 1;
|
uint16_t msg_len = strlen(buffer) + 1;
|
||||||
mqtt_client.beginPublish(mqtt_outtopic, msg_len, true);
|
mqtt_client->beginPublish(mqtt_outtopic, msg_len, true);
|
||||||
mqtt_client.write((const uint8_t*)json.c_str(), msg_len);
|
mqtt_client->write((const uint8_t*)buffer, msg_len);
|
||||||
mqtt_client.endPublish();
|
mqtt_client->endPublish();
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_MQTT == 1
|
#if ENABLE_MQTT == 1
|
||||||
mqtt_client.publish(mqtt_outtopic, qospub, false, json.c_str());
|
mqtt_client->publish(mqtt_outtopic, qospub, false, buffer);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
DBG_OUTPUT_PORT.print("WS: ");
|
DBG_OUTPUT_PORT.print("WS: ");
|
||||||
webSocket.sendTXT(num, "OK");
|
webSocket.sendTXT(num, "OK");
|
||||||
webSocket.sendTXT(num, json);
|
webSocket.sendTXT(num, buffer);
|
||||||
}
|
}
|
||||||
DBG_OUTPUT_PORT.println("Get WS2812 modes.");
|
DBG_OUTPUT_PORT.println("Get WS2812 modes.");
|
||||||
DBG_OUTPUT_PORT.println(json);
|
DBG_OUTPUT_PORT.println(buffer);
|
||||||
|
free (buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// / ==> Set WS2812 mode.
|
// / ==> Set WS2812 mode.
|
||||||
@@ -1126,11 +1138,11 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
serializeJson(root, buffer, sizeof(buffer));
|
serializeJson(root, buffer, sizeof(buffer));
|
||||||
jsonBuffer.clear();
|
jsonBuffer.clear();
|
||||||
#if ENABLE_MQTT == 0
|
#if ENABLE_MQTT == 0
|
||||||
mqtt_client.publish(mqtt_ha_state_out, buffer, true);
|
mqtt_client->publish(mqtt_ha_state_out, buffer, true);
|
||||||
DBG_OUTPUT_PORT.printf("MQTT: Send [%s]: %s\r\n", mqtt_ha_state_out, buffer);
|
DBG_OUTPUT_PORT.printf("MQTT: Send [%s]: %s\r\n", mqtt_ha_state_out, buffer);
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_MQTT == 1
|
#if ENABLE_MQTT == 1
|
||||||
mqtt_client.publish(mqtt_ha_state_out, 1, true, buffer);
|
mqtt_client->publish(mqtt_ha_state_out, 1, true, buffer);
|
||||||
DBG_OUTPUT_PORT.printf("MQTT: Send [%s]: %s\r\n", mqtt_ha_state_out, buffer);
|
DBG_OUTPUT_PORT.printf("MQTT: Send [%s]: %s\r\n", mqtt_ha_state_out, buffer);
|
||||||
#endif
|
#endif
|
||||||
new_ha_mqtt_msg = false;
|
new_ha_mqtt_msg = false;
|
||||||
@@ -1283,51 +1295,51 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
#if ENABLE_MQTT == 0
|
#if ENABLE_MQTT == 0
|
||||||
void mqtt_reconnect() {
|
void mqtt_reconnect() {
|
||||||
// Loop until we're reconnected
|
// Loop until we're reconnected
|
||||||
while (!mqtt_client.connected() && mqtt_reconnect_retries < MQTT_MAX_RECONNECT_TRIES) {
|
while (!mqtt_client->connected() && mqtt_reconnect_retries < MQTT_MAX_RECONNECT_TRIES) {
|
||||||
mqtt_reconnect_retries++;
|
mqtt_reconnect_retries++;
|
||||||
DBG_OUTPUT_PORT.printf("Attempting MQTT connection %d / %d ...\r\n", mqtt_reconnect_retries, MQTT_MAX_RECONNECT_TRIES);
|
DBG_OUTPUT_PORT.printf("Attempting MQTT connection %d / %d ...\r\n", mqtt_reconnect_retries, MQTT_MAX_RECONNECT_TRIES);
|
||||||
// Attempt to connect
|
// Attempt to connect
|
||||||
if (mqtt_client.connect(mqtt_clientid, mqtt_user, mqtt_pass, mqtt_will_topic, 2, true, mqtt_will_payload, true)) {
|
if (mqtt_client->connect(mqtt_clientid, mqtt_user, mqtt_pass, mqtt_will_topic, 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[18 + strlen(HOSTNAME) + 1];
|
char message[18 + strlen(HOSTNAME) + 1];
|
||||||
strcpy(message, "McLighting ready: ");
|
strcpy(message, "McLighting ready: ");
|
||||||
strcat(message, HOSTNAME);
|
strcat(message, HOSTNAME);
|
||||||
mqtt_client.publish(mqtt_outtopic, message);
|
mqtt_client->publish(mqtt_outtopic, message);
|
||||||
// ... and resubscribe
|
// ... and resubscribe
|
||||||
mqtt_client.subscribe(mqtt_intopic, qossub);
|
mqtt_client->subscribe(mqtt_intopic, qossub);
|
||||||
if(mqtt_lwt_boot_flag) {
|
if(mqtt_lwt_boot_flag) {
|
||||||
mqtt_client.publish(mqtt_will_topic, "ONLINE");
|
mqtt_client->publish(mqtt_will_topic, "ONLINE");
|
||||||
//mqtt_lwt_boot_flag = false;
|
//mqtt_lwt_boot_flag = false;
|
||||||
}
|
}
|
||||||
#if defined(ENABLE_HOMEASSISTANT)
|
#if defined(ENABLE_HOMEASSISTANT)
|
||||||
ha_send_data.detach();
|
ha_send_data.detach();
|
||||||
mqtt_client.subscribe(mqtt_ha_state_in, qossub);
|
mqtt_client->subscribe(mqtt_ha_state_in, qossub);
|
||||||
ha_send_data.once(5, tickerSendState);
|
ha_send_data.once(5, tickerSendState);
|
||||||
#if defined(MQTT_HOME_ASSISTANT_SUPPORT)
|
#if defined(MQTT_HOME_ASSISTANT_SUPPORT)
|
||||||
const size_t bufferSize = JSON_ARRAY_SIZE(strip->getModeCount()+ 4) + JSON_OBJECT_SIZE(11) + 1500;
|
const size_t bufferSize = JSON_ARRAY_SIZE(strip->getModeCount()+ 4) + JSON_OBJECT_SIZE(11) + 1500;
|
||||||
DynamicJsonDocument jsonBuffer(bufferSize);
|
DynamicJsonDocument jsonBuffer(bufferSize);
|
||||||
JsonObject json = jsonBuffer.to<JsonObject>();
|
JsonObject root = jsonBuffer.to<JsonObject>();
|
||||||
json["name"] = HOSTNAME;
|
root["name"] = HOSTNAME;
|
||||||
#if defined(MQTT_HOME_ASSISTANT_0_87_SUPPORT)
|
#if defined(MQTT_HOME_ASSISTANT_0_87_SUPPORT)
|
||||||
json["schema"] = "json";
|
root["schema"] = "json";
|
||||||
#else
|
#else
|
||||||
json["platform"] = "mqtt_json";
|
root["platform"] = "mqtt_json";
|
||||||
#endif
|
#endif
|
||||||
json["state_topic"] = mqtt_ha_state_out;
|
root["state_topic"] = mqtt_ha_state_out;
|
||||||
json["command_topic"] = mqtt_ha_state_in;
|
root["command_topic"] = mqtt_ha_state_in;
|
||||||
#if !defined(MQTT_HOME_ASSISTANT_0_87_SUPPORT)
|
#if !defined(MQTT_HOME_ASSISTANT_0_87_SUPPORT)
|
||||||
json["on_command_type"] = "first";
|
root["on_command_type"] = "first";
|
||||||
#endif
|
#endif
|
||||||
json["brightness"] = "true";
|
root["brightness"] = "true";
|
||||||
json["rgb"] = "true";
|
root["rgb"] = "true";
|
||||||
if (strstr(WS2812FXStripSettings.RGBOrder, "W") != NULL) {
|
if (strstr(WS2812FXStripSettings.RGBOrder, "W") != NULL) {
|
||||||
json["white_value"]= "true";
|
root["white_value"]= "true";
|
||||||
}
|
}
|
||||||
json["optimistic"] = "false";
|
root["optimistic"] = "false";
|
||||||
json["color_temp"] = "true";
|
root["color_temp"] = "true";
|
||||||
json["effect"] = "true";
|
root["effect"] = "true";
|
||||||
JsonArray effect_list = json.createNestedArray("effect_list");
|
JsonArray effect_list = root.createNestedArray("effect_list");
|
||||||
effect_list.add("OFF");
|
effect_list.add("OFF");
|
||||||
effect_list.add("AUTO");
|
effect_list.add("AUTO");
|
||||||
#if defined(ENABLE_TV)
|
#if defined(ENABLE_TV)
|
||||||
@@ -1341,17 +1353,17 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
}
|
}
|
||||||
// Following will never work for PubSubClient as message size > 1.6kB
|
// Following will never work for PubSubClient as message size > 1.6kB
|
||||||
// char buffer[measureJson(json) + 1];
|
// char buffer[measureJson(json) + 1];
|
||||||
// serializeJson(json, buffer, sizeof(buffer));
|
// serializeJson(root, buffer, sizeof(buffer));
|
||||||
// mqtt_client.publish(String("homeassistant/light/" + String(HOSTNAME) + "/config").c_str(), buffer, true);
|
// mqtt_client->publish(String("homeassistant/light/" + String(HOSTNAME) + "/config").c_str(), buffer, true);
|
||||||
|
|
||||||
// Alternate way to publish large messages using PubSubClient
|
// Alternate way to publish large messages using PubSubClient
|
||||||
uint16_t msg_len = measureJson(json) + 1;
|
uint16_t msg_len = measureJson(root) + 1;
|
||||||
char buffer[msg_len];
|
char buffer[msg_len];
|
||||||
serializeJson(json, buffer, sizeof(buffer));
|
serializeJson(root, buffer, sizeof(buffer));
|
||||||
DBG_OUTPUT_PORT.println(buffer);
|
DBG_OUTPUT_PORT.println(buffer);
|
||||||
mqtt_client.beginPublish(String("homeassistant/light/" + String(HOSTNAME) + "/config").c_str(), msg_len-1, true);
|
mqtt_client->beginPublish(mqtt_ha_config, msg_len-1, true);
|
||||||
mqtt_client.write((const uint8_t*)buffer, msg_len-1);
|
mqtt_client->write((const uint8_t*)buffer, msg_len-1);
|
||||||
mqtt_client.endPublish();
|
mqtt_client->endPublish();
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1359,7 +1371,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
DBG_OUTPUT_PORT.printf("MQTT topic out: %s\r\n", mqtt_outtopic);
|
DBG_OUTPUT_PORT.printf("MQTT topic out: %s\r\n", mqtt_outtopic);
|
||||||
} else {
|
} else {
|
||||||
DBG_OUTPUT_PORT.print("failed, rc=");
|
DBG_OUTPUT_PORT.print("failed, rc=");
|
||||||
DBG_OUTPUT_PORT.print(mqtt_client.state());
|
DBG_OUTPUT_PORT.print(mqtt_client->state());
|
||||||
DBG_OUTPUT_PORT.println(" try again in 5 seconds");
|
DBG_OUTPUT_PORT.println(" try again in 5 seconds");
|
||||||
// Wait 5 seconds before retrying
|
// Wait 5 seconds before retrying
|
||||||
delay(5000);
|
delay(5000);
|
||||||
@@ -1380,7 +1392,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
|
|
||||||
void connectToMqtt() {
|
void connectToMqtt() {
|
||||||
DBG_OUTPUT_PORT.println("Connecting to MQTT...");
|
DBG_OUTPUT_PORT.println("Connecting to MQTT...");
|
||||||
mqtt_client.connect();
|
mqtt_client->connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onWifiConnect(const WiFiEventStationModeGotIP& event) {
|
void onWifiConnect(const WiFiEventStationModeGotIP& event) {
|
||||||
@@ -1404,42 +1416,42 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
char message[18 + strlen(HOSTNAME) + 1];
|
char message[18 + strlen(HOSTNAME) + 1];
|
||||||
strcpy(message, "McLighting ready: ");
|
strcpy(message, "McLighting ready: ");
|
||||||
strcat(message, HOSTNAME);
|
strcat(message, HOSTNAME);
|
||||||
mqtt_client.publish(mqtt_outtopic, qospub, false, message);
|
mqtt_client->publish(mqtt_outtopic, qospub, false, message);
|
||||||
//Subscribe
|
//Subscribe
|
||||||
uint16_t packetIdSub1 = mqtt_client.subscribe(mqtt_intopic, qossub);
|
uint16_t packetIdSub1 = mqtt_client->subscribe(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);
|
||||||
if(mqtt_lwt_boot_flag) {
|
if(mqtt_lwt_boot_flag) {
|
||||||
mqtt_client.publish(mqtt_will_topic, qospub, false, "ONLINE");
|
mqtt_client->publish(mqtt_will_topic, qospub, false, "ONLINE");
|
||||||
mqtt_lwt_boot_flag = false;
|
mqtt_lwt_boot_flag = false;
|
||||||
}
|
}
|
||||||
#if defined(ENABLE_HOMEASSISTANT)
|
#if defined(ENABLE_HOMEASSISTANT)
|
||||||
ha_send_data.detach();
|
ha_send_data.detach();
|
||||||
uint16_t packetIdSub2 = mqtt_client.subscribe((char *)mqtt_ha_state_in, qossub);
|
uint16_t packetIdSub2 = mqtt_client->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);
|
||||||
#if defined(MQTT_HOME_ASSISTANT_SUPPORT)
|
#if defined(MQTT_HOME_ASSISTANT_SUPPORT)
|
||||||
const size_t bufferSize = JSON_ARRAY_SIZE(strip->getModeCount()+ 4) + JSON_OBJECT_SIZE(11) + 1500;
|
const size_t bufferSize = JSON_ARRAY_SIZE(strip->getModeCount()+ 4) + JSON_OBJECT_SIZE(11) + 1500;
|
||||||
DynamicJsonDocument jsonBuffer(bufferSize);
|
DynamicJsonDocument jsonBuffer(bufferSize);
|
||||||
JsonObject json = jsonBuffer.to<JsonObject>();
|
JsonObject root = jsonBuffer.to<JsonObject>();
|
||||||
json["name"] = HOSTNAME;
|
root["name"] = HOSTNAME;
|
||||||
#if defined(MQTT_HOME_ASSISTANT_0_87_SUPPORT)
|
#if defined(MQTT_HOME_ASSISTANT_0_87_SUPPORT)
|
||||||
json["schema"] = "json";
|
root["schema"] = "json";
|
||||||
#else
|
#else
|
||||||
json["platform"] = "mqtt_json";
|
root["platform"] = "mqtt_json";
|
||||||
#endif
|
#endif
|
||||||
json["state_topic"] = mqtt_ha_state_out;
|
root["state_topic"] = mqtt_ha_state_out;
|
||||||
json["command_topic"] = mqtt_ha_state_in;
|
root["command_topic"] = mqtt_ha_state_in;
|
||||||
#if !defined(MQTT_HOME_ASSISTANT_0_87_SUPPORT)
|
#if !defined(MQTT_HOME_ASSISTANT_0_87_SUPPORT)
|
||||||
json["on_command_type"] = "first";
|
root["on_command_type"] = "first";
|
||||||
#endif
|
#endif
|
||||||
json["brightness"] = "true";
|
root["brightness"] = "true";
|
||||||
json["rgb"] = "true";
|
root["rgb"] = "true";
|
||||||
if (strstr(WS2812FXStripSettings.RGBOrder, "W") != NULL) {
|
if (strstr(WS2812FXStripSettings.RGBOrder, "W") != NULL) {
|
||||||
json["white_value"]= "true";
|
root["white_value"]= "true";
|
||||||
}
|
}
|
||||||
json["optimistic"] = "false";
|
root["optimistic"] = "false";
|
||||||
json["color_temp"] = "true";
|
root["color_temp"] = "true";
|
||||||
json["effect"] = "true";
|
root["effect"] = "true";
|
||||||
JsonArray effect_list = json.createNestedArray("effect_list");
|
JsonArray effect_list = root.createNestedArray("effect_list");
|
||||||
effect_list.add("OFF");
|
effect_list.add("OFF");
|
||||||
effect_list.add("AUTO");
|
effect_list.add("AUTO");
|
||||||
#if defined(ENABLE_TV)
|
#if defined(ENABLE_TV)
|
||||||
@@ -1451,10 +1463,10 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
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));
|
||||||
}
|
}
|
||||||
char buffer[measureJson(json) + 1];
|
char buffer[measureJson(root) + 1];
|
||||||
serializeJson(json, buffer, sizeof(buffer));
|
serializeJson(root, buffer, sizeof(buffer));
|
||||||
jsonBuffer.clear();
|
jsonBuffer.clear();
|
||||||
mqtt_client.publish(mqtt_ha_config, qospub, true, buffer);
|
mqtt_client->publish(mqtt_ha_config, qospub, true, buffer);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -1650,23 +1662,23 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
DBG_OUTPUT_PORT.print("Config: ");
|
DBG_OUTPUT_PORT.print("Config: ");
|
||||||
if (!error) {
|
if (!error) {
|
||||||
DBG_OUTPUT_PORT.println("Parsed!");
|
DBG_OUTPUT_PORT.println("Parsed!");
|
||||||
JsonObject json = jsonBuffer.as<JsonObject>();
|
JsonObject root = jsonBuffer.as<JsonObject>();
|
||||||
serializeJson(json, DBG_OUTPUT_PORT);
|
serializeJson(root, DBG_OUTPUT_PORT);
|
||||||
DBG_OUTPUT_PORT.println("");
|
DBG_OUTPUT_PORT.println("");
|
||||||
strcpy(HOSTNAME, json["hostname"]);
|
strcpy(HOSTNAME, root["hostname"]);
|
||||||
#if defined(ENABLE_MQTT)
|
#if defined(ENABLE_MQTT)
|
||||||
strcpy(mqtt_host, json["mqtt_host"]);
|
strcpy(mqtt_host, root["mqtt_host"]);
|
||||||
mqtt_port = (uint16_t) json["mqtt_port"];
|
mqtt_port = (uint16_t) root["mqtt_port"];
|
||||||
strcpy(mqtt_user, json["mqtt_user"]);
|
strcpy(mqtt_user, root["mqtt_user"]);
|
||||||
strcpy(mqtt_pass, json["mqtt_pass"]);
|
strcpy(mqtt_pass, root["mqtt_pass"]);
|
||||||
#endif
|
#endif
|
||||||
WS2812FXStripSettings.stripSize = constrain ((uint8_t) json["ws_cnt"], 1, MAXLEDS);
|
WS2812FXStripSettings.stripSize = constrain ((uint16_t) root["ws_cnt"], 1, MAXLEDS);
|
||||||
char tmp_rgbOrder[5];
|
char tmp_rgbOrder[5];
|
||||||
strcpy(tmp_rgbOrder, json["ws_rgbo"]);
|
strcpy(tmp_rgbOrder, root["ws_rgbo"]);
|
||||||
checkRGBOrder(tmp_rgbOrder);
|
checkRGBOrder(tmp_rgbOrder);
|
||||||
uint8_t temp_pin;
|
uint8_t temp_pin;
|
||||||
WS2812FXStripSettings.pin = checkPin((uint8_t) json["ws_pin"]);
|
checkPin((uint8_t) root["ws_pin"]);
|
||||||
WS2812FXStripSettings.fxoptions = ((constrain((uint8_t) json["ws_fxopt"], 0, 255)>>1)<<1);
|
WS2812FXStripSettings.fxoptions = ((constrain((uint8_t) root["ws_fxopt"], 0, 255)>>1)<<1);
|
||||||
jsonBuffer.clear();
|
jsonBuffer.clear();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@@ -1730,25 +1742,25 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
DBG_OUTPUT_PORT.print("Config: ");
|
DBG_OUTPUT_PORT.print("Config: ");
|
||||||
if (!error) {
|
if (!error) {
|
||||||
DBG_OUTPUT_PORT.print("Parsed");
|
DBG_OUTPUT_PORT.print("Parsed");
|
||||||
JsonObject json = jsonBuffer.as<JsonObject>();
|
JsonObject root = jsonBuffer.as<JsonObject>();
|
||||||
serializeJson(json, DBG_OUTPUT_PORT);
|
serializeJson(root, DBG_OUTPUT_PORT);
|
||||||
DBG_OUTPUT_PORT.println("");
|
DBG_OUTPUT_PORT.println("");
|
||||||
mode = static_cast<MODE>((int) json["mode"]);
|
mode = static_cast<MODE>((int) root["mode"]);
|
||||||
ws2812fx_mode = json["ws2812fx_mode"];
|
ws2812fx_mode = root["ws2812fx_mode"];
|
||||||
ws2812fx_speed = json["speed"];
|
ws2812fx_speed = root["speed"];
|
||||||
brightness = json["brightness"];
|
brightness = root["brightness"];
|
||||||
main_color.white = (uint8_t) json["color"][0];
|
main_color.white = (uint8_t) root["color"][0];
|
||||||
main_color.red = (uint8_t) json["color"][1];
|
main_color.red = (uint8_t) root["color"][1];
|
||||||
main_color.green = (uint8_t) json["color"][2];
|
main_color.green = (uint8_t) root["color"][2];
|
||||||
main_color.blue = (uint8_t) json["color"][3];
|
main_color.blue = (uint8_t) root["color"][3];
|
||||||
back_color.white = (uint8_t) json["color"][4];
|
back_color.white = (uint8_t) root["color"][4];
|
||||||
back_color.red = (uint8_t) json["color"][5];
|
back_color.red = (uint8_t) root["color"][5];
|
||||||
back_color.green = (uint8_t) json["color"][6];
|
back_color.green = (uint8_t) root["color"][6];
|
||||||
back_color.blue = (uint8_t) json["color"][7];
|
back_color.blue = (uint8_t) root["color"][7];
|
||||||
xtra_color.white = (uint8_t) json["color"][8];
|
xtra_color.white = (uint8_t) root["color"][8];
|
||||||
xtra_color.red = (uint8_t) json["color"][9];
|
xtra_color.red = (uint8_t) root["color"][9];
|
||||||
xtra_color.green = (uint8_t) json["color"][10];
|
xtra_color.green = (uint8_t) root["color"][10];
|
||||||
xtra_color.blue = (uint8_t) json["color"][11];
|
xtra_color.blue = (uint8_t) root["color"][11];
|
||||||
convertColors();
|
convertColors();
|
||||||
jsonBuffer.clear();
|
jsonBuffer.clear();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -19,23 +19,23 @@
|
|||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
|
|
||||||
server.on("/", HTTP_GET, [&](){
|
server.on("/", HTTP_GET, [&](){
|
||||||
#if defined(USE_HTML_MIN_GZ)
|
if (USE_HTML_MIN_GZ) {
|
||||||
server.sendHeader("Content-Encoding", "gzip", true);
|
server.sendHeader("Content-Encoding", "gzip", true);
|
||||||
server.send_P(200, PSTR("text/html"), index_htm_gz, index_htm_gz_len);
|
server.send_P(200, PSTR("text/html"), index_htm_gz, index_htm_gz_len);
|
||||||
#else
|
} else {
|
||||||
if (!handleFileRead(server.uri()))
|
if (!handleFileRead(server.uri()))
|
||||||
handleNotFound();
|
handleNotFound();
|
||||||
#endif
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/edit", HTTP_GET, [&](){
|
server.on("/edit", HTTP_GET, [&](){
|
||||||
#if defined(USE_HTML_MIN_GZ)
|
if (USE_HTML_MIN_GZ) {
|
||||||
server.sendHeader("Content-Encoding", "gzip", true);
|
server.sendHeader("Content-Encoding", "gzip", true);
|
||||||
server.send_P(200, PSTR("text/html"), edit_htm_gz, edit_htm_gz_len);
|
server.send_P(200, PSTR("text/html"), edit_htm_gz, edit_htm_gz_len);
|
||||||
#else
|
} else {
|
||||||
if (!handleFileRead("/edit.htm"))
|
if (!handleFileRead("/edit.htm"))
|
||||||
handleNotFound();
|
handleNotFound();
|
||||||
#endif
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -51,114 +51,115 @@
|
|||||||
server.on("/esp_status", HTTP_GET, []() { //get heap status, analog input value and all GPIO statuses in one json call
|
server.on("/esp_status", HTTP_GET, []() { //get heap status, analog input value and all GPIO statuses in one json call
|
||||||
const size_t bufferSize = JSON_OBJECT_SIZE(31) + 1500;
|
const size_t bufferSize = JSON_OBJECT_SIZE(31) + 1500;
|
||||||
DynamicJsonDocument jsonBuffer(bufferSize);
|
DynamicJsonDocument jsonBuffer(bufferSize);
|
||||||
JsonObject json = jsonBuffer.to<JsonObject>();
|
JsonObject root = jsonBuffer.to<JsonObject>();
|
||||||
json["HOSTNAME"] = HOSTNAME;
|
root["HOSTNAME"] = HOSTNAME;
|
||||||
json["version"] = SKETCH_VERSION;
|
root["version"] = SKETCH_VERSION;
|
||||||
json["heap"] = ESP.getFreeHeap();
|
root["heap"] = ESP.getFreeHeap();
|
||||||
json["sketch_size"] = ESP.getSketchSize();
|
root["sketch_size"] = ESP.getSketchSize();
|
||||||
json["free_sketch_space"] = ESP.getFreeSketchSpace();
|
root["free_sketch_space"] = ESP.getFreeSketchSpace();
|
||||||
json["flash_chip_size"] = ESP.getFlashChipSize();
|
root["flash_chip_size"] = ESP.getFlashChipSize();
|
||||||
json["flash_chip_real_size"] = ESP.getFlashChipRealSize();
|
root["flash_chip_real_size"] = ESP.getFlashChipRealSize();
|
||||||
json["flash_chip_speed"] = ESP.getFlashChipSpeed();
|
root["flash_chip_speed"] = ESP.getFlashChipSpeed();
|
||||||
json["sdk_version"] = ESP.getSdkVersion();
|
root["sdk_version"] = ESP.getSdkVersion();
|
||||||
json["core_version"] = ESP.getCoreVersion();
|
root["core_version"] = ESP.getCoreVersion();
|
||||||
json["cpu_freq"] = ESP.getCpuFreqMHz();
|
root["cpu_freq"] = ESP.getCpuFreqMHz();
|
||||||
json["chip_id"] = ESP.getFlashChipId();
|
root["chip_id"] = ESP.getFlashChipId();
|
||||||
#if defined(USE_WS2812FX_DMA)
|
#if defined(USE_WS2812FX_DMA)
|
||||||
#if USE_WS2812FX_DMA == 0
|
#if USE_WS2812FX_DMA == 0
|
||||||
json["animation_lib"] = "WS2812FX_DMA";
|
root["animation_lib"] = "WS2812FX_DMA";
|
||||||
#endif
|
#endif
|
||||||
#if USE_WS2812FX_DMA == 1
|
#if USE_WS2812FX_DMA == 1
|
||||||
json["animation_lib"] = "WS2812FX_UART1";
|
root["animation_lib"] = "WS2812FX_UART1";
|
||||||
#endif
|
#endif
|
||||||
#if USE_WS2812FX_DMA == 2
|
#if USE_WS2812FX_DMA == 2
|
||||||
json["animation_lib"] = "WS2812FX_UART2";
|
root["animation_lib"] = "WS2812FX_UART2";
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
json["animation_lib"] = "WS2812FX";
|
root["animation_lib"] = "WS2812FX";
|
||||||
#endif
|
#endif
|
||||||
json["ws2812_pin"] = WS2812FXStripSettings.pin;
|
root["ws2812_pin"] = WS2812FXStripSettings.pin;
|
||||||
json["led_count"] = WS2812FXStripSettings.stripSize;
|
root["led_count"] = WS2812FXStripSettings.stripSize;
|
||||||
json["rgb_order"] = WS2812FXStripSettings.RGBOrder;
|
root["rgb_order"] = WS2812FXStripSettings.RGBOrder;
|
||||||
if (strstr(WS2812FXStripSettings.RGBOrder, "W") != NULL) {
|
if (strstr(WS2812FXStripSettings.RGBOrder, "W") != NULL) {
|
||||||
json["rgbw_mode"] = "ON";
|
root["rgbw_mode"] = "ON";
|
||||||
} else {
|
} else {
|
||||||
json["rgbw_mode"] = "OFF";
|
root["rgbw_mode"] = "OFF";
|
||||||
}
|
}
|
||||||
#if defined(ENABLE_BUTTON)
|
#if defined(ENABLE_BUTTON)
|
||||||
json["button_mode"] = "ON";
|
root["button_mode"] = "ON";
|
||||||
json["button_pin"] = ENABLE_BUTTON;
|
root["button_pin"] = ENABLE_BUTTON;
|
||||||
#else
|
#else
|
||||||
json["button_mode"] = "OFF";
|
root["button_mode"] = "OFF";
|
||||||
#endif
|
#endif
|
||||||
#if defined(ENABLE_BUTTON_GY33)
|
#if defined(ENABLE_BUTTON_GY33)
|
||||||
json["button_gy33"] = "ON";
|
root["button_gy33"] = "ON";
|
||||||
json["gy33_pin"] = ENABLE_BUTTON_GY33;
|
root["gy33_pin"] = ENABLE_BUTTON_GY33;
|
||||||
#else
|
#else
|
||||||
json["button_gy33"] = "OFF";
|
root["button_gy33"] = "OFF";
|
||||||
#endif
|
#endif
|
||||||
#if defined(ENABLE_REMOTE)
|
#if defined(ENABLE_REMOTE)
|
||||||
json["ir_remote"] = "ON";
|
root["ir_remote"] = "ON";
|
||||||
json["tsop_ir_pin"] = ENABLE_REMOTE;
|
root["tsop_ir_pin"] = ENABLE_REMOTE;
|
||||||
#else
|
#else
|
||||||
json["ir_remote"] = "OFF";
|
root["ir_remote"] = "OFF";
|
||||||
#endif
|
#endif
|
||||||
#if defined(ENABLE_MQTT)
|
#if defined(ENABLE_MQTT)
|
||||||
#if ENABLE_MQTT == 0
|
#if ENABLE_MQTT == 0
|
||||||
json["mqtt"] = "MQTT";
|
root["mqtt"] = "MQTT";
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_MQTT == 1
|
#if ENABLE_MQTT == 1
|
||||||
json["mqtt"] = "AMQTT";
|
root["mqtt"] = "AMQTT";
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
json["mqtt"] = "OFF";
|
root["mqtt"] = "OFF";
|
||||||
#endif
|
#endif
|
||||||
#if defined(ENABLE_HOMEASSISTANT)
|
#if defined(ENABLE_HOMEASSISTANT)
|
||||||
json["home_assistant"] = "ON";
|
root["home_assistant"] = "ON";
|
||||||
#else
|
#else
|
||||||
json["home_assistant"] = "OFF";
|
root["home_assistant"] = "OFF";
|
||||||
#endif
|
#endif
|
||||||
#if defined(ENABLE_LEGACY_ANIMATIONS)
|
#if defined(ENABLE_LEGACY_ANIMATIONS)
|
||||||
json["legacy_animations"] = "ON";
|
root["legacy_animations"] = "ON";
|
||||||
#else
|
#else
|
||||||
json["legacy_animations"] = "OFF";
|
root["legacy_animations"] = "OFF";
|
||||||
#endif
|
#endif
|
||||||
#if defined(ENABLE_TV)
|
#if defined(ENABLE_TV)
|
||||||
json["tv_animation"] = "ON";
|
root["tv_animation"] = "ON";
|
||||||
#else
|
#else
|
||||||
json["tv_animation"] = "OFF";
|
root["tv_animation"] = "OFF";
|
||||||
#endif
|
#endif
|
||||||
#if defined(ENABLE_E131)
|
#if defined(ENABLE_E131)
|
||||||
json["e131_animations"] = "ON";
|
root["e131_animations"] = "ON";
|
||||||
#else
|
#else
|
||||||
json["e131_animations"] = "OFF";
|
root["e131_animations"] = "OFF";
|
||||||
#endif
|
#endif
|
||||||
#if defined(ENABLE_OTA)
|
#if defined(ENABLE_OTA)
|
||||||
#if ENABLE_OTA == 0
|
#if ENABLE_OTA == 0
|
||||||
json["ota"] = "ARDUINO";
|
root["ota"] = "ARDUINO";
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_OTA == 1
|
#if ENABLE_OTA == 1
|
||||||
json["ota"] = "HTTP";
|
root["ota"] = "HTTP";
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
json["ota"] = "OFF";
|
root["ota"] = "OFF";
|
||||||
#endif
|
#endif
|
||||||
#if defined(ENABLE_STATE_SAVE)
|
#if defined(ENABLE_STATE_SAVE)
|
||||||
#if ENABLE_STATE_SAVE == 1
|
#if ENABLE_STATE_SAVE == 1
|
||||||
json["state_save"] = "SPIFFS";
|
root["state_save"] = "SPIFFS";
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_STATE_SAVE == 0
|
#if ENABLE_STATE_SAVE == 0
|
||||||
json["state_save"] = "EEPROM";
|
root["state_save"] = "EEPROM";
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
json["state_save"] = "OFF";
|
root["state_save"] = "OFF";
|
||||||
#endif
|
#endif
|
||||||
|
uint16_t msg_len = measureJson(root) + 1;
|
||||||
String json_str;
|
char * buffer = (char *) malloc(msg_len);
|
||||||
serializeJson(json, json_str);
|
serializeJson(root, buffer, msg_len);
|
||||||
jsonBuffer.clear();
|
jsonBuffer.clear();
|
||||||
server.sendHeader("Access-Control-Allow-Origin", "*");
|
server.sendHeader("Access-Control-Allow-Origin", "*");
|
||||||
server.send(200, "application/json", json_str);
|
server.send(200, "application/json", buffer);
|
||||||
|
free (buffer);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/restart", []() {
|
server.on("/restart", []() {
|
||||||
@@ -291,7 +292,7 @@
|
|||||||
|
|
||||||
#if !defined(USE_WS2812FX_DMA)
|
#if !defined(USE_WS2812FX_DMA)
|
||||||
if(server.hasArg("wspin")){
|
if(server.hasArg("wspin")){
|
||||||
if (checkPin(server.arg("wspin").toInt()) {
|
if (checkPin(server.arg("wspin").toInt())) {
|
||||||
updateStrip = true;
|
updateStrip = true;
|
||||||
DBG_OUTPUT_PORT.println(WS2812FXStripSettings.pin);
|
DBG_OUTPUT_PORT.println(WS2812FXStripSettings.pin);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -140,4 +140,9 @@
|
|||||||
* Version Bump to 2.2.3 rgbw 3colors
|
* Version Bump to 2.2.3 rgbw 3colors
|
||||||
* PubSubClient Bug fixes
|
* PubSubClient Bug fixes
|
||||||
* Reverted Pointers for MQTT for the moment
|
* Reverted Pointers for MQTT for the moment
|
||||||
|
*
|
||||||
|
* 21 Mar 2019
|
||||||
|
* Bugfixes
|
||||||
|
* added pointer for MQTT again
|
||||||
|
* Removed some String datatype and replaced with char array
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1341,7 +1341,7 @@ function displayColors(all = false) {
|
|||||||
document.getElementById("colorHex" + data.color_num).innerHTML = "#" + rgbToHex([white.value, red.value, green.value, blue.value]);
|
document.getElementById("colorHex" + data.color_num).innerHTML = "#" + rgbToHex([white.value, red.value, green.value, blue.value]);
|
||||||
// Send color
|
// Send color
|
||||||
clearTimeout(sendIt);
|
clearTimeout(sendIt);
|
||||||
sendIt = setTimeout(function() { set_color(); }, 500);
|
sendIt = setTimeout(function() { set_color(); }, 50);
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("colorSel1").style.backgroundColor = `rgb(${data.color.r}, ${data.color.g}, ${data.color.b})`;
|
document.getElementById("colorSel1").style.backgroundColor = `rgb(${data.color.r}, ${data.color.g}, ${data.color.b})`;
|
||||||
document.getElementById("colorHex1").innerHTML = "#" + data.color.hex;
|
document.getElementById("colorHex1").innerHTML = "#" + data.color.hex;
|
||||||
@@ -1430,7 +1430,7 @@ function changeRangeNumVal(){
|
|||||||
initSliderColors();
|
initSliderColors();
|
||||||
// Send Brightness
|
// Send Brightness
|
||||||
clearTimeout(sendIt);
|
clearTimeout(sendIt);
|
||||||
sendIt = setTimeout(function() { set_brightness(); }, 500);
|
sendIt = setTimeout(function() { set_brightness(); }, 50);
|
||||||
});
|
});
|
||||||
speedNumVal.addEventListener('change', ()=>{
|
speedNumVal.addEventListener('change', ()=>{
|
||||||
// make sure numbers are entered between 0 to 255
|
// make sure numbers are entered between 0 to 255
|
||||||
@@ -1438,7 +1438,7 @@ function changeRangeNumVal(){
|
|||||||
data.speed = speed.value;
|
data.speed = speed.value;
|
||||||
// Send Speed
|
// Send Speed
|
||||||
clearTimeout(sendIt);
|
clearTimeout(sendIt);
|
||||||
sendIt = setTimeout(function() { set_speed(); }, 500);
|
sendIt = setTimeout(function() { set_speed(); }, 50);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function checkNumVal(numVal, curVal) {
|
function checkNumVal(numVal, curVal) {
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user