Compare commits
1 Commits
master
...
development
| Author | SHA1 | Date | |
|---|---|---|---|
| 82c48006d5 |
@@ -271,9 +271,11 @@ void initMqtt() {
|
|||||||
mqtt_intopic[sizeof(mqtt_intopic) - 1] = 0x00;
|
mqtt_intopic[sizeof(mqtt_intopic) - 1] = 0x00;
|
||||||
snprintf(mqtt_outtopic, sizeof(mqtt_outtopic), "%s/out", mqtt_clientid);
|
snprintf(mqtt_outtopic, sizeof(mqtt_outtopic), "%s/out", mqtt_clientid);
|
||||||
mqtt_outtopic[sizeof(mqtt_outtopic) - 1] = 0x00;
|
mqtt_outtopic[sizeof(mqtt_outtopic) - 1] = 0x00;
|
||||||
#if defined(MQTT_HOME_ASSISTANT_SUPPORT)
|
#if defined(ENABLE_HOMEASSISTANT)
|
||||||
snprintf(mqtt_ha_config, sizeof(mqtt_ha_config), "homeassistant/light/%s/config", mqtt_clientid);
|
#if defined(MQTT_HOMEASSISTANT_SUPPORT)
|
||||||
mqtt_ha_config[sizeof(mqtt_ha_config) - 1] = 0x00;
|
snprintf(mqtt_ha_config, sizeof(mqtt_ha_config), "homeassistant/light/%s/config", mqtt_clientid);
|
||||||
|
mqtt_ha_config[sizeof(mqtt_ha_config) - 1] = 0x00;
|
||||||
|
#endif
|
||||||
snprintf(mqtt_ha_state_in, sizeof(mqtt_ha_state_in), "home/%s_ha/state/in", mqtt_clientid);
|
snprintf(mqtt_ha_state_in, sizeof(mqtt_ha_state_in), "home/%s_ha/state/in", mqtt_clientid);
|
||||||
mqtt_ha_state_in[sizeof(mqtt_ha_state_in) - 1] = 0x00;
|
mqtt_ha_state_in[sizeof(mqtt_ha_state_in) - 1] = 0x00;
|
||||||
snprintf(mqtt_ha_state_out, sizeof(mqtt_ha_state_out), "home/%s_ha/state/out", mqtt_clientid);
|
snprintf(mqtt_ha_state_out, sizeof(mqtt_ha_state_out), "home/%s_ha/state/out", mqtt_clientid);
|
||||||
@@ -655,9 +657,6 @@ void loop() {
|
|||||||
|
|
||||||
if (State.mode == OFF) {
|
if (State.mode == OFF) {
|
||||||
if (prevmode != State.mode) {
|
if (prevmode != State.mode) {
|
||||||
#if defined(ENABLE_MQTT)
|
|
||||||
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK =off", "");
|
|
||||||
#endif
|
|
||||||
#if defined(POWER_SUPPLY)
|
#if defined(POWER_SUPPLY)
|
||||||
digitalWrite(POWER_SUPPLY, !POWER_ON); // power off -> external power supply
|
digitalWrite(POWER_SUPPLY, !POWER_ON); // power off -> external power supply
|
||||||
#endif
|
#endif
|
||||||
@@ -674,19 +673,9 @@ void loop() {
|
|||||||
|
|
||||||
if (State.mode == SET) {
|
if (State.mode == SET) {
|
||||||
State.mode = HOLD;
|
State.mode = HOLD;
|
||||||
// Segment
|
|
||||||
if (prevsegment != State.segment) {
|
|
||||||
#if defined(ENABLE_MQTT)
|
|
||||||
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK Ss%i", State.segment);
|
|
||||||
#endif
|
|
||||||
//prevsegment = State.segment;
|
|
||||||
}
|
|
||||||
// Mode
|
// Mode
|
||||||
if (segState.mode[State.segment] != fx_mode) {
|
if ((segState.mode[State.segment] != fx_mode) || prevmode == OFF) {
|
||||||
segState.mode[State.segment] = fx_mode;
|
segState.mode[State.segment] = fx_mode;
|
||||||
#if defined(ENABLE_MQTT)
|
|
||||||
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK /%i", segState.mode[State.segment]);
|
|
||||||
#endif
|
|
||||||
strip->strip_off();
|
strip->strip_off();
|
||||||
autoCount[State.segment] = 0;
|
autoCount[State.segment] = 0;
|
||||||
autoDelay[State.segment] = 0;
|
autoDelay[State.segment] = 0;
|
||||||
@@ -701,13 +690,10 @@ void loop() {
|
|||||||
}*/
|
}*/
|
||||||
// Brightness
|
// Brightness
|
||||||
if (strip->getBrightness() != State.brightness) {
|
if (strip->getBrightness() != State.brightness) {
|
||||||
#if defined(ENABLE_MQTT)
|
|
||||||
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK %%%i", State.brightness);
|
|
||||||
#endif
|
|
||||||
brightness_trans = State.brightness;
|
brightness_trans = State.brightness;
|
||||||
}
|
}
|
||||||
// Speed
|
// Speed
|
||||||
if (fx_speed != segState.speed[State.segment]) {
|
if (fx_speed != segState.speed[prevsegment]) {
|
||||||
#if defined(ENABLE_MQTT)
|
#if defined(ENABLE_MQTT)
|
||||||
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK ?%i", segState.speed[prevsegment]);
|
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK ?%i", segState.speed[prevsegment]);
|
||||||
#endif
|
#endif
|
||||||
@@ -739,12 +725,6 @@ void loop() {
|
|||||||
}
|
}
|
||||||
//strip->setBrightness(brightness_actual);
|
//strip->setBrightness(brightness_actual);
|
||||||
#if defined(ENABLE_MQTT)
|
#if defined(ENABLE_MQTT)
|
||||||
#if ENABLE_MQTT == 0
|
|
||||||
mqtt_client->publish(mqtt_outtopic, mqtt_buf);
|
|
||||||
#endif
|
|
||||||
#if ENABLE_MQTT == 1
|
|
||||||
mqtt_client->publish(mqtt_outtopic, qospub, false, mqtt_buf);
|
|
||||||
#endif
|
|
||||||
#if defined(ENABLE_HOMEASSISTANT)
|
#if defined(ENABLE_HOMEASSISTANT)
|
||||||
if(ha_send_data.active()) ha_send_data.detach();
|
if(ha_send_data.active()) ha_send_data.detach();
|
||||||
ha_send_data.once(DELAY_MQTT_HA_MESSAGE, tickerSendState);
|
ha_send_data.once(DELAY_MQTT_HA_MESSAGE, tickerSendState);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ char HOSTNAME[65] = "McLightingRGBW"; // Friedly hostname is configurable just
|
|||||||
//#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_MQTT_INCLUDE_IP // uncomment/comment to add the IP-adress to the MQTT message
|
//#define ENABLE_MQTT_INCLUDE_IP // uncomment/comment to add the IP-adress to the MQTT message
|
||||||
#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_HOMEASSISTANT_SUPPORT // If defined, use AMQTT and select Tools -> IwIP Variant -> Higher Bandwidth
|
||||||
#define DELAY_MQTT_HA_MESSAGE 5 // HA Status is send after DELAY_MQTT_HA_MESSAGE seconds, to save bandwith
|
#define DELAY_MQTT_HA_MESSAGE 5 // HA Status is send after DELAY_MQTT_HA_MESSAGE seconds, to save bandwith
|
||||||
|
|
||||||
//#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.
|
||||||
@@ -28,7 +28,7 @@ char HOSTNAME[65] = "McLightingRGBW"; // Friedly hostname is configurable just
|
|||||||
#if defined(POWER_SUPPLY)
|
#if defined(POWER_SUPPLY)
|
||||||
#define POWER_ON HIGH // Define the output state to turn on the power supply, either HIGH or LOW. Opposite will be uses for power off.
|
#define POWER_ON HIGH // Define the output state to turn on the power supply, either HIGH or LOW. Opposite will be uses for power off.
|
||||||
#endif
|
#endif
|
||||||
#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
|
||||||
|
|
||||||
#if defined(ENABLE_BUTTON_GY33)
|
#if defined(ENABLE_BUTTON_GY33)
|
||||||
#define GAMMA 2.5 // Gamma correction for GY-33 sensor
|
#define GAMMA 2.5 // Gamma correction for GY-33 sensor
|
||||||
@@ -74,7 +74,7 @@ uint8_t prevsegment = 0;
|
|||||||
uint8_t _sn[4] = {255,255,255,0};
|
uint8_t _sn[4] = {255,255,255,0};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MQTT_HOME_ASSISTANT_SUPPORT)
|
#if defined(MQTT_HOMEASSISTANT_SUPPORT)
|
||||||
#define MQTT_HOME_ASSISTANT_0_87_SUPPORT // Comment if using HA version < 0.87
|
#define MQTT_HOME_ASSISTANT_0_87_SUPPORT // Comment if using HA version < 0.87
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ uint8_t prevsegment = 0;
|
|||||||
#if defined(ENABLE_HOMEASSISTANT) and !defined(ENABLE_MQTT)
|
#if defined(ENABLE_HOMEASSISTANT) and !defined(ENABLE_MQTT)
|
||||||
#error "To use HA, you have to either enable PubCubClient or AsyncMQTT"
|
#error "To use HA, you have to either enable PubCubClient or AsyncMQTT"
|
||||||
#endif
|
#endif
|
||||||
#if !defined(ENABLE_HOMEASSISTANT) and defined(MQTT_HOME_ASSISTANT_SUPPORT)
|
#if !defined(ENABLE_HOMEASSISTANT) and defined(MQTT_HOMEASSISTANT_SUPPORT)
|
||||||
#error "To use HA support, you have to either enable Homeassistant component"
|
#error "To use HA support, you have to either enable Homeassistant component"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -321,3 +321,15 @@ uint32_t trans(uint32_t _newcolor, uint32_t _oldcolor, uint8_t _level, uint8_t _
|
|||||||
_oldcolor = scale_wrgb(_oldcolor, 255-_level);
|
_oldcolor = scale_wrgb(_oldcolor, 255-_level);
|
||||||
return _newcolor + _oldcolor;
|
return _newcolor + _oldcolor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(ENABLE_MQTT)
|
||||||
|
void sendmqtt() {
|
||||||
|
#if ENABLE_MQTT == 0
|
||||||
|
mqtt_client->publish(mqtt_outtopic, mqtt_buf);
|
||||||
|
#endif
|
||||||
|
#if ENABLE_MQTT == 1
|
||||||
|
mqtt_client->publish(mqtt_outtopic, qospub, false, mqtt_buf);
|
||||||
|
#endif
|
||||||
|
memset(mqtt_buf,0,sizeof(mqtt_buf));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -199,9 +199,25 @@ void handleSetWS2812FXMode(uint8_t * mypayload) {
|
|||||||
fx_mode = (uint8_t) strtol((const char *) &mypayload[1], NULL, 10);
|
fx_mode = (uint8_t) strtol((const char *) &mypayload[1], NULL, 10);
|
||||||
fx_mode = constrain(fx_mode, 0, strip->getModeCount() - 1);
|
fx_mode = constrain(fx_mode, 0, strip->getModeCount() - 1);
|
||||||
State.mode = SET;
|
State.mode = SET;
|
||||||
|
#if defined(ENABLE_MQTT)
|
||||||
|
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK /%i", fx_mode);
|
||||||
|
sendmqtt();
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
if (strcmp((char *) &mypayload[1], "off") == 0) {
|
if (strcmp((char *) &mypayload[1], "off") == 0) {
|
||||||
if (State.mode == OFF) { State.mode = SET; } else { State.mode = OFF; };
|
if (State.mode == OFF) {
|
||||||
|
State.mode = SET;
|
||||||
|
#if defined(ENABLE_MQTT)
|
||||||
|
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK /%i", segState.mode[State.segment]);
|
||||||
|
sendmqtt();
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
State.mode = OFF;
|
||||||
|
#if defined(ENABLE_MQTT)
|
||||||
|
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK /off", "");
|
||||||
|
sendmqtt();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (strcmp((char *) &mypayload[1], "on") == 0) {
|
if (strcmp((char *) &mypayload[1], "on") == 0) {
|
||||||
State.mode = SET;
|
State.mode = SET;
|
||||||
@@ -276,7 +292,11 @@ void checkpayload(uint8_t * _payload, bool mqtt = false, uint8_t num = 0) {
|
|||||||
//memcpy(hexcolors_trans, segState.colors[State.segment], sizeof(hexcolors_trans));
|
//memcpy(hexcolors_trans, segState.colors[State.segment], sizeof(hexcolors_trans));
|
||||||
_updateState = true;
|
_updateState = true;
|
||||||
Dbg_Prefix(mqtt, num);
|
Dbg_Prefix(mqtt, num);
|
||||||
DBG_OUTPUT_PORT.printf("Set segment to: [%u]\r\n", State.segment);
|
DBG_OUTPUT_PORT.printf("Set segment to: [%u]\r\n", _seg);
|
||||||
|
#if defined(ENABLE_MQTT)
|
||||||
|
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK Ss%i", _seg);
|
||||||
|
sendmqtt();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// / ==> Set segment first LED
|
// / ==> Set segment first LED
|
||||||
@@ -289,6 +309,10 @@ void checkpayload(uint8_t * _payload, bool mqtt = false, uint8_t num = 0) {
|
|||||||
setSegmentSize();
|
setSegmentSize();
|
||||||
Dbg_Prefix(mqtt, num);
|
Dbg_Prefix(mqtt, num);
|
||||||
DBG_OUTPUT_PORT.printf("Set segment start to: [%u]\r\n", _seg_start);
|
DBG_OUTPUT_PORT.printf("Set segment start to: [%u]\r\n", _seg_start);
|
||||||
|
#if defined(ENABLE_MQTT)
|
||||||
|
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK S[%i", _seg_start);
|
||||||
|
sendmqtt();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// / ==> Set segment last LED
|
// / ==> Set segment last LED
|
||||||
@@ -301,18 +325,25 @@ void checkpayload(uint8_t * _payload, bool mqtt = false, uint8_t num = 0) {
|
|||||||
setSegmentSize();
|
setSegmentSize();
|
||||||
Dbg_Prefix(mqtt, num);
|
Dbg_Prefix(mqtt, num);
|
||||||
DBG_OUTPUT_PORT.printf("Set segment stop to: [%u]\r\n", _seg_stop);
|
DBG_OUTPUT_PORT.printf("Set segment stop to: [%u]\r\n", _seg_stop);
|
||||||
|
#if defined(ENABLE_MQTT)
|
||||||
|
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK S]%i", _seg_stop);
|
||||||
|
sendmqtt();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_payload[1] == 'o') {
|
if (_payload[1] == 'o') {
|
||||||
char _fx_options[4];
|
uint8_t _fx_options = (uint8_t) strtol((const char *) &_payload[2], NULL, 10);
|
||||||
snprintf(_fx_options, sizeof(_fx_options), "%s", &_payload[2]);
|
_fx_options = ((constrain(server.arg("fxopt").toInt(), 0, 255)>>1)<<1);
|
||||||
_fx_options[3] = 0x00;
|
if (_fx_options != segState.options) {
|
||||||
if (((constrain(atoi(_fx_options), 0, 255)>>1)<<1) != segState.options) {
|
segState.options= _fx_options;
|
||||||
segState.options= ((constrain(atoi(_fx_options), 0, 255)>>1)<<1);
|
|
||||||
_updateSegState = true;
|
_updateSegState = true;
|
||||||
strip->setOptions(State.segment, segState.options);
|
strip->setOptions(State.segment, segState.options);
|
||||||
Dbg_Prefix(mqtt, num);
|
Dbg_Prefix(mqtt, num);
|
||||||
DBG_OUTPUT_PORT.printf("Set segment options to: [%u]\r\n", segState.options);
|
DBG_OUTPUT_PORT.printf("Set segment options to: [%u]\r\n", _fx_options);
|
||||||
|
#if defined(ENABLE_MQTT)
|
||||||
|
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK So%i", _fx_options);
|
||||||
|
sendmqtt();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
char * buffer = listSegmentStateJSON(State.segment);
|
char * buffer = listSegmentStateJSON(State.segment);
|
||||||
@@ -373,11 +404,16 @@ void checkpayload(uint8_t * _payload, bool mqtt = false, uint8_t num = 0) {
|
|||||||
// ? ==> Set speed
|
// ? ==> Set speed
|
||||||
if (_payload[0] == '?') {
|
if (_payload[0] == '?') {
|
||||||
uint16_t _fx_speed = (uint16_t) strtol((const char *) &_payload[1], NULL, 10);
|
uint16_t _fx_speed = (uint16_t) strtol((const char *) &_payload[1], NULL, 10);
|
||||||
segState.speed[State.segment] = constrain(_fx_speed, SPEED_MIN, SPEED_MAX );
|
_fx_speed = constrain(_fx_speed, SPEED_MIN, SPEED_MAX );
|
||||||
State.mode = SET;
|
//if (segState.speed[State.segment] != _fx_speed) {}
|
||||||
|
segState.speed[State.segment] = _fx_speed;
|
||||||
_updateSegState = true;
|
_updateSegState = true;
|
||||||
Dbg_Prefix(mqtt, num);
|
Dbg_Prefix(mqtt, num);
|
||||||
DBG_OUTPUT_PORT.printf("Set speed to: [%u]\r\n", segState.speed[State.segment]);
|
DBG_OUTPUT_PORT.printf("Set speed to: [%u]\r\n", _fx_speed);
|
||||||
|
#if defined(ENABLE_MQTT)
|
||||||
|
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK ?%i", _fx_speed);
|
||||||
|
sendmqtt();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// % ==> Set brightness
|
// % ==> Set brightness
|
||||||
@@ -385,10 +421,13 @@ void checkpayload(uint8_t * _payload, bool mqtt = false, uint8_t num = 0) {
|
|||||||
uint8_t b = (uint8_t) strtol((const char *) &_payload[1], NULL, 10);
|
uint8_t b = (uint8_t) strtol((const char *) &_payload[1], NULL, 10);
|
||||||
State.brightness = constrain(b, 0, 255);
|
State.brightness = constrain(b, 0, 255);
|
||||||
if (strip->getBrightness() != State.brightness) {
|
if (strip->getBrightness() != State.brightness) {
|
||||||
State.mode = SET;
|
|
||||||
Dbg_Prefix(mqtt, num);
|
Dbg_Prefix(mqtt, num);
|
||||||
DBG_OUTPUT_PORT.printf("Set brightness to: [%u]\r\n", State.brightness);
|
DBG_OUTPUT_PORT.printf("Set brightness to: [%u]\r\n", State.brightness);
|
||||||
_updateState = true;
|
_updateState = true;
|
||||||
|
#if defined(ENABLE_MQTT)
|
||||||
|
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK %%%i", State.brightness);
|
||||||
|
sendmqtt();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -432,6 +471,7 @@ void checkpayload(uint8_t * _payload, bool mqtt = false, uint8_t num = 0) {
|
|||||||
}
|
}
|
||||||
#if defined(ENABLE_STATE_SAVE)
|
#if defined(ENABLE_STATE_SAVE)
|
||||||
if (_updateState) {
|
if (_updateState) {
|
||||||
|
State.mode = SET;
|
||||||
if(save_state.active()) save_state.detach();
|
if(save_state.active()) save_state.detach();
|
||||||
save_state.once(3, tickerSaveState);
|
save_state.once(3, tickerSaveState);
|
||||||
}
|
}
|
||||||
@@ -941,7 +981,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
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(DELAY_MQTT_HA_MESSAGE, tickerSendState);
|
ha_send_data.once(DELAY_MQTT_HA_MESSAGE, tickerSendState);
|
||||||
#if defined(MQTT_HOME_ASSISTANT_SUPPORT)
|
#if defined(MQTT_HOMEASSISTANT_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 root = jsonBuffer.to<JsonObject>();
|
JsonObject root = jsonBuffer.to<JsonObject>();
|
||||||
@@ -1047,7 +1087,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
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_HOMEASSISTANT_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 root = jsonBuffer.to<JsonObject>();
|
JsonObject root = jsonBuffer.to<JsonObject>();
|
||||||
|
|||||||
@@ -319,7 +319,19 @@ server.on("/config", []() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
server.on("/off", []() {
|
server.on("/off", []() {
|
||||||
if (State.mode == OFF) { State.mode = SET; } else { State.mode = OFF; };
|
if (State.mode == OFF) {
|
||||||
|
State.mode = SET;
|
||||||
|
#if defined(ENABLE_MQTT)
|
||||||
|
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK /%i", segState.mode[State.segment]);
|
||||||
|
sendmqtt();
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
State.mode = OFF;
|
||||||
|
#if defined(ENABLE_MQTT)
|
||||||
|
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK /off", "");
|
||||||
|
sendmqtt();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
getACK("OK");
|
getACK("OK");
|
||||||
#if defined(ENABLE_STATE_SAVE)
|
#if defined(ENABLE_STATE_SAVE)
|
||||||
if(save_state.active()) save_state.detach();
|
if(save_state.active()) save_state.detach();
|
||||||
@@ -330,6 +342,10 @@ server.on("/off", []() {
|
|||||||
server.on("/on", []() {
|
server.on("/on", []() {
|
||||||
if (prevmode == OFF) {
|
if (prevmode == OFF) {
|
||||||
State.mode = SET;
|
State.mode = SET;
|
||||||
|
#if defined(ENABLE_MQTT)
|
||||||
|
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK /%i", segState.mode[State.segment]);
|
||||||
|
sendmqtt();
|
||||||
|
#endif
|
||||||
getACK("OK");
|
getACK("OK");
|
||||||
#if defined(ENABLE_STATE_SAVE)
|
#if defined(ENABLE_STATE_SAVE)
|
||||||
if(save_state.active()) save_state.detach();
|
if(save_state.active()) save_state.detach();
|
||||||
@@ -354,6 +370,10 @@ server.on("/set", []() {
|
|||||||
//memcpy(hexcolors_trans, segState.colors[State.segment], sizeof(hexcolors_trans));
|
//memcpy(hexcolors_trans, segState.colors[State.segment], sizeof(hexcolors_trans));
|
||||||
State.mode = SET;
|
State.mode = SET;
|
||||||
_updateState = true;
|
_updateState = true;
|
||||||
|
#if defined(ENABLE_MQTT)
|
||||||
|
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK Ss%i", _seg);
|
||||||
|
sendmqtt();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((server.arg("start") != "") && (server.arg("start").toInt() >= 0) && (server.arg("start").toInt() <= segState.stop)) {
|
if ((server.arg("start") != "") && (server.arg("start").toInt() >= 0) && (server.arg("start").toInt() <= segState.stop)) {
|
||||||
@@ -363,6 +383,10 @@ server.on("/set", []() {
|
|||||||
segState.start = _seg_start;
|
segState.start = _seg_start;
|
||||||
setSegmentSize();
|
setSegmentSize();
|
||||||
_updateSegState = true;
|
_updateSegState = true;
|
||||||
|
#if defined(ENABLE_MQTT)
|
||||||
|
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK S[%i", _seg_start);
|
||||||
|
sendmqtt();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((server.arg("stop") != "") && (server.arg("stop").toInt() >= segState.start) && (server.arg("stop").toInt() <= Config.stripSize)) {
|
if ((server.arg("stop") != "") && (server.arg("stop").toInt() >= segState.start) && (server.arg("stop").toInt() <= Config.stripSize)) {
|
||||||
@@ -372,6 +396,10 @@ server.on("/set", []() {
|
|||||||
segState.stop = _seg_stop;
|
segState.stop = _seg_stop;
|
||||||
setSegmentSize();
|
setSegmentSize();
|
||||||
_updateSegState = true;
|
_updateSegState = true;
|
||||||
|
#if defined(ENABLE_MQTT)
|
||||||
|
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK S]%i", _seg_stop);
|
||||||
|
sendmqtt();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,6 +409,10 @@ server.on("/set", []() {
|
|||||||
segState.options = _fx_options;
|
segState.options = _fx_options;
|
||||||
strip->setOptions(State.segment, segState.options);
|
strip->setOptions(State.segment, segState.options);
|
||||||
_updateSegState = true;
|
_updateSegState = true;
|
||||||
|
#if defined(ENABLE_MQTT)
|
||||||
|
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK So%i", _fx_options);
|
||||||
|
sendmqtt();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//color wrgb
|
//color wrgb
|
||||||
@@ -475,14 +507,24 @@ server.on("/set", []() {
|
|||||||
|
|
||||||
// Speed
|
// Speed
|
||||||
if ((server.arg("s") != "") && (server.arg("s").toInt() >= 0) && (server.arg("s").toInt() <= 255)) {
|
if ((server.arg("s") != "") && (server.arg("s").toInt() >= 0) && (server.arg("s").toInt() <= 255)) {
|
||||||
segState.speed[State.segment] = constrain(server.arg("s").toInt(), 0, 255);
|
uint8_t _fx_speed = constrain(server.arg("s").toInt(), 0, 255);
|
||||||
|
segState.speed[State.segment] = _fx_speed;
|
||||||
_updateSegState = true;
|
_updateSegState = true;
|
||||||
|
#if defined(ENABLE_MQTT)
|
||||||
|
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK ?%i", _fx_speed);
|
||||||
|
sendmqtt();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//Mode
|
//Mode
|
||||||
if ((server.arg("m") != "") && (server.arg("m").toInt() >= 0) && (server.arg("m").toInt() <= strip->getModeCount())) {
|
if ((server.arg("m") != "") && (server.arg("m").toInt() >= 0) && (server.arg("m").toInt() <= strip->getModeCount())) {
|
||||||
fx_mode = constrain(server.arg("m").toInt(), 0, strip->getModeCount() - 1);
|
fx_mode = constrain(server.arg("m").toInt(), 0, strip->getModeCount() - 1);
|
||||||
if (fx_mode != segState.mode[State.segment]) {
|
if (fx_mode != segState.mode[State.segment]) {
|
||||||
_updateSegState = true;
|
_updateSegState = true;
|
||||||
|
#if defined(ENABLE_MQTT)
|
||||||
|
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK /%i", fx_mode);
|
||||||
|
sendmqtt();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -495,6 +537,10 @@ server.on("/set", []() {
|
|||||||
if (strip->getBrightness() != State.brightness) {
|
if (strip->getBrightness() != State.brightness) {
|
||||||
State.mode = SET;
|
State.mode = SET;
|
||||||
_updateState = true;
|
_updateState = true;
|
||||||
|
#if defined(ENABLE_MQTT)
|
||||||
|
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK %%%i", State.brightness);
|
||||||
|
sendmqtt();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
//DBG_OUTPUT_PORT.printf("Get Args: %s\r\n", listStateJSONfull()); //possibly causing heap problems
|
//DBG_OUTPUT_PORT.printf("Get Args: %s\r\n", listStateJSONfull()); //possibly causing heap problems
|
||||||
getACK("OK");
|
getACK("OK");
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
#define SKETCH_VERSION "3.1.1"
|
#define SKETCH_VERSION "3.1.2"
|
||||||
|
|||||||
@@ -261,4 +261,9 @@
|
|||||||
* 18 April 2020
|
* 18 April 2020
|
||||||
* Version Bump to 3.1.1
|
* Version Bump to 3.1.1
|
||||||
* bugfixes regarding issue #80
|
* bugfixes regarding issue #80
|
||||||
*/
|
*
|
||||||
|
* 19 April 2020
|
||||||
|
* Version Bump to 3.1.2
|
||||||
|
* Almost finished: bugfixes regarding issue #80
|
||||||
|
* ToDo: bugfixes regarding issue #70
|
||||||
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user