sonoff iobroker support (FIRST MUST BE ENABLED IN FLAGS), tele sending

This commit is contained in:
openshwprojects
2023-01-24 19:26:16 +01:00
parent 189d14d7db
commit 840339f675
9 changed files with 206 additions and 21 deletions

View File

@ -786,7 +786,10 @@ int http_fn_index(http_request_t* request) {
else {
const char *stateStr;
const char *colorStr;
if (Main_HasMQTTConnected() == 1) {
if (mqtt_reconnect > 0) {
stateStr = "awaiting reconnect";
colorStr = "orange";
} else if (Main_HasMQTTConnected() == 1) {
stateStr = "connected";
colorStr = "green";
}
@ -939,6 +942,8 @@ int http_fn_cfg_mqtt_set(http_request_t* request) {
poststr(request, "Please wait for module to connect... if there is problem, restart it from Index html page...");
g_mqtt_bBaseTopicDirty = 1;
poststr(request, "<br>");
poststr(request, "<a href=\"cfg_mqtt\">Return to MQTT settings</a>");
poststr(request, "<br>");
@ -2194,7 +2199,7 @@ const char* g_obk_flagNames[] = {
"[HASS] Invoke HomeAssistant discovery on change to ip address, configuration",
"[LED] Setting RGB white (FFFFFF) enables temperature mode",
"[NETIF] Use short device name as a hostname instead of a long name",
"error",
"[MQTT] Enable Tasmota TELE etc publishes (for ioBroker etc)",
"error",
"error",
"error",

View File

@ -282,11 +282,13 @@ unsigned int NTP_GetCurrentTimeWithoutOffset() {
}
}
*/
static int http_tasmota_json_status_STS(void* request, jsonCb_t printer) {
static int http_tasmota_json_status_STS(void* request, jsonCb_t printer, bool bAppendHeader) {
char buff[20];
time_t localTime = (time_t)NTP_GetCurrentTime();
printer(request, "\"StatusSTS\":");
if (bAppendHeader) {
printer(request, "\"StatusSTS\":");
}
printer(request, "{");
strftime(buff, sizeof(buff), "%Y-%m-%dT%H:%M:%S", localtime(&localTime));
printer(request, "\"Time\":\"%s\",", buff);
@ -573,7 +575,7 @@ static int http_tasmota_json_status_generic(void* request, jsonCb_t printer) {
printer(request, ",");
http_tasmota_json_status_STS(request, printer);
http_tasmota_json_status_STS(request, printer, true);
// end
printer(request, "}");
@ -621,6 +623,15 @@ int JSON_ProcessCommandReply(const char *cmd, const char *arg, void *request, js
MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s *)request, "RESULT");
}
}
else if (!wal_strnicmp(cmd, "STATE", 5)) {
http_tasmota_json_status_STS(request, printer, false);
if (flags == COMMAND_FLAG_SOURCE_MQTT) {
MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s *)request, "RESULT");
}
if (flags == COMMAND_FLAG_SOURCE_TELESENDER) {
MQTT_PublishPrinterContentsToTele((struct obk_mqtt_publishReplyPrinter_s *)request, "STATE");
}
}
else if (!wal_strnicmp(cmd, "STATUS", 6)) {
if (!stricmp(arg, "8") || !stricmp(arg, "10")) {
printer(request, "{");