mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
-default topics prefix used if no "/" in "emit" parameters of output
-Thermostat should be working with DHT22 -Negative PIN# in thermostat item - reverse logic: HIGH level of output should stop heating
This commit is contained in:
@@ -162,8 +162,9 @@ void Input::counterPoll() {
|
|||||||
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
||||||
if (emit) {
|
if (emit) {
|
||||||
char valstr[10];
|
char valstr[10];
|
||||||
char addrstr[100] = "";
|
char addrstr[MQTT_TOPIC_LENGTH];
|
||||||
strcat(addrstr, emit->valuestring);
|
strncpy(addrstr,emit->valuestring,sizeof(addrstr));
|
||||||
|
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
||||||
sprintf(valstr, "%d", counterValue);
|
sprintf(valstr, "%d", counterValue);
|
||||||
mqttClient.publish(addrstr, valstr);
|
mqttClient.publish(addrstr, valstr);
|
||||||
setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT);
|
setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT);
|
||||||
@@ -225,9 +226,11 @@ void Input::dht22Poll() {
|
|||||||
float humidity = dht.readHumidity();
|
float humidity = dht.readHumidity();
|
||||||
#endif
|
#endif
|
||||||
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
||||||
|
aJsonObject *item = aJson.getObjectItem(inputObj, "item");
|
||||||
|
if (item) thermoSetCurTemp(item, temp);
|
||||||
debugSerial << F("IN:") << pin << F(" DHT22 type. T=") << temp << F("°C H=") << humidity << F("%");
|
debugSerial << F("IN:") << pin << F(" DHT22 type. T=") << temp << F("°C H=") << humidity << F("%");
|
||||||
if (emit && temp && humidity && temp == temp && humidity == humidity) {
|
if (emit && temp && humidity && temp == temp && humidity == humidity) {
|
||||||
char addrstr[100] = "";
|
char addrstr[MQTT_TOPIC_LENGTH] = "";
|
||||||
#ifdef WITH_DOMOTICZ
|
#ifdef WITH_DOMOTICZ
|
||||||
if(getIdxField()){
|
if(getIdxField()){
|
||||||
publishDataToDomoticz(DHT_POLL_DELAY_DEFAULT, emit, "{\"idx\":%s,\"svalue\":\"%.1f;%.0f;0\"}", getIdxField(), temp, humidity);
|
publishDataToDomoticz(DHT_POLL_DELAY_DEFAULT, emit, "{\"idx\":%s,\"svalue\":\"%.1f;%.0f;0\"}", getIdxField(), temp, humidity);
|
||||||
@@ -235,7 +238,9 @@ void Input::dht22Poll() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
char valstr[10];
|
char valstr[10];
|
||||||
strcat(addrstr, emit->valuestring);
|
|
||||||
|
strncpy(addrstr, emit->valuestring, sizeof(addrstr));
|
||||||
|
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
||||||
strcat(addrstr, "T");
|
strcat(addrstr, "T");
|
||||||
printFloatValueToStr(temp, valstr);
|
printFloatValueToStr(temp, valstr);
|
||||||
mqttClient.publish(addrstr, valstr);
|
mqttClient.publish(addrstr, valstr);
|
||||||
@@ -444,13 +449,16 @@ void Input::onContactChanged(int newValue) {
|
|||||||
: publishDataToDomoticz(0,emit,"{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"Off\"}",getIdxField());
|
: publishDataToDomoticz(0,emit,"{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"Off\"}",getIdxField());
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
|
char addrstr[MQTT_TOPIC_LENGTH];
|
||||||
|
strncpy(addrstr,emit->valuestring,sizeof(addrstr));
|
||||||
|
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
||||||
if (newValue) { //send set command
|
if (newValue) { //send set command
|
||||||
if (!scmd) mqttClient.publish(emit->valuestring, "ON", true);
|
if (!scmd) mqttClient.publish(addrstr, "ON", true);
|
||||||
else if (strlen(scmd->valuestring))
|
else if (strlen(scmd->valuestring))
|
||||||
mqttClient.publish(emit->valuestring, scmd->valuestring, true);
|
mqttClient.publish(addrstr, scmd->valuestring, true);
|
||||||
} else { //send reset command
|
} else { //send reset command
|
||||||
if (!rcmd) mqttClient.publish(emit->valuestring, "OFF", true);
|
if (!rcmd) mqttClient.publish(addrstr, "OFF", true);
|
||||||
else if (strlen(rcmd->valuestring))mqttClient.publish(emit->valuestring, rcmd->valuestring, true);
|
else if (strlen(rcmd->valuestring))mqttClient.publish(addrstr, rcmd->valuestring, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -485,9 +493,12 @@ void Input::onAnalogChanged(int newValue) {
|
|||||||
// : publishDataToDomoticz(0,emit,"{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"Off\"}",getIdxField());
|
// : publishDataToDomoticz(0,emit,"{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"Off\"}",getIdxField());
|
||||||
// } else
|
// } else
|
||||||
//#endif
|
//#endif
|
||||||
|
char addrstr[MQTT_TOPIC_LENGTH];
|
||||||
|
strncpy(addrstr,emit->valuestring,sizeof(addrstr));
|
||||||
|
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
||||||
char strVal[16];
|
char strVal[16];
|
||||||
itoa(newValue,strVal,10);
|
itoa(newValue,strVal,10);
|
||||||
mqttClient.publish(emit->valuestring, strVal, true);
|
mqttClient.publish(addrstr, strVal, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item) {
|
if (item) {
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ if (isSet)
|
|||||||
Par[0] = map(hsv.h, 0, 255, 0, 365);
|
Par[0] = map(hsv.h, 0, 255, 0, 365);
|
||||||
Par[1] = map(hsv.s, 0, 255, 0, 100);
|
Par[1] = map(hsv.s, 0, 255, 0, 100);
|
||||||
Par[2] = map(hsv.v, 0, 255, 0, 100);
|
Par[2] = map(hsv.v, 0, 255, 0, 100);
|
||||||
return Ctrl(0, 3, Par, send, subItem);
|
return Ctrl(0, 3, Par, send, subItemN);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -296,21 +296,21 @@ if (isSet)
|
|||||||
|
|
||||||
// if (item.getEnableCMD(500) || lanStatus == 4)
|
// if (item.getEnableCMD(500) || lanStatus == 4)
|
||||||
return Ctrl(cmd, 0, NULL,
|
return Ctrl(cmd, 0, NULL,
|
||||||
send, subItem); //Accept ON command not earlier then 500 ms after set settings (Homekit hack)
|
send, subItemN); //Accept ON command not earlier then 500 ms after set settings (Homekit hack)
|
||||||
// else debugSerial<<F("on Skipped"));
|
// else debugSerial<<F("on Skipped"));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default: //some known command
|
default: //some known command
|
||||||
return Ctrl(cmd, 0, NULL, send, subItem);
|
return Ctrl(cmd, 0, NULL, send, subItemN);
|
||||||
|
|
||||||
} //ctrl
|
} //ctrl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, char * subItem) {
|
int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int subItemN) {
|
||||||
|
|
||||||
debugSerial<<F(" MEM=")<<freeRam()<<F(" Item=")<<itemArr->name<<F(" Sub=")<<subItem<<F(" Cmd=")<<cmd<<F(" Par= ");
|
debugSerial<<F(" MEM=")<<freeRam()<<F(" Item=")<<itemArr->name<<F(" Sub=")<<subItemN<<F(" Cmd=")<<cmd<<F(" Par= ");
|
||||||
if (!itemArr) return -1;
|
if (!itemArr) return -1;
|
||||||
int Par[MAXCTRLPAR] = {0, 0, 0};
|
int Par[MAXCTRLPAR] = {0, 0, 0};
|
||||||
if (Parameters)
|
if (Parameters)
|
||||||
@@ -630,7 +630,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, char * subItem
|
|||||||
while (i) {
|
while (i) {
|
||||||
Item it(i->valuestring);
|
Item it(i->valuestring);
|
||||||
// it.copyPar(itemVal);
|
// it.copyPar(itemVal);
|
||||||
it.Ctrl(cmd, n, Par, send); //// was true
|
it.Ctrl(cmd, n, Par, send,subItemN); //// was true
|
||||||
i = i->next;
|
i = i->next;
|
||||||
} //while
|
} //while
|
||||||
} //if
|
} //if
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ class Item
|
|||||||
Item(char * name);
|
Item(char * name);
|
||||||
Item(aJsonObject * obj);
|
Item(aJsonObject * obj);
|
||||||
boolean isValid ();
|
boolean isValid ();
|
||||||
virtual int Ctrl(short cmd, short n=0, int * Parameters=NULL, boolean send=true, char * subItem=NULL);
|
virtual int Ctrl(short cmd, short n=0, int * Parameters=NULL, boolean send=true, int subItem=0);
|
||||||
virtual int Ctrl(char * payload, boolean send=true, char * subItem=NULL);
|
virtual int Ctrl(char * payload, boolean send=true, char * subItem=NULL);
|
||||||
|
|
||||||
int getArg(short n=0);
|
int getArg(short n=0);
|
||||||
|
|||||||
@@ -1622,15 +1622,15 @@ void thermoLoop(void) {
|
|||||||
<< F(" cmd:") << thermoStateCommand;
|
<< F(" cmd:") << thermoStateCommand;
|
||||||
pinMode(thermoPin, OUTPUT);
|
pinMode(thermoPin, OUTPUT);
|
||||||
if (thermoDisabledOrDisconnected(thermoExtensionArray, thermoStateCommand)) {
|
if (thermoDisabledOrDisconnected(thermoExtensionArray, thermoStateCommand)) {
|
||||||
digitalWrite(thermoPin, LOW);
|
if (thermoPin<0) digitalWrite(-thermoPin, HIGH); digitalWrite(thermoPin, LOW);
|
||||||
debugSerial<<F(" OFF");
|
debugSerial<<F(" OFF");
|
||||||
} else {
|
} else {
|
||||||
if (curTemp < thermoSetting - THERMO_GIST_CELSIUS) {
|
if (curTemp < thermoSetting - THERMO_GIST_CELSIUS) {
|
||||||
digitalWrite(thermoPin, HIGH);
|
if (thermoPin<0) digitalWrite(-thermoPin, LOW); digitalWrite(thermoPin, HIGH);
|
||||||
debugSerial<<F(" ON");
|
debugSerial<<F(" ON");
|
||||||
} //too cold
|
} //too cold
|
||||||
else if (curTemp >= thermoSetting) {
|
else if (curTemp >= thermoSetting) {
|
||||||
digitalWrite(thermoPin, LOW);
|
if (thermoPin<0) digitalWrite(-thermoPin, HIGH); digitalWrite(thermoPin, LOW);
|
||||||
debugSerial<<F(" OFF");
|
debugSerial<<F(" OFF");
|
||||||
} //Reached settings
|
} //Reached settings
|
||||||
else debugSerial<<F(" -target zone-"); // Nothing to do
|
else debugSerial<<F(" -target zone-"); // Nothing to do
|
||||||
@@ -1650,8 +1650,10 @@ publishStat();
|
|||||||
}
|
}
|
||||||
|
|
||||||
short thermoSetCurTemp(char *name, float t) {
|
short thermoSetCurTemp(char *name, float t) {
|
||||||
|
if (!name || !strlen(name)) return 0;
|
||||||
if (items) {
|
if (items) {
|
||||||
aJsonObject *thermoItem = aJson.getObjectItem(items, name);
|
aJsonObject *thermoItem = aJson.getObjectItem(items, name);
|
||||||
|
if (!thermoItem) return 0;
|
||||||
if (isThermostatWithMinArraySize(thermoItem, 4)) {
|
if (isThermostatWithMinArraySize(thermoItem, 4)) {
|
||||||
aJsonObject *extArray = NULL;
|
aJsonObject *extArray = NULL;
|
||||||
|
|
||||||
@@ -1672,5 +1674,5 @@ short thermoSetCurTemp(char *name, float t) {
|
|||||||
att->valueint = (int) T_ATTEMPTS;
|
att->valueint = (int) T_ATTEMPTS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return 1;}
|
||||||
}
|
return 0;}
|
||||||
|
|||||||
@@ -98,7 +98,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MQTT_SUBJECT_LENGTH 20
|
#define MQTT_SUBJECT_LENGTH 20
|
||||||
#define MQTT_TOPIC_LENGTH 20
|
#define MQTT_TOPIC_LENGTH 64
|
||||||
|
|
||||||
#ifndef DMX_DISABLE
|
#ifndef DMX_DISABLE
|
||||||
#define _dmxin
|
#define _dmxin
|
||||||
|
|||||||
Reference in New Issue
Block a user