cleanup and odd cleanConf fix

This commit is contained in:
2024-08-22 00:35:47 +03:00
parent 806e99eb92
commit e21541aa7a
3 changed files with 31 additions and 56 deletions

View File

@@ -322,8 +322,8 @@ switch (state)
if (CANConfStream.peek() == '{') { if (CANConfStream.peek() == '{') {
debugSerial<<F("CAN: JSON detected")<<endl; debugSerial<<F("CAN: JSON detected")<<endl;
aJsonStream as = aJsonStream(&CANConfStream);
cleanConf(1); cleanConf(1);
aJsonStream as = aJsonStream(&CANConfStream);
root = aJson.parse(&as); root = aJson.parse(&as);
CANConfStream.close(); CANConfStream.close();
if (!root) { if (!root) {

View File

@@ -115,24 +115,24 @@ UID UniqueID;
#endif #endif
uint8_t brokers = 0; uint8_t brokers = 0;
char *deviceName = NULL; char *deviceName = NULL;
aJsonObject *topics = NULL; aJsonObject *topics = NULL;
aJsonObject *root = NULL; aJsonObject *root = NULL;
aJsonObject *items = NULL; aJsonObject *items = NULL;
aJsonObject *inputs = NULL; aJsonObject *inputs = NULL;
aJsonObject *brokersArr = NULL; aJsonObject *brokersArr = NULL;
aJsonObject *mqttArr = NULL; aJsonObject *mqttArr = NULL;
#ifdef _modbus #ifdef _modbus
aJsonObject *modbusObj = NULL; aJsonObject *modbusObj = NULL;
#endif #endif
#ifdef _owire #ifdef _owire
aJsonObject *owArr = NULL; aJsonObject *owArr = NULL;
#endif #endif
#ifdef _dmxout #ifdef _dmxout
aJsonObject *dmxArr = NULL; aJsonObject *dmxArr = NULL;
#endif #endif
#ifdef SYSLOG_ENABLE #ifdef SYSLOG_ENABLE
bool syslogInitialized = false; volatile bool syslogInitialized = false;
#endif #endif
#ifdef WIFI_ENABLE #ifdef WIFI_ENABLE
@@ -153,11 +153,11 @@ volatile uint32_t ultrasonicInputCheck=0;
aJsonObject *pollingItem = NULL; aJsonObject *pollingItem = NULL;
bool owReady = false; volatile bool owReady = false;
bool configOk = false; // At least once connected to MQTT volatile bool configOk = false; // At least once connected to MQTT
bool configLoaded = false; volatile bool configLoaded = false;
bool initializedListeners = false; volatile bool initializedListeners = false;
uint8_t DHCP_failures = 0; volatile uint8_t DHCP_failures = 0;
volatile int8_t ethernetIdleCount =0; volatile int8_t ethernetIdleCount =0;
volatile int8_t configLocked = 0; volatile int8_t configLocked = 0;
@@ -179,43 +179,17 @@ void watchdogSetup(void) {} //Do not remove - strong re-definition WDT Init f
bool cleanConf(short locksAlowed ) bool cleanConf(short locksAlowed )
{ {
if (!root) return true; if (!root)
bool clean = true; {
//debugSerial<<F("No root")<<endl;
return true;
}
if (configLocked>locksAlowed) if (configLocked>locksAlowed)
{ {
errorSerial<<F("Can not clean - locked")<<endl; errorSerial<<F("Can not clean - locked")<<endl;
return false; return false;
} }
/*
No more unsafe operations
if (wait)
{
debugSerial<<F("Unlocking config ...")<<endl;
uint32_t stamp=millis();
while (configLocked && !isTimeOver(stamp,millis(),10000))
{
//wdt_res();
cmdPoll();
#ifdef _owire
if (owReady && owArr) owLoop();
#endif
#ifdef _dmxin
DMXCheck();
#endif
if (isNotRetainingStatus()) pollingLoop();
thermoLoop();
inputLoop(CHECK_INPUT);
yield();
}
if (configLocked)
{
errorSerial<<F("Not unlocked in 10s - continue ...")<<endl;
clean = false;
}
} //wait
*/
debugSerial<<F("Stopping channels ...")<<endl; debugSerial<<F("Stopping channels ...")<<endl;
timerHandlerBusy++; timerHandlerBusy++;
//Stoping the channels //Stoping the channels
@@ -265,7 +239,7 @@ debugSerial<<F("Deleting conf. RAM was:")<<freeRam();
configOk=false; configOk=false;
timerHandlerBusy--; timerHandlerBusy--;
return clean; return true;
} }
bool isNotRetainingStatus() { bool isNotRetainingStatus() {
@@ -1671,8 +1645,9 @@ int loadConfigFromEEPROM()
if (sysConfStream.peek() == '{') { if (sysConfStream.peek() == '{') {
debugSerial<<F("JSON detected")<<endl; debugSerial<<F("JSON detected")<<endl;
cleanConf(1);
aJsonStream as = aJsonStream(&sysConfStream); aJsonStream as = aJsonStream(&sysConfStream);
cleanConf(0); ///WTF!
root = aJson.parse(&as); root = aJson.parse(&as);
sysConfStream.close(); sysConfStream.close();
if (!root) { if (!root) {
@@ -1974,7 +1949,7 @@ if (!sysConf.getServer(configServer,sizeof(configServer)))
infoSerial<<F("got Config\n"); delay(500); infoSerial<<F("got Config\n"); delay(500);
aJsonFileStream as = aJsonFileStream(configStream); aJsonFileStream as = aJsonFileStream(configStream);
noInterrupts(); noInterrupts();
if (!cleanConf(true)) if (!cleanConf(0))
{ {
errorSerial<<F("Get aborted")<<endl; errorSerial<<F("Get aborted")<<endl;
hclient.closeStream(configStream); hclient.closeStream(configStream);
@@ -2051,7 +2026,7 @@ if (!sysConf.getServer(configServer,sizeof(configServer)))
if (responseStatusCode == 200) { if (responseStatusCode == 200) {
aJsonStream socketStream = aJsonStream(&htclient); aJsonStream socketStream = aJsonStream(&htclient);
debugSerial<<F("Free:")<<freeRam()<<endl; debugSerial<<F("Free:")<<freeRam()<<endl;
if (!cleanConf(true)) if (!cleanConf(0))
{ {
errorSerial<<F("Get aborted")<<endl; errorSerial<<F("Get aborted")<<endl;
htclient.stop(); htclient.stop();
@@ -2130,7 +2105,7 @@ if (!sysConf.getServer(configServer,sizeof(configServer)))
sysConf.setETAG(httpClient.header("ETag")); sysConf.setETAG(httpClient.header("ETag"));
//String response = httpClient.getString(); //String response = httpClient.getString();
//debugSerial<<response; //debugSerial<<response;
if (!cleanConf(true)) if (!cleanConf(0))
{ {
errorSerial<<F("Get aborted")<<endl; errorSerial<<F("Get aborted")<<endl;
httpClient.end(); httpClient.end();

View File

@@ -983,10 +983,10 @@ uint16_t getCRC(aJsonObject * in)
if (!in) return 0; if (!in) return 0;
CRCStream crcStream; CRCStream crcStream;
aJsonStream aJsonCrcStream = aJsonStream(&crcStream); aJsonStream aJsonCrcStream = aJsonStream(&crcStream);
debugSerial<<"CRC: in"; //debugSerial<<"CRC: in";
debugSerial.print(aJson.print(in)); //debugSerial.print(aJson.print(in));
aJson.print(in,&aJsonCrcStream,false); aJson.print(in,&aJsonCrcStream,false);
debugSerial<<"\nCRC:"<<crcStream.getCRC16(); //debugSerial<<"\nCRC:"<<crcStream.getCRC16();
return crcStream.getCRC16(); return crcStream.getCRC16();
} }