mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
mapping val bondaries added
timer tuning more logging to thermostat & map MBUS chan stop if not configured well
This commit is contained in:
@@ -1687,13 +1687,13 @@ if ((!driver || driver->isAllowed(cmd))
|
|||||||
tStore.asint=getExt();
|
tStore.asint=getExt();
|
||||||
if (!tStore.timestamp16)
|
if (!tStore.timestamp16)
|
||||||
{
|
{
|
||||||
infoSerial<<F("Cleaning alarm ")<<itemArr->name<<endl;
|
infoSerial<<F("Cleaning alarm ")<<itemArr->name<<" Ext:"<<tStore.asint<<endl;
|
||||||
#if not defined (NOIP)
|
#if not defined (NOIP)
|
||||||
mqttClient.publish("/alarmoff/snsr", itemArr->name);
|
mqttClient.publish("/alarmoff/snsr", itemArr->name);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
tStore.tempX100=cmd.getFloat()*100.; //Save measurement
|
tStore.tempX100=cmd.getFloat()*100.; //Save measurement
|
||||||
tStore.timestamp16=millisNZ(8) & 0xFFFF; //And timestamp
|
tStore.timestamp16=millisNZ(8) & 0xFFFFU; //And timestamp
|
||||||
debugSerial<<F("THERM:")<<itemArr->name<<F(" T:")<<tStore.tempX100<<F(" TS:")<<tStore.timestamp16<<endl;
|
debugSerial<<F("THERM:")<<itemArr->name<<F(" T:")<<tStore.tempX100<<F(" TS:")<<tStore.timestamp16<<endl;
|
||||||
setExt(tStore.asint);
|
setExt(tStore.asint);
|
||||||
res=1;
|
res=1;
|
||||||
|
|||||||
@@ -1367,17 +1367,40 @@ return false;
|
|||||||
|
|
||||||
if (matchedCmd && matchedCmd->type != aJson_NULL)
|
if (matchedCmd && matchedCmd->type != aJson_NULL)
|
||||||
{
|
{
|
||||||
|
traceSerial<<F("MAP: cmd mapped to ")<<matchedCmd->valueint<<endl;
|
||||||
return itemCmd().Int((uint32_t)matchedCmd->valueint);
|
return itemCmd().Int((uint32_t)matchedCmd->valueint);
|
||||||
}
|
}
|
||||||
|
|
||||||
aJsonObject *valMapping = aJson.getObjectItem(mappingData, "val");
|
aJsonObject *valMapping = aJson.getObjectItem(mappingData, "val");
|
||||||
if (isValue() && valMapping && valMapping->type == aJson_Array && aJson.getArraySize(valMapping) == 4)
|
if (isValue() && valMapping && valMapping->type == aJson_Array && aJson.getArraySize(valMapping) >= 4)
|
||||||
{
|
{ //ПРЯМОЕ
|
||||||
if (getInt()<aJson.getArrayItem(valMapping,0)->valueint) return itemCmd().Int((uint32_t) 0);
|
//"val":[0-вход_мин, 1-вход_макс, 2-выход_мин, 3-выход_макс, 4-вход<мин_прямое, 5-вых<мин_обратное, 6-вход>макс_прямое, 7-вых>макс_обратное]
|
||||||
return itemCmd().Int((uint32_t)
|
aJsonObject *leftBoundObj = aJson.getArrayItem(valMapping,4);
|
||||||
map(getInt(),
|
aJsonObject *rightBoundObj = aJson.getArrayItem(valMapping,6);
|
||||||
|
|
||||||
|
//if (getInt()<aJson.getArrayItem(valMapping,0)->valueint) return itemCmd().Int((uint32_t) 0); было если меньше левой границы то ноль. Неперь для такого поведения надо пятым элементом явно поставить ноль
|
||||||
|
|
||||||
|
if (getInt()<aJson.getArrayItem(valMapping,0)->valueint)
|
||||||
|
{
|
||||||
|
traceSerial<<F("MAP: value ")<<getInt()<<F(" is below left bound ")<<aJson.getArrayItem(valMapping,0)->valueint<<endl;
|
||||||
|
if (leftBoundObj && leftBoundObj->type == aJson_Int )
|
||||||
|
return itemCmd().Int(leftBoundObj->valueint);
|
||||||
|
else return itemCmd(ST_VOID,CMD_VOID);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getInt()>aJson.getArrayItem(valMapping,1)->valueint)
|
||||||
|
{
|
||||||
|
traceSerial<<F("MAP: value above right bound ")<<endl;
|
||||||
|
if (rightBoundObj && rightBoundObj->type == aJson_Int )
|
||||||
|
return itemCmd().Int(rightBoundObj->valueint);
|
||||||
|
else return itemCmd(ST_VOID,CMD_VOID);
|
||||||
|
}
|
||||||
|
long res = map(getInt(),
|
||||||
aJson.getArrayItem(valMapping,0)->valueint,aJson.getArrayItem(valMapping,1)->valueint,
|
aJson.getArrayItem(valMapping,0)->valueint,aJson.getArrayItem(valMapping,1)->valueint,
|
||||||
aJson.getArrayItem(valMapping,2)->valueint,aJson.getArrayItem(valMapping,3)->valueint));
|
aJson.getArrayItem(valMapping,2)->valueint,aJson.getArrayItem(valMapping,3)->valueint);
|
||||||
|
traceSerial<<F("MAP: val mapped to ")<<res<<endl;
|
||||||
|
return itemCmd().Int((uint32_t) res);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (valMapping && valMapping->type == aJson_NULL) return itemCmd(ST_VOID,CMD_VOID);
|
else if (valMapping && valMapping->type == aJson_NULL) return itemCmd(ST_VOID,CMD_VOID);
|
||||||
return *this;
|
return *this;
|
||||||
@@ -1445,14 +1468,36 @@ if (isValue() && valMapping && valMapping->type == aJson_Array && aJson.getArray
|
|||||||
if (matchedCmd) return itemCmd().Cmd(matchedCmd->valueint);
|
if (matchedCmd) return itemCmd().Cmd(matchedCmd->valueint);
|
||||||
|
|
||||||
aJsonObject *valMapping = aJson.getObjectItem(mappingData, "val");
|
aJsonObject *valMapping = aJson.getObjectItem(mappingData, "val");
|
||||||
if (valMapping && valMapping->type == aJson_Array && aJson.getArraySize(valMapping) == 4)
|
if (valMapping && valMapping->type == aJson_Array && aJson.getArraySize(valMapping) >= 4)
|
||||||
{
|
{
|
||||||
|
//ОБРАТНОЕ
|
||||||
|
//"val":[0-вход_мин, 1-вход_макс, 2-выход_мин, 3-выход_макс, 4-вход<мин_прямое, 5-вых<мин_обратное, 6-вход>макс_прямое, 7-вых>макс_обратное]
|
||||||
int a = aJson.getArrayItem(valMapping,0)->valueint;
|
int a = aJson.getArrayItem(valMapping,0)->valueint;
|
||||||
int b = aJson.getArrayItem(valMapping,1)->valueint;
|
int b = aJson.getArrayItem(valMapping,1)->valueint;
|
||||||
int c = aJson.getArrayItem(valMapping,2)->valueint;
|
int c = aJson.getArrayItem(valMapping,2)->valueint;
|
||||||
int d = aJson.getArrayItem(valMapping,3)->valueint;
|
int d = aJson.getArrayItem(valMapping,3)->valueint;
|
||||||
|
|
||||||
if (getInt()<aJson.getArrayItem(valMapping,2)->valueint) return itemCmd().Int((uint32_t) 0);
|
aJsonObject *leftBoundObj = aJson.getArrayItem(valMapping,5);
|
||||||
|
aJsonObject *rightBoundObj = aJson.getArrayItem(valMapping,7);
|
||||||
|
// Dev to unified
|
||||||
|
//было если меньше левой границы то ноль. Неперь для такого поведения надо 7m элементом явно поставить ноль
|
||||||
|
//if (getInt()<aJson.getArrayItem(valMapping,2)->valueint) return itemCmd().Int((uint32_t) 0);
|
||||||
|
|
||||||
|
|
||||||
|
if (getInt()<aJson.getArrayItem(valMapping,2)->valueint)
|
||||||
|
{
|
||||||
|
if (leftBoundObj && leftBoundObj->type == aJson_Int )
|
||||||
|
return itemCmd().Int(leftBoundObj->valueint);
|
||||||
|
else return itemCmd(ST_VOID,CMD_VOID);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getInt()>aJson.getArrayItem(valMapping,3)->valueint)
|
||||||
|
{
|
||||||
|
if (rightBoundObj && rightBoundObj->type == aJson_Int )
|
||||||
|
return itemCmd().Int(rightBoundObj->valueint);
|
||||||
|
else return itemCmd(ST_VOID,CMD_VOID);
|
||||||
|
}
|
||||||
|
|
||||||
int diff = ((b-a)/(d-c))/2;
|
int diff = ((b-a)/(d-c))/2;
|
||||||
//return itemCmd().Int((uint32_t) constrain(map(getInt(),c,d,a,b)+diff,0,255));
|
//return itemCmd().Int((uint32_t) constrain(map(getInt(),c,d,a,b)+diff,0,255));
|
||||||
return itemCmd().Int((uint32_t) constrain(map(getInt(),c,d,a,b)+diff,0,b));
|
return itemCmd().Int((uint32_t) constrain(map(getInt(),c,d,a,b)+diff,0,b));
|
||||||
|
|||||||
@@ -289,6 +289,7 @@ if (getConfig())
|
|||||||
else
|
else
|
||||||
{ errorSerial<<F("MBUS: config error")<<endl;
|
{ errorSerial<<F("MBUS: config error")<<endl;
|
||||||
setStatus(CST_FAILED);
|
setStatus(CST_FAILED);
|
||||||
|
Stop();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,7 @@
|
|||||||
#define TIMEOUT_RETAIN 8000UL
|
#define TIMEOUT_RETAIN 8000UL
|
||||||
#define TIMEOUT_REINIT_NOT_CONFIGURED 120000UL
|
#define TIMEOUT_REINIT_NOT_CONFIGURED 120000UL
|
||||||
#define INTERVAL_1W 5000UL
|
#define INTERVAL_1W 5000UL
|
||||||
#define PERIOD_THERMOSTAT_FAILED (600 * 1000UL)
|
#define PERIOD_THERMOSTAT_FAILED (600 * 1000UL) //16000 sec (4h) max
|
||||||
|
|
||||||
//#define T_ATTEMPTS 200
|
//#define T_ATTEMPTS 200
|
||||||
//#define IET_TEMP 0
|
//#define IET_TEMP 0
|
||||||
|
|||||||
@@ -626,7 +626,7 @@ RebootFunc();
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
bool isTimeOver(uint32_t timestamp, uint32_t currTime, uint32_t time, uint32_t modulo)
|
bool isTimeOver(uint32_t timestamp, uint32_t currTime, uint32_t time, uint32_t modulo)
|
||||||
{
|
{
|
||||||
uint32_t endTime;
|
uint32_t endTime;
|
||||||
@@ -638,7 +638,19 @@ bool isTimeOver(uint32_t timestamp, uint32_t currTime, uint32_t time, uint32_t m
|
|||||||
return ((currTime>endTime) && (currTime <timestamp)) ||
|
return ((currTime>endTime) && (currTime <timestamp)) ||
|
||||||
((timestamp<endTime) && ((currTime>endTime) || (currTime <timestamp)));
|
((timestamp<endTime) && ((currTime>endTime) || (currTime <timestamp)));
|
||||||
}
|
}
|
||||||
//millis() - tmr1 >= MY_PERIOD
|
*/
|
||||||
|
|
||||||
|
bool isTimeOver(uint32_t timestamp, uint32_t currTime, uint32_t time, uint32_t modulo)
|
||||||
|
{
|
||||||
|
uint32_t elapsed;
|
||||||
|
if (!time) return true;
|
||||||
|
|
||||||
|
if (modulo) elapsed = ((currTime & modulo) - (timestamp & modulo)) & modulo ;
|
||||||
|
else elapsed = currTime - timestamp ;
|
||||||
|
|
||||||
|
return elapsed >= time;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -819,9 +831,9 @@ itemCmd mapInt(int32_t arg, aJsonObject* map)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Same as millis() but never return 0 or -1
|
//Same as millis() but never return 0 or -1
|
||||||
unsigned long millisNZ(uint8_t shift)
|
uint32_t millisNZ(uint8_t shift)
|
||||||
{
|
{
|
||||||
unsigned long now = millis()>>shift;
|
uint32_t now = millis()>>shift;
|
||||||
if (!now || !(now+1)) now=1;
|
if (!now || !(now+1)) now=1;
|
||||||
return now;
|
return now;
|
||||||
}
|
}
|
||||||
@@ -1017,7 +1029,7 @@ if (element && element->type == aJson_String) return element->valuestring;
|
|||||||
long getIntFromJson(aJsonObject * a, int i, long def)
|
long getIntFromJson(aJsonObject * a, int i, long def)
|
||||||
{
|
{
|
||||||
aJsonObject * element = NULL;
|
aJsonObject * element = NULL;
|
||||||
if (!a) return NULL;
|
if (!a) return def;
|
||||||
if (a->type == aJson_Array)
|
if (a->type == aJson_Array)
|
||||||
element = aJson.getArrayItem(a, i);
|
element = aJson.getArrayItem(a, i);
|
||||||
// TODO - human readable JSON objects as alias
|
// TODO - human readable JSON objects as alias
|
||||||
@@ -1030,7 +1042,7 @@ return def;
|
|||||||
long getIntFromJson(aJsonObject * a, char * name, long def)
|
long getIntFromJson(aJsonObject * a, char * name, long def)
|
||||||
{
|
{
|
||||||
aJsonObject * element = NULL;
|
aJsonObject * element = NULL;
|
||||||
if (!a) return NULL;
|
if (!a) return def;
|
||||||
if (a->type == aJson_Object)
|
if (a->type == aJson_Object)
|
||||||
element = aJson.getObjectItem(a, name);
|
element = aJson.getObjectItem(a, name);
|
||||||
if (element && element->type == aJson_Int) return element->valueint;
|
if (element && element->type == aJson_Int) return element->valueint;
|
||||||
@@ -1041,7 +1053,7 @@ return def;
|
|||||||
float getFloatFromJson(aJsonObject * a, int i, float def)
|
float getFloatFromJson(aJsonObject * a, int i, float def)
|
||||||
{
|
{
|
||||||
aJsonObject * element = NULL;
|
aJsonObject * element = NULL;
|
||||||
if (!a) return NULL;
|
if (!a) return def;
|
||||||
if (a->type == aJson_Array)
|
if (a->type == aJson_Array)
|
||||||
element = aJson.getArrayItem(a, i);
|
element = aJson.getArrayItem(a, i);
|
||||||
// TODO - human readable JSON objects as alias
|
// TODO - human readable JSON objects as alias
|
||||||
@@ -1054,7 +1066,7 @@ return def;
|
|||||||
float getFloatFromJson(aJsonObject * a, char * name, float def)
|
float getFloatFromJson(aJsonObject * a, char * name, float def)
|
||||||
{
|
{
|
||||||
aJsonObject * element = NULL;
|
aJsonObject * element = NULL;
|
||||||
if (!a) return NULL;
|
if (!a) return def;
|
||||||
if (a->type == aJson_Object)
|
if (a->type == aJson_Object)
|
||||||
element = aJson.getObjectItem(a, name);
|
element = aJson.getObjectItem(a, name);
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ bool isTimeOver(uint32_t timestamp, uint32_t currTime, uint32_t time, uint32_t m
|
|||||||
bool executeCommand(aJsonObject* cmd, int8_t toggle = -1);
|
bool executeCommand(aJsonObject* cmd, int8_t toggle = -1);
|
||||||
bool executeCommand(aJsonObject* cmd, int8_t toggle, itemCmd _itemCmd, aJsonObject* defaultItem=NULL, aJsonObject* defaultEmit=NULL, aJsonObject* defaultCan = NULL);
|
bool executeCommand(aJsonObject* cmd, int8_t toggle, itemCmd _itemCmd, aJsonObject* defaultItem=NULL, aJsonObject* defaultEmit=NULL, aJsonObject* defaultCan = NULL);
|
||||||
itemCmd mapInt(int32_t arg, aJsonObject* map);
|
itemCmd mapInt(int32_t arg, aJsonObject* map);
|
||||||
unsigned long millisNZ(uint8_t shift=0);
|
uint32_t millisNZ(uint8_t shift=0);
|
||||||
serialParamType str2SerialParam(char * str);
|
serialParamType str2SerialParam(char * str);
|
||||||
String toString(const IPAddress& address);
|
String toString(const IPAddress& address);
|
||||||
bool getPinVal(uint8_t pin);
|
bool getPinVal(uint8_t pin);
|
||||||
|
|||||||
@@ -796,7 +796,7 @@ lib_deps =
|
|||||||
Adafruit BusIO
|
Adafruit BusIO
|
||||||
https://github.com/arcao/Syslog.git
|
https://github.com/arcao/Syslog.git
|
||||||
;br3ttb/PID@^1.2.1
|
;br3ttb/PID@^1.2.1
|
||||||
https://github.com/anklimov/Arduino-PID-Library.gitv
|
https://github.com/anklimov/Arduino-PID-Library.git
|
||||||
ArduinoMDNS
|
ArduinoMDNS
|
||||||
https://github.com/khoih-prog/TimerInterrupt_Generic.git
|
https://github.com/khoih-prog/TimerInterrupt_Generic.git
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user