mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 19:59:50 +03:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 18fbc783b5 | |||
|
|
5235bb67c1 | ||
| 9683e51c18 | |||
| fd65c1a3a1 |
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,3 +1,3 @@
|
|||||||
export PORT=cu.usbmodem14101
|
export PORT=cu.usbmodem141101
|
||||||
echo . | stty -f /dev/$PORT speed 1200
|
echo . | stty -f /dev/$PORT speed 1200
|
||||||
../tools/mac/tool-bossac/bossac -U false -p $PORT -i -e -w -v -b firmware.bin -R
|
../tools/mac/tool-bossac/bossac -U false -p $PORT -i -w -v -b firmware.bin -R
|
||||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -11,7 +11,7 @@ public:
|
|||||||
virtual ~abstractCh(){};
|
virtual ~abstractCh(){};
|
||||||
virtual int Poll(short cause) {return 0;}
|
virtual int Poll(short cause) {return 0;}
|
||||||
virtual int Setup() =0; //Should initialize hardware and reserve resources
|
virtual int Setup() =0; //Should initialize hardware and reserve resources
|
||||||
virtual int Anounce () {return 0;};
|
// virtual int Anounce () {return 0;};
|
||||||
virtual int Stop() {return 0;}; //Should free resources
|
virtual int Stop() {return 0;}; //Should free resources
|
||||||
virtual int Status() {return CST_UNKNOWN;}
|
virtual int Status() {return CST_UNKNOWN;}
|
||||||
virtual void setStatus(uint8_t status) {}
|
virtual void setStatus(uint8_t status) {}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public:
|
|||||||
virtual bool isAllowed(itemCmd cmd){return true;};
|
virtual bool isAllowed(itemCmd cmd){return true;};
|
||||||
virtual itemCmd getDefaultOnVal(){return itemCmd().Percents255(255);};
|
virtual itemCmd getDefaultOnVal(){return itemCmd().Percents255(255);};
|
||||||
virtual int getChanType(){return 0;}
|
virtual int getChanType(){return 0;}
|
||||||
virtual int getDefaultStorageType(){return 0;} /// Remove?? Now getChanType used instead
|
// virtual int getDefaultStorageType(){return 0;} /// Remove?? Now getChanType used instead
|
||||||
virtual int Status() override;
|
virtual int Status() override;
|
||||||
virtual void setStatus(uint8_t status) override;
|
virtual void setStatus(uint8_t status) override;
|
||||||
int Setup() override;
|
int Setup() override;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ short colorChannel::getChannelAddr(short n)
|
|||||||
return item->getArg(n);
|
return item->getArg(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
int colorChannel::getDefaultStorageType()
|
int colorChannel::getDefaultStorageType()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ int colorChannel::getDefaultStorageType()
|
|||||||
return ST_VOID;
|
return ST_VOID;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
int colorChannel::isActive()
|
int colorChannel::isActive()
|
||||||
{
|
{
|
||||||
itemCmd st;
|
itemCmd st;
|
||||||
@@ -58,7 +58,6 @@ case S_NOTFOUND:
|
|||||||
// turn on and set
|
// turn on and set
|
||||||
toExecute = true;
|
toExecute = true;
|
||||||
case S_SET:
|
case S_SET:
|
||||||
//case S_ESET:
|
|
||||||
case S_HSV:
|
case S_HSV:
|
||||||
PixelCtrl(cmd, subItem, toExecute, authorized);
|
PixelCtrl(cmd, subItem, toExecute, authorized);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public:
|
|||||||
numArgs = item->getArgCount(); // and how many addresses is configured
|
numArgs = item->getArgCount(); // and how many addresses is configured
|
||||||
};
|
};
|
||||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized=false) override;
|
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized=false) override;
|
||||||
int getDefaultStorageType()override;
|
//int getDefaultStorageType()override;
|
||||||
virtual int PixelCtrl(itemCmd cmd, char* subItem=NULL, bool show=true, bool authorized = false ) =0;
|
virtual int PixelCtrl(itemCmd cmd, char* subItem=NULL, bool show=true, bool authorized = false ) =0;
|
||||||
short getChannelAddr(short n =0);
|
short getChannelAddr(short n =0);
|
||||||
// int isActive() override;
|
// int isActive() override;
|
||||||
|
|||||||
@@ -104,8 +104,15 @@ int subitem2cmd(char *payload) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int txt2subItem(char *payload) {
|
int txt2subItem(char *payload) {
|
||||||
int cmd = S_NOTFOUND;
|
|
||||||
if (!payload || !strlen(payload)) return S_NOTFOUND;
|
if (!payload || !strlen(payload)) return S_NOTFOUND;
|
||||||
|
for(uint8_t i=1; i<suffixNum ;i++)
|
||||||
|
if (strcmp_P(payload, suffix_P[i]) == 0)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return S_NOTFOUND;
|
||||||
|
/*
|
||||||
|
int cmd = S_NOTFOUND;
|
||||||
// Check for command
|
// Check for command
|
||||||
if (strcmp_P(payload, SET_P) == 0) cmd = S_SET;
|
if (strcmp_P(payload, SET_P) == 0) cmd = S_SET;
|
||||||
else if (strcmp_P(payload, CTRL_P) == 0) cmd = S_CTRL;
|
else if (strcmp_P(payload, CTRL_P) == 0) cmd = S_CTRL;
|
||||||
@@ -120,7 +127,8 @@ int txt2subItem(char *payload) {
|
|||||||
else if (strcmp_P(payload, VAL_P) == 0) cmd = S_VAL;
|
else if (strcmp_P(payload, VAL_P) == 0) cmd = S_VAL;
|
||||||
else if (strcmp_P(payload, DEL_P) == 0) cmd = S_DELAYED;
|
else if (strcmp_P(payload, DEL_P) == 0) cmd = S_DELAYED;
|
||||||
else if (strcmp_P(payload, _RAW_P) == 0) cmd = S_RAW;
|
else if (strcmp_P(payload, _RAW_P) == 0) cmd = S_RAW;
|
||||||
return cmd;
|
return cmd; */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//const short defval[4] = {0, 0, 0, 0}; //Type,Arg,Val,Cmd
|
//const short defval[4] = {0, 0, 0, 0}; //Type,Arg,Val,Cmd
|
||||||
@@ -487,7 +495,7 @@ void Item::setExt(long int par) // Only store if VAL is int (autogenerated or c
|
|||||||
if(itemExt->type == aJson_NULL) itemExt->type=aJson_Int;
|
if(itemExt->type == aJson_NULL) itemExt->type=aJson_Int;
|
||||||
else if(itemExt->type != aJson_Int ) return;
|
else if(itemExt->type != aJson_Int ) return;
|
||||||
itemExt->valueint = par;
|
itemExt->valueint = par;
|
||||||
debugSerial<<F("Stored EXT:")<<par<<endl;
|
//debugSerial<<F("Stored EXT:")<<par<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -908,6 +916,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
|
|||||||
int res = -1;
|
int res = -1;
|
||||||
uint16_t status2Send = 0;
|
uint16_t status2Send = 0;
|
||||||
uint8_t command2Set = 0;
|
uint8_t command2Set = 0;
|
||||||
|
itemCmd originalCmd = cmd;
|
||||||
|
|
||||||
/// Common (GRP & NO GRP) commands
|
/// Common (GRP & NO GRP) commands
|
||||||
switch (cmd.getCmd())
|
switch (cmd.getCmd())
|
||||||
@@ -1063,7 +1072,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
|
|||||||
|
|
||||||
if ((suffixCode==S_CMD) && cmd.isValue())
|
if ((suffixCode==S_CMD) && cmd.isValue())
|
||||||
{
|
{
|
||||||
scheduleOppositeCommand(cmd,chActive,authorized);
|
scheduleOppositeCommand(originalCmd,chActive,authorized);
|
||||||
scheduledOppositeCommand = true;
|
scheduledOppositeCommand = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1372,7 +1381,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
|
|||||||
|
|
||||||
if (oppositeCommandToBeSchedulled) //invoked not as group part, delayed
|
if (oppositeCommandToBeSchedulled) //invoked not as group part, delayed
|
||||||
{
|
{
|
||||||
scheduleOppositeCommand(cmd,chActive,authorized);
|
scheduleOppositeCommand(originalCmd,chActive,authorized);
|
||||||
status2Send &=~FLAG_PARAMETERS;
|
status2Send &=~FLAG_PARAMETERS;
|
||||||
}
|
}
|
||||||
} // NO GROUP
|
} // NO GROUP
|
||||||
@@ -1464,7 +1473,7 @@ if ((!driver || driver->isAllowed(cmd)) && (!getFlag(FLAG_FREEZED)))
|
|||||||
if (!tStore.timestamp16) mqttClient.publish("/alarmoff/snsr", itemArr->name);
|
if (!tStore.timestamp16) mqttClient.publish("/alarmoff/snsr", itemArr->name);
|
||||||
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) & 0xFFFF; //And timestamp
|
||||||
debugSerial<<F(" T:")<<tStore.tempX100<<F(" TS:")<<tStore.timestamp16<<endl;
|
//debugSerial<<F(" T:")<<tStore.tempX100<<F(" TS:")<<tStore.timestamp16<<endl;
|
||||||
setExt(tStore.asint);
|
setExt(tStore.asint);
|
||||||
res=1;
|
res=1;
|
||||||
}
|
}
|
||||||
@@ -1801,9 +1810,14 @@ int Item::SendStatus(int sendFlags) {
|
|||||||
|
|
||||||
strncat(addrstr, "/", sizeof(addrstr)-1);
|
strncat(addrstr, "/", sizeof(addrstr)-1);
|
||||||
|
|
||||||
|
// if (sendFlags & FLAG_SEND_DELAYED)
|
||||||
|
// strncat_P(addrstr, DEL_P, sizeof(addrstr)-1);
|
||||||
|
// else strncat_P(addrstr, SET_P, sizeof(addrstr)-1);
|
||||||
|
|
||||||
if (sendFlags & FLAG_SEND_DELAYED)
|
if (sendFlags & FLAG_SEND_DELAYED)
|
||||||
strncat_P(addrstr, DEL_P, sizeof(addrstr)-1);
|
strncat_P(addrstr, suffix_P[S_DELAYED], sizeof(addrstr)-1);
|
||||||
else strncat_P(addrstr, SET_P, sizeof(addrstr)-1);
|
else strncat_P(addrstr, suffix_P[S_SET], sizeof(addrstr)-1);
|
||||||
|
|
||||||
|
|
||||||
// Preparing parameters payload //////////
|
// Preparing parameters payload //////////
|
||||||
switch (st.getArgType()) {
|
switch (st.getArgType()) {
|
||||||
@@ -1872,7 +1886,8 @@ int Item::SendStatus(int sendFlags) {
|
|||||||
strncat(addrstr, subItem, sizeof(addrstr)-1);
|
strncat(addrstr, subItem, sizeof(addrstr)-1);
|
||||||
}
|
}
|
||||||
strncat(addrstr, "/", sizeof(addrstr)-1);
|
strncat(addrstr, "/", sizeof(addrstr)-1);
|
||||||
strncat_P(addrstr, CMD_P, sizeof(addrstr)-1);
|
// strncat_P(addrstr, CMD_P, sizeof(addrstr)-1);
|
||||||
|
strncat_P(addrstr, suffix_P[S_CMD], sizeof(addrstr)-1);
|
||||||
|
|
||||||
debugSerial<<F("Pub: ")<<addrstr<<F("->")<<cmdstr<<endl;
|
debugSerial<<F("Pub: ")<<addrstr<<F("->")<<cmdstr<<endl;
|
||||||
if (mqttClient.connected() && !ethernetIdleCount)
|
if (mqttClient.connected() && !ethernetIdleCount)
|
||||||
@@ -1909,7 +1924,8 @@ int Item::SendStatus(int sendFlags) {
|
|||||||
strncat(addrstr, subItem, sizeof(addrstr)-1);
|
strncat(addrstr, subItem, sizeof(addrstr)-1);
|
||||||
}
|
}
|
||||||
strncat(addrstr, "/", sizeof(addrstr)-1);
|
strncat(addrstr, "/", sizeof(addrstr)-1);
|
||||||
strncat_P(addrstr, CTRL_P, sizeof(addrstr)-1);
|
//strncat_P(addrstr, CTRL_P, sizeof(addrstr)-1);
|
||||||
|
strncat_P(addrstr, suffix_P[S_CTRL], sizeof(addrstr)-1);
|
||||||
|
|
||||||
debugSerial<<F("Pub: ")<<addrstr<<F("->")<<cmdstr<<endl;
|
debugSerial<<F("Pub: ")<<addrstr<<F("->")<<cmdstr<<endl;
|
||||||
if (mqttClient.connected() && !ethernetIdleCount)
|
if (mqttClient.connected() && !ethernetIdleCount)
|
||||||
@@ -2006,38 +2022,6 @@ int Item::checkRetry() {
|
|||||||
return M_CLEAN;
|
return M_CLEAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
bool Item::resumeModbus()
|
|
||||||
{
|
|
||||||
|
|
||||||
if (modbusBusy) return false;
|
|
||||||
bool success = true;
|
|
||||||
|
|
||||||
//debugSerial<<F("Pushing MB: ");
|
|
||||||
configLocked++;
|
|
||||||
if (items) {
|
|
||||||
aJsonObject * item = items->child;
|
|
||||||
while (items && item)
|
|
||||||
if (item->type == aJson_Array && aJson.getArraySize(item)>1) {
|
|
||||||
Item it(item);
|
|
||||||
if (it.isValid()) {
|
|
||||||
|
|
||||||
short res = it.checkModbusRetry();
|
|
||||||
if (res<=0) success = false;
|
|
||||||
|
|
||||||
} //isValid
|
|
||||||
yield();
|
|
||||||
item = item->next;
|
|
||||||
} //if
|
|
||||||
debugSerial<<endl;
|
|
||||||
}
|
|
||||||
configLocked--;
|
|
||||||
if (success) isPendedModbusWrites=false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
//////////////////// Begin of legacy MODBUS code - to be moved in separate module /////////////////////
|
//////////////////// Begin of legacy MODBUS code - to be moved in separate module /////////////////////
|
||||||
|
|
||||||
|
|
||||||
@@ -2409,14 +2393,6 @@ int Item::checkModbusDimmer() {
|
|||||||
uint16_t reg = getArg(MODBUS_CMD_ARG_REG);
|
uint16_t reg = getArg(MODBUS_CMD_ARG_REG);
|
||||||
int _regType = MODBUS_HOLDING_REG_TYPE;
|
int _regType = MODBUS_HOLDING_REG_TYPE;
|
||||||
if (numpar >= (MODBUS_CMD_ARG_REG_TYPE+1)) _regType = aJson.getArrayItem(itemArg, MODBUS_CMD_ARG_REG_TYPE)->valueint;
|
if (numpar >= (MODBUS_CMD_ARG_REG_TYPE+1)) _regType = aJson.getArrayItem(itemArg, MODBUS_CMD_ARG_REG_TYPE)->valueint;
|
||||||
// short mask = getArg(2);
|
|
||||||
// debugSerial<<F("Modbus polling "));
|
|
||||||
// debugSerial<<addr);
|
|
||||||
// debugSerial<<F("=>"));
|
|
||||||
// debugSerial<<reg, HEX);
|
|
||||||
// debugSerial<<F("(T:"));
|
|
||||||
// debugSerial<<_regType);
|
|
||||||
// debugSerial<<F(")"));
|
|
||||||
|
|
||||||
int data;
|
int data;
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,11 @@ e-mail anklimov@gmail.com
|
|||||||
#define S_TEMP 12
|
#define S_TEMP 12
|
||||||
#define S_RAW 13
|
#define S_RAW 13
|
||||||
|
|
||||||
|
typedef char suffixstr[5];
|
||||||
|
const suffixstr suffix_P[] PROGMEM =
|
||||||
|
{"","cmd","set","val","del","HSV","RGB","fan","mode","ctrl","hue","sat","temp","raw"};
|
||||||
|
#define suffixNum sizeof(suffix_P)/sizeof(suffixstr)
|
||||||
|
|
||||||
#define S_ADDITIONAL 13
|
#define S_ADDITIONAL 13
|
||||||
|
|
||||||
#define CH_DIMMER 0 //DMX 1-4 ch
|
#define CH_DIMMER 0 //DMX 1-4 ch
|
||||||
@@ -63,16 +68,6 @@ e-mail anklimov@gmail.com
|
|||||||
#define CH_HUMIDIFIER 21
|
#define CH_HUMIDIFIER 21
|
||||||
#define CH_MERCURY 22
|
#define CH_MERCURY 22
|
||||||
|
|
||||||
//#define CHANNEL_TYPES 13
|
|
||||||
|
|
||||||
//static uint32_t pollInterval[CHANNEL_TYPES] = {0,0,0,0,MODB};
|
|
||||||
//static uint32_t nextPollTime[CHANNEL_TYPES] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
|
|
||||||
|
|
||||||
#define CH_WHITE 127//
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define POLLING_SLOW 1
|
#define POLLING_SLOW 1
|
||||||
#define POLLING_FAST 2
|
#define POLLING_FAST 2
|
||||||
#define POLLING_INT 3
|
#define POLLING_INT 3
|
||||||
@@ -157,24 +152,16 @@ class Item
|
|||||||
int VacomSetFan (itemCmd st);
|
int VacomSetFan (itemCmd st);
|
||||||
int VacomSetHeat(itemCmd st);
|
int VacomSetHeat(itemCmd st);
|
||||||
int modbusDimmerSet(itemCmd st);
|
int modbusDimmerSet(itemCmd st);
|
||||||
|
|
||||||
int modbusDimmerSet(int addr, uint16_t _reg, int _regType, int _mask, uint16_t value);
|
int modbusDimmerSet(int addr, uint16_t _reg, int _regType, int _mask, uint16_t value);
|
||||||
void mb_fail(int result=0);
|
void mb_fail(int result=0);
|
||||||
void Parse();
|
void Parse();
|
||||||
int checkModbusDimmer();
|
int checkModbusDimmer();
|
||||||
int checkModbusDimmer(int data);
|
int checkModbusDimmer(int data);
|
||||||
|
|
||||||
int checkRetry();
|
int checkRetry();
|
||||||
//boolean checkVCRetry();
|
|
||||||
//boolean checkHeatRetry();
|
|
||||||
void sendDelayedStatus();
|
void sendDelayedStatus();
|
||||||
//bool resumeModbus();
|
|
||||||
|
|
||||||
|
|
||||||
int checkFM();
|
int checkFM();
|
||||||
char defaultSubItem[16];
|
char defaultSubItem[16];
|
||||||
int defaultSuffixCode;
|
int defaultSuffixCode;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef union
|
typedef union
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ debugSerial<<F("Deleting conf. RAM was:")<<freeRam();
|
|||||||
topics = NULL;
|
topics = NULL;
|
||||||
mqttArr = NULL;
|
mqttArr = NULL;
|
||||||
deviceName = NULL;
|
deviceName = NULL;
|
||||||
topics = NULL;
|
|
||||||
#ifdef _dmxout
|
#ifdef _dmxout
|
||||||
dmxArr = NULL;
|
dmxArr = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public:
|
|||||||
int Stop() override;
|
int Stop() override;
|
||||||
int isActive() override;
|
int isActive() override;
|
||||||
int getChanType() override;
|
int getChanType() override;
|
||||||
int getDefaultStorageType(){return ST_FLOAT_CELSIUS;};
|
// int getDefaultStorageType(){return ST_FLOAT_CELSIUS;};
|
||||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
||||||
void SubmitParameters(const char * name, itemCmd value);
|
void SubmitParameters(const char * name, itemCmd value);
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public:
|
|||||||
int Stop() override;
|
int Stop() override;
|
||||||
int getChanType() override;
|
int getChanType() override;
|
||||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
||||||
int getDefaultStorageType(){return ST_INT32;};
|
//int getDefaultStorageType(){return ST_INT32;};
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -327,7 +327,7 @@ itemCmd out_Modbus::findRegister(uint16_t registerNum, uint16_t posInBuffer, uin
|
|||||||
mappedParam.Int((uint32_t)param);
|
mappedParam.Int((uint32_t)param);
|
||||||
}
|
}
|
||||||
|
|
||||||
debugSerial << F("MBUSD: got ")<<mappedParam.toString(buf,sizeof(buf))<< F(" from type ")<<parType<<F(":")<<paramObj->name<<endl;
|
traceSerial << F("MBUSD: got ")<<mappedParam.toString(buf,sizeof(buf))<< F(" from type ")<<parType<<F(":")<<paramObj->name<<endl;
|
||||||
|
|
||||||
if (mapObj && (mapObj->type==aJson_Array || mapObj->type==aJson_Object))
|
if (mapObj && (mapObj->type==aJson_Array || mapObj->type==aJson_Object))
|
||||||
{
|
{
|
||||||
@@ -401,7 +401,7 @@ itemCmd out_Modbus::findRegister(uint16_t registerNum, uint16_t posInBuffer, uin
|
|||||||
|
|
||||||
aJsonObject * nestedMapObj = aJson.getObjectItem(templateParObj, "map");
|
aJsonObject * nestedMapObj = aJson.getObjectItem(templateParObj, "map");
|
||||||
if (nestedMapObj && (nestedMapObj->type==aJson_Array || nestedMapObj->type==aJson_Object)) mappedParam=mappedParam.doReverseMapping(nestedMapObj);
|
if (nestedMapObj && (nestedMapObj->type==aJson_Array || nestedMapObj->type==aJson_Object)) mappedParam=mappedParam.doReverseMapping(nestedMapObj);
|
||||||
debugSerial << F("MBUSD: NestedMapped:")<<mappedParam.toString(buf,sizeof(buf))<<endl;
|
traceSerial << F("MBUSD: NestedMapped:")<<mappedParam.toString(buf,sizeof(buf))<<endl;
|
||||||
|
|
||||||
if (!(lastMeasured->subtype & MB_VALUE_OUTDATED))
|
if (!(lastMeasured->subtype & MB_VALUE_OUTDATED))
|
||||||
{
|
{
|
||||||
@@ -449,7 +449,7 @@ itemCmd out_Modbus::findRegister(uint16_t registerNum, uint16_t posInBuffer, uin
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
debugSerial << F("MBUSD: Mapped:")<<mappedParam.toString(buf,sizeof(buf))<<endl;
|
traceSerial << F("MBUSD: Mapped:")<<mappedParam.toString(buf,sizeof(buf))<<endl;
|
||||||
} //mapping
|
} //mapping
|
||||||
|
|
||||||
if (doExecution && idObj && idObj->type==aJson_Int)
|
if (doExecution && idObj && idObj->type==aJson_Int)
|
||||||
@@ -505,7 +505,7 @@ itemCmd out_Modbus::findRegister(uint16_t registerNum, uint16_t posInBuffer, uin
|
|||||||
aJsonObject *settedValue = aJson.getObjectItem(markObj,"@V");
|
aJsonObject *settedValue = aJson.getObjectItem(markObj,"@V");
|
||||||
if (settedValue && settedValue->type==aJson_Int && (settedValue->valueint == param))
|
if (settedValue && settedValue->type==aJson_Int && (settedValue->valueint == param))
|
||||||
{
|
{
|
||||||
debugSerial<<F("MBUSD: Ignored - equal with setted val")<<endl;
|
traceSerial<<F("MBUSD: Ignored - equal with setted val")<<endl;
|
||||||
*submitParam=false;
|
*submitParam=false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -719,7 +719,7 @@ if (itemParametersObj && itemParametersObj->type ==aJson_Object)
|
|||||||
// if some polling configured
|
// if some polling configured
|
||||||
if (store->pollingRegisters || store->pollingIrs || store->pollingCoils || store->poolingDiscreteIns)
|
if (store->pollingRegisters || store->pollingIrs || store->pollingCoils || store->poolingDiscreteIns)
|
||||||
{
|
{
|
||||||
debugSerial<<F("MBUSD: Poll ")<< item->itemArr->name << endl;
|
traceSerial<<F("MBUSD: Poll ")<< item->itemArr->name << endl;
|
||||||
modbusBusy=1;
|
modbusBusy=1;
|
||||||
|
|
||||||
if (!lineInitialized)
|
if (!lineInitialized)
|
||||||
@@ -732,7 +732,7 @@ if (store->pollingRegisters || store->pollingIrs || store->pollingCoils || store
|
|||||||
pollModbus(store->pollingIrs,MODBUS_INPUT_REG_TYPE);
|
pollModbus(store->pollingIrs,MODBUS_INPUT_REG_TYPE);
|
||||||
pollModbus(store->pollingCoils,MODBUS_COIL_REG_TYPE);
|
pollModbus(store->pollingCoils,MODBUS_COIL_REG_TYPE);
|
||||||
pollModbus(store->poolingDiscreteIns ,MODBUS_DISCRETE_REG_TYPE);
|
pollModbus(store->poolingDiscreteIns ,MODBUS_DISCRETE_REG_TYPE);
|
||||||
debugSerial<<F("MBUSD: endPoll ")<< item->itemArr->name << endl;
|
traceSerial<<F("MBUSD: endPoll ")<< item->itemArr->name << endl;
|
||||||
|
|
||||||
//Non blocking waiting to release line
|
//Non blocking waiting to release line
|
||||||
uint32_t time = millis();
|
uint32_t time = millis();
|
||||||
@@ -794,7 +794,7 @@ aJsonObject * mapObj = aJson.getObjectItem(templateParamObj, "map");
|
|||||||
Value=cmdValue.getTens_raw()*(100/TENS_BASE);
|
Value=cmdValue.getTens_raw()*(100/TENS_BASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
debugSerial<<F("MBUSD: suffix:")<<suffixStr<< F(" Val: ")<<Value<<endl;
|
traceSerial<<F("MBUSD: suffix:")<<suffixStr<< F(" Val: ")<<Value<<endl;
|
||||||
aJsonObject * itemParametersObj = aJson.getArrayItem(item->itemArg, 2);
|
aJsonObject * itemParametersObj = aJson.getArrayItem(item->itemArg, 2);
|
||||||
if (itemParametersObj && itemParametersObj->type ==aJson_Object)
|
if (itemParametersObj && itemParametersObj->type ==aJson_Object)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public:
|
|||||||
int Stop() override;
|
int Stop() override;
|
||||||
int getChanType() override;
|
int getChanType() override;
|
||||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
||||||
int getDefaultStorageType(){return ST_INT32;};
|
//int getDefaultStorageType(){return ST_INT32;};
|
||||||
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
|
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public:
|
|||||||
int Stop() override;
|
int Stop() override;
|
||||||
//int isActive() override;
|
//int isActive() override;
|
||||||
int getChanType() override;
|
int getChanType() override;
|
||||||
int getDefaultStorageType(){return ST_PERCENTS255;};
|
//int getDefaultStorageType(){return ST_PERCENTS255;};
|
||||||
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
|
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
|
||||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public:
|
|||||||
int Stop() override;
|
int Stop() override;
|
||||||
//int isActive() override;
|
//int isActive() override;
|
||||||
int getChanType() override;
|
int getChanType() override;
|
||||||
int getDefaultStorageType(){return ST_PERCENTS255;};
|
//int getDefaultStorageType(){return ST_PERCENTS255;};
|
||||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
||||||
protected:
|
protected:
|
||||||
void getConfig();
|
void getConfig();
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public:
|
|||||||
int Stop() override;
|
int Stop() override;
|
||||||
int isActive() override;
|
int isActive() override;
|
||||||
int getChanType() override;
|
int getChanType() override;
|
||||||
int getDefaultStorageType(){return ST_FLOAT;};
|
//int getDefaultStorageType(){return ST_FLOAT;};
|
||||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
||||||
void alarm(bool);
|
void alarm(bool);
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public:
|
|||||||
int Stop() override;
|
int Stop() override;
|
||||||
int getChanType() override;
|
int getChanType() override;
|
||||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
||||||
int getDefaultStorageType(){return ST_INT32;};
|
//int getDefaultStorageType(){return ST_INT32;};
|
||||||
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
|
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -127,8 +127,8 @@ int owSetup() {
|
|||||||
if (oneWire) return true; // Already initialized
|
if (oneWire) return true; // Already initialized
|
||||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||||
|
|
||||||
debugSerial<<F("DS2482_100_I2C_TO_1W_BRIDGE init")<<endl;
|
debugSerial<<F("1WT: DS2482_100_I2C_TO_1W_BRIDGE init")<<endl;
|
||||||
debugSerial<<F("Free:")<<freeRam()<<endl;
|
//debugSerial<<F("Free:")<<freeRam()<<endl;
|
||||||
oneWire = new OneWire;
|
oneWire = new OneWire;
|
||||||
#else
|
#else
|
||||||
debugSerial.print(F("One wire setup on PIN:"));
|
debugSerial.print(F("One wire setup on PIN:"));
|
||||||
@@ -146,7 +146,7 @@ if (!oneWire)
|
|||||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
if (oneWire->checkPresence()) {
|
if (oneWire->checkPresence()) {
|
||||||
infoSerial.println(F("1WT: DS2482-100 present"));
|
infoSerial.println(F("1WT: DS2482-100 present, reset"));
|
||||||
oneWire->deviceReset();
|
oneWire->deviceReset();
|
||||||
#ifdef APU_OFF
|
#ifdef APU_OFF
|
||||||
debugSerial.println(F("APU off"));
|
debugSerial.println(F("APU off"));
|
||||||
@@ -154,11 +154,11 @@ if (!oneWire)
|
|||||||
oneWire->setActivePullup();
|
oneWire->setActivePullup();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
debugSerial.println(F("\tChecking for 1-Wire devices..."));
|
// debugSerial.println(F("\tChecking for 1-Wire devices..."));
|
||||||
if (oneWire->wireReset())
|
if (oneWire->wireReset())
|
||||||
debugSerial.println(F("\tReset done"));
|
debugSerial.println(F("1WT: Bus Reset done"));
|
||||||
else
|
else
|
||||||
debugSerial.println(F("\tDS2482 reset error"));
|
debugSerial.println(F("1WT: Bus reset error"));
|
||||||
//return true;
|
//return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -226,25 +226,25 @@ int sensors_loop(void) {
|
|||||||
|
|
||||||
case DS2482_ERROR_CONFIG:
|
case DS2482_ERROR_CONFIG:
|
||||||
errorSerial<<F("1WT: DS2482_ERROR_CONFIG")<<endl;
|
errorSerial<<F("1WT: DS2482_ERROR_CONFIG")<<endl;
|
||||||
oneWire->wireReset();
|
i2cReset();
|
||||||
return INTERVAL_1W;
|
break;
|
||||||
|
|
||||||
case DS2482_ERROR_TIMEOUT:
|
case DS2482_ERROR_TIMEOUT: //Busy over time
|
||||||
errorSerial<<F("1WT: 1-wire shorted")<<endl;
|
errorSerial<<F("1WT: BUSY timeout")<<endl;
|
||||||
oneWire->wireReset();
|
i2cReset();
|
||||||
return INTERVAL_1W;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
errorSerial<<F("1WT: error")<<endl;
|
break;
|
||||||
oneWire->wireReset();
|
|
||||||
return INTERVAL_1W;
|
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
if (!oneWire->checkPresence())
|
if (!oneWire->checkPresence())
|
||||||
{
|
{
|
||||||
infoSerial.println(F("1WT: lost DS2482-100"));
|
infoSerial.println(F("1WT: lost DS2482-100"));
|
||||||
i2cReset();
|
i2cReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -24,10 +24,12 @@ extern uint8_t udpDebugLevel;
|
|||||||
#define SerialPortType HardwareSerial
|
#define SerialPortType HardwareSerial
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define LOG_TRACE 9
|
||||||
#define LOG_DEBUG 7
|
#define LOG_DEBUG 7
|
||||||
#define LOG_INFO 6
|
#define LOG_INFO 6
|
||||||
#define LOG_ERROR 3
|
#define LOG_ERROR 3
|
||||||
|
|
||||||
|
#define traceSerial if (serialDebugLevel>=LOG_TRACE || udpDebugLevel>=LOG_TRACE) debugSerial
|
||||||
class Streamlog : public Print
|
class Streamlog : public Print
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
0
lighthub/templateStr.cpp
Normal file
0
lighthub/templateStr.cpp
Normal file
110
lighthub/templateStr.h
Normal file
110
lighthub/templateStr.h
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
#ifndef _TEMPLATE_STREAM_H_
|
||||||
|
#define _TEMPLATE_STREAM_H_
|
||||||
|
|
||||||
|
#include <Stream.h>
|
||||||
|
#include <aJSON.h>
|
||||||
|
#include <streamlog.h>
|
||||||
|
//#define KEYLEN 8
|
||||||
|
extern aJsonObject * topics;
|
||||||
|
|
||||||
|
class templateStream : public Stream
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
templateStream(char *s, short sfx=0) : str(s), pos(0), val(NULL), valpos(0), bucket(0),suffix(sfx) { }
|
||||||
|
|
||||||
|
// Stream methods
|
||||||
|
virtual int available() { return str[pos]; }
|
||||||
|
virtual int read() {
|
||||||
|
if (bucket)
|
||||||
|
|
||||||
|
{ int ch = bucket;
|
||||||
|
bucket=0;
|
||||||
|
return ch;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (str[pos]=='$')
|
||||||
|
{
|
||||||
|
if (str[pos+1]=='{')
|
||||||
|
{
|
||||||
|
unsigned int i = 0;
|
||||||
|
while (str[pos+2+i] && str[pos+2+i]!='}') i++;
|
||||||
|
if (i && (str[pos+2+i]=='}'))
|
||||||
|
{
|
||||||
|
str[pos+2+i]='\0';
|
||||||
|
val=resolveKey(str+pos+2);
|
||||||
|
valpos=0;
|
||||||
|
str[pos+2+i]='}';
|
||||||
|
pos+=3+i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (val)
|
||||||
|
{
|
||||||
|
char ch = val[valpos];
|
||||||
|
if (ch)
|
||||||
|
{
|
||||||
|
valpos++;
|
||||||
|
return ch;
|
||||||
|
}
|
||||||
|
else val = NULL;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str)
|
||||||
|
{
|
||||||
|
char ch = str[pos];
|
||||||
|
if (ch)
|
||||||
|
{
|
||||||
|
pos++;
|
||||||
|
return ch;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
str=NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
virtual int peek()
|
||||||
|
{
|
||||||
|
int bucket = read();
|
||||||
|
return bucket;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void flush() { };
|
||||||
|
// Print methods
|
||||||
|
virtual size_t write(uint8_t c) { return 0; };
|
||||||
|
virtual char * resolveKey(char *key)
|
||||||
|
{
|
||||||
|
if (topics && topics->type == aJson_Object)
|
||||||
|
{
|
||||||
|
aJsonObject *valObj = aJson.getObjectItem(topics, key);
|
||||||
|
if (valObj->type == aJson_String) return valObj->valuestring;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (suffix && (suffix<suffixNum) && !strcmp(key,"sfx"))
|
||||||
|
{
|
||||||
|
//debugSerial<<F("Template: Suffix=")<<suffix<<endl;
|
||||||
|
buffer[0]='/';
|
||||||
|
strncpy_P(buffer+1,suffix_P[suffix],sizeof(buffer)-2);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
char *str;
|
||||||
|
unsigned int pos;
|
||||||
|
char *val;
|
||||||
|
unsigned int valpos;
|
||||||
|
int bucket;
|
||||||
|
short suffix;
|
||||||
|
char buffer[8];
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _TEMPLATE_STREAM_H_
|
||||||
@@ -82,17 +82,29 @@ const char on_P[] PROGMEM = "on";
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define ON_P commands_P[CMD_ON]
|
||||||
|
#define OFF_P commands_P[CMD_OFF]
|
||||||
|
#define REST_P commands_P[CMD_RESTORE]
|
||||||
|
#define TOGGLE_P commands_P[CMD_TOGGLE]
|
||||||
|
#define HALT_P commands_P[CMD_HALT]
|
||||||
|
#define XON_P commands_P[CMD_XON]
|
||||||
|
#define XOFF_P commands_P[CMD_XOFF]
|
||||||
|
#define HEAT_P commands_P[CMD_HEAT]
|
||||||
|
#define COOL_P commands_P[CMD_COOL]
|
||||||
|
#define AUTO_P commands_P[CMD_AUTO]
|
||||||
|
#define FAN_ONLY_P commands_P[CMD_FAN]
|
||||||
|
#define DRY_P commands_P[CMD_DRY]
|
||||||
|
#define HIGH_P commands_P[CMD_HIGH]
|
||||||
|
#define MED_P commands_P[CMD_MED]
|
||||||
|
#define LOW_P commands_P[CMD_LOW]
|
||||||
|
#define ENABLE_P commands_P[CMD_ENABLE]
|
||||||
|
#define DISABLE_P commands_P[CMD_DISABLE]
|
||||||
|
#define FREEZE_P commands_P[CMD_FREEZE]
|
||||||
|
#define UNFREEZE_P commands_P[CMD_UNFREEZE]
|
||||||
|
|
||||||
|
const char ERROR_P[] PROGMEM = "ERR";
|
||||||
|
|
||||||
//Commands
|
//Commands
|
||||||
|
|
||||||
const char ON_P[] PROGMEM = "ON";
|
|
||||||
const char OFF_P[] PROGMEM = "OFF";
|
|
||||||
const char REST_P[] PROGMEM = "REST";
|
|
||||||
const char TOGGLE_P[] PROGMEM = "TOGGLE";
|
|
||||||
const char HALT_P[] PROGMEM = "HALT";
|
|
||||||
const char XON_P[] PROGMEM = "XON";
|
|
||||||
const char XOFF_P[] PROGMEM = "XOFF";
|
|
||||||
/*
|
/*
|
||||||
const char INCREASE_P[] PROGMEM = "INCREASE";
|
const char INCREASE_P[] PROGMEM = "INCREASE";
|
||||||
const char DECREASE_P[] PROGMEM = "DECREASE";
|
const char DECREASE_P[] PROGMEM = "DECREASE";
|
||||||
@@ -102,6 +114,15 @@ const char FALSE_P[] PROGMEM = "FALSE";
|
|||||||
const char ENABLED_P[] PROGMEM = "ENABLED";
|
const char ENABLED_P[] PROGMEM = "ENABLED";
|
||||||
const char DISABLED_P[] PROGMEM = "DISABLED";
|
const char DISABLED_P[] PROGMEM = "DISABLED";
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
const char ON_P[] PROGMEM = "ON";
|
||||||
|
const char OFF_P[] PROGMEM = "OFF";
|
||||||
|
const char REST_P[] PROGMEM = "REST";
|
||||||
|
const char TOGGLE_P[] PROGMEM = "TOGGLE";
|
||||||
|
const char HALT_P[] PROGMEM = "HALT";
|
||||||
|
const char XON_P[] PROGMEM = "XON";
|
||||||
|
const char XOFF_P[] PROGMEM = "XOFF";
|
||||||
const char HEAT_P[] PROGMEM = "HEAT";
|
const char HEAT_P[] PROGMEM = "HEAT";
|
||||||
const char COOL_P[] PROGMEM = "COOL";
|
const char COOL_P[] PROGMEM = "COOL";
|
||||||
const static char AUTO_P[] PROGMEM = "AUTO";
|
const static char AUTO_P[] PROGMEM = "AUTO";
|
||||||
@@ -112,13 +133,15 @@ const char DRY_P[] PROGMEM = "DRY";
|
|||||||
const char HIGH_P[] PROGMEM = "HIGH";
|
const char HIGH_P[] PROGMEM = "HIGH";
|
||||||
const char MED_P[] PROGMEM = "MEDIUM";
|
const char MED_P[] PROGMEM = "MEDIUM";
|
||||||
const char LOW_P[] PROGMEM = "LOW";
|
const char LOW_P[] PROGMEM = "LOW";
|
||||||
const char ERROR_P[] PROGMEM = "ERR";
|
|
||||||
const char ENABLE_P[] PROGMEM = "ENABLE";
|
const char ENABLE_P[] PROGMEM = "ENABLE";
|
||||||
const char DISABLE_P[] PROGMEM = "DISABLE";
|
const char DISABLE_P[] PROGMEM = "DISABLE";
|
||||||
const char FREEZE_P[] PROGMEM = "FREEZE";
|
const char FREEZE_P[] PROGMEM = "FREEZE";
|
||||||
const char UNFREEZE_P[] PROGMEM = "UNFREEZE";
|
const char UNFREEZE_P[] PROGMEM = "UNFREEZE";
|
||||||
|
*/
|
||||||
|
|
||||||
// SubTopics
|
// SubTopics
|
||||||
|
/*
|
||||||
const char SET_P[] PROGMEM = "set";
|
const char SET_P[] PROGMEM = "set";
|
||||||
const char CMD_P[] PROGMEM = "cmd";
|
const char CMD_P[] PROGMEM = "cmd";
|
||||||
const char MODE_P[] PROGMEM = "mode";
|
const char MODE_P[] PROGMEM = "mode";
|
||||||
@@ -132,7 +155,7 @@ const char VAL_P[] PROGMEM = "val";
|
|||||||
const char DEL_P[] PROGMEM = "del";
|
const char DEL_P[] PROGMEM = "del";
|
||||||
const char _RAW_P[] PROGMEM = "raw";
|
const char _RAW_P[] PROGMEM = "raw";
|
||||||
const char CTRL_P[] PROGMEM = "ctrl";
|
const char CTRL_P[] PROGMEM = "ctrl";
|
||||||
|
*/
|
||||||
/*
|
/*
|
||||||
const char RPM_P[] PROGMEM = "rpm";
|
const char RPM_P[] PROGMEM = "rpm";
|
||||||
const char STATE_P[] PROGMEM = "state";
|
const char STATE_P[] PROGMEM = "state";
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ e-mail anklimov@gmail.com
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
#include <HardwareSerial.h>
|
#include <HardwareSerial.h>
|
||||||
|
#include "templateStr.h"
|
||||||
|
|
||||||
#ifdef CRYPT
|
#ifdef CRYPT
|
||||||
#include "SHA256.h"
|
#include "SHA256.h"
|
||||||
@@ -690,8 +691,22 @@ switch (cmdType)
|
|||||||
//else itemCommand = _itemCmd.toString(Buffer,sizeof(Buffer));
|
//else itemCommand = _itemCmd.toString(Buffer,sizeof(Buffer));
|
||||||
|
|
||||||
char * emitCommand;
|
char * emitCommand;
|
||||||
|
short suffix=0;
|
||||||
|
// aJsonObject * dict=NULL;
|
||||||
|
|
||||||
if(ecmd && ecmd->type == aJson_String) emitCommand = ecmd->valuestring;
|
if(ecmd && ecmd->type == aJson_String) emitCommand = ecmd->valuestring;
|
||||||
else emitCommand = _itemCmd.toString(Buffer,sizeof(Buffer));
|
else
|
||||||
|
{
|
||||||
|
emitCommand = _itemCmd.toString(Buffer,sizeof(Buffer));
|
||||||
|
// dict = aJson.createObject();
|
||||||
|
// aJson.addStringToObject(dict, "sfx", )
|
||||||
|
suffix=_itemCmd.getSuffix();
|
||||||
|
if (!suffix)
|
||||||
|
{
|
||||||
|
if (_itemCmd.isCommand()) suffix=S_CMD;
|
||||||
|
else if (_itemCmd.isValue()) suffix = S_SET;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//debugSerial << F("IN:") << (pin) << F(" : ") <<endl;
|
//debugSerial << F("IN:") << (pin) << F(" : ") <<endl;
|
||||||
if (item) {
|
if (item) {
|
||||||
@@ -705,7 +720,12 @@ switch (cmdType)
|
|||||||
|
|
||||||
|
|
||||||
if (emit && emitCommand && emit->type == aJson_String) {
|
if (emit && emitCommand && emit->type == aJson_String) {
|
||||||
debugSerial << F("Emit: ")<<emit->valuestring<< F(" -> ")<<emitCommand<<endl;
|
|
||||||
|
templateStream ts(emit->valuestring,suffix);
|
||||||
|
char addrstr[MQTT_TOPIC_LENGTH];
|
||||||
|
//ts.setTimeout(0);
|
||||||
|
addrstr[ts.readBytesUntil('\0',addrstr,sizeof(addrstr))]='\0';
|
||||||
|
debugSerial << F("Emit: <")<<emit->valuestring<<"> "<<addrstr<< F(" -> ")<<emitCommand<<endl;
|
||||||
/*
|
/*
|
||||||
TODO implement
|
TODO implement
|
||||||
#ifdef WITH_DOMOTICZ
|
#ifdef WITH_DOMOTICZ
|
||||||
@@ -720,8 +740,8 @@ switch (cmdType)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
char addrstr[MQTT_TOPIC_LENGTH];
|
|
||||||
strncpy(addrstr,emit->valuestring,sizeof(addrstr));
|
//strncpy(addrstr,emit->valuestring,sizeof(addrstr));
|
||||||
if (mqttClient.connected() && !ethernetIdleCount)
|
if (mqttClient.connected() && !ethernetIdleCount)
|
||||||
{
|
{
|
||||||
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
||||||
@@ -880,7 +900,7 @@ bool checkToken(char * token, char * data)
|
|||||||
|
|
||||||
|
|
||||||
bool i2cReset(){
|
bool i2cReset(){
|
||||||
debugSerial.println("I2C Reset");
|
debugSerial.println(F("I2C Reset"));
|
||||||
|
|
||||||
Wire.endTransmission(true);
|
Wire.endTransmission(true);
|
||||||
#if !defined(ARDUINO_ARCH_ESP8266)
|
#if !defined(ARDUINO_ARCH_ESP8266)
|
||||||
@@ -896,19 +916,22 @@ pinMode(SDA,INPUT);
|
|||||||
pulse=!pulse;
|
pulse=!pulse;
|
||||||
delay(10);//10us мкс
|
delay(10);//10us мкс
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delay(20);
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
|
|
||||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||||
if (oneWire && oneWire->checkPresence())
|
if (oneWire && oneWire->checkPresence())
|
||||||
{
|
{
|
||||||
oneWire->deviceReset();
|
oneWire->deviceReset();
|
||||||
|
debugSerial.println(F("1WT: DS2482 present, reset"));
|
||||||
#ifndef APU_OFF
|
#ifndef APU_OFF
|
||||||
oneWire->setActivePullup();
|
oneWire->setActivePullup();
|
||||||
#endif
|
#endif
|
||||||
if (oneWire->wireReset())
|
if (oneWire->wireReset())
|
||||||
debugSerial.println(F("\tReset done"));
|
debugSerial.println(F("1WT: Bus Reset done"));
|
||||||
else
|
else
|
||||||
debugSerial.println(F("\tDS2482 reset error"));
|
debugSerial.println(F("1WT: Bus reset error"));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -916,5 +939,8 @@ if (oneWire && oneWire->checkPresence())
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#pragma message(VAR_NAME_VALUE(debugSerial))
|
#pragma message(VAR_NAME_VALUE(debugSerial))
|
||||||
#pragma message(VAR_NAME_VALUE(SERIAL_BAUD))
|
#pragma message(VAR_NAME_VALUE(SERIAL_BAUD))
|
||||||
|
|||||||
Reference in New Issue
Block a user