mirror of
https://github.com/anklimov/lighthub
synced 2025-12-08 04:39:49 +03:00
Config re-reading memory corruption issue fixed
This commit is contained in:
@@ -157,6 +157,7 @@ aJsonObject *pollingItem = NULL;
|
||||
bool owReady = false;
|
||||
bool configOk = false;
|
||||
int8_t ethernetIdleCount =0;
|
||||
int8_t configLocked = 0;
|
||||
|
||||
#ifdef _modbus
|
||||
ModbusMaster node;
|
||||
@@ -177,6 +178,24 @@ void watchdogSetup(void) {} //Do not remove - strong re-definition WDT Init f
|
||||
void cleanConf()
|
||||
{
|
||||
if (!root) return;
|
||||
debugSerial<<F("Unlocking config ...");
|
||||
while (configLocked)
|
||||
{
|
||||
//wdt_res();
|
||||
cmdPoll();
|
||||
#ifdef _owire
|
||||
if (owReady && owArr) owLoop();
|
||||
#endif
|
||||
#ifdef _dmxin
|
||||
DMXCheck();
|
||||
#endif
|
||||
if (lanStatus != RETAINING_COLLECTING) pollingLoop();
|
||||
thermoLoop();
|
||||
inputLoop();
|
||||
}
|
||||
|
||||
pollingItem = NULL;;
|
||||
|
||||
debugSerial<<F("Deleting conf. RAM was:")<<freeRam();
|
||||
aJson.deleteItem(root);
|
||||
root = NULL;
|
||||
@@ -304,11 +323,8 @@ lan_status lanLoop() {
|
||||
break;
|
||||
|
||||
case HAVE_IP_ADDRESS:
|
||||
#ifdef OTA
|
||||
// start the OTEthernet library with internal (flash) based storage
|
||||
ArduinoOTA.begin(Ethernet.localIP(), "Lighthub", "password", InternalStorage);
|
||||
#endif
|
||||
|
||||
if (configLocked) return HAVE_IP_ADDRESS;
|
||||
if (!configOk)
|
||||
lanStatus = loadConfigFromHttp(0, NULL);
|
||||
else lanStatus = IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER;
|
||||
@@ -452,7 +468,7 @@ void onMQTTConnect(){
|
||||
strncat_P(topic, homie_P, sizeof(topic));
|
||||
strncpy_P(buf, homiever_P, sizeof(buf));
|
||||
mqttClient.publish(topic,buf,true);
|
||||
|
||||
configLocked++;
|
||||
if (items) {
|
||||
char datatype[32]="\0";
|
||||
char format [64]="\0";
|
||||
@@ -514,6 +530,7 @@ void onMQTTConnect(){
|
||||
strncat_P(topic, nodes_P, sizeof(topic));
|
||||
/// mqttClient.publish(topic,buf,true);
|
||||
}
|
||||
configLocked--;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -715,6 +732,10 @@ wifiManager.setTimeout(30);
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
debugSerial<<F("WiFi connected. IP address: ")<<WiFi.localIP()<<endl;
|
||||
lanStatus = HAVE_IP_ADDRESS;//1;
|
||||
#ifdef OTA
|
||||
// start the OTEthernet library with internal (flash) based storage
|
||||
ArduinoOTA.begin(Ethernet.localIP(), "Lighthub", "password", InternalStorage);
|
||||
#endif
|
||||
} else
|
||||
{
|
||||
debugSerial<<F("Problem with WiFi!");
|
||||
@@ -749,6 +770,10 @@ wifiManager.setTimeout(30);
|
||||
} else Ethernet.begin(mac, ip);
|
||||
debugSerial<<endl;
|
||||
lanStatus = HAVE_IP_ADDRESS;
|
||||
#ifdef OTA
|
||||
// start the OTEthernet library with internal (flash) based storage
|
||||
ArduinoOTA.begin(Ethernet.localIP(), "Lighthub", "password", InternalStorage);
|
||||
#endif
|
||||
#ifdef _artnet
|
||||
if (artnet) artnet->begin();
|
||||
#endif
|
||||
@@ -777,6 +802,10 @@ wifiManager.setTimeout(30);
|
||||
debugSerial<<F("Got IP address:");
|
||||
printIPAddress(Ethernet.localIP());
|
||||
lanStatus = HAVE_IP_ADDRESS;//1;
|
||||
#ifdef OTA
|
||||
// start the OTEthernet library with internal (flash) based storage
|
||||
ArduinoOTA.begin(Ethernet.localIP(), "Lighthub", "password", InternalStorage);
|
||||
#endif
|
||||
#ifdef _artnet
|
||||
if (artnet) artnet->begin();
|
||||
#endif
|
||||
@@ -894,6 +923,7 @@ void cmdFunctionReboot(int arg_cnt, char **args) {
|
||||
|
||||
void applyConfig() {
|
||||
if (!root) return;
|
||||
configLocked++;
|
||||
#ifdef _dmxin
|
||||
int itemsCount;
|
||||
dmxArr = aJson.getObjectItem(root, "dmxin");
|
||||
@@ -921,6 +951,7 @@ void applyConfig() {
|
||||
owReady = owSetup(&Changed);
|
||||
if (owReady) debugSerial<<F("One wire Ready\n");
|
||||
t_count = 0;
|
||||
|
||||
while (item && owReady) {
|
||||
if ((item->type == aJson_Object)) {
|
||||
DeviceAddress addr;
|
||||
@@ -980,6 +1011,8 @@ void applyConfig() {
|
||||
udpSyslogArr = aJson.getObjectItem(root, "syslog");
|
||||
#endif
|
||||
printConfigSummary();
|
||||
|
||||
configLocked--;
|
||||
}
|
||||
|
||||
void printConfigSummary() {
|
||||
@@ -1703,9 +1736,9 @@ void loop_main() {
|
||||
#endif
|
||||
|
||||
if (items) {
|
||||
#ifndef MODBUS_DISABLE
|
||||
// #ifndef MODBUS_DISABLE
|
||||
if (lanStatus != RETAINING_COLLECTING) pollingLoop();
|
||||
#endif
|
||||
// #endif
|
||||
//#ifdef _owire
|
||||
thermoLoop();
|
||||
//#endif
|
||||
@@ -1771,9 +1804,10 @@ void modbusIdle(void) {
|
||||
void inputLoop(void) {
|
||||
if (!inputs) return;
|
||||
|
||||
|
||||
configLocked++;
|
||||
if (millis() > nextInputCheck) {
|
||||
aJsonObject *input = inputs->child;
|
||||
|
||||
while (input) {
|
||||
if ((input->type == aJson_Object)) {
|
||||
Input in(input);
|
||||
@@ -1795,12 +1829,12 @@ void inputLoop(void) {
|
||||
}
|
||||
nextSensorCheck = millis() + INTERVAL_CHECK_SENSOR;
|
||||
}
|
||||
|
||||
configLocked--;
|
||||
}
|
||||
|
||||
void inputSetup(void) {
|
||||
if (!inputs) return;
|
||||
|
||||
configLocked++;
|
||||
aJsonObject *input = inputs->child;
|
||||
while (input) {
|
||||
if ((input->type == aJson_Object)) {
|
||||
@@ -1809,11 +1843,13 @@ void inputSetup(void) {
|
||||
}
|
||||
input = input->next;
|
||||
}
|
||||
configLocked--;
|
||||
}
|
||||
|
||||
|
||||
void pollingLoop(void) {
|
||||
// FAST POLLINT - as often AS possible every item
|
||||
configLocked++;
|
||||
if (items) {
|
||||
aJsonObject * item = items->child;
|
||||
while (items && item)
|
||||
@@ -1825,7 +1861,7 @@ if (items) {
|
||||
item = item->next;
|
||||
} //if
|
||||
}
|
||||
|
||||
configLocked--;
|
||||
// SLOW POLLING
|
||||
boolean done = false;
|
||||
if (lanStatus == RETAINING_COLLECTING) return;
|
||||
@@ -1840,6 +1876,7 @@ if (items) {
|
||||
done = true;
|
||||
}
|
||||
}//if
|
||||
if (!pollingItem) return; //Config was re-readed
|
||||
pollingItem = pollingItem->next;
|
||||
if (!pollingItem) {
|
||||
pollingItem = items->child;
|
||||
@@ -1873,6 +1910,7 @@ void thermoLoop(void) {
|
||||
return;
|
||||
if (!items) return;
|
||||
bool thermostatCheckPrinted = false;
|
||||
configLocked++;
|
||||
for (aJsonObject *thermoItem = items->child; thermoItem; thermoItem = thermoItem->next) {
|
||||
if (isThermostatWithMinArraySize(thermoItem, 5)) {
|
||||
aJsonObject *thermoExtensionArray = aJson.getArrayItem(thermoItem, I_EXT);
|
||||
@@ -1916,7 +1954,7 @@ void thermoLoop(void) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
configLocked--;
|
||||
nextThermostatCheck = millis() + THERMOSTAT_CHECK_PERIOD;
|
||||
publishStat();
|
||||
#ifndef DISABLE_FREERAM_PRINT
|
||||
|
||||
Reference in New Issue
Block a user