(critical) Syslog memory corruption fixed

LAN startup improved
This commit is contained in:
2020-10-05 15:07:51 +03:00
parent 13efb609d3
commit a511869498
6 changed files with 4717 additions and 4686 deletions

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -149,8 +149,8 @@ aJsonObject *owArr = NULL;
#ifdef _dmxout #ifdef _dmxout
aJsonObject *dmxArr = NULL; aJsonObject *dmxArr = NULL;
#endif #endif
#ifdef SYSLOG_ENABLE #ifdef SYSLOG_ENABLE
aJsonObject *udpSyslogArr = NULL;
bool syslogInitialized = false; bool syslogInitialized = false;
#endif #endif
@@ -189,7 +189,7 @@ void watchdogSetup(void) {} //Do not remove - strong re-definition WDT Init f
void cleanConf() void cleanConf()
{ {
if (!root) return; if (!root) return;
debugSerial<<F("Unlocking config ..."); debugSerial<<F("Unlocking config ...")<<endl;
while (configLocked) while (configLocked)
{ {
//wdt_res(); //wdt_res();
@@ -205,7 +205,7 @@ while (configLocked)
inputLoop(); inputLoop();
yield(); yield();
} }
debugSerial<<F("Stopping channels ...")<<endl;
//Stoping the channels //Stoping the channels
aJsonObject * item = items->child; aJsonObject * item = items->child;
while (items && item) while (items && item)
@@ -220,7 +220,9 @@ while (items && item)
item = item->next; item = item->next;
} }
pollingItem = NULL; pollingItem = NULL;
debugSerial<<F("Stopped")<<endl;
//stopSyslog();
syslogInitialized=false; //Garbage in memory
debugSerial<<F("Deleting conf. RAM was:")<<freeRam(); debugSerial<<F("Deleting conf. RAM was:")<<freeRam();
aJson.deleteItem(root); aJson.deleteItem(root);
root = NULL; root = NULL;
@@ -374,14 +376,26 @@ void setupOTA(void)
//OTA_initialized=true; //OTA_initialized=true;
#endif #endif
} }
void stopSyslog()
{
syslogInitialized = false;
}
void setupSyslog() void setupSyslog()
{ {
#ifdef SYSLOG_ENABLE #ifdef SYSLOG_ENABLE
int syslogPort = 514; int syslogPort = 514;
short n = 0; short n = 0;
aJsonObject *udpSyslogArr = NULL;
if (syslogInitialized) return;
if (lanStatus<HAVE_IP_ADDRESS) return;
if (!root) return;
udpSyslogClient.begin(SYSLOG_LOCAL_SOCKET); udpSyslogClient.begin(SYSLOG_LOCAL_SOCKET);
udpSyslogArr = aJson.getObjectItem(root, "syslog");
if (udpSyslogArr && (n = aJson.getArraySize(udpSyslogArr))) { if (udpSyslogArr && (n = aJson.getArraySize(udpSyslogArr))) {
char *syslogServer = getStringFromConfig(udpSyslogArr, 0); char *syslogServer = getStringFromConfig(udpSyslogArr, 0);
if (n>1) syslogPort = aJson.getArrayItem(udpSyslogArr, 1)->valueint; if (n>1) syslogPort = aJson.getArrayItem(udpSyslogArr, 1)->valueint;
@@ -395,6 +409,7 @@ void setupSyslog()
if (deviceName) udpSyslog.appName(deviceName); if (deviceName) udpSyslog.appName(deviceName);
udpSyslog.defaultPriority(LOG_KERN); udpSyslog.defaultPriority(LOG_KERN);
syslogInitialized=true; syslogInitialized=true;
infoSerial<<F("UDP Syslog initialized!\n"); infoSerial<<F("UDP Syslog initialized!\n");
} }
#endif #endif
@@ -406,10 +421,11 @@ lan_status lanLoop() {
#ifdef NOETHER #ifdef NOETHER
lanStatus=DO_NOTHING;//-14; lanStatus=DO_NOTHING;//-14;
#endif #endif
//Serial.println(lanStatus);
switch (lanStatus) { switch (lanStatus) {
case INITIAL_STATE: case INITIAL_STATE:
// LED.set(ledRED|((configLoaded)?ledBLINK:0));
LED.set(ledRED|((configLoaded)?ledBLINK:0)); LED.set(ledRED|((configLoaded)?ledBLINK:0));
#if defined(WIFI_ENABLE) #if defined(WIFI_ENABLE)
@@ -443,6 +459,7 @@ lan_status lanLoop() {
case HAVE_IP_ADDRESS: case HAVE_IP_ADDRESS:
if (!initializedListeners) if (!initializedListeners)
{ {
setupSyslog();
setupOTA(); setupOTA();
#ifdef _artnet #ifdef _artnet
if (artnet) artnet->begin(); if (artnet) artnet->begin();
@@ -831,15 +848,7 @@ if (WiFi.status() == WL_CONNECTED) {
*/ */
#else // Ethernet connection #else // Ethernet connection
#ifdef W5500_CS_PIN
#ifndef Wiz5500
Ethernet.init(W5500_CS_PIN);
#else
Ethernet.w5500_cspin = W5500_CS_PIN;
#endif
infoSerial<<F("Use W5500 pin: ");
infoSerial<<QUOTE(W5500_CS_PIN)<<endl;
#endif
IPAddress ip, dns, gw, mask; IPAddress ip, dns, gw, mask;
int res = 1; int res = 1;
infoSerial<<F("Starting lan")<<endl; infoSerial<<F("Starting lan")<<endl;
@@ -1005,7 +1014,6 @@ inputs = aJson.getObjectItem(root, "in");
mqttArr = aJson.getObjectItem(root, "mqtt"); mqttArr = aJson.getObjectItem(root, "mqtt");
#ifdef SYSLOG_ENABLE #ifdef SYSLOG_ENABLE
udpSyslogArr = aJson.getObjectItem(root, "syslog");
setupSyslog(); setupSyslog();
#endif #endif
@@ -1118,10 +1126,12 @@ void printConfigSummary() {
infoSerial<<F("\n1-wire "); infoSerial<<F("\n1-wire ");
printBool(owArr); printBool(owArr);
#endif #endif
/*
#ifdef SYSLOG_ENABLE #ifdef SYSLOG_ENABLE
infoSerial<<F("\nudp syslog "); infoSerial<<F("\nudp syslog ");
printBool(udpSyslogArr); printBool(udpSyslogArr);
#endif #endif
*/
infoSerial << endl; infoSerial << endl;
infoSerial<<F("RAM=")<<freeRam()<<endl; infoSerial<<F("RAM=")<<freeRam()<<endl;
} }
@@ -1453,19 +1463,19 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
response = htclient.responseBody(); response = htclient.responseBody();
htclient.stop(); htclient.stop();
wdt_res(); wdt_res();
infoSerial<<F("HTTP Status code: "); infoSerial<<F("HTTP Status code: ")<<responseStatusCode<<endl;
infoSerial<<responseStatusCode<<" ";
//debugSerial<<"GET Response: "); //debugSerial<<"GET Response: ");
//delay(1000);
if (responseStatusCode == 200) { if (responseStatusCode == 200) {
cleanConf(); cleanConf();
debugSerial<<F("Configuration cleaned")<<endl;
root = aJson.parse((char *) response.c_str()); root = aJson.parse((char *) response.c_str());
if (!root) { if (!root) {
errorSerial<<F("Config parsing failed\n"); errorSerial<<F("Config parsing failed\n");
return READ_RE_CONFIG;//-11; //Load from NVRAM return READ_RE_CONFIG;//-11; //Load from NVRAM
} else { } else {
debugSerial<<response; //debugSerial<<response;
applyConfig(); applyConfig();
infoSerial<<F("Done.\n"); infoSerial<<F("Done.\n");
} }
@@ -1564,7 +1574,7 @@ void setup_main() {
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
EEPROM.begin(ESP_EEPROM_SIZE); EEPROM.begin(ESP_EEPROM_SIZE);
#endif #endif
loadConfigFromEEPROM();
#ifdef _modbus #ifdef _modbus
#ifdef CONTROLLINO #ifdef CONTROLLINO
@@ -1608,6 +1618,18 @@ void setup_main() {
delay(LAN_INIT_DELAY);//for LAN-shield initializing delay(LAN_INIT_DELAY);//for LAN-shield initializing
//TODO: checkForRemoteSketchUpdate(); //TODO: checkForRemoteSketchUpdate();
#ifdef W5500_CS_PIN
//#ifndef Wiz5500
Ethernet.init(W5500_CS_PIN);
//#else
// Ethernet.w5500_cspin = W5500_CS_PIN;
//#endif
infoSerial<<F("Use W5500 pin: ");
infoSerial<<QUOTE(W5500_CS_PIN)<<endl;
#endif
loadConfigFromEEPROM();
} }
void printFirmwareVersionAndBuildOptions() { void printFirmwareVersionAndBuildOptions() {
@@ -1731,6 +1753,7 @@ infoSerial<<F("\n(-)MCP23017");
#endif #endif
#ifdef SYSLOG_ENABLE #ifdef SYSLOG_ENABLE
//udpSyslogClient.begin(SYSLOG_LOCAL_SOCKET);
infoSerial<<F("\n(+)SYSLOG"); infoSerial<<F("\n(+)SYSLOG");
#else #else
infoSerial<<F("\n(-)SYSLOG"); infoSerial<<F("\n(-)SYSLOG");
@@ -1745,8 +1768,8 @@ infoSerial<<endl;
infoSerial<< F ("ID: "); infoSerial<< F ("ID: ");
for (byte b = 0 ; b < 4 ; b++) for (byte b = 0 ; b < 4 ; b++)
infoSerial<< _HEX((unsigned int) UniqueID.UID_Long [b]) <<endl ; infoSerial<< _HEX((unsigned int) UniqueID.UID_Long [b]);
//debugSerial<< endl; infoSerial<< endl;
#endif #endif
} }

View File

@@ -637,7 +637,7 @@ statusLED::statusLED(uint8_t pattern)
pinMode(pinGREEN, OUTPUT); pinMode(pinGREEN, OUTPUT);
pinMode(pinBLUE, OUTPUT); pinMode(pinBLUE, OUTPUT);
set(pattern); set(pattern);
timestamp=0; timestamp=millis()+ledDelayms;
#endif #endif
} }

View File

@@ -14,7 +14,7 @@ src_dir = lighthub
default_envs = default_envs =
; ****** UNCOMMENT single environment name for target platform below ******* ; ****** UNCOMMENT single environment name for target platform below *******
; Arduino Mega (without onewire) + Ethernet shield Wiznet 5100 ; Arduino Mega (without onewire) + Ethernet shield Wiznet 5100
; mega2560slim-5100 mega2560slim-5100
; Arduino Mega + Ethernet shield Wiznet 5100 ; Arduino Mega + Ethernet shield Wiznet 5100
; mega2560-5100 ; mega2560-5100
@@ -592,6 +592,7 @@ lib_ignore =
DmxSimple DmxSimple
httpClient httpClient
Ethernet2 Ethernet2
;Ethernet
Ethernet3 Ethernet3
Ethernet5100 Ethernet5100
NRFFlashStorage NRFFlashStorage