fix esp32c6 & add ble, Fix Date Log, add BL0942, upd Descovery

This commit is contained in:
Mit4el
2025-01-06 20:35:19 +03:00
parent a844d08ebf
commit 68fea2ae37
18 changed files with 719 additions and 85 deletions

View File

@@ -28,25 +28,25 @@ public:
// mqttSubscribeExternal(_topic);
}
}
/*
void onMqttRecive(String &topic, String &msg)
{
if (!HA)
return;
if (msg.indexOf("HELLO") == -1)
/*
void onMqttRecive(String &topic, String &msg)
{
String dev = selectToMarkerLast(topic, "/");
dev.toUpperCase();
dev.replace(":", "");
if (_topic != topic)
{
// SerialPrint("i", "ExternalMQTT", _id + " not equal: " + topic + " msg: " + msg);
if (!HA)
return;
if (msg.indexOf("HELLO") == -1)
{
String dev = selectToMarkerLast(topic, "/");
dev.toUpperCase();
dev.replace(":", "");
if (_topic != topic)
{
// SerialPrint("i", "ExternalMQTT", _id + " not equal: " + topic + " msg: " + msg);
return;
}
// обработка топика, на который подписались
}
// обработка топика, на который подписались
}
} */
} */
void doByInterval()
{
@@ -96,7 +96,7 @@ public:
jsonWriteInt(errorsHeapJson, F("jse3"), 1); // Ошибка чтения json файла с виджетами при отправки в mqtt
}
int i = 0;
// String path = jsonReadStr(settingsFlashJson, F("HomeAssistant"));
// String HATopic = jsonReadStr(settingsFlashJson, F("HomeAssistant"));
JsonArray arr = doc.as<JsonArray>();
for (JsonVariant value : arr)
{
@@ -104,7 +104,7 @@ public:
dev.replace(":", "");
String HAjson = "";
HAjson = "{\"availability\":[{\"topic\": \"" + mqttRootDevice + "/state\",\"value_template\": \"{{ value_json.status }}\"}],\"availability_mode\": \"any\",";
HAjson = HAjson + " \"device\": {\"identifiers\": [\"" + value["page"].as<String>() + "\"],";
HAjson = HAjson + " \"device\": {\"identifiers\": [\"" + mqttRootDevice + value["page"].as<String>() + "\"],";
HAjson = HAjson + " \"name\": \" " + value["page"].as<String>() + "\"},";
HAjson = HAjson + " \"name\": \"" + value["descr"].as<String>() + "\",";
HAjson = HAjson + " \"state_topic\": \"" + value["topic"].as<String>() + "/status\",";
@@ -114,22 +114,39 @@ public:
if (value["name"].as<String>() == "anydataTmp")
{
HAjson = HAjson + " \"value_template\": \"{{ float( value_json.status, default = 0) | default }}\",";
HAjson = HAjson + " \"unique_id\": \"" + dev + "\",";
HAjson = HAjson + " \"state_class\": \"measurement\",";
HAjson = HAjson + " \"unique_id\": \"" + mqttRootDevice + dev + "\",";
HAjson = HAjson + " \"unit_of_measurement\": \"°C\"";
}
else if (value["name"].as<String>() == "anydataHum")
{
HAjson = HAjson + " \"value_template\": \"{{ float( value_json.status, default = 0) | default }}\",";
HAjson = HAjson + " \"unique_id\": \"" + dev + "\",";
HAjson = HAjson + " \"state_class\": \"measurement\",";
HAjson = HAjson + " \"unique_id\": \"" + mqttRootDevice + dev + "\",";
HAjson = HAjson + " \"unit_of_measurement\": \"%\"";
}
// ввод числа
else if (value["name"].as<String>() == "anydataMm")
{
HAjson = HAjson + " \"value_template\": \"{{ float( value_json.status, default = 0) | default }}\",";
HAjson = HAjson + " \"unique_id\": \"" + mqttRootDevice + dev + "\",";
HAjson = HAjson + " \"unit_of_measurement\": \"mm\"";
}
else if (value["name"].as<String>() == "anydataBar")
{
HAjson = HAjson + " \"value_template\": \"{{ float( value_json.status, default = 0) | default }}\",";
HAjson = HAjson + " \"unique_id\": \"" + mqttRootDevice + dev + "\",";
HAjson = HAjson + " \"unit_of_measurement\": \"Bar\"";
}
else if (value["name"].as<String>() == "anydataPpm")
{
HAjson = HAjson + " \"value_template\": \"{{ float( value_json.status, default = 0) | default }}\",";
HAjson = HAjson + " \"unique_id\": \"" + mqttRootDevice + dev + "\",";
HAjson = HAjson + " \"unit_of_measurement\": \"ppm\"";
}
// ввод числаФВ
else if (value["name"].as<String>() == "inputDgt")
{
HAjson = HAjson + " \"value_template\": \"{{ float( value_json.status, default = 0) | default }}\",";
HAjson = HAjson + " \"unique_id\": \"" + dev + "\",";
HAjson = HAjson + " \"unique_id\": \"" + mqttRootDevice + dev + "\",";
HAjson = HAjson + " \"command_topic\": \"" + value["topic"].as<String>() + "/control\",";
HAjson = HAjson + " \"mode\": \"box\",";
HAjson = HAjson + " \"min\": " + -1000000 + ",";
@@ -139,14 +156,14 @@ public:
else if (value["name"].as<String>() == "inputTxt")
{
HAjson = HAjson + " \"value_template\": \"{{ value_json.status | default }}\",";
HAjson = HAjson + " \"unique_id\": \"" + dev + "\",";
HAjson = HAjson + " \"unique_id\": \"" + mqttRootDevice + dev + "\",";
HAjson = HAjson + " \"command_topic\": \"" + value["topic"].as<String>() + "/control\"";
}
// переключатель
else if (value["name"].as<String>() == "toggle")
{
HAjson = HAjson + " \"value_template\": \"{{ value_json.status | default }}\",";
HAjson = HAjson + " \"unique_id\": \"" + dev + "\",";
HAjson = HAjson + " \"unique_id\": \"" + mqttRootDevice + dev + "\",";
HAjson = HAjson + " \"command_topic\": \"" + value["topic"].as<String>() + "/control\",";
HAjson = HAjson + " \"device_class\": \"switch\",";
HAjson = HAjson + " \"payload_off\": " + 0 + ",";
@@ -157,7 +174,7 @@ public:
else
{
HAjson = HAjson + " \"value_template\": \"{{ value_json.status | default }}\",";
HAjson = HAjson + " \"unique_id\": \"" + dev + "\"";
HAjson = HAjson + " \"unique_id\": \"" + mqttRootDevice + dev + "\"";
}
HAjson = HAjson + " }";

View File

@@ -8,16 +8,29 @@ private:
bool sendOk = false;
// bool topicOk = false;
bool HOMEd = false;
int _names = 0;
String esp_id = chipId;
public:
DiscoveryHomeD(String parameters) : IoTDiscovery(parameters)
{
_topic = jsonReadStr(parameters, "topic");
_names = jsonReadInt(parameters, "names");
if (_topic && _topic != "" && _topic != "null")
{
HOMEd = true;
HOMEdTopic = _topic;
}
if (_names)
{
esp_id = jsonReadStr(settingsFlashJson, F("name"));
jsonWriteInt(settingsFlashJson, F("HOMEd_names"), 1);
}
else
{
jsonWriteInt(settingsFlashJson, F("HOMEd_names"), 0);
}
if (mqttIsConnect() && HOMEd)
{
mqttReconnect();
@@ -33,14 +46,14 @@ public:
if (payloadStr.indexOf("HELLO") == -1)
{
/* String dev = selectToMarkerLast(topic, "/");
dev.toUpperCase();
dev.replace(":", "");
if (_topic != topic)
{
// SerialPrint("i", "ExternalMQTT", _id + " not equal: " + topic + " msg: " + msg);
return;
} */
/* String dev = selectToMarkerLast(topic, "/");
dev.toUpperCase();
dev.replace(":", "");
if (_topic != topic)
{
// SerialPrint("i", "ExternalMQTT", _id + " not equal: " + topic + " msg: " + msg);
return;
} */
// обработка топика, на который подписались
if (topic.indexOf(F("/td/custom")) != -1)
{
@@ -52,7 +65,6 @@ public:
{
String key = kvp.key().c_str();
SerialPrint("i", F("=>MQTT"), "Msg from HOMEd: " + key);
String value = kvp.value().as<const char *>();
if (key.indexOf(F("status_")) != -1)
{
@@ -71,11 +83,17 @@ public:
generateOrder(key, val);
}
}
if (!value)
else
{
float val = kvp.value();
generateOrder(key, (String)(val));
if (!value)
{
float val = kvp.value();
generateOrder(key, (String)(val));
}
else
{
generateOrder(key, value);
}
}
}
@@ -90,8 +108,8 @@ public:
if (mqttIsConnect() && !sendOk && topicOk)
{
sendOk = true;
publishRetain(_topic + "/device/custom/" + nameId, "{\"status\":\"online\"}");
String HOMEdsubscribeTopic = _topic + "/td/custom/" + nameId;
publishRetain(_topic + "/device/custom/" + esp_id, "{\"status\":\"online\"}");
String HOMEdsubscribeTopic = _topic + "/td/custom/" + esp_id;
// mqtt.subscribe(HOMEdsubscribeTopic.c_str());
mqttSubscribeExternal(HOMEdsubscribeTopic);
}
@@ -103,7 +121,7 @@ public:
void publishStatusHOMEd(const String &topic, const String &data)
{
String path_h = HOMEdTopic + "/fd/custom/" + nameId;
String path_h = HOMEdTopic + "/fd/custom/" + esp_id;
String json_h = "{}";
if (topic != "onStart")
{
@@ -133,8 +151,8 @@ public:
{
deleteFromHOMEd();
getlayoutHOMEd();
publishRetain(HOMEdTopic + "/device/custom/" + nameId, "{\"status\":\"online\"}");
String HOMEdsubscribeTopic = HOMEdTopic + "/td/custom/" + nameId;
publishRetain(HOMEdTopic + "/device/custom/" + esp_id, "{\"status\":\"online\"}");
String HOMEdsubscribeTopic = HOMEdTopic + "/td/custom/" + esp_id;
mqtt.subscribe(HOMEdsubscribeTopic.c_str());
}
}
@@ -164,7 +182,7 @@ public:
JsonArray arr = doc.as<JsonArray>();
String HOMEdJSON = "";
HOMEdJSON = "{\"action\":\"updateDevice\",";
HOMEdJSON = HOMEdJSON + "\"device\":\"" + nameId + "\",";
HOMEdJSON = HOMEdJSON + "\"device\":\"" + chipId + "\",";
HOMEdJSON = HOMEdJSON + "\"data\":{";
HOMEdJSON = HOMEdJSON + "\"active\": true,";
HOMEdJSON = HOMEdJSON + "\"cloud\": false,";
@@ -178,7 +196,7 @@ public:
{
String name = value["descr"];
String device = selectToMarkerLast(value["topic"].as<String>(), "/");
//String id = chipId + "-" + device;
// String id = ChipId + "-" + device;
String expose = value["name"];
if (value["name"].as<String>() == "toggle")
{
@@ -219,7 +237,7 @@ public:
file.close();
publishRetain(HOMEdTopic + "/device/custom/" + nameId, "{\"status\":\"online\"}");
publishRetain(HOMEdTopic + "/device/custom/" + esp_id, "{\"status\":\"online\"}");
for (std::list<IoTItem *>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it)
{
@@ -243,7 +261,7 @@ public:
String HOMEdjson = "";
HOMEdjson = "{\"action\":\"removeDevice\",";
HOMEdjson = HOMEdjson + "\"device\":\"";
HOMEdjson = HOMEdjson + nameId;
HOMEdjson = HOMEdjson + chipId;
HOMEdjson = HOMEdjson + "\"}";
String topic = (HOMEdTopic + "/command/custom").c_str();
if (!publish(topic, HOMEdjson))

View File

@@ -10,7 +10,8 @@
"widget": "",
"page": "",
"descr": "",
"topic": "homed"
"topic": "homed",
"names":1
}
],
"about": {