|
|
@@ -296,13 +296,13 @@ String listStatusJSON(void) {
|
|
|
|
|
|
|
|
|
|
|
|
const size_t bufferSize = JSON_ARRAY_SIZE(3) + JSON_OBJECT_SIZE(6);
|
|
|
|
const size_t bufferSize = JSON_ARRAY_SIZE(3) + JSON_OBJECT_SIZE(6);
|
|
|
|
DynamicJsonDocument jsonBuffer(bufferSize);
|
|
|
|
DynamicJsonDocument jsonBuffer(bufferSize);
|
|
|
|
JsonObject& root = jsonBuffer.to<JsonObject>();
|
|
|
|
JsonObject root = jsonBuffer.to<JsonObject>();
|
|
|
|
root["mode"] = (uint8_t) mode;
|
|
|
|
root["mode"] = (uint8_t) mode;
|
|
|
|
root["ws2812fx_mode"] = tmp_mode;
|
|
|
|
root["ws2812fx_mode"] = tmp_mode;
|
|
|
|
root["ws2812fx_mode_name"] = strip.getModeName(tmp_mode);
|
|
|
|
root["ws2812fx_mode_name"] = strip.getModeName(tmp_mode);
|
|
|
|
root["speed"] = ws2812fx_speed;
|
|
|
|
root["speed"] = ws2812fx_speed;
|
|
|
|
root["brightness"] = brightness;
|
|
|
|
root["brightness"] = brightness;
|
|
|
|
JsonArray& color = root.createNestedArray("color");
|
|
|
|
JsonArray color = root.createNestedArray("color");
|
|
|
|
color.add(main_color.white);
|
|
|
|
color.add(main_color.white);
|
|
|
|
color.add(main_color.red);
|
|
|
|
color.add(main_color.red);
|
|
|
|
color.add(main_color.green);
|
|
|
|
color.add(main_color.green);
|
|
|
@@ -322,13 +322,13 @@ void getStatusJSON() {
|
|
|
|
String listModesJSON(void) {
|
|
|
|
String listModesJSON(void) {
|
|
|
|
const size_t bufferSize = JSON_ARRAY_SIZE(strip.getModeCount()+1) + strip.getModeCount()*JSON_OBJECT_SIZE(2);
|
|
|
|
const size_t bufferSize = JSON_ARRAY_SIZE(strip.getModeCount()+1) + strip.getModeCount()*JSON_OBJECT_SIZE(2);
|
|
|
|
DynamicJsonDocument jsonBuffer(bufferSize);
|
|
|
|
DynamicJsonDocument jsonBuffer(bufferSize);
|
|
|
|
JsonArray& json = jsonBuffer.to<JsonArray>();
|
|
|
|
JsonArray json = jsonBuffer.to<JsonArray>();
|
|
|
|
for (uint8_t i = 0; i < strip.getModeCount(); i++) {
|
|
|
|
for (uint8_t i = 0; i < strip.getModeCount(); i++) {
|
|
|
|
JsonObject& object = json.createNestedObject();
|
|
|
|
JsonObject object = json.createNestedObject();
|
|
|
|
object["mode"] = i;
|
|
|
|
object["mode"] = i;
|
|
|
|
object["name"] = strip.getModeName(i);
|
|
|
|
object["name"] = strip.getModeName(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JsonObject& object = json.createNestedObject();
|
|
|
|
JsonObject object = json.createNestedObject();
|
|
|
|
|
|
|
|
|
|
|
|
String json_str;
|
|
|
|
String json_str;
|
|
|
|
serializeJson(json, json_str);
|
|
|
|
serializeJson(json, json_str);
|
|
|
@@ -749,10 +749,10 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|
|
|
void sendState() {
|
|
|
|
void sendState() {
|
|
|
|
const size_t bufferSize = JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(6);
|
|
|
|
const size_t bufferSize = JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(6);
|
|
|
|
DynamicJsonDocument jsonBuffer(bufferSize);
|
|
|
|
DynamicJsonDocument jsonBuffer(bufferSize);
|
|
|
|
JsonObject& root = jsonBuffer.to<JsonObject>();
|
|
|
|
JsonObject root = jsonBuffer.to<JsonObject>();
|
|
|
|
|
|
|
|
|
|
|
|
root["state"] = (stateOn) ? on_cmd : off_cmd;
|
|
|
|
root["state"] = (stateOn) ? on_cmd : off_cmd;
|
|
|
|
JsonObject& color = root.createNestedObject("color");
|
|
|
|
JsonObject color = root.createNestedObject("color");
|
|
|
|
color["r"] = main_color.red;
|
|
|
|
color["r"] = main_color.red;
|
|
|
|
color["g"] = main_color.green;
|
|
|
|
color["g"] = main_color.green;
|
|
|
|
color["b"] = main_color.blue;
|
|
|
|
color["b"] = main_color.blue;
|
|
|
@@ -793,7 +793,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//DBG_OUTPUT_PORT.println("JSON ParseObject() done!");
|
|
|
|
//DBG_OUTPUT_PORT.println("JSON ParseObject() done!");
|
|
|
|
JsonObject& root = jsonBuffer.as<JsonObject>();
|
|
|
|
JsonObject root = jsonBuffer.as<JsonObject>();
|
|
|
|
|
|
|
|
|
|
|
|
if (root.containsKey("state")) {
|
|
|
|
if (root.containsKey("state")) {
|
|
|
|
const char* state_in = root["state"];
|
|
|
|
const char* state_in = root["state"];
|
|
|
@@ -811,7 +811,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (root.containsKey("color")) {
|
|
|
|
if (root.containsKey("color")) {
|
|
|
|
JsonObject& color = root["color"];
|
|
|
|
JsonObject color = root["color"];
|
|
|
|
main_color.red = (uint8_t) color["r"];
|
|
|
|
main_color.red = (uint8_t) color["r"];
|
|
|
|
main_color.green = (uint8_t) color["g"];
|
|
|
|
main_color.green = (uint8_t) color["g"];
|
|
|
|
main_color.blue = (uint8_t) color["b"];
|
|
|
|
main_color.blue = (uint8_t) color["b"];
|
|
|
@@ -921,7 +921,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|
|
|
mqtt_client.subscribe(mqtt_ha_state_in.c_str(), qossub);
|
|
|
|
mqtt_client.subscribe(mqtt_ha_state_in.c_str(), qossub);
|
|
|
|
#ifdef MQTT_HOME_ASSISTANT_SUPPORT
|
|
|
|
#ifdef MQTT_HOME_ASSISTANT_SUPPORT
|
|
|
|
DynamicJsonDocument jsonBuffer(JSON_ARRAY_SIZE(strip.getModeCount()) + JSON_OBJECT_SIZE(11));
|
|
|
|
DynamicJsonDocument jsonBuffer(JSON_ARRAY_SIZE(strip.getModeCount()) + JSON_OBJECT_SIZE(11));
|
|
|
|
JsonObject& json = jsonBuffer.to<JsonObject>();
|
|
|
|
JsonObject json = jsonBuffer.to<JsonObject>();
|
|
|
|
json["name"] = HOSTNAME;
|
|
|
|
json["name"] = HOSTNAME;
|
|
|
|
json["platform"] = "mqtt_json";
|
|
|
|
json["platform"] = "mqtt_json";
|
|
|
|
json["state_topic"] = mqtt_ha_state_out;
|
|
|
|
json["state_topic"] = mqtt_ha_state_out;
|
|
|
@@ -932,11 +932,11 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|
|
|
json["optimistic"] = "false";
|
|
|
|
json["optimistic"] = "false";
|
|
|
|
json["color_temp"] = "true";
|
|
|
|
json["color_temp"] = "true";
|
|
|
|
json["effect"] = "true";
|
|
|
|
json["effect"] = "true";
|
|
|
|
JsonArray& effect_list = json.createNestedArray("effect_list");
|
|
|
|
JsonArray effect_list = json.createNestedArray("effect_list");
|
|
|
|
for (uint8_t i = 0; i < strip.getModeCount(); i++) {
|
|
|
|
for (uint8_t i = 0; i < strip.getModeCount(); i++) {
|
|
|
|
effect_list.add(strip.getModeName(i));
|
|
|
|
effect_list.add(strip.getModeName(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
char buffer[json.measureJson() + 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);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
@@ -1001,7 +1001,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|
|
|
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);
|
|
|
|
#ifdef MQTT_HOME_ASSISTANT_SUPPORT
|
|
|
|
#ifdef MQTT_HOME_ASSISTANT_SUPPORT
|
|
|
|
DynamicJsonDocument jsonBuffer(JSON_ARRAY_SIZE(strip.getModeCount()) + JSON_OBJECT_SIZE(11));
|
|
|
|
DynamicJsonDocument jsonBuffer(JSON_ARRAY_SIZE(strip.getModeCount()) + JSON_OBJECT_SIZE(11));
|
|
|
|
JsonObject& json = jsonBuffer.to<JsonObject>();
|
|
|
|
JsonObject json = jsonBuffer.to<JsonObject>();
|
|
|
|
json["name"] = HOSTNAME;
|
|
|
|
json["name"] = HOSTNAME;
|
|
|
|
json["platform"] = "mqtt_json";
|
|
|
|
json["platform"] = "mqtt_json";
|
|
|
|
json["state_topic"] = mqtt_ha_state_out;
|
|
|
|
json["state_topic"] = mqtt_ha_state_out;
|
|
|
@@ -1012,11 +1012,11 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|
|
|
json["optimistic"] = "false";
|
|
|
|
json["optimistic"] = "false";
|
|
|
|
json["color_temp"] = "true";
|
|
|
|
json["color_temp"] = "true";
|
|
|
|
json["effect"] = "true";
|
|
|
|
json["effect"] = "true";
|
|
|
|
JsonArray& effect_list = json.createNestedArray("effect_list");
|
|
|
|
JsonArray effect_list = json.createNestedArray("effect_list");
|
|
|
|
for (uint8_t i = 0; i < strip.getModeCount(); i++) {
|
|
|
|
for (uint8_t i = 0; i < strip.getModeCount(); i++) {
|
|
|
|
effect_list.add(strip.getModeName(i));
|
|
|
|
effect_list.add(strip.getModeName(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
char buffer[json.measureJson() + 1];
|
|
|
|
char buffer[measureJson(json) + 1];
|
|
|
|
serializeJson(json, buffer, sizeof(buffer));
|
|
|
|
serializeJson(json, buffer, sizeof(buffer));
|
|
|
|
DBG_OUTPUT_PORT.println(buffer);
|
|
|
|
DBG_OUTPUT_PORT.println(buffer);
|
|
|
|
amqttClient.publish(String("homeassistant/light/" + String(HOSTNAME) + "/config").c_str(), qospub, true, buffer);
|
|
|
|
amqttClient.publish(String("homeassistant/light/" + String(HOSTNAME) + "/config").c_str(), qospub, true, buffer);
|
|
|
@@ -1242,7 +1242,7 @@ bool writeConfigFS(bool saveConfig){
|
|
|
|
updateFS = true;
|
|
|
|
updateFS = true;
|
|
|
|
DBG_OUTPUT_PORT.print("Saving config: ");
|
|
|
|
DBG_OUTPUT_PORT.print("Saving config: ");
|
|
|
|
DynamicJsonDocument jsonBuffer(JSON_OBJECT_SIZE(4));
|
|
|
|
DynamicJsonDocument jsonBuffer(JSON_OBJECT_SIZE(4));
|
|
|
|
JsonObject& json = jsonBuffer.to<JsonObject>();
|
|
|
|
JsonObject json = jsonBuffer.to<JsonObject>();
|
|
|
|
json["mqtt_host"] = mqtt_host;
|
|
|
|
json["mqtt_host"] = mqtt_host;
|
|
|
|
json["mqtt_port"] = mqtt_port;
|
|
|
|
json["mqtt_port"] = mqtt_port;
|
|
|
|
json["mqtt_user"] = mqtt_user;
|
|
|
|
json["mqtt_user"] = mqtt_user;
|
|
|
@@ -1282,7 +1282,7 @@ bool readConfigFS() {
|
|
|
|
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 json = jsonBuffer.as<JsonObject>();
|
|
|
|
serializeJson(json, DBG_OUTPUT_PORT);
|
|
|
|
serializeJson(json, DBG_OUTPUT_PORT);
|
|
|
|
strcpy(mqtt_host, json["mqtt_host"]);
|
|
|
|
strcpy(mqtt_host, json["mqtt_host"]);
|
|
|
|
strcpy(mqtt_port, json["mqtt_port"]);
|
|
|
|
strcpy(mqtt_port, json["mqtt_port"]);
|
|
|
@@ -1311,7 +1311,7 @@ bool writeStateFS(){
|
|
|
|
//save the strip state to FS JSON
|
|
|
|
//save the strip state to FS JSON
|
|
|
|
DBG_OUTPUT_PORT.print("Saving cfg: ");
|
|
|
|
DBG_OUTPUT_PORT.print("Saving cfg: ");
|
|
|
|
DynamicJsonDocument jsonBuffer(JSON_OBJECT_SIZE(7));
|
|
|
|
DynamicJsonDocument jsonBuffer(JSON_OBJECT_SIZE(7));
|
|
|
|
JsonObject& json = jsonBuffer.to<JsonObject>();
|
|
|
|
JsonObject json = jsonBuffer.to<JsonObject>();
|
|
|
|
json["mode"] = static_cast<int>(mode);
|
|
|
|
json["mode"] = static_cast<int>(mode);
|
|
|
|
json["strip_mode"] = (int) strip.getMode();
|
|
|
|
json["strip_mode"] = (int) strip.getMode();
|
|
|
|
json["brightness"] = brightness;
|
|
|
|
json["brightness"] = brightness;
|
|
|
@@ -1356,7 +1356,7 @@ bool readStateFS() {
|
|
|
|
DynamicJsonDocument jsonBuffer(JSON_OBJECT_SIZE(7)+200);
|
|
|
|
DynamicJsonDocument jsonBuffer(JSON_OBJECT_SIZE(7)+200);
|
|
|
|
DeserializationError error = deserializeJson(jsonBuffer, buf.get());
|
|
|
|
DeserializationError error = deserializeJson(jsonBuffer, buf.get());
|
|
|
|
if (!error) {
|
|
|
|
if (!error) {
|
|
|
|
JsonObject& json = jsonBuffer.as<JsonObject>();
|
|
|
|
JsonObject json = jsonBuffer.as<JsonObject>();
|
|
|
|
serializeJson(json, DBG_OUTPUT_PORT);
|
|
|
|
serializeJson(json, DBG_OUTPUT_PORT);
|
|
|
|
mode = static_cast<MODE>((int) json["mode"]);
|
|
|
|
mode = static_cast<MODE>((int) json["mode"]);
|
|
|
|
ws2812fx_mode = json["strip_mode"];
|
|
|
|
ws2812fx_mode = json["strip_mode"];
|
|
|
|