mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
Code review, many bugfixes. Synchronization items with Openhab improved. Modbus pulling developed
This commit is contained in:
344
item.cpp
344
item.cpp
@@ -25,7 +25,7 @@ e-mail anklimov@gmail.com
|
|||||||
#include <ModbusMaster.h>
|
#include <ModbusMaster.h>
|
||||||
#include <PubSubClient2.h>
|
#include <PubSubClient2.h>
|
||||||
|
|
||||||
|
short modbusBusy=0;
|
||||||
|
|
||||||
extern int modbusSet(int addr, uint16_t _reg, int _mask, uint16_t value);
|
extern int modbusSet(int addr, uint16_t _reg, int _mask, uint16_t value);
|
||||||
extern PubSubClient client;
|
extern PubSubClient client;
|
||||||
@@ -48,16 +48,20 @@ int txt2cmd (char * payload)
|
|||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
Item::Item(char * name) //Constructor
|
const short defval[4] = {0,0,0,0}; //Type,Arg,Val,Cmd
|
||||||
{
|
|
||||||
if (name)
|
|
||||||
itemArr= aJson.getObjectItem(items, name);
|
|
||||||
else itemArr=NULL;
|
|
||||||
|
|
||||||
|
Item::Item(aJsonObject * obj)//Constructor
|
||||||
|
{
|
||||||
|
itemArr= obj;
|
||||||
|
Parse();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Item::Parse()
|
||||||
|
{
|
||||||
if (isValid())
|
if (isValid())
|
||||||
{
|
{
|
||||||
// Todo - avoid static enlarge for every types
|
// Todo - avoid static enlarge for every types
|
||||||
for (int i=aJson.getArraySize(itemArr);i<4;i++) aJson.addItemToArray(itemArr,aJson.createItem(int(0))); //Enlarge item to 4 elements. VAL=int if no other definition in conf
|
for (int i=aJson.getArraySize(itemArr);i<4;i++) aJson.addItemToArray(itemArr,aJson.createItem(int(defval[i]))); //Enlarge item to 4 elements. VAL=int if no other definition in conf
|
||||||
|
|
||||||
|
|
||||||
itemType = aJson.getArrayItem(itemArr,I_TYPE)->valueint;
|
itemType = aJson.getArrayItem(itemArr,I_TYPE)->valueint;
|
||||||
@@ -66,11 +70,20 @@ Item::Item(char * name) //Constructor
|
|||||||
|
|
||||||
|
|
||||||
Serial.print(F(" Item:"));
|
Serial.print(F(" Item:"));
|
||||||
Serial.println(name);
|
Serial.print(itemArr->name);Serial.print(F(" T:"));
|
||||||
Serial.print(itemType);Serial.print(":");Serial.println(getArg());
|
Serial.print(itemType);Serial.print(" =");Serial.println(getArg());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Item::Item(char * name) //Constructor
|
||||||
|
{
|
||||||
|
if (name)
|
||||||
|
itemArr= aJson.getObjectItem(items, name);
|
||||||
|
else itemArr=NULL;
|
||||||
|
|
||||||
|
Parse();
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t Item::getCmd()
|
uint8_t Item::getCmd()
|
||||||
{
|
{
|
||||||
aJsonObject *t = aJson.getArrayItem(itemArr,I_CMD);
|
aJsonObject *t = aJson.getArrayItem(itemArr,I_CMD);
|
||||||
@@ -87,10 +100,10 @@ void Item::setCmd(uint8_t cmd)
|
|||||||
t->valueint=cmd;
|
t->valueint=cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Item::getArg() //Return arg int or first array element if Arg is array
|
int Item::getArg(short n) //Return arg int or first array element if Arg is array
|
||||||
{ if (!itemArg) return -1;
|
{ if (!itemArg) return -1;
|
||||||
if (itemArg->type==aJson_Int) return itemArg->valueint;
|
if (itemArg->type==aJson_Int) return itemArg->valueint;
|
||||||
else if (itemArg->type==aJson_Array) return aJson.getArrayItem(itemArg,0)->valueint;
|
else if (itemArg->type==aJson_Array) return aJson.getArrayItem(itemArg,n)->valueint;
|
||||||
else return -2;
|
else return -2;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@@ -168,17 +181,15 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
|||||||
|
|
||||||
int iaddr=getArg();
|
int iaddr=getArg();
|
||||||
HSVstore st;
|
HSVstore st;
|
||||||
|
|
||||||
|
|
||||||
//Store Parameter(s) into json VAL
|
//Store Parameter(s) into json VAL
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
|
int t;
|
||||||
case CMD_TOGGLE:
|
case CMD_TOGGLE:
|
||||||
switch (getCmd())
|
switch (t=getCmd())
|
||||||
{
|
{
|
||||||
case CMD_ON:
|
case CMD_ON:
|
||||||
case CMD_SET:
|
case CMD_SET:
|
||||||
@@ -186,19 +197,24 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
|||||||
break;
|
break;
|
||||||
case CMD_OFF:
|
case CMD_OFF:
|
||||||
case CMD_HALT:
|
case CMD_HALT:
|
||||||
|
case 0:
|
||||||
|
case -1: //No stored command yet
|
||||||
cmd=CMD_ON;
|
cmd=CMD_ON;
|
||||||
break;
|
break;
|
||||||
}//switch old cmd
|
}//switch old cmd
|
||||||
|
//Serial.print("Tog/oldcmd:");Serial.print(t);Serial.print(" new ");Serial.println(cmd);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_RESTORE:
|
case CMD_RESTORE:
|
||||||
if (itemType!=CH_GROUP) //individual threating of channels
|
if (itemType!=CH_GROUP) //individual threating of channels. Ignore restore command for groups
|
||||||
switch (getCmd())
|
switch (t=getCmd())
|
||||||
{ case CMD_HALT:
|
{
|
||||||
// Serial.print("LastCmd:");Serial.println(t);
|
case CMD_HALT: //previous command was HALT ?
|
||||||
cmd=CMD_ON;
|
Serial.print("Restored from:");Serial.println(t);
|
||||||
|
cmd=CMD_ON; //turning on
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
return -3;
|
||||||
}//switch old cmd
|
}//switch old cmd
|
||||||
} //switch cmd
|
} //switch cmd
|
||||||
|
|
||||||
@@ -210,8 +226,11 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
|||||||
|
|
||||||
switch (itemType)
|
switch (itemType)
|
||||||
{
|
{
|
||||||
case CH_GROUP:
|
|
||||||
case CH_RGBW: //only if configured VAL array
|
case CH_RGBW: //only if configured VAL array
|
||||||
|
if (!Par[1]) itemType=CH_WHITE;
|
||||||
|
case CH_GROUP: //Save for groups as well
|
||||||
|
case CH_RGB:
|
||||||
st.h=Par[0];
|
st.h=Par[0];
|
||||||
st.s=Par[1];
|
st.s=Par[1];
|
||||||
st.v=Par[2];
|
st.v=Par[2];
|
||||||
@@ -232,18 +251,54 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_ON: //retrive stored values
|
case CMD_ON:
|
||||||
if (getCmd()!=CMD_ON)
|
if (getCmd()!=CMD_ON)
|
||||||
|
|
||||||
{
|
{
|
||||||
st.aslong=getVal();//Serial.print("Returned getVal: ");Serial.println(st.aslong);
|
short params=0;
|
||||||
if (st.aslong>=0)
|
//retrive stored values
|
||||||
|
st.aslong=getVal();
|
||||||
|
if (st.aslong>0) //Stored smthng
|
||||||
|
|
||||||
|
switch (itemType)
|
||||||
{
|
{
|
||||||
|
//case CH_GROUP:
|
||||||
|
case CH_RGBW:
|
||||||
|
case CH_RGB:
|
||||||
Par[0]=st.h;
|
Par[0]=st.h;
|
||||||
Par[1]=st.s;
|
Par[1]=st.s;
|
||||||
Par[2]=st.v;
|
Par[2]=st.v;
|
||||||
|
params=3;
|
||||||
|
SendCmd(0,params,Par); // Send restored triplet
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CH_DIMMER: //Everywhere, in flat VAL
|
||||||
|
case CH_MODBUS:
|
||||||
|
case CH_VC:
|
||||||
|
case CH_VCTEMP:
|
||||||
|
Par[0]=st.aslong;
|
||||||
|
params=1;
|
||||||
|
SendCmd(0,params,Par); // Send restored parameter
|
||||||
|
break;
|
||||||
|
case CH_THERMO:
|
||||||
|
Par[0]=st.aslong;
|
||||||
|
params=0;
|
||||||
|
SendCmd(CMD_ON); // Just ON (switch)
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
SendCmd(cmd); // Just send ON
|
||||||
|
}//itemtype
|
||||||
|
else
|
||||||
|
{// Default settings
|
||||||
|
Serial.print(st.aslong);
|
||||||
|
Serial.println(F(": No stored values - default"));
|
||||||
|
Par[0]=100;
|
||||||
|
Par[1]=0;
|
||||||
|
Par[2]=100;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (short i=0;i<3 ;i++)
|
|
||||||
|
for (short i=0;i<params ;i++)
|
||||||
{
|
{
|
||||||
Serial.print(F("Restored: "));Serial.print(i);Serial.print("=");Serial.println(Par[i]);
|
Serial.print(F("Restored: "));Serial.print(i);Serial.print("=");Serial.println(Par[i]);
|
||||||
}
|
}
|
||||||
@@ -252,48 +307,55 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
|||||||
setCmd(cmd);
|
setCmd(cmd);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ //Double ON - apply special preset
|
{ //Double ON - apply special preset - clean white full power
|
||||||
switch (itemType)
|
switch (itemType)
|
||||||
{
|
{
|
||||||
case CH_RGBW:
|
case CH_RGBW:
|
||||||
Serial.println(F("White: "));
|
Serial.println(F("Force White"));
|
||||||
itemType=CH_WHITE;
|
itemType=CH_WHITE;
|
||||||
// Par[2]=getVal(2);
|
Par[1]=0; //Zero saturation
|
||||||
// if (Par[2]<0)
|
Par[2]=100; //Full power
|
||||||
Par[2]=100;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Store
|
||||||
|
st.h=Par[0];
|
||||||
|
st.s=Par[1];
|
||||||
|
st.v=Par[2];
|
||||||
|
setVal(st.aslong);
|
||||||
|
|
||||||
|
//Send to OH
|
||||||
|
SendCmd(0,3,Par);
|
||||||
break;
|
break;
|
||||||
|
} //itemtype
|
||||||
|
} //else
|
||||||
|
|
||||||
|
//Serial.print("Sa:");Serial.println(Par[1]);
|
||||||
|
if ((itemType==CH_RGBW) && (Par[1]==0)) itemType=CH_WHITE;
|
||||||
|
|
||||||
|
|
||||||
|
break; //CMD_ON
|
||||||
|
|
||||||
case CMD_OFF:
|
case CMD_OFF:
|
||||||
|
|
||||||
Par[0]=0;Par[1]=0;Par[2]=0;
|
Par[0]=0;Par[1]=0;Par[2]=0;
|
||||||
setCmd(cmd);
|
setCmd(cmd);
|
||||||
|
SendCmd(cmd);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_HALT:
|
case CMD_HALT:
|
||||||
if (getCmd()!=CMD_OFF)
|
|
||||||
|
if (isActive()>0)
|
||||||
{
|
{
|
||||||
Par[0]=0;Par[1]=0;Par[2]=0;
|
Par[0]=0;Par[1]=0;Par[2]=0;
|
||||||
setCmd(cmd);
|
setCmd(cmd);
|
||||||
Serial.print(itemType);Serial.println(" Halted");
|
SendCmd(CMD_OFF);
|
||||||
|
Serial.println(" Halted");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}//switch cmd
|
}//switch cmd
|
||||||
|
|
||||||
/*
|
|
||||||
Serial.print("go: ");
|
|
||||||
for (short i=0;i<3 ;i++)
|
|
||||||
{
|
|
||||||
Serial.print(i);Serial.print("=");Serial.println(Par[i]);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (send) SendCmd(cmd,n,Par);
|
|
||||||
|
|
||||||
switch (itemType)
|
switch (itemType)
|
||||||
{
|
{
|
||||||
@@ -339,7 +401,7 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
|||||||
int _reg = aJson.getArrayItem(itemArg,1)->valueint;
|
int _reg = aJson.getArrayItem(itemArg,1)->valueint;
|
||||||
int _mask= aJson.getArrayItem(itemArg,2)->valueint;
|
int _mask= aJson.getArrayItem(itemArg,2)->valueint;
|
||||||
|
|
||||||
modbusSet(_addr,_reg,_mask,map(Par[0],0,100,0,0x1f));
|
modbusSet(_addr,_reg,_mask,map(Par[0],0,100,0,0x3f));
|
||||||
}
|
}
|
||||||
break;}
|
break;}
|
||||||
|
|
||||||
@@ -353,7 +415,7 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
|||||||
{
|
{
|
||||||
Item it (i->valuestring);
|
Item it (i->valuestring);
|
||||||
// it.copyPar(itemVal);
|
// it.copyPar(itemVal);
|
||||||
it.Ctrl(cmd,n,Par,true);
|
it.Ctrl(cmd,n,Par,send); //// was true
|
||||||
i=i->next;
|
i=i->next;
|
||||||
} //while
|
} //while
|
||||||
} //if
|
} //if
|
||||||
@@ -434,7 +496,7 @@ if (items)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
void PooledItem::Idle()
|
void PooledItem::Idle()
|
||||||
{
|
{
|
||||||
if (PoolingInterval)
|
if (PoolingInterval)
|
||||||
@@ -448,7 +510,7 @@ if (PoolingInterval)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
addr 10d
|
addr 10d
|
||||||
Снять аварию 42001 (2001=7d1) =>4
|
Снять аварию 42001 (2001=7d1) =>4
|
||||||
|
|
||||||
@@ -481,12 +543,7 @@ POOL 2101x10
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int Item::Pool()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
extern short modbusBusy;
|
|
||||||
extern ModbusMaster node;
|
extern ModbusMaster node;
|
||||||
|
|
||||||
int Item::VacomSetFan (int addr, int8_t val)
|
int Item::VacomSetFan (int addr, int8_t val)
|
||||||
@@ -541,8 +598,8 @@ int Item::VacomSetHeat(int addr, int8_t val, int8_t cmd)
|
|||||||
int Item::SendCmd(short cmd,short n, int * Par)
|
int Item::SendCmd(short cmd,short n, int * Par)
|
||||||
{
|
{
|
||||||
char addrstr[32];
|
char addrstr[32];
|
||||||
char addrbuf[17];
|
//char addrbuf[17];
|
||||||
char valstr[16];
|
char valstr[16]="";
|
||||||
|
|
||||||
strcpy_P (addrstr,outprefix);
|
strcpy_P (addrstr,outprefix);
|
||||||
strncat (addrstr,itemArr->name,sizeof(addrstr)); ////
|
strncat (addrstr,itemArr->name,sizeof(addrstr)); ////
|
||||||
@@ -558,9 +615,21 @@ int Item::SendCmd(short cmd,short n, int * Par)
|
|||||||
strcpy(valstr,"OFF");
|
strcpy(valstr,"OFF");
|
||||||
break;
|
break;
|
||||||
// TODO send Par
|
// TODO send Par
|
||||||
//case 0:
|
case 0:
|
||||||
//case CMD_SET:
|
case CMD_SET:
|
||||||
///////////sprintf(valstr,"%d",Par[0]);
|
if (Par)
|
||||||
|
for (short i=0;i<n;i++)
|
||||||
|
{
|
||||||
|
char num [4];
|
||||||
|
snprintf(num,sizeof(num),"%d",Par[i]);
|
||||||
|
strncat(valstr,num,sizeof(valstr));
|
||||||
|
if (i!=n-1)
|
||||||
|
{
|
||||||
|
strcpy(num,",");
|
||||||
|
strncat(valstr,num,sizeof(valstr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -570,4 +639,161 @@ int Item::SendCmd(short cmd,short n, int * Par)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Item::isActive()
|
||||||
|
{
|
||||||
|
HSVstore st;
|
||||||
|
int val=0;
|
||||||
|
|
||||||
|
if (!isValid()) return -1;
|
||||||
|
//Serial.print(itemArr->name);
|
||||||
|
int cmd=getCmd();
|
||||||
|
switch (cmd)
|
||||||
|
{
|
||||||
|
case CMD_ON:
|
||||||
|
//Serial.println(" active");
|
||||||
|
return 1;
|
||||||
|
case CMD_OFF:
|
||||||
|
case CMD_HALT:
|
||||||
|
//Serial.println(" inactive");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
st.aslong=getVal();
|
||||||
|
|
||||||
|
switch (itemType)
|
||||||
|
{
|
||||||
|
//case CH_GROUP:
|
||||||
|
case CH_RGBW:
|
||||||
|
case CH_RGB:
|
||||||
|
|
||||||
|
val=st.v;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CH_DIMMER: //Everywhere, in flat VAL
|
||||||
|
case CH_MODBUS:
|
||||||
|
case CH_THERMO:
|
||||||
|
case CH_VC:
|
||||||
|
case CH_VCTEMP:
|
||||||
|
val=st.aslong;
|
||||||
|
} //switch
|
||||||
|
Serial.print(":=");Serial.println(val);
|
||||||
|
if (val) return 1; else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int modbusSet(int addr, uint16_t _reg, int _mask, uint16_t value)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (modbusBusy) return -1;
|
||||||
|
modbusBusy=1;
|
||||||
|
node.begin(9600,SERIAL_8E1,13);
|
||||||
|
node.setSlave(addr);
|
||||||
|
|
||||||
|
if (_mask)
|
||||||
|
{value <<= 8; value |= (0xff);}
|
||||||
|
else {value &= 0xff; value |= (0xff00);}
|
||||||
|
|
||||||
|
Serial.print(addr);Serial.print("=>");Serial.print(_reg,HEX);Serial.print(":");Serial.println(value,HEX);
|
||||||
|
|
||||||
|
node.writeSingleRegister(_reg,value);
|
||||||
|
modbusBusy=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int Item::checkFM()
|
||||||
|
{
|
||||||
|
if (modbusBusy) return -1;
|
||||||
|
modbusBusy=1;
|
||||||
|
|
||||||
|
uint8_t j, result;
|
||||||
|
uint16_t data[1];
|
||||||
|
node.begin(9600,SERIAL_8N1,13);
|
||||||
|
|
||||||
|
node.setSlave(getArg());
|
||||||
|
|
||||||
|
result = node.readHoldingRegisters(2101-1, 10);
|
||||||
|
|
||||||
|
// do something with data if read is successful
|
||||||
|
if (result == node.ku8MBSuccess)
|
||||||
|
{ Serial.print(F(" FM Val :"));
|
||||||
|
for (j = 0; j < 10; j++)
|
||||||
|
{
|
||||||
|
data[j] = node.getResponseBuffer(j);
|
||||||
|
Serial.print(data[j],HEX);Serial.print("-");
|
||||||
|
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
} else {Serial.print(F("Modbus pooling error=")); Serial.println(result,HEX); }
|
||||||
|
|
||||||
|
result = node.readHoldingRegisters(20-1, 4);
|
||||||
|
|
||||||
|
// do something with data if read is successful
|
||||||
|
if (result == node.ku8MBSuccess)
|
||||||
|
{ Serial.print(F(" PI Val :"));
|
||||||
|
for (j = 0; j < 4; j++)
|
||||||
|
{
|
||||||
|
data[j] = node.getResponseBuffer(j);
|
||||||
|
Serial.print(data[j]);Serial.print("-");
|
||||||
|
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
} else {Serial.print(F("Modbus pooling error=")); Serial.println(result,HEX); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
modbusBusy=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int Item::checkModbus()
|
||||||
|
{
|
||||||
|
if (modbusBusy) return -1;
|
||||||
|
modbusBusy=1;
|
||||||
|
node.begin(9600,SERIAL_8E1,13);
|
||||||
|
|
||||||
|
uint8_t result;
|
||||||
|
int data;
|
||||||
|
|
||||||
|
node.setSlave(getArg());
|
||||||
|
result = node.readHoldingRegisters(0, 1);
|
||||||
|
|
||||||
|
// do something with data if read is successful
|
||||||
|
if (result == node.ku8MBSuccess)
|
||||||
|
{
|
||||||
|
|
||||||
|
data=node.getResponseBuffer(0);
|
||||||
|
Serial.print(F("Modbus Val: ")); Serial.println(data,HEX);
|
||||||
|
if (getArg(2)) data>>=8; data&=0xff;
|
||||||
|
data=map(data,0,0x3f,0,100);
|
||||||
|
|
||||||
|
if (getVal()!=data)
|
||||||
|
{
|
||||||
|
SendCmd(0,1,&data); //update OH
|
||||||
|
|
||||||
|
switch (getCmd()) //Save value if not turned off
|
||||||
|
{case CMD_OFF:
|
||||||
|
case CMD_HALT:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
setVal(data);
|
||||||
|
} //switch
|
||||||
|
} //if data changed
|
||||||
|
|
||||||
|
} else {Serial.print(F("Modbus pooling error=")); Serial.println(result,HEX); }
|
||||||
|
|
||||||
|
modbusBusy=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Item::Pool()
|
||||||
|
{
|
||||||
|
switch (itemType)
|
||||||
|
{
|
||||||
|
case CH_MODBUS:
|
||||||
|
checkModbus();
|
||||||
|
break;
|
||||||
|
case CH_VC:
|
||||||
|
checkFM();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
10
item.h
10
item.h
@@ -69,9 +69,10 @@ class Item
|
|||||||
|
|
||||||
|
|
||||||
Item(char * name);
|
Item(char * name);
|
||||||
|
Item(aJsonObject * obj);
|
||||||
boolean isValid ();
|
boolean isValid ();
|
||||||
virtual int Ctrl(short cmd, short n=0, int * Par=NULL, boolean send=false);
|
virtual int Ctrl(short cmd, short n=0, int * Par=NULL, boolean send=false);
|
||||||
int getArg();
|
int getArg(short n=0);
|
||||||
boolean getEnableCMD(int delta);
|
boolean getEnableCMD(int delta);
|
||||||
//int getVal(short n); //From VAL array. Negative if no array
|
//int getVal(short n); //From VAL array. Negative if no array
|
||||||
long int getVal(); //From int val OR array
|
long int getVal(); //From int val OR array
|
||||||
@@ -89,10 +90,15 @@ class Item
|
|||||||
protected:
|
protected:
|
||||||
int VacomSetFan (int addr, int8_t val);
|
int VacomSetFan (int addr, int8_t val);
|
||||||
int VacomSetHeat(int addr, int8_t val, int8_t cmd=0);
|
int VacomSetHeat(int addr, int8_t val, int8_t cmd=0);
|
||||||
|
int isActive();
|
||||||
|
void Parse();
|
||||||
|
int checkModbus();
|
||||||
|
int checkFM();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
class PooledItem : public Item
|
class PooledItem : public Item
|
||||||
{
|
{
|
||||||
@@ -108,7 +114,7 @@ class PooledItem : public Item
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
class Vacon : public Item
|
class Vacon : public Item
|
||||||
{
|
{
|
||||||
|
|||||||
304
lighthub.ino
304
lighthub.ino
@@ -36,31 +36,20 @@ e-mail anklimov@gmail.com
|
|||||||
|
|
||||||
Todo
|
Todo
|
||||||
===
|
===
|
||||||
A/C control
|
A/C control/Dimmer ?
|
||||||
rotary encoder local ctrl
|
rotary encoder local ctrl
|
||||||
analog in local ctrl
|
analog in local ctrl
|
||||||
Light sensor analog in
|
|
||||||
Smooth regulation/fading
|
Smooth regulation/fading
|
||||||
Phase dimmer board
|
|
||||||
PID Termostat out
|
PID Termostat out
|
||||||
dmx relay out
|
dmx relay out
|
||||||
-IRDA in
|
|
||||||
-MCS 350 out ?
|
|
||||||
-HDMI sw out?
|
|
||||||
Simple bridging (1w <-> dmx,modbus etc) ?
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//define NOETHER
|
//define NOETHER
|
||||||
|
|
||||||
|
|
||||||
//#include <lib_dmx.h>
|
|
||||||
#include <Ethernet.h>
|
#include <Ethernet.h>
|
||||||
#include <PubSubClient2.h>
|
#include <PubSubClient2.h>
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
|
|
||||||
//#include "owSwitch.h"
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "owTerm.h"
|
#include "owTerm.h"
|
||||||
|
|
||||||
@@ -68,22 +57,30 @@ Simple bridging (1w <-> dmx,modbus etc) ?
|
|||||||
//#include "pixeltypes.h"
|
//#include "pixeltypes.h"
|
||||||
//#include "hsv2rgb.h"
|
//#include "hsv2rgb.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
//#include <DMXSerial.h>
|
|
||||||
#include <ModbusMaster.h>
|
#include <ModbusMaster.h>
|
||||||
#include "aJSON.h"
|
#include "aJSON.h"
|
||||||
#include "HTTPClient.h"
|
#include "HTTPClient.h"
|
||||||
//#include "CommandLine.h"
|
|
||||||
#include <Cmd.h>
|
#include <Cmd.h>
|
||||||
#include "stdarg.h"
|
#include "stdarg.h"
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
//#include <Artnet.h>
|
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
#include "dmx.h"
|
#include "dmx.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "inputs.h"
|
#include "inputs.h"
|
||||||
#include <avr/wdt.h>
|
#include <avr/wdt.h>
|
||||||
|
|
||||||
|
// Hardcoded definitions
|
||||||
|
#define GIST 2
|
||||||
|
#define serverip "192.168.88.2"
|
||||||
|
IPAddress server(192, 168, 88, 2); //TODO - configure it
|
||||||
|
//char* inprefix=("/myhome/in/");
|
||||||
|
//char* outprefix=("/myhome/s_out/");
|
||||||
|
//char* subprefix=("/myhome/in/#");
|
||||||
|
|
||||||
|
#define inprefix "/myhome/in/"
|
||||||
|
const char outprefix[] PROGMEM = "/myhome/s_out/";
|
||||||
|
#define subprefix "/myhome/in/#"
|
||||||
|
//
|
||||||
|
|
||||||
aJsonObject *root = NULL;
|
aJsonObject *root = NULL;
|
||||||
aJsonObject *items = NULL;
|
aJsonObject *items = NULL;
|
||||||
@@ -93,6 +90,13 @@ aJsonObject *mqttArr = NULL;
|
|||||||
aJsonObject *modbusArr = NULL;
|
aJsonObject *modbusArr = NULL;
|
||||||
aJsonObject *owArr = NULL;
|
aJsonObject *owArr = NULL;
|
||||||
|
|
||||||
|
unsigned long modbuscheck=0;
|
||||||
|
unsigned long incheck =0;
|
||||||
|
unsigned long lanCheck =0;
|
||||||
|
unsigned long thermocheck=0;
|
||||||
|
|
||||||
|
aJsonObject * modbusitem= NULL;
|
||||||
|
|
||||||
|
|
||||||
// CommandLine instance.
|
// CommandLine instance.
|
||||||
//CommandLine commandLine(Serial, "> ");
|
//CommandLine commandLine(Serial, "> ");
|
||||||
@@ -104,39 +108,16 @@ int lanStatus = 0;
|
|||||||
ModbusMaster node(2,0x60); //TODO dynamic alloc
|
ModbusMaster node(2,0x60); //TODO dynamic alloc
|
||||||
|
|
||||||
|
|
||||||
IPAddress server(192, 168, 88, 2);
|
|
||||||
byte mac[6];
|
byte mac[6];
|
||||||
|
|
||||||
EthernetClient ethClient;
|
EthernetClient ethClient;
|
||||||
PubSubClient client(ethClient);
|
PubSubClient client(ethClient);
|
||||||
|
|
||||||
|
|
||||||
//char* inprefix=("/myhome/in/");
|
|
||||||
//char* outprefix=("/myhome/s_out/");
|
|
||||||
//char* subprefix=("/myhome/in/#");
|
|
||||||
|
|
||||||
#define inprefix "/myhome/in/"
|
|
||||||
const char outprefix[] PROGMEM = "/myhome/s_out/";
|
|
||||||
#define subprefix "/myhome/in/#"
|
|
||||||
//#define subprefix "#"
|
|
||||||
|
|
||||||
int modbusSet(int addr, uint16_t _reg, int _mask, uint16_t value);
|
int modbusSet(int addr, uint16_t _reg, int _mask, uint16_t value);
|
||||||
int freeRam (void) ;
|
int freeRam (void) ;
|
||||||
|
|
||||||
int getInt(char ** chan)
|
|
||||||
{
|
|
||||||
int ch = atoi(*chan);
|
|
||||||
*chan=strchr(*chan,',');
|
|
||||||
|
|
||||||
if (*chan) *chan+=1;
|
|
||||||
//Serial.print(F("Par:")); Serial.println(ch);
|
|
||||||
return ch;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////
|
|
||||||
int itemCtrl2(char* name,int r,int g, int b, int w)
|
int itemCtrl2(char* name,int r,int g, int b, int w)
|
||||||
{
|
{
|
||||||
aJsonObject *itemArr= aJson.getObjectItem(items, name);
|
aJsonObject *itemArr= aJson.getObjectItem(items, name);
|
||||||
@@ -199,14 +180,6 @@ void callback(char* topic, byte* payload, unsigned int length) {
|
|||||||
// short outtopic = strncmp(topic,F(outprefix),strlen(outprefix));
|
// short outtopic = strncmp(topic,F(outprefix),strlen(outprefix));
|
||||||
|
|
||||||
cmd= txt2cmd((char*) payload);
|
cmd= txt2cmd((char*) payload);
|
||||||
/*
|
|
||||||
// Check for command
|
|
||||||
if (strcmp((char*)payload,"ON")==0) cmd=CMD_ON;
|
|
||||||
else if (strcmp((char*)payload,"OFF")==0) cmd=CMD_OFF;
|
|
||||||
else if (strcmp((char*)payload,"RESTORE")==0) cmd=CMD_RESTORE;
|
|
||||||
else if (strcmp((char*)payload,"TOGGLE")==0) cmd=CMD_TOGGLE;
|
|
||||||
//Serial.print("Cmd:");Serial.println(cmd);
|
|
||||||
*/
|
|
||||||
char * t;
|
char * t;
|
||||||
if (t=strrchr (topic,'/')) strncpy(subtopic,t+1 , 20);
|
if (t=strrchr (topic,'/')) strncpy(subtopic,t+1 , 20);
|
||||||
|
|
||||||
@@ -279,10 +252,10 @@ void restoreState()
|
|||||||
client.publish("/myhome/out/RestoreState","ON");
|
client.publish("/myhome/out/RestoreState","ON");
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned long lanCheck=0;
|
|
||||||
|
|
||||||
int getConfig (int arg_cnt, char **args);
|
int getConfig (int arg_cnt, char **args);
|
||||||
int lanloop() {
|
int lanLoop() {
|
||||||
static short _once=1;
|
static short _once=1;
|
||||||
|
|
||||||
#ifdef NOETHER
|
#ifdef NOETHER
|
||||||
@@ -489,7 +462,7 @@ void Changed (int i, DeviceAddress addr, int val)
|
|||||||
|
|
||||||
if (owItem)
|
if (owItem)
|
||||||
{
|
{
|
||||||
thermoSetCurTemp(owItem,val);
|
thermoSetCurTemp(owItem,val); ///TODO: Refactore using Items interface
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -540,6 +513,7 @@ void parseConfig()
|
|||||||
}
|
}
|
||||||
|
|
||||||
items = aJson.getObjectItem(root,"items");
|
items = aJson.getObjectItem(root,"items");
|
||||||
|
modbusitem = items->child;
|
||||||
inputs = aJson.getObjectItem(root,"in");
|
inputs = aJson.getObjectItem(root,"in");
|
||||||
|
|
||||||
modbusArr= aJson.getObjectItem(root, "modbus");
|
modbusArr= aJson.getObjectItem(root, "modbus");
|
||||||
@@ -688,7 +662,7 @@ int getConfig (int arg_cnt, char **args)
|
|||||||
snprintf(URI, sizeof(URI), "/%02x-%02x-%02x-%02x-%02x-%02x.config.json",mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
snprintf(URI, sizeof(URI), "/%02x-%02x-%02x-%02x-%02x-%02x.config.json",mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
Serial.println(F("Config URI: "));Serial.println(URI);
|
Serial.println(F("Config URI: "));Serial.println(URI);
|
||||||
|
|
||||||
HTTPClient hclient("192.168.88.2",hserver,80);
|
HTTPClient hclient(serverip,hserver,80);
|
||||||
|
|
||||||
// FILE is the return STREAM type of the HTTPClient
|
// FILE is the return STREAM type of the HTTPClient
|
||||||
result = hclient.getURI( URI);
|
result = hclient.getURI( URI);
|
||||||
@@ -746,7 +720,7 @@ void setup() {
|
|||||||
//Serial.begin(115200);
|
//Serial.begin(115200);
|
||||||
cmdInit(115200);
|
cmdInit(115200);
|
||||||
|
|
||||||
Serial.println(F("\nLazyhome.ru LightHub controller v0.8"));
|
Serial.println(F("\nLazyhome.ru LightHub controller v0.9"));
|
||||||
|
|
||||||
|
|
||||||
for (short i=0;i<6;i++) mac[i]=EEPROM.read(i);
|
for (short i=0;i<6;i++) mac[i]=EEPROM.read(i);
|
||||||
@@ -783,117 +757,11 @@ void setup() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
unsigned long modbus_check=0;
|
//unsigned long modbus_check=0;
|
||||||
short modbusBusy=0;
|
|
||||||
|
|
||||||
int modbusSet(int addr, uint16_t _reg, int _mask, uint16_t value)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (modbusBusy) return -1;
|
|
||||||
modbusBusy=1;
|
|
||||||
node.begin(9600,SERIAL_8E1,13);
|
|
||||||
node.setSlave(addr);
|
|
||||||
/*
|
/*
|
||||||
uint8_t res = node.readHoldingRegisters(_reg, 1);
|
|
||||||
if (res != node.ku8MBSuccess) return -1;
|
|
||||||
uint16_t b0=node.getResponseBuffer(0);
|
|
||||||
//uint8_t b1=node.getResponseBuffer(1);
|
|
||||||
//Serial.print(b0,HEX);Serial.println(b1,HEX);
|
|
||||||
delay(5);
|
|
||||||
|
|
||||||
|
|
||||||
if (_mask)
|
|
||||||
{value <<= 8; value |= (b0 & 0xff);}
|
|
||||||
else {value &= 0xff; value |= (b0 & 0xff00);}
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (_mask)
|
|
||||||
{value <<= 8; value |= (0xff);}
|
|
||||||
else {value &= 0xff; value |= (0xff00);}
|
|
||||||
|
|
||||||
Serial.print(addr);Serial.print("=>");Serial.print(_reg,HEX);Serial.print(":");Serial.println(value,HEX);
|
|
||||||
|
|
||||||
node.writeSingleRegister(_reg,value);
|
|
||||||
modbusBusy=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int checkFMDev(int dev)
|
|
||||||
{
|
|
||||||
if (modbusBusy) return -1;
|
|
||||||
modbusBusy=1;
|
|
||||||
|
|
||||||
uint8_t j, result;
|
|
||||||
uint16_t data[1];
|
|
||||||
node.begin(9600,SERIAL_8N1,13);
|
|
||||||
|
|
||||||
node.setSlave(dev);
|
|
||||||
|
|
||||||
result = node.readHoldingRegisters(2101-1, 10);
|
|
||||||
|
|
||||||
// do something with data if read is successful
|
|
||||||
if (result == node.ku8MBSuccess)
|
|
||||||
{ Serial.print(F(" FM Val :"));
|
|
||||||
for (j = 0; j < 10; j++)
|
|
||||||
{
|
|
||||||
data[j] = node.getResponseBuffer(j);
|
|
||||||
Serial.print(data[j],HEX);Serial.print("-");
|
|
||||||
|
|
||||||
}
|
|
||||||
Serial.println();
|
|
||||||
} else {Serial.print(F("Modbus pooling error=")); Serial.println(result,HEX); }
|
|
||||||
|
|
||||||
result = node.readHoldingRegisters(20-1, 4);
|
|
||||||
|
|
||||||
// do something with data if read is successful
|
|
||||||
if (result == node.ku8MBSuccess)
|
|
||||||
{ Serial.print(F(" PI Val :"));
|
|
||||||
for (j = 0; j < 4; j++)
|
|
||||||
{
|
|
||||||
data[j] = node.getResponseBuffer(j);
|
|
||||||
Serial.print(data[j]);Serial.print("-");
|
|
||||||
|
|
||||||
}
|
|
||||||
Serial.println();
|
|
||||||
} else {Serial.print(F("Modbus pooling error=")); Serial.println(result,HEX); }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
modbusBusy=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int checkDev(int dev)
|
|
||||||
{
|
|
||||||
if (modbusBusy) return -1;
|
|
||||||
modbusBusy=1;
|
|
||||||
node.begin(9600,SERIAL_8E1,13);
|
|
||||||
|
|
||||||
uint8_t j, result;
|
|
||||||
uint16_t data[1];
|
|
||||||
|
|
||||||
node.setSlave(dev);
|
|
||||||
result = node.readHoldingRegisters(0, 1);
|
|
||||||
|
|
||||||
// do something with data if read is successful
|
|
||||||
if (result == node.ku8MBSuccess)
|
|
||||||
{ Serial.print(F(" Modbus Val :"));
|
|
||||||
for (j = 0; j < 1; j++)
|
|
||||||
{
|
|
||||||
data[j] = node.getResponseBuffer(j);
|
|
||||||
Serial.print(data[j],HEX);Serial.print("-");
|
|
||||||
|
|
||||||
}
|
|
||||||
Serial.println();
|
|
||||||
} else {Serial.print(F("Modbus pooling error=")); Serial.println(result,HEX); }
|
|
||||||
|
|
||||||
modbusBusy=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void modbusloop()
|
void modbusloop()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -910,29 +778,27 @@ void modbusloop()
|
|||||||
Serial.println(freeRam());
|
Serial.println(freeRam());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
wdt_reset();
|
wdt_reset();
|
||||||
|
|
||||||
//commandLine.update();
|
//commandLine.update();
|
||||||
cmdPoll();
|
cmdPoll();
|
||||||
if (lanloop() >1) {client.loop(); if (artnet) artnet->read();}
|
if (lanLoop() >1) {client.loop(); if (artnet) artnet->read();}
|
||||||
if (owReady && owArr) owLoop();
|
if (owReady && owArr) owLoop();
|
||||||
|
|
||||||
unsigned long lastpacket = DMXSerial.noDataSince();
|
unsigned long lastpacket = DMXSerial.noDataSince();
|
||||||
// if (lastpacket && (lastpacket%10==0)) Serial.println(lastpacket);
|
// if (lastpacket && (lastpacket%10==0)) Serial.println(lastpacket);
|
||||||
|
|
||||||
DMXCheck();
|
DMXCheck();
|
||||||
if (modbusArr) modbusloop();
|
if (modbusArr && items) modbusLoop();
|
||||||
if (items) thermoIdle();
|
if (items) thermoLoop();
|
||||||
if (inputs) inputIdle();
|
if (inputs) inputLoop();
|
||||||
|
|
||||||
}
|
}
|
||||||
//int imodbus=0;
|
|
||||||
//unsigned short modbuspoll[]={0x60,0x61};
|
|
||||||
|
|
||||||
|
|
||||||
|
// Idle handlers
|
||||||
void owIdle(void)
|
void owIdle(void)
|
||||||
{ if (artnet) artnet->read();
|
{ if (artnet) artnet->read();
|
||||||
wdt_reset();
|
wdt_reset();
|
||||||
@@ -940,10 +806,10 @@ void owIdle(void)
|
|||||||
return;///
|
return;///
|
||||||
Serial.print("o");
|
Serial.print("o");
|
||||||
|
|
||||||
if (lanloop() == 1) client.loop();
|
if (lanLoop() == 1) client.loop();
|
||||||
//if (owReady) owLoop();
|
//if (owReady) owLoop();
|
||||||
DMXCheck();
|
DMXCheck();
|
||||||
//modbusloop();
|
//modbusLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -952,17 +818,79 @@ void modbusIdle(void)
|
|||||||
//Serial.print("m");
|
//Serial.print("m");
|
||||||
wdt_reset();
|
wdt_reset();
|
||||||
|
|
||||||
if (lanloop() > 1) {client.loop();if (artnet) artnet->read();}
|
if (lanLoop() > 1) {client.loop();if (artnet) artnet->read();}
|
||||||
//if (owReady) owLoop();
|
//if (owReady) owLoop();
|
||||||
DMXCheck();
|
DMXCheck();
|
||||||
//modbusloop();
|
//modbusloop();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GIST 2
|
|
||||||
unsigned long thermocheck=0;
|
|
||||||
|
|
||||||
|
|
||||||
void thermoIdle(void)
|
// Loops
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void inputLoop(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (millis()>incheck)
|
||||||
|
{
|
||||||
|
|
||||||
|
aJsonObject * input= inputs->child;
|
||||||
|
|
||||||
|
while (input)
|
||||||
|
{
|
||||||
|
if ((input->type==aJson_Object) )
|
||||||
|
{
|
||||||
|
Input in(input);
|
||||||
|
in.Pool();
|
||||||
|
}
|
||||||
|
input=input->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
incheck=millis()+50;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void modbusLoop(void)
|
||||||
|
{
|
||||||
|
boolean done=false;
|
||||||
|
if (millis()>modbuscheck)
|
||||||
|
{
|
||||||
|
while (modbusitem && !done)
|
||||||
|
{
|
||||||
|
if (modbusitem->type==aJson_Array)
|
||||||
|
{
|
||||||
|
switch (aJson.getArrayItem(modbusitem, 0)->valueint)
|
||||||
|
{
|
||||||
|
case CH_MODBUS:
|
||||||
|
//case CH_VCTEMP:
|
||||||
|
case CH_VC:
|
||||||
|
{
|
||||||
|
Item it(modbusitem);
|
||||||
|
it.Pool();
|
||||||
|
modbuscheck=millis()+2000;
|
||||||
|
done=true;
|
||||||
|
break; //case;
|
||||||
|
}
|
||||||
|
} //switch
|
||||||
|
|
||||||
|
}//if
|
||||||
|
modbusitem=modbusitem->next;
|
||||||
|
if (!modbusitem) {modbusitem=items->child;return;} //start from 1-st element
|
||||||
|
} //while
|
||||||
|
}//if
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// To be refactored
|
||||||
|
|
||||||
|
void thermoLoop(void)
|
||||||
{
|
{
|
||||||
#define T_ATTEMPTS 20
|
#define T_ATTEMPTS 20
|
||||||
#define IET_TEMP 0
|
#define IET_TEMP 0
|
||||||
@@ -987,7 +915,7 @@ void thermoIdle(void)
|
|||||||
if (extArr && (aJson.getArraySize(extArr)>1) )
|
if (extArr && (aJson.getArraySize(extArr)>1) )
|
||||||
{
|
{
|
||||||
int curtemp = aJson.getArrayItem(extArr, IET_TEMP)->valueint;
|
int curtemp = aJson.getArrayItem(extArr, IET_TEMP)->valueint;
|
||||||
if (!aJson.getArrayItem(extArr, IET_ATTEMPTS)->valueint) {Serial.println(F("Expired"));} else aJson.getArrayItem(extArr, IET_ATTEMPTS)->valueint--;
|
if (!aJson.getArrayItem(extArr, IET_ATTEMPTS)->valueint) {Serial.print(item->name);Serial.println(F(" Expired"));} else aJson.getArrayItem(extArr, IET_ATTEMPTS)->valueint--;
|
||||||
|
|
||||||
Serial.print(item->name);Serial.print(F(" Set:"));Serial.print(temp); Serial.print(F(" Curtemp:"));Serial.print(curtemp); Serial.print(F( " cmd:")); Serial.print(cmd),
|
Serial.print(item->name);Serial.print(F(" Set:"));Serial.print(temp); Serial.print(F(" Curtemp:"));Serial.print(curtemp); Serial.print(F( " cmd:")); Serial.print(cmd),
|
||||||
|
|
||||||
@@ -1012,32 +940,6 @@ void thermoIdle(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long int incheck =0;
|
|
||||||
|
|
||||||
void inputIdle(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (millis()>incheck)
|
|
||||||
{
|
|
||||||
|
|
||||||
aJsonObject * input= inputs->child;
|
|
||||||
|
|
||||||
while (input)
|
|
||||||
{
|
|
||||||
if ((input->type==aJson_Object) )
|
|
||||||
{
|
|
||||||
Input in(input);
|
|
||||||
in.Pool();
|
|
||||||
}
|
|
||||||
input=input->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
incheck=millis()+50;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
short thermoSetCurTemp(char * name, short t)
|
short thermoSetCurTemp(char * name, short t)
|
||||||
@@ -1072,7 +974,6 @@ if (items)
|
|||||||
} //proc
|
} //proc
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int freeRam ()
|
int freeRam ()
|
||||||
{
|
{
|
||||||
extern int __heap_start, *__brkval;
|
extern int __heap_start, *__brkval;
|
||||||
@@ -1080,4 +981,3 @@ int freeRam ()
|
|||||||
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
|
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
11
utils.cpp
11
utils.cpp
@@ -59,3 +59,14 @@ void SetAddr(char * out, uint8_t* addr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int getInt(char ** chan)
|
||||||
|
{
|
||||||
|
int ch = atoi(*chan);
|
||||||
|
*chan=strchr(*chan,',');
|
||||||
|
|
||||||
|
if (*chan) *chan+=1;
|
||||||
|
//Serial.print(F("Par:")); Serial.println(ch);
|
||||||
|
return ch;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
1
utils.h
1
utils.h
@@ -23,3 +23,4 @@ void PrintBytes(uint8_t* addr, uint8_t count, bool newline=0);
|
|||||||
void SetBytes(uint8_t* addr, uint8_t count, char * out);
|
void SetBytes(uint8_t* addr, uint8_t count, char * out);
|
||||||
void SetAddr(char * out, uint8_t* addr);
|
void SetAddr(char * out, uint8_t* addr);
|
||||||
uint8_t HEX2DEC(char i);
|
uint8_t HEX2DEC(char i);
|
||||||
|
int getInt(char ** chan);
|
||||||
|
|||||||
Reference in New Issue
Block a user