increase stability. no need for home/<HOSTNAME>_ha/out to be subscribed.
This commit is contained in:
parent
e7fb54f717
commit
0da3e90f71
1 changed files with 917 additions and 852 deletions
|
@ -191,30 +191,57 @@ void handleSetNamedMode(String str_mode) {
|
||||||
|
|
||||||
if (str_mode.startsWith("=off")) {
|
if (str_mode.startsWith("=off")) {
|
||||||
mode = OFF;
|
mode = OFF;
|
||||||
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
stateOn = false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (str_mode.startsWith("=all")) {
|
if (str_mode.startsWith("=all")) {
|
||||||
mode = ALL;
|
mode = ALL;
|
||||||
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
stateOn = true;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (str_mode.startsWith("=wipe")) {
|
if (str_mode.startsWith("=wipe")) {
|
||||||
mode = WIPE;
|
mode = WIPE;
|
||||||
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
stateOn = true;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (str_mode.startsWith("=rainbow")) {
|
if (str_mode.startsWith("=rainbow")) {
|
||||||
mode = RAINBOW;
|
mode = RAINBOW;
|
||||||
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
stateOn = true;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (str_mode.startsWith("=rainbowCycle")) {
|
if (str_mode.startsWith("=rainbowCycle")) {
|
||||||
mode = RAINBOWCYCLE;
|
mode = RAINBOWCYCLE;
|
||||||
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
stateOn = true;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (str_mode.startsWith("=theaterchase")) {
|
if (str_mode.startsWith("=theaterchase")) {
|
||||||
mode = THEATERCHASE;
|
mode = THEATERCHASE;
|
||||||
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
stateOn = true;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (str_mode.startsWith("=twinkleRandom")) {
|
if (str_mode.startsWith("=twinkleRandom")) {
|
||||||
mode = TWINKLERANDOM;
|
mode = TWINKLERANDOM;
|
||||||
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
stateOn = true;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (str_mode.startsWith("=theaterchaseRainbow")) {
|
if (str_mode.startsWith("=theaterchaseRainbow")) {
|
||||||
mode = THEATERCHASERAINBOW;
|
mode = THEATERCHASERAINBOW;
|
||||||
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
stateOn = true;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (str_mode.startsWith("=tv")) {
|
if (str_mode.startsWith("=tv")) {
|
||||||
mode = TV;
|
mode = TV;
|
||||||
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
stateOn = true;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,6 +408,10 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
||||||
handleSetMainColor(payload);
|
handleSetMainColor(payload);
|
||||||
DBG_OUTPUT_PORT.printf("Set main color to: [%u] [%u] [%u]\n", main_color.red, main_color.green, main_color.blue);
|
DBG_OUTPUT_PORT.printf("Set main color to: [%u] [%u] [%u]\n", main_color.red, main_color.green, main_color.blue);
|
||||||
webSocket.sendTXT(num, "OK");
|
webSocket.sendTXT(num, "OK");
|
||||||
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
stateOn = true;
|
||||||
|
sendState();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// ? ==> Set speed
|
// ? ==> Set speed
|
||||||
|
@ -399,12 +430,20 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
||||||
DBG_OUTPUT_PORT.printf("WS: Set brightness to: [%u]\n", brightness);
|
DBG_OUTPUT_PORT.printf("WS: Set brightness to: [%u]\n", brightness);
|
||||||
strip.setBrightness(brightness);
|
strip.setBrightness(brightness);
|
||||||
webSocket.sendTXT(num, "OK");
|
webSocket.sendTXT(num, "OK");
|
||||||
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
stateOn = true;
|
||||||
|
sendState();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// * ==> Set main color and light all LEDs (Shortcut)
|
// * ==> Set main color and light all LEDs (Shortcut)
|
||||||
if (payload[0] == '*') {
|
if (payload[0] == '*') {
|
||||||
handleSetAllMode(payload);
|
handleSetAllMode(payload);
|
||||||
webSocket.sendTXT(num, "OK");
|
webSocket.sendTXT(num, "OK");
|
||||||
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
stateOn = true;
|
||||||
|
sendState();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// ! ==> Set single LED in given color
|
// ! ==> Set single LED in given color
|
||||||
|
@ -434,6 +473,9 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
||||||
|
|
||||||
DBG_OUTPUT_PORT.printf("Activated mode [%u]!\n", mode);
|
DBG_OUTPUT_PORT.printf("Activated mode [%u]!\n", mode);
|
||||||
webSocket.sendTXT(num, "OK");
|
webSocket.sendTXT(num, "OK");
|
||||||
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
sendState();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// $ ==> Get status Info.
|
// $ ==> Get status Info.
|
||||||
|
@ -458,6 +500,10 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
||||||
if (payload[0] == '/') {
|
if (payload[0] == '/') {
|
||||||
handleSetWS2812FXMode(payload);
|
handleSetWS2812FXMode(payload);
|
||||||
webSocket.sendTXT(num, "OK");
|
webSocket.sendTXT(num, "OK");
|
||||||
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
stateOn = true;
|
||||||
|
sendState();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// start auto cycling
|
// start auto cycling
|
||||||
|
@ -471,11 +517,6 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
||||||
handleAutoStop();
|
handleAutoStop();
|
||||||
webSocket.sendTXT(num, "OK");
|
webSocket.sendTXT(num, "OK");
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_HOMEASSISTANT
|
|
||||||
sendState();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -483,6 +524,9 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
||||||
void checkForRequests() {
|
void checkForRequests() {
|
||||||
webSocket.loop();
|
webSocket.loop();
|
||||||
server.handleClient();
|
server.handleClient();
|
||||||
|
#ifdef ENABLE_MQTT
|
||||||
|
mqtt_client.loop();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -628,7 +672,7 @@ void checkForRequests() {
|
||||||
DBG_OUTPUT_PORT.printf("MQTT: Message arrived [%s]\n", payload);
|
DBG_OUTPUT_PORT.printf("MQTT: Message arrived [%s]\n", payload);
|
||||||
|
|
||||||
#ifdef ENABLE_HOMEASSISTANT
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
if ((strcmp(topic, mqtt_ha_state_in.c_str()) == 0)) {
|
if (strcmp(topic, mqtt_ha_state_in.c_str()) == 0) {
|
||||||
if (!processJson((char*)payload)) {
|
if (!processJson((char*)payload)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -647,6 +691,10 @@ void checkForRequests() {
|
||||||
handleSetMainColor(payload);
|
handleSetMainColor(payload);
|
||||||
DBG_OUTPUT_PORT.printf("MQTT: Set main color to [%u] [%u] [%u]\n", main_color.red, main_color.green, main_color.blue);
|
DBG_OUTPUT_PORT.printf("MQTT: Set main color to [%u] [%u] [%u]\n", main_color.red, main_color.green, main_color.blue);
|
||||||
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
|
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
|
||||||
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
stateOn = true;
|
||||||
|
sendState();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// ? ==> Set speed
|
// ? ==> Set speed
|
||||||
|
@ -665,6 +713,10 @@ void checkForRequests() {
|
||||||
strip.setBrightness(brightness);
|
strip.setBrightness(brightness);
|
||||||
DBG_OUTPUT_PORT.printf("MQTT: Set brightness to [%u]\n", brightness);
|
DBG_OUTPUT_PORT.printf("MQTT: Set brightness to [%u]\n", brightness);
|
||||||
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
|
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
|
||||||
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
stateOn = true;
|
||||||
|
sendState();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// * ==> Set main color and light all LEDs (Shortcut)
|
// * ==> Set main color and light all LEDs (Shortcut)
|
||||||
|
@ -672,6 +724,10 @@ void checkForRequests() {
|
||||||
handleSetAllMode(payload);
|
handleSetAllMode(payload);
|
||||||
DBG_OUTPUT_PORT.printf("MQTT: Set main color and light all LEDs [%s]\n", payload);
|
DBG_OUTPUT_PORT.printf("MQTT: Set main color and light all LEDs [%s]\n", payload);
|
||||||
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
|
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
|
||||||
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
stateOn = true;
|
||||||
|
sendState();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// ! ==> Set single LED in given color
|
// ! ==> Set single LED in given color
|
||||||
|
@ -700,6 +756,9 @@ void checkForRequests() {
|
||||||
handleSetNamedMode(str_mode);
|
handleSetNamedMode(str_mode);
|
||||||
DBG_OUTPUT_PORT.printf("MQTT: Activate named mode [%s]\n", payload);
|
DBG_OUTPUT_PORT.printf("MQTT: Activate named mode [%s]\n", payload);
|
||||||
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
|
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
|
||||||
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
sendState();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// $ ==> Get status Info.
|
// $ ==> Get status Info.
|
||||||
|
@ -728,10 +787,13 @@ void checkForRequests() {
|
||||||
handleSetWS2812FXMode(payload);
|
handleSetWS2812FXMode(payload);
|
||||||
DBG_OUTPUT_PORT.printf("MQTT: Set WS2812 mode [%s]\n", payload);
|
DBG_OUTPUT_PORT.printf("MQTT: Set WS2812 mode [%s]\n", payload);
|
||||||
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
|
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
|
||||||
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
stateOn = true;
|
||||||
|
sendState();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_HOMEASSISTANT
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
sendState();
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
free(payload);
|
free(payload);
|
||||||
|
@ -753,7 +815,7 @@ void checkForRequests() {
|
||||||
// ... and resubscribe
|
// ... and resubscribe
|
||||||
mqtt_client.subscribe(mqtt_intopic);
|
mqtt_client.subscribe(mqtt_intopic);
|
||||||
#ifdef ENABLE_HOMEASSISTANT
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
mqtt_client.subscribe(String(mqtt_ha + "#").c_str());
|
mqtt_client.subscribe(mqtt_ha_state_in.c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DBG_OUTPUT_PORT.printf("MQTT topic in: %s\n", mqtt_intopic);
|
DBG_OUTPUT_PORT.printf("MQTT topic in: %s\n", mqtt_intopic);
|
||||||
|
@ -791,6 +853,7 @@ void checkForRequests() {
|
||||||
#ifdef ENABLE_MQTT
|
#ifdef ENABLE_MQTT
|
||||||
mqtt_client.publish(mqtt_outtopic, String("OK =off").c_str());
|
mqtt_client.publish(mqtt_outtopic, String("OK =off").c_str());
|
||||||
#ifdef ENABLE_HOMEASSISTANT
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
stateOn = false;
|
||||||
sendState();
|
sendState();
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -804,6 +867,7 @@ void checkForRequests() {
|
||||||
#ifdef ENABLE_MQTT
|
#ifdef ENABLE_MQTT
|
||||||
mqtt_client.publish(mqtt_outtopic, String("OK =fire flicker").c_str());
|
mqtt_client.publish(mqtt_outtopic, String("OK =fire flicker").c_str());
|
||||||
#ifdef ENABLE_HOMEASSISTANT
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
stateOn = true;
|
||||||
sendState();
|
sendState();
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -816,6 +880,7 @@ void checkForRequests() {
|
||||||
#ifdef ENABLE_MQTT
|
#ifdef ENABLE_MQTT
|
||||||
mqtt_client.publish(mqtt_outtopic, String("OK =fireworks random").c_str());
|
mqtt_client.publish(mqtt_outtopic, String("OK =fireworks random").c_str());
|
||||||
#ifdef ENABLE_HOMEASSISTANT
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
stateOn = true;
|
||||||
sendState();
|
sendState();
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue