Socket (syslog,artnet) optim. Relay pwm thermo fix

This commit is contained in:
2022-01-03 20:42:46 +03:00
parent 1316835cad
commit 0c3108c620
20 changed files with 29210 additions and 21621 deletions

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.

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.

View File

@@ -346,7 +346,7 @@ float Item::getFloatArg(short n) //Return arg float or first array element if Ar
else if (itemArg->type == aJson_Float) return itemArg->valuefloat; else if (itemArg->type == aJson_Float) return itemArg->valuefloat;
else return 0; else return 0;
} }
if ((itemArg->type == aJson_Array) && ( n < aJson.getArraySize(itemArg))) if ((itemArg->type == aJson_Array) && ( n < aJson.getArraySize(itemArg)))
{ {
aJsonObject * obj = aJson.getArrayItem(itemArg, n); aJsonObject * obj = aJson.getArrayItem(itemArg, n);
@@ -691,7 +691,8 @@ return false;
//Main routine to control Item //Main routine to control Item
int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion) int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion)
{ {
uint32_t time=millis(); uint32_t time=millis();
int suffixCode = cmd.getSuffix(); int suffixCode = cmd.getSuffix();
bool operation = isNotRetainingStatus(); bool operation = isNotRetainingStatus();
@@ -721,7 +722,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion)
} }
cmd.debugOut(); cmd.debugOut();
//debugSerial<<endl; //debugSerial<<endl;
if (subItem && subItem[0] == '$') {debugSerial<<F("Skipped homie stuff")<<endl;return -4; }
if (!itemArr) return -1; if (!itemArr) return -1;
/// DELAYED COMMANDS processing /// DELAYED COMMANDS processing
@@ -888,9 +889,9 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion)
{ {
if (allowRecursion && itemArg->type == aJson_Array && operation) if (allowRecursion && itemArg->type == aJson_Array && operation)
{ {
digGroup(itemArg,&cmd,subItem); digGroup(itemArg,&cmd,subItem);
res=1;
} }
res=1;
// Post-processing of group command - converting HALT,REST,XON,XOFF to conventional ON/OFF for status // Post-processing of group command - converting HALT,REST,XON,XOFF to conventional ON/OFF for status
switch (cmd.getCmd()) { switch (cmd.getCmd()) {

View File

@@ -406,7 +406,7 @@ else
cmd_parse((char *)payload); cmd_parse((char *)payload);
return;// -4; return;// -4;
} }
/*
if (subItem = strchr(itemName, '/')) if (subItem = strchr(itemName, '/'))
{ {
*subItem = 0; *subItem = 0;
@@ -421,6 +421,12 @@ else
//return //return
item.Ctrl((char *)payload,subItem); item.Ctrl((char *)payload,subItem);
} //valid item } //valid item
*/
if (itemName[0]=='$') return;// -6; //Skipping homie stuff
Item item(itemName);
if (item.isValid()) item.Ctrl((char *)payload);
return;// -7; return;// -7;
} }
@@ -489,7 +495,7 @@ void setupSyslog()
if (lanStatus<HAVE_IP_ADDRESS) return; if (lanStatus<HAVE_IP_ADDRESS) return;
if (!root) return; if (!root) return;
udpSyslogClient.begin(SYSLOG_LOCAL_SOCKET); // udpSyslogClient.begin(SYSLOG_LOCAL_SOCKET);
udpSyslogArr = aJson.getObjectItem(root, "syslog"); udpSyslogArr = aJson.getObjectItem(root, "syslog");
if (udpSyslogArr && (n = aJson.getArraySize(udpSyslogArr))) { if (udpSyslogArr && (n = aJson.getArraySize(udpSyslogArr))) {
@@ -498,6 +504,8 @@ void setupSyslog()
_inet_ntoa_r(Ethernet.localIP(),syslogDeviceHostname,sizeof(syslogDeviceHostname)); _inet_ntoa_r(Ethernet.localIP(),syslogDeviceHostname,sizeof(syslogDeviceHostname));
infoSerial<<F("Syslog params:")<<syslogServer<<":"<<syslogPort<<":"<<syslogDeviceHostname<<endl; infoSerial<<F("Syslog params:")<<syslogServer<<":"<<syslogPort<<":"<<syslogDeviceHostname<<endl;
udpSyslogClient.begin(SYSLOG_LOCAL_SOCKET);
udpSyslog.server(syslogServer, syslogPort); udpSyslog.server(syslogServer, syslogPort);
udpSyslog.deviceHostname(syslogDeviceHostname); udpSyslog.deviceHostname(syslogDeviceHostname);
@@ -547,7 +555,7 @@ lan_status lanLoop() {
mdnsName[8+4]='\0'; mdnsName[8+4]='\0';
if (!MDNS.begin(mdnsName)) if (!MDNS.begin(mdnsName))
errorSerial<<("Error setting up MDNS responder!")<<endl; errorSerial<<F("Error setting up MDNS responder!")<<endl;
else infoSerial<<F("mDNS responder started: ")<<mdnsName<<F(".local")<<endl; else infoSerial<<F("mDNS responder started: ")<<mdnsName<<F(".local")<<endl;
MDNS.addService("http", "tcp", OTA_PORT); MDNS.addService("http", "tcp", OTA_PORT);
@@ -880,7 +888,9 @@ void ip_ready_config_loaded_connecting_to_broker() {
infoSerial<<F("Device Name:")<<deviceName<<endl; infoSerial<<F("Device Name:")<<deviceName<<endl;
#if defined (MDNS_ENABLE) && ! defined (WIFI_ENABLE) #if defined (MDNS_ENABLE) && ! defined (WIFI_ENABLE)
mdns.setName(deviceName); if (!mdns.setName(deviceName))
errorSerial<<("Error updating MDNS name!")<<endl;
else infoSerial<<F("mDNS name updated: ")<<deviceName<<F(".local")<<endl;
#endif #endif
//debugSerial<<F("N:")<<n<<endl; //debugSerial<<F("N:")<<n<<endl;
@@ -1059,6 +1069,7 @@ if (WiFi.status() == WL_CONNECTED) {
} else { } else {
infoSerial<<F("Got IP address:"); infoSerial<<F("Got IP address:");
printIPAddress(Ethernet.localIP()); printIPAddress(Ethernet.localIP());
infoSerial<<endl;
lanStatus = HAVE_IP_ADDRESS; lanStatus = HAVE_IP_ADDRESS;
} }
}//DHCP }//DHCP
@@ -1067,12 +1078,17 @@ if (WiFi.status() == WL_CONNECTED) {
char mdnsName[32] = "LightHub"; char mdnsName[32] = "LightHub";
SetBytes(sysConf.mac+4,2,mdnsName+8); SetBytes(sysConf.mac+4,2,mdnsName+8);
mdns.begin(Ethernet.localIP(), mdnsName); if(!mdns.begin(Ethernet.localIP(), mdnsName))
errorSerial<<F("Error setting up MDNS responder!")<<endl;
else infoSerial<<F("mDNS responder started.")<<endl;
char txtRecord[32] = "\x10mac="; char txtRecord[32] = "\x10mac=";
SetBytes(sysConf.mac,6,txtRecord+5); SetBytes(sysConf.mac,6,txtRecord+5);
strncat(mdnsName,"._http",sizeof(mdnsName)); strncat(mdnsName,"._http",sizeof(mdnsName));
mdns.addServiceRecord(mdnsName, OTA_PORT, MDNSServiceTCP, txtRecord); if (!mdns.addServiceRecord(mdnsName, OTA_PORT, MDNSServiceTCP, txtRecord))
errorSerial<<("Error setting up service record!")<<endl;
else infoSerial<<F("Service record: ")<<mdnsName<<F(".local")<<endl;
#endif #endif
#endif //Ethernet #endif //Ethernet
@@ -1239,6 +1255,7 @@ setupSyslog();
if (artnetMaxCh>maxChannels) artnetMaxCh=maxChannels; if (artnetMaxCh>maxChannels) artnetMaxCh=maxChannels;
} }
infoSerial<<F("Artnet start. Channels:")<<artnetMinCh<<F("-")<<artnetMaxCh<<endl; infoSerial<<F("Artnet start. Channels:")<<artnetMinCh<<F("-")<<artnetMaxCh<<endl;
artnetSetup();
artnetSetChans(artnetMinCh,artnetMaxCh); artnetSetChans(artnetMinCh,artnetMaxCh);
//artnetInitialized=true; //artnetInitialized=true;
} }
@@ -1349,6 +1366,14 @@ void printConfigSummary() {
infoSerial<<F("\n1-wire "); infoSerial<<F("\n1-wire ");
printBool(owArr); printBool(owArr);
#endif #endif
#ifdef SYSLOG_ENABLE
infoSerial<<F("\nSyslog ");
printBool(syslogInitialized);
#endif
#ifdef _artnet
infoSerial<<F("\nArtnet ");
printBool(artnet);
#endif
infoSerial << endl; infoSerial << endl;
infoSerial<<F("RAM=")<<freeRam()<<endl; infoSerial<<F("RAM=")<<freeRam()<<endl;
@@ -2003,9 +2028,9 @@ void setup_main() {
mqttClient.setCallback(mqttCallback); mqttClient.setCallback(mqttCallback);
#ifdef _artnet //#ifdef _artnet
artnetSetup(); // artnetSetup();
#endif //#endif
#if defined(WIFI_ENABLE) and not defined(WIFI_MANAGER_DISABLE) #if defined(WIFI_ENABLE) and not defined(WIFI_MANAGER_DISABLE)
// WiFiManager wifiManager; // WiFiManager wifiManager;
@@ -2176,8 +2201,19 @@ infoSerial<<F("\n(+)MDNS");
#else #else
infoSerial<<F("\n(-)MDNS"); infoSerial<<F("\n(-)MDNS");
#endif #endif
infoSerial<<endl;
#ifndef RELAY_DISABLE
infoSerial<<F("\n(+)PWM_RELAY");
#else
infoSerial<<F("\n(-)PWM_RELAY");
#endif
#ifndef MULTIVENT_DISABLE
infoSerial<<F("\n(+)MULTIVENT");
#else
infoSerial<<F("\n(-)MULTIVENT");
#endif
infoSerial<<endl;
// WDT_Disable( WDT ) ; // WDT_Disable( WDT ) ;
#if defined(__SAM3X8E__) #if defined(__SAM3X8E__)

View File

@@ -22,7 +22,7 @@ void out_relay::getConfig()
inverted=true; inverted=true;
} }
if(pin==0 || pin>=PINS_COUNT) pin=32; if(pin==0 || pin>=PINS_COUNT) pin=32;
period = item->getFloatArg(1)*1000.0; period = item->getFloatArg(1)*1000.0;
if (!period) period = 5000UL; if (!period) period = 5000UL;
@@ -37,13 +37,17 @@ int out_relay::Setup()
abstractOut::Setup(); abstractOut::Setup();
debugSerial<<F("Relay-Out #")<<pin<<F(" init")<<endl; debugSerial<<F("Relay-Out #")<<pin<<F(" init")<<endl;
if (!item ) return 0;
pinMode(pin, OUTPUT); pinMode(pin, OUTPUT);
item->setExt(0);
digitalWrite(pin,INACTIVE); digitalWrite(pin,INACTIVE);
if (item) item->setExt(0);
//if (item->getCmd()) item->setFlag(SEND_COMMAND); //if (item->getCmd()) item->setFlag(SEND_COMMAND);
//if (item->itemVal) item->setFlag(SEND_PARAMETERS); //if (item->itemVal) item->setFlag(SEND_PARAMETERS);
driverStatus = CST_INITIALIZED; driverStatus = CST_INITIALIZED;
if (!item->isActive())
{
item->setExt(millisNZ());
}
return 1; return 1;
} }
@@ -60,7 +64,7 @@ int out_relay::Status()
return driverStatus; return driverStatus;
} }
const char action_P[] PROGMEM = "/action"; const char action_P[] PROGMEM = "action";
const char cooling_P[] PROGMEM = "cooling"; const char cooling_P[] PROGMEM = "cooling";
const char heating_P[] PROGMEM = "heating"; const char heating_P[] PROGMEM = "heating";
const char drying_P[] PROGMEM = "drying"; const char drying_P[] PROGMEM = "drying";
@@ -71,13 +75,13 @@ const char off_P[] PROGMEM = "off";
void out_relay::relay(bool state) void out_relay::relay(bool state)
{ {
char subtopic[10]; char subtopic[10]="/";
char val[10]; char val[10];
digitalWrite(pin,(state)?ACTIVE:INACTIVE); digitalWrite(pin,(state)?ACTIVE:INACTIVE);
if (period<1000) return; if (period<1000) return;
debugSerial<<F("Out ")<<pin<<F(" is ")<<(state)<<endl; debugSerial<<F("Out ")<<pin<<F(" is ")<<(state)<<endl;
strcpy_P(subtopic,action_P); strcat_P(subtopic,action_P);
short cmd=item->getCmd(); short cmd=item->getCmd();
if (state) if (state)
switch(cmd) switch(cmd)
@@ -103,21 +107,26 @@ if (state)
if (cmd==CMD_OFF) strcpy_P(val,off_P); if (cmd==CMD_OFF) strcpy_P(val,off_P);
else strcpy_P(val,idle_P); else strcpy_P(val,idle_P);
publishTopic(item->itemArr->name,val,subtopic); debugSerial << F("pub action ") << publishTopic(item->itemArr->name,val,subtopic)<<F(":")<<item->itemArr->name<<subtopic<<F("=>")<<val<<endl;
} }
bool getPinVal(uint8_t pin) bool getPinVal(uint8_t pin)
{return (0!=(*portOutputRegister( digitalPinToPort(pin) ) & digitalPinToBitMask(pin)));} {
return (0!=(*portOutputRegister( digitalPinToPort(pin) ) & digitalPinToBitMask(pin)));
}
int out_relay::Poll(short cause) int out_relay::Poll(short cause)
{ {
if (!item) return 0; if (!item) return 0;
itemCmd st; itemCmd st;
st.loadItem(item); st.loadItem(item);
int val = st.getPercents255(); int val = st.getPercents255();
short cmd = st.getCmd(); short cmd = st.getCmd();
uint32_t timer = item->getExt(); uint32_t timer = item->getExt();
bool needToOff = isTimeOver(timer,millis(),period*val/255);
if (timer && isTimeOver(timer,millis(),period)) if (timer && isTimeOver(timer,millis(),period))
{ {
@@ -125,12 +134,15 @@ uint32_t timer = item->getExt();
if (val && (getPinVal(pin) == INACTIVE)) relay(true); if (val && (getPinVal(pin) == INACTIVE)) relay(true);
} }
else if (timer && (getPinVal(pin) == ACTIVE) && isTimeOver(timer,millis(),period*val/255)) else if (timer && (getPinVal(pin) == ACTIVE) && needToOff)
{ {
relay(false); relay(false);
if (!item->isActive()) item->setExt(0); if (!item->isActive()) item->setExt(0);
} }
else if (timer && val && (getPinVal(pin) == INACTIVE) && !needToOff)
relay(true);
return 0; return 0;
}; };
@@ -140,6 +152,7 @@ int out_relay::Ctrl(itemCmd cmd, char* subItem, bool toExecute)
{ {
debugSerial<<F("relayCtr: "); debugSerial<<F("relayCtr: ");
cmd.debugOut(); cmd.debugOut();
if (! strcmp_P(subItem,action_P)) return 0;
int suffixCode; int suffixCode;
if (cmd.isCommand()) suffixCode = S_CMD; if (cmd.isCommand()) suffixCode = S_CMD;
else suffixCode = cmd.getSuffix(); else suffixCode = cmd.getSuffix();
@@ -157,7 +170,7 @@ case S_SET:
if (!item->getExt()) if (!item->getExt())
{ {
item->setExt(millisNZ()); item->setExt(millisNZ());
relay(true); //relay(true);
} }
} }
else else
@@ -180,7 +193,7 @@ case S_CMD:
if (!item->getExt()) if (!item->getExt())
{ {
item->setExt(millisNZ()); item->setExt(millisNZ());
relay(true); //relay(true);
} }
return 1; return 1;

View File

@@ -558,7 +558,12 @@ RebootFunc();
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=(timestamp + time) % modulo; uint32_t endTime;
if (!time) return true;
if (modulo) endTime = (timestamp + time) % modulo;
else endTime = timestamp + time;
return ((currTime>endTime) && (currTime <timestamp)) || return ((currTime>endTime) && (currTime <timestamp)) ||
((timestamp<endTime) && ((currTime>endTime) || (currTime <timestamp))); ((timestamp<endTime) && ((currTime>endTime) || (currTime <timestamp)));
} }

View File

@@ -67,7 +67,7 @@ char* setTopic(char* buf, int8_t buflen, topicType tt, const char* suffix = NULL
void printUlongValueToStr(char *valstr, unsigned long value); void printUlongValueToStr(char *valstr, unsigned long value);
void scan_i2c_bus(); void scan_i2c_bus();
void softRebootFunc(); void softRebootFunc();
bool isTimeOver(uint32_t timestamp, uint32_t currTime, uint32_t time, uint32_t modulo = 0xFFFFFFFF); bool isTimeOver(uint32_t timestamp, uint32_t currTime, uint32_t time, uint32_t modulo = 0);
//bool executeCommand(aJsonObject* cmd, int8_t toggle = -1, char* defCmd = NULL); //bool executeCommand(aJsonObject* cmd, int8_t toggle = -1, char* defCmd = NULL);
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); bool executeCommand(aJsonObject* cmd, int8_t toggle, itemCmd _itemCmd, aJsonObject* defaultItem=NULL, aJsonObject* defaultEmit=NULL);

View File

@@ -278,7 +278,7 @@ build_flags = !python get_build_flags.py due
;upload_command = arduinoOTA -address 192.168.1.17 -port 80 -username arduino -password password -b -upload /sketch -sketch $SOURCE ;sleep 6 ;upload_command = arduinoOTA -address 192.168.1.17 -port 80 -username arduino -password password -b -upload /sketch -sketch $SOURCE ;sleep 6
;Alternatively, use OTA script for target ota (pio -t ota). Place appropriate script to custom-build-flags/ to allow OTA by one click ;Alternatively, use OTA script for target ota (pio -t ota). Place appropriate script to custom-build-flags/ to allow OTA by one click
_upload_command = custom-build-flags/upload_lighthub21 $SOURCE _upload_command = custom-build-flags/upload_due $SOURCE
lib_ignore = lib_ignore =
;DS2482_OneWire //UNCOMMENT for software 1-wire driver ;DS2482_OneWire //UNCOMMENT for software 1-wire driver