@@ -38,7 +38,7 @@
|
|||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
WiFiClient espClient;
|
WiFiClient espClient;
|
||||||
PubSubClient* mqtt_client = NULL;
|
PubSubClient mqtt_client(espClient);
|
||||||
#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 = NULL;
|
AsyncMqttClient mqtt_client;
|
||||||
WiFiEventHandler wifiConnectHandler;
|
WiFiEventHandler wifiConnectHandler;
|
||||||
WiFiEventHandler wifiDisconnectHandler;
|
WiFiEventHandler wifiDisconnectHandler;
|
||||||
#endif
|
#endif
|
||||||
@@ -189,7 +189,7 @@ Ticker ticker;
|
|||||||
|
|
||||||
void tick() {
|
void tick() {
|
||||||
//toggle state
|
//toggle state
|
||||||
int state = digitalRead(LED_BUILTIN); // get the current state of GPIO1 pin
|
uint16_t state = digitalRead(LED_BUILTIN); // get the current state of GPIO1 pin
|
||||||
digitalWrite(LED_BUILTIN, !state); // set pin to the opposite state
|
digitalWrite(LED_BUILTIN, !state); // set pin to the opposite state
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,13 +205,13 @@ Ticker settings_save_state;
|
|||||||
// Saved state handling in WifiManager
|
// Saved state handling in WifiManager
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
// https://stackoverflow.com/questions/9072320/split-string-into-string-array
|
// https://stackoverflow.com/questions/9072320/split-string-into-string-array
|
||||||
String getValue(String data, char separator, int index)
|
String getValue(String data, char separator, uint8_t index)
|
||||||
{
|
{
|
||||||
int found = 0;
|
uint8_t found = 0;
|
||||||
int strIndex[] = {0, -1};
|
uint8_t strIndex[] = {0, -1};
|
||||||
int maxIndex = data.length()-1;
|
uint8_t maxIndex = data.length()-1;
|
||||||
|
|
||||||
for(int i=0; i<=maxIndex && found<=index; i++){
|
for(uint8_t i=0; i<=maxIndex && found<=index; i++){
|
||||||
if(data.charAt(i)==separator || i==maxIndex){
|
if(data.charAt(i)==separator || i==maxIndex){
|
||||||
found++;
|
found++;
|
||||||
strIndex[0] = strIndex[1]+1;
|
strIndex[0] = strIndex[1]+1;
|
||||||
@@ -300,7 +300,6 @@ void initStrip(uint16_t stripSize = WS2812FXStripSettings.stripSize, char RGBOrd
|
|||||||
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
|
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
|
||||||
// and minimize distance between Arduino and first pixel. Avoid connecting
|
// and minimize distance between Arduino and first pixel. Avoid connecting
|
||||||
// on a live circuit...if you must, connect GND first.
|
// on a live circuit...if you must, connect GND first.
|
||||||
|
|
||||||
strip->init();
|
strip->init();
|
||||||
#if defined(USE_WS2812FX_DMA)
|
#if defined(USE_WS2812FX_DMA)
|
||||||
initDMA(stripSize);
|
initDMA(stripSize);
|
||||||
@@ -335,12 +334,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());
|
||||||
@@ -358,25 +357,24 @@ 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
// MAIN Setup
|
// MAIN Setup
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
@@ -504,7 +502,6 @@ void setup() {
|
|||||||
wifiManager.setConfigPortalTimeout(WIFIMGR_PORTAL_TIMEOUT);
|
wifiManager.setConfigPortalTimeout(WIFIMGR_PORTAL_TIMEOUT);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Uncomment if you want to set static IP
|
|
||||||
// Order is: IP, Gateway and Subnet
|
// Order is: IP, Gateway and Subnet
|
||||||
#if defined(WIFIMGR_SET_MANUAL_IP)
|
#if defined(WIFIMGR_SET_MANUAL_IP)
|
||||||
wifiManager.setSTAStaticIPConfig(IPAddress(_ip[0], _ip[1], _ip[2], _ip[3]), IPAddress(_gw[0], _gw[1], _gw[2], _gw[3]), IPAddress(_sn[0], _sn[1], _sn[2], _sn[3]));
|
wifiManager.setSTAStaticIPConfig(IPAddress(_ip[0], _ip[1], _ip[2], _ip[3]), IPAddress(_gw[0], _gw[1], _gw[2], _gw[3]), IPAddress(_sn[0], _sn[1], _sn[2], _sn[3]));
|
||||||
@@ -532,7 +529,7 @@ void setup() {
|
|||||||
strcpy(mqtt_pass, custom_mqtt_pass.getValue());
|
strcpy(mqtt_pass, custom_mqtt_pass.getValue());
|
||||||
#endif
|
#endif
|
||||||
strcpy(tmp_strip_size, custom_strip_size.getValue());
|
strcpy(tmp_strip_size, custom_strip_size.getValue());
|
||||||
WS2812FXStripSettings.stripSize = constrain(atoi(custom_strip_size.getValue()), 0, MAXLEDS);
|
WS2812FXStripSettings.stripSize = constrain(atoi(custom_strip_size.getValue()), 1, MAXLEDS);
|
||||||
#if !defined(USE_WS2812FX_DMA)
|
#if !defined(USE_WS2812FX_DMA)
|
||||||
checkPin(atoi(custom_led_pin.getValue()));
|
checkPin(atoi(custom_led_pin.getValue()));
|
||||||
#endif
|
#endif
|
||||||
@@ -541,7 +538,6 @@ void setup() {
|
|||||||
WS2812FXStripSettings.fxoptions = atoi(custom_fxoptions.getValue());
|
WS2812FXStripSettings.fxoptions = atoi(custom_fxoptions.getValue());
|
||||||
#if ENABLE_STATE_SAVE == 1
|
#if ENABLE_STATE_SAVE == 1
|
||||||
(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!");
|
||||||
(writeStateFS(shouldSaveConfig)) ? DBG_OUTPUT_PORT.println("State config FS Save success!"): DBG_OUTPUT_PORT.println("State config FS Save failure!");
|
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_STATE_SAVE == 0
|
#if ENABLE_STATE_SAVE == 0
|
||||||
if (shouldSaveConfig) {
|
if (shouldSaveConfig) {
|
||||||
@@ -592,7 +588,7 @@ void setup() {
|
|||||||
ArduinoOTA.onEnd([]() {
|
ArduinoOTA.onEnd([]() {
|
||||||
DBG_OUTPUT_PORT.println("Arduino OTA: End");
|
DBG_OUTPUT_PORT.println("Arduino OTA: End");
|
||||||
});
|
});
|
||||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
ArduinoOTA.onProgress([](uint16_t progress, uint16_t total) {
|
||||||
DBG_OUTPUT_PORT.printf("Arduino OTA Progress: %u%%\r", (progress / (total / 100)));
|
DBG_OUTPUT_PORT.printf("Arduino OTA Progress: %u%%\r", (progress / (total / 100)));
|
||||||
});
|
});
|
||||||
ArduinoOTA.onError([](ota_error_t error) {
|
ArduinoOTA.onError([](ota_error_t error) {
|
||||||
@@ -716,14 +712,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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -835,6 +831,7 @@ void loop() {
|
|||||||
strip->setColors(0, hex_colors);
|
strip->setColors(0, hex_colors);
|
||||||
mode = prevmode;
|
mode = prevmode;
|
||||||
prevmode = SET_COLOR;
|
prevmode = SET_COLOR;
|
||||||
|
//DBG_OUTPUT_PORT.printf("mode: %d\r\n", mode);
|
||||||
if (mode == HOLD) strip->trigger();
|
if (mode == HOLD) strip->trigger();
|
||||||
}
|
}
|
||||||
if (mode == SET_SPEED) {
|
if (mode == SET_SPEED) {
|
||||||
@@ -853,6 +850,7 @@ void loop() {
|
|||||||
strip->setBrightness(brightness);
|
strip->setBrightness(brightness);
|
||||||
mode = prevmode;
|
mode = prevmode;
|
||||||
prevmode = SET_BRIGHTNESS;
|
prevmode = SET_BRIGHTNESS;
|
||||||
|
//DBG_OUTPUT_PORT.printf("mode: %d\r\n", mode);
|
||||||
if (mode == HOLD) strip->trigger();
|
if (mode == HOLD) strip->trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -865,10 +863,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);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
char HOSTNAME[65] = "McLightingRGBW"; // Friedly hostname is configurable just for the start
|
char HOSTNAME[65] = "McLightingRGBW"; // Friedly hostname is configurable just for the start
|
||||||
|
|
||||||
#define ENABLE_OTA 1 // If defined, enable Arduino OTA code. If set to 0 enable Arduino OTA code, if set to 1 enable ESP8266HTTPUpdateServer OTA code.
|
#define ENABLE_OTA 1 // If defined, enable Arduino OTA code. If set to 0 enable Arduino OTA code, if set to 1 enable ESP8266HTTPUpdateServer OTA code.
|
||||||
#define ENABLE_MQTT 1 // If defined use MQTT OR AMQTT, if set to 0 enable MQTT client code, see: https://github.com/toblum/McLighting/wiki/MQTT-API, if set to 1, enable Async MQTT code, see: https://github.com/marvinroger/async-mqtt-client
|
#define ENABLE_MQTT 0 // If defined use MQTT OR AMQTT, if set to 0 enable MQTT client code, see: https://github.com/toblum/McLighting/wiki/MQTT-API, if set to 1, enable Async MQTT code, see: https://github.com/marvinroger/async-mqtt-client
|
||||||
//#define ENABLE_MQTT_HOSTNAME_CHIPID // Uncomment/comment to add ESPChipID to end of MQTT hostname
|
//#define ENABLE_MQTT_HOSTNAME_CHIPID // Uncomment/comment to add ESPChipID to end of MQTT hostname
|
||||||
#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
|
||||||
@@ -36,7 +36,7 @@ char HOSTNAME[65] = "McLightingRGBW"; // Friedly hostname is configurable just
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ENABLE_REMOTE)
|
#if defined(ENABLE_REMOTE)
|
||||||
int selected_color = 1;
|
uint8_t selected_color = 1;
|
||||||
uint64_t last_remote_cmd;
|
uint64_t last_remote_cmd;
|
||||||
enum RMT_BTN {ON_OFF, MODE_UP, MODE_DOWN, RED_UP, RED_DOWN, GREEN_UP, GREEN_DOWN, BLUE_UP, BLUE_DOWN, WHITE_UP, WHITE_DOWN, BRIGHTNESS_UP, BRIGHTNESS_DOWN, SPEED_UP, SPEED_DOWN, COL_M, COL_B, COL_X, AUTOMODE, CUST_1, CUST_2, CUST_3, CUST_4, CUST_5, REPEATCMD, BTN_CNT};
|
enum RMT_BTN {ON_OFF, MODE_UP, MODE_DOWN, RED_UP, RED_DOWN, GREEN_UP, GREEN_DOWN, BLUE_UP, BLUE_DOWN, WHITE_UP, WHITE_DOWN, BRIGHTNESS_UP, BRIGHTNESS_DOWN, SPEED_UP, SPEED_DOWN, COL_M, COL_B, COL_X, AUTOMODE, CUST_1, CUST_2, CUST_3, CUST_4, CUST_5, REPEATCMD, BTN_CNT};
|
||||||
// Change your IR Commands here. You can see them in console, after you pressed a button on the remote
|
// Change your IR Commands here. You can see them in console, after you pressed a button on the remote
|
||||||
@@ -93,7 +93,7 @@ uint32_t autoParams[][6] = { // main_color, back_color, xtra_color, speed, mod
|
|||||||
#if ENABLE_MQTT == 0
|
#if ENABLE_MQTT == 0
|
||||||
#define MQTT_MAX_PACKET_SIZE 512
|
#define MQTT_MAX_PACKET_SIZE 512
|
||||||
#define MQTT_MAX_RECONNECT_TRIES 4
|
#define MQTT_MAX_RECONNECT_TRIES 4
|
||||||
int mqtt_reconnect_retries = 0;
|
uint8_t mqtt_reconnect_retries = 0;
|
||||||
uint8_t qossub = 0; // PubSubClient can sub qos 0 or 1
|
uint8_t qossub = 0; // PubSubClient can sub qos 0 or 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -134,10 +134,10 @@ uint32_t autoParams[][6] = { // main_color, back_color, xtra_color, speed, mod
|
|||||||
MODE mode = SET_ALL; // Standard mode that is active when software starts
|
MODE mode = SET_ALL; // Standard mode that is active when software starts
|
||||||
MODE prevmode = mode;
|
MODE prevmode = mode;
|
||||||
|
|
||||||
int ws2812fx_speed = 196; // Global variable for storing the delay between color changes --> smaller == faster
|
uint8_t ws2812fx_speed = 196; // Global variable for storing the delay between color changes --> smaller == faster
|
||||||
int brightness = 196; // Global variable for storing the brightness (255 == 100%)
|
uint8_t brightness = 196; // Global variable for storing the brightness (255 == 100%)
|
||||||
|
|
||||||
int ws2812fx_mode = 0; // Global variable for storing the WS2812FX modes
|
uint8_t ws2812fx_mode = 0; // Global variable for storing the WS2812FX modes
|
||||||
|
|
||||||
bool shouldSaveConfig = false; // For WiFiManger custom config
|
bool shouldSaveConfig = false; // For WiFiManger custom config
|
||||||
|
|
||||||
|
|||||||
+1208
-1208
File diff suppressed because it is too large
Load Diff
@@ -58,25 +58,25 @@ void Fire2012() {
|
|||||||
// Array of temperature readings at each simulation cell
|
// Array of temperature readings at each simulation cell
|
||||||
|
|
||||||
// Step 1. Cool down every cell a little
|
// Step 1. Cool down every cell a little
|
||||||
for( int i = 0; i < WS2812FXStripSettings.stripSize; i++) {
|
for( uint16_t i = 0; i < WS2812FXStripSettings.stripSize; i++) {
|
||||||
ledstates[i] = qsub8( ledstates[i], random8(0, ((COOLING * 10) / WS2812FXStripSettings.stripSize) + 2));
|
ledstates[i] = qsub8( ledstates[i], random8(0, ((COOLING * 10) / WS2812FXStripSettings.stripSize) + 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 2. Heat from each cell drifts 'up' and diffuses a little
|
// Step 2. Heat from each cell drifts 'up' and diffuses a little
|
||||||
for( int k= WS2812FXStripSettings.stripSize - 1; k >= 2; k--) {
|
for( uint16_t k= WS2812FXStripSettings.stripSize - 1; k >= 2; k--) {
|
||||||
ledstates[k] = (ledstates[k - 1] + ledstates[k - 2] + ledstates[k - 2]) / 3;
|
ledstates[k] = (ledstates[k - 1] + ledstates[k - 2] + ledstates[k - 2]) / 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 3. Randomly ignite new 'sparks' of heat near the bottom
|
// Step 3. Randomly ignite new 'sparks' of heat near the bottom
|
||||||
if( random8() < SPARKING ) {
|
if( random8() < SPARKING ) {
|
||||||
int y = random8(7);
|
uint8_t y = random8(7);
|
||||||
ledstates[y] = qadd8(ledstates[y], random8(160,255) );
|
ledstates[y] = qadd8(ledstates[y], random8(160,255) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 4. Map from heat cells to LED colors
|
// Step 4. Map from heat cells to LED colors
|
||||||
for( int j = 0; j < WS2812FXStripSettings.stripSize; j++) {
|
for( uint16_t j = 0; j < WS2812FXStripSettings.stripSize; j++) {
|
||||||
CRGB color = HeatColor( ledstates[j]);
|
CRGB color = HeatColor( ledstates[j]);
|
||||||
int pixelnumber;
|
uint16_t pixelnumber;
|
||||||
if( gReverseDirection ) {
|
if( gReverseDirection ) {
|
||||||
pixelnumber = (WS2812FXStripSettings.stripSize - 1) - j;
|
pixelnumber = (WS2812FXStripSettings.stripSize - 1) - j;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ void hsb2rgbAN1(uint16_t index, uint8_t sat, uint8_t bright, uint8_t myled) {
|
|||||||
|
|
||||||
void updateLed (uint16_t led, uint8_t brightness) {
|
void updateLed (uint16_t led, uint8_t brightness) {
|
||||||
ledstates[led] = brightness;
|
ledstates[led] = brightness;
|
||||||
for (int i=0; i<WS2812FXStripSettings.stripSize; i++) {
|
for (uint16_t i=0; i<WS2812FXStripSettings.stripSize; i++) {
|
||||||
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);
|
||||||
}
|
}
|
||||||
@@ -66,12 +66,12 @@ void handleTV() {
|
|||||||
DBG_OUTPUT_PORT.println("Dip Time");
|
DBG_OUTPUT_PORT.println("Dip Time");
|
||||||
currentDipTime = millis();
|
currentDipTime = millis();
|
||||||
if (currentDipTime - dipStartTime < darkTime) {
|
if (currentDipTime - dipStartTime < darkTime) {
|
||||||
for (int i=3; i<WS2812FXStripSettings.stripSize; i++) {
|
for (uint16_t i=3; i<WS2812FXStripSettings.stripSize; i++) {
|
||||||
updateLed(i, 0);
|
updateLed(i, 0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
timeToDip = false;
|
timeToDip = false;
|
||||||
}
|
}
|
||||||
strip->show();
|
//strip->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -301,9 +301,9 @@ bool checkPin(uint8_t pin) {
|
|||||||
|
|
||||||
|
|
||||||
neoPixelType checkRGBOrder(char rgbOrder[5]) {
|
neoPixelType checkRGBOrder(char rgbOrder[5]) {
|
||||||
for( int i=0 ; i < sizeof(rgbOrder) ; ++i ) rgbOrder[i] = toupper(rgbOrder[i]) ;
|
for( uint8_t i=0 ; i < sizeof(rgbOrder) ; ++i ) rgbOrder[i] = toupper(rgbOrder[i]) ;
|
||||||
DBG_OUTPUT_PORT.printf("Checking RGB Order: %s ...", rgbOrder);
|
DBG_OUTPUT_PORT.printf("Checking RGB Order: %s ...", rgbOrder);
|
||||||
neoPixelType returnOrder;
|
neoPixelType returnOrder = 0;
|
||||||
if (strcmp(rgbOrder, "GRB") == 0) {
|
if (strcmp(rgbOrder, "GRB") == 0) {
|
||||||
returnOrder = NEO_GRB;
|
returnOrder = NEO_GRB;
|
||||||
} else if (strcmp(rgbOrder, "GBR") == 0) {
|
} else if (strcmp(rgbOrder, "GBR") == 0) {
|
||||||
@@ -366,7 +366,14 @@ neoPixelType checkRGBOrder(char rgbOrder[5]) {
|
|||||||
returnOrder = NEO_BGRW;
|
returnOrder = NEO_BGRW;
|
||||||
} else {
|
} else {
|
||||||
DBG_OUTPUT_PORT.print("invalid input!");
|
DBG_OUTPUT_PORT.print("invalid input!");
|
||||||
returnOrder = static_cast<neoPixelType>(checkRGBOrder(WS2812FXStripSettings.RGBOrder));
|
uint16_t check = checkRGBOrder(WS2812FXStripSettings.RGBOrder);
|
||||||
|
if (check != 0) {
|
||||||
|
returnOrder = static_cast<neoPixelType>(check);
|
||||||
|
strcpy(rgbOrder, WS2812FXStripSettings.RGBOrder);
|
||||||
|
} else {
|
||||||
|
returnOrder = static_cast<neoPixelType>(checkRGBOrder(RGBORDER));
|
||||||
|
strcpy(rgbOrder, RGBORDER);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
DBG_OUTPUT_PORT.println("success!");
|
DBG_OUTPUT_PORT.println("success!");
|
||||||
strcpy(WS2812FXStripSettings.RGBOrder, rgbOrder);
|
strcpy(WS2812FXStripSettings.RGBOrder, rgbOrder);
|
||||||
@@ -383,12 +390,12 @@ bool setConfByConfString(String saved_conf_string) {
|
|||||||
getValue(saved_conf_string, '|', 4).toCharArray(mqtt_user, 32);
|
getValue(saved_conf_string, '|', 4).toCharArray(mqtt_user, 32);
|
||||||
getValue(saved_conf_string, '|', 5).toCharArray(mqtt_pass, 32);
|
getValue(saved_conf_string, '|', 5).toCharArray(mqtt_pass, 32);
|
||||||
#endif
|
#endif
|
||||||
WS2812FXStripSettings.stripSize = constrain(getValue(saved_conf_string, '|', 6).toInt(), 0, MAXLEDS);
|
WS2812FXStripSettings.stripSize = constrain(getValue(saved_conf_string, '|', 6).toInt(), 1, MAXLEDS);
|
||||||
checkPin(getValue(saved_conf_string, '|', 7).toInt());
|
checkPin(getValue(saved_conf_string, '|', 7).toInt());
|
||||||
char tmp_rgbOrder[5];
|
char tmp_rgbOrder[5];
|
||||||
getValue(saved_conf_string, '|', 8).toCharArray(tmp_rgbOrder, 4);
|
getValue(saved_conf_string, '|', 8).toCharArray(tmp_rgbOrder, 4);
|
||||||
checkRGBOrder(tmp_rgbOrder);
|
checkRGBOrder(tmp_rgbOrder);
|
||||||
WS2812FXStripSettings.fxoptions = getValue(saved_conf_string, '|', 9).toInt();
|
WS2812FXStripSettings.fxoptions = constrain(((getValue(saved_conf_string, '|', 9).toInt()>>1)<<1), 0, 255);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
DBG_OUTPUT_PORT.println("Saved conf not found!");
|
DBG_OUTPUT_PORT.println("Saved conf not found!");
|
||||||
@@ -680,7 +687,7 @@ void handleNotFound() {
|
|||||||
// Functions and variables for automatic cycling
|
// Functions and variables for automatic cycling
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
Ticker autoTicker;
|
Ticker autoTicker;
|
||||||
int autoCount = 0;
|
uint8_t autoCount = 0;
|
||||||
|
|
||||||
void autoTick() {
|
void autoTick() {
|
||||||
uint32_t setcolors[] = {autoParams[autoCount][0],autoParams[autoCount][1],autoParams[autoCount][2]};
|
uint32_t setcolors[] = {autoParams[autoCount][0],autoParams[autoCount][1],autoParams[autoCount][2]};
|
||||||
@@ -808,10 +815,10 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
|
|||||||
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, json.c_str());
|
||||||
#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, json.c_str());
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
@@ -832,7 +839,7 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
|
|||||||
char tmp_count[6];
|
char tmp_count[6];
|
||||||
snprintf(tmp_count, sizeof(tmp_count), "%s", &payload[3]);
|
snprintf(tmp_count, sizeof(tmp_count), "%s", &payload[3]);
|
||||||
tmp_count[5] = 0x00;
|
tmp_count[5] = 0x00;
|
||||||
WS2812FXStripSettings.stripSize = constrain(atoi(tmp_count), 0, MAXLEDS);
|
WS2812FXStripSettings.stripSize = constrain(atoi(tmp_count), 1, MAXLEDS);
|
||||||
updateStrip = true;
|
updateStrip = true;
|
||||||
}
|
}
|
||||||
if (payload[2] == 'r') {
|
if (payload[2] == 'r') {
|
||||||
@@ -856,7 +863,7 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
|
|||||||
char tmp_fxoptions[4];
|
char tmp_fxoptions[4];
|
||||||
snprintf(tmp_fxoptions, sizeof(tmp_fxoptions), "%s", &payload[3]);
|
snprintf(tmp_fxoptions, sizeof(tmp_fxoptions), "%s", &payload[3]);
|
||||||
tmp_fxoptions[3] = 0x00;
|
tmp_fxoptions[3] = 0x00;
|
||||||
WS2812FXStripSettings.fxoptions = constrain(atoi(tmp_fxoptions), 0, 255);
|
WS2812FXStripSettings.fxoptions = ((constrain(atoi(tmp_fxoptions), 0, 255)>>1)<<1);
|
||||||
updateStrip = true;
|
updateStrip = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -910,16 +917,16 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
|
|||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
String json = listConfigJSON();
|
String json = 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, json.c_str());
|
||||||
#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, json.c_str());
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
@@ -938,17 +945,14 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
|
|||||||
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 == 2
|
||||||
String json = listModesJSON();
|
uint16_t msg_len = strlen(json.c_str()) + 1;
|
||||||
unsigned int msg_len = measureJson(json) + 1;
|
mqtt_client.beginPublish(mqtt_outtopic, msg_len, true);
|
||||||
char buffer[msg_len];
|
mqtt_client.write((const uint8_t*)json.c_str(), msg_len);
|
||||||
serializeJson(json, buffer, sizeof(buffer));
|
mqtt_client.endPublish();
|
||||||
mqtt_client->beginPublish(mqtt_outtopic, msg_len, true);
|
|
||||||
mqtt_client->write((const uint8_t*)buffer, msg_len);
|
|
||||||
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, json.c_str());
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
@@ -1016,8 +1020,8 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
new_ha_mqtt_msg = true;
|
new_ha_mqtt_msg = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
LEDState temp2rgb(unsigned int kelvin) {
|
LEDState temp2rgb(uint16_t kelvin) {
|
||||||
int tmp_internal = kelvin / 100.0;
|
uint16_t tmp_internal = kelvin / 100.0;
|
||||||
LEDState tmp_color;
|
LEDState tmp_color;
|
||||||
|
|
||||||
// red
|
// red
|
||||||
@@ -1122,11 +1126,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;
|
||||||
@@ -1195,7 +1199,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
if (root.containsKey("color_temp")) {
|
if (root.containsKey("color_temp")) {
|
||||||
//temp comes in as mireds, need to convert to kelvin then to RGB
|
//temp comes in as mireds, need to convert to kelvin then to RGB
|
||||||
color_temp = (uint16_t) root["color_temp"];
|
color_temp = (uint16_t) root["color_temp"];
|
||||||
unsigned int kelvin = 1000000 / color_temp;
|
uint16_t kelvin = 1000000 / color_temp;
|
||||||
main_color = temp2rgb(kelvin);
|
main_color = temp2rgb(kelvin);
|
||||||
mode = SET_COLOR;
|
mode = SET_COLOR;
|
||||||
}
|
}
|
||||||
@@ -1252,7 +1256,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLE_MQTT == 0
|
#if ENABLE_MQTT == 0
|
||||||
void mqtt_callback(char* topic, byte* payload_in, unsigned int length) {
|
void mqtt_callback(char* topic, byte* payload_in, uint16_t length) {
|
||||||
uint8_t * payload = (uint8_t *)malloc(length + 1);
|
uint8_t * payload = (uint8_t *)malloc(length + 1);
|
||||||
memcpy(payload, payload_in, length);
|
memcpy(payload, payload_in, length);
|
||||||
payload[length] = 0;
|
payload[length] = 0;
|
||||||
@@ -1279,26 +1283,26 @@ 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;
|
||||||
@@ -1338,16 +1342,16 @@ 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(json, 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
|
||||||
unsigned int msg_len = measureJson(json) + 1;
|
uint16_t msg_len = measureJson(json) + 1;
|
||||||
char buffer[msg_len];
|
char buffer[msg_len];
|
||||||
serializeJson(json, buffer, sizeof(buffer));
|
serializeJson(json, 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(String("homeassistant/light/" + String(HOSTNAME) + "/config").c_str(), 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
|
||||||
|
|
||||||
@@ -1355,7 +1359,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);
|
||||||
@@ -1376,7 +1380,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) {
|
||||||
@@ -1400,17 +1404,17 @@ 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;
|
||||||
@@ -1450,7 +1454,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
char buffer[measureJson(json) + 1];
|
char buffer[measureJson(json) + 1];
|
||||||
serializeJson(json, buffer, sizeof(buffer));
|
serializeJson(json, 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
|
||||||
}
|
}
|
||||||
@@ -1656,13 +1660,13 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
strcpy(mqtt_user, json["mqtt_user"]);
|
strcpy(mqtt_user, json["mqtt_user"]);
|
||||||
strcpy(mqtt_pass, json["mqtt_pass"]);
|
strcpy(mqtt_pass, json["mqtt_pass"]);
|
||||||
#endif
|
#endif
|
||||||
WS2812FXStripSettings.stripSize = constrain ((uint8_t) json["ws_cnt"],0, MAXLEDS);
|
WS2812FXStripSettings.stripSize = constrain ((uint8_t) json["ws_cnt"], 1, MAXLEDS);
|
||||||
char tmp_rgbOrder[5];
|
char tmp_rgbOrder[5];
|
||||||
strcpy(tmp_rgbOrder, json["ws_rgbo"]);
|
strcpy(tmp_rgbOrder, json["ws_rgbo"]);
|
||||||
checkRGBOrder(tmp_rgbOrder);
|
checkRGBOrder(tmp_rgbOrder);
|
||||||
uint8_t temp_pin;
|
uint8_t temp_pin;
|
||||||
WS2812FXStripSettings.pin = (uint8_t) json["ws_pin"];
|
WS2812FXStripSettings.pin = checkPin((uint8_t) json["ws_pin"]);
|
||||||
WS2812FXStripSettings.fxoptions = (uint8_t) json["ws_fxopt"];
|
WS2812FXStripSettings.fxoptions = ((constrain((uint8_t) json["ws_fxopt"], 0, 255)>>1)<<1);
|
||||||
jsonBuffer.clear();
|
jsonBuffer.clear();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@@ -1769,9 +1773,9 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
// EEPROM helper
|
// EEPROM helper
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
String readEEPROM(int offset, int len) {
|
String readEEPROM(uint16_t offset, uint16_t len) {
|
||||||
String res = "";
|
String res = "";
|
||||||
for (int i = 0; i < len; ++i)
|
for (uint16_t i = 0; i < len; ++i)
|
||||||
{
|
{
|
||||||
res += char(EEPROM.read(i + offset));
|
res += char(EEPROM.read(i + offset));
|
||||||
//DBG_OUTPUT_PORT.println(char(EEPROM.read(i + offset)));
|
//DBG_OUTPUT_PORT.println(char(EEPROM.read(i + offset)));
|
||||||
@@ -1780,9 +1784,9 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeEEPROM(int offset, int len, String value) {
|
void writeEEPROM(uint16_t offset, uint16_t len, String value) {
|
||||||
DBG_OUTPUT_PORT.printf("writeEEPROM(): %s\r\n", value.c_str());
|
DBG_OUTPUT_PORT.printf("writeEEPROM(): %s\r\n", value.c_str());
|
||||||
for (int i = 0; i < len; ++i)
|
for (uint16_t i = 0; i < len; ++i)
|
||||||
{
|
{
|
||||||
if (i < value.length()) {
|
if (i < value.length()) {
|
||||||
EEPROM.write(i + offset, value[i]);
|
EEPROM.write(i + offset, value[i]);
|
||||||
@@ -1802,7 +1806,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
// Request handler for IR remote support
|
// Request handler for IR remote support
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void handleRemote() {
|
void handleRemote() {
|
||||||
int chng = 1;
|
uint8_t chng = 1;
|
||||||
if (irrecv.decode(&results)) {
|
if (irrecv.decode(&results)) {
|
||||||
DBG_OUTPUT_PORT.print("IR Code: 0x");
|
DBG_OUTPUT_PORT.print("IR Code: 0x");
|
||||||
DBG_OUTPUT_PORT.print(uint64ToString(results.value, HEX));
|
DBG_OUTPUT_PORT.print(uint64ToString(results.value, HEX));
|
||||||
|
|||||||
@@ -277,7 +277,7 @@
|
|||||||
if(server.hasArg("ws_cnt")){
|
if(server.hasArg("ws_cnt")){
|
||||||
uint16_t pixelCt = server.arg("ws_cnt").toInt();
|
uint16_t pixelCt = server.arg("ws_cnt").toInt();
|
||||||
if (pixelCt > 0) {
|
if (pixelCt > 0) {
|
||||||
WS2812FXStripSettings.stripSize = pixelCt;
|
WS2812FXStripSettings.stripSize = constrain(pixelCt, 1, MAXLEDS);
|
||||||
updateStrip = true;
|
updateStrip = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -301,7 +301,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(server.hasArg("ws_fxopt")){
|
if(server.hasArg("ws_fxopt")){
|
||||||
WS2812FXStripSettings.fxoptions = server.arg("ws_fxopt").toInt();
|
WS2812FXStripSettings.fxoptions = ((constrain(server.arg("ws_fxopt").toInt(), 0, 255)>>1)<<1);
|
||||||
updateStrip = true;
|
updateStrip = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -995,11 +995,11 @@ input[type=number], label{
|
|||||||
<div class="layout row wrap">
|
<div class="layout row wrap">
|
||||||
<div class="flex xs12" style="text-align: left; margin:20px 0;"><p>selectColors</p>
|
<div class="flex xs12" style="text-align: left; margin:20px 0;"><p>selectColors</p>
|
||||||
<span style="white-space: nowrap;">
|
<span style="white-space: nowrap;">
|
||||||
colorMain<input type="color" id="color-main" value="#ffffff">
|
<span>colorMain</span><input type="color" id="color-main" value="#ffffff">
|
||||||
colorFont<input type="color" id="color-font" value="#ffffff">
|
<span>colorFont</span><input type="color" id="color-font" value="#ffffff">
|
||||||
colorBack<input type="color" id="color-back" value="#ffffff">
|
<span>colorBack</span><input type="color" id="color-back" value="#ffffff">
|
||||||
colorBtn<input type="color" id="color-btn" value="#ffffff">
|
<span>colorBtn</span><input type="color" id="color-btn" value="#ffffff">
|
||||||
colorBtnSel<input type="color" id="color-btnsel" value="#ffffff">
|
<span>colorBtnSel</span><input type="color" id="color-btnsel" value="#ffffff">
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex xs12" style="text-align: left; margin:20px 0;"><p>slaveNodes</p>
|
<div class="flex xs12" style="text-align: left; margin:20px 0;"><p>slaveNodes</p>
|
||||||
@@ -1239,6 +1239,7 @@ var selectoptrev = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var selectoptfade = {
|
var selectoptfade = {
|
||||||
|
0: "NONE",
|
||||||
16: "FADE_XFAST",
|
16: "FADE_XFAST",
|
||||||
32: "FADE_FAST",
|
32: "FADE_FAST",
|
||||||
48: "FADE_MEDIUM",
|
48: "FADE_MEDIUM",
|
||||||
@@ -1750,7 +1751,7 @@ function initSettings() {
|
|||||||
hostname.value = config.hostname;
|
hostname.value = config.hostname;
|
||||||
hostname.addEventListener('change', ()=>{
|
hostname.addEventListener('change', ()=>{
|
||||||
config.hostname = hostname.value;
|
config.hostname = hostname.value;
|
||||||
//ws_send("Ch" + config.hostname);
|
ws_send("Ch" + config.hostname);
|
||||||
ws_send("C");
|
ws_send("C");
|
||||||
});
|
});
|
||||||
var mqtt_host = document.getElementById("mqtt_host");
|
var mqtt_host = document.getElementById("mqtt_host");
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user