mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 03:39:49 +03:00
config reload issues fixed
This commit is contained in:
1
compiled/lighthub21/uploadOTA.BAT
Normal file
1
compiled/lighthub21/uploadOTA.BAT
Normal file
@@ -0,0 +1 @@
|
||||
..\tools\arduinoOTA -address 192.168.11.204 -port 80 -username arduino -password password -sketch firmware.bin -b -upload /sketch
|
||||
@@ -1,3 +1,5 @@
|
||||
|
||||
|
||||
#pragma once
|
||||
#include "Arduino.h"
|
||||
#include "abstractch.h"
|
||||
|
||||
@@ -815,11 +815,11 @@ int Item::scheduleCommand(itemCmd cmd,bool authorized)
|
||||
aJsonObject *timestampObj = aJson.getArrayItem(itemArr, I_TIMESTAMP);
|
||||
if (timestampObj && cmd.getCmd()<=0xf)
|
||||
{
|
||||
if ((cmd.getInt()>0) && (timestampObj->type == aJson_Int || timestampObj->type == aJson_NULL))
|
||||
if ((cmd.getInt()>0) && (timestampObj->type == aJson_Int || timestampObj->type == aJson_NULL || timestampObj->type == aJson_Reserved))
|
||||
{
|
||||
timestampObj->valueint = millis()+cmd.getInt();
|
||||
timestampObj->type = aJson_Int;
|
||||
timestampObj->subtype=(cmd.getCmd() & 0xF) | ((authorized?1:0)<<4);
|
||||
timestampObj->type = (authorized?aJson_Reserved:aJson_Int);
|
||||
timestampObj->subtype=(cmd.getCmd() & 0xF);
|
||||
|
||||
debugSerial<<F( "Armed for ")<< cmd.getInt() << F(" ms :")<<timestampObj->valueint<<endl;
|
||||
}
|
||||
@@ -1585,7 +1585,8 @@ aJsonObject *timestampObj = aJson.getArrayItem(itemArr, I_TIMESTAMP);
|
||||
if (timestampObj)
|
||||
{
|
||||
uint8_t cmd = timestampObj->subtype & 0xF;
|
||||
bool authorized = timestampObj->subtype & 0x10;
|
||||
bool authorized = (timestampObj->type==aJson_Reserved);
|
||||
|
||||
int32_t remain = (uint32_t) timestampObj->valueint - (uint32_t)millis();
|
||||
|
||||
if (cmd) {
|
||||
|
||||
@@ -165,10 +165,12 @@ int8_t mqttErrorRate=0;
|
||||
void watchdogSetup(void) {} //Do not remove - strong re-definition WDT Init for DUE
|
||||
#endif
|
||||
|
||||
bool cleanConf()
|
||||
bool cleanConf(bool wait)
|
||||
{
|
||||
if (!root) return true;
|
||||
bool clean = true;
|
||||
if (wait)
|
||||
{
|
||||
debugSerial<<F("Unlocking config ...")<<endl;
|
||||
uint32_t stamp=millis();
|
||||
while (configLocked && !isTimeOver(stamp,millis(),10000))
|
||||
@@ -192,6 +194,7 @@ if (configLocked)
|
||||
errorSerial<<F("Not unlocked in 10s - continue ...")<<endl;
|
||||
clean = false;
|
||||
}
|
||||
} //wait
|
||||
|
||||
debugSerial<<F("Stopping channels ...")<<endl;
|
||||
timerHandlerBusy++;
|
||||
@@ -201,19 +204,16 @@ if (items)
|
||||
aJsonObject * item = items->child;
|
||||
while (item)
|
||||
{
|
||||
if (item->type == aJson_Array && aJson.getArraySize(item)>0)
|
||||
{
|
||||
if (item->type == aJson_Array && aJson.getArraySize(item)>0)
|
||||
{
|
||||
if (item->type == aJson_Array && (aJson.getArraySize(item)>0))
|
||||
{
|
||||
Item it(item->name);
|
||||
if (it.isValid()) it.Stop();
|
||||
yield();
|
||||
|
||||
}
|
||||
item = item->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else debugSerial<<F("nothing to stop")<<endl;
|
||||
pollingItem = NULL;
|
||||
debugSerial<<F("Stopped")<<endl;
|
||||
delay(100);
|
||||
@@ -747,22 +747,19 @@ lan_status lanLoop() {
|
||||
lanStatus = IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER;//2;
|
||||
break;
|
||||
|
||||
case DO_READ_RE_CONFIG: // Pause and re-read EEPROM
|
||||
timerLanCheckTime = millis();
|
||||
lanStatus = READ_RE_CONFIG;
|
||||
//statusLED.set(ledRED|((configLoaded)?ledBLINK:0));
|
||||
case DO_READ_RE_CONFIG:
|
||||
timerLanCheckTime = millis();
|
||||
lanStatus=READ_RE_CONFIG;
|
||||
break;
|
||||
|
||||
case READ_RE_CONFIG: // Restore config from FLASH, re-init LAN
|
||||
if (isTimeOver(timerLanCheckTime,millis(),TIMEOUT_REINIT))
|
||||
{
|
||||
debugSerial<<F("Restoring config from EEPROM")<<endl;
|
||||
if (loadConfigFromEEPROM()) lanStatus = IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER;//2;
|
||||
else {
|
||||
//timerLanCheckTime = millis();// + 5000;
|
||||
lanStatus = DO_REINIT;//-10;
|
||||
}
|
||||
}
|
||||
if (loadConfigFromEEPROM()) lanStatus = IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER;
|
||||
else
|
||||
if (isTimeOver(timerLanCheckTime,millis(),TIMEOUT_RELOAD))
|
||||
{
|
||||
errorSerial<<F("30s EEPROM is not reloaded. Reboot");
|
||||
softRebootFunc();
|
||||
}
|
||||
break;
|
||||
|
||||
case DO_NOTHING:
|
||||
@@ -1513,12 +1510,14 @@ void printConfigSummary() {
|
||||
}
|
||||
|
||||
int cmdFunctionLoad(int arg_cnt, char **args) {
|
||||
|
||||
/*
|
||||
if (!loadConfigFromEEPROM())
|
||||
{
|
||||
lanStatus=DO_REINIT;
|
||||
return 500;
|
||||
}
|
||||
}
|
||||
*/
|
||||
lanStatus=DO_READ_RE_CONFIG;
|
||||
return 200;
|
||||
}
|
||||
|
||||
@@ -1526,6 +1525,8 @@ int cmdFunctionLoad(int arg_cnt, char **args) {
|
||||
int loadConfigFromEEPROM()
|
||||
{
|
||||
if (configLocked) return 0;
|
||||
configLocked++;
|
||||
|
||||
infoSerial<<F("Loading Config from EEPROM")<<endl;
|
||||
#if defined(FS_STORAGE)
|
||||
sysConfStream.open("/config.json",'r');
|
||||
@@ -1536,16 +1537,18 @@ int loadConfigFromEEPROM()
|
||||
if (sysConfStream.peek() == '{') {
|
||||
debugSerial<<F("JSON detected")<<endl;
|
||||
aJsonStream as = aJsonStream(&sysConfStream);
|
||||
cleanConf();
|
||||
cleanConf(false);
|
||||
root = aJson.parse(&as);
|
||||
sysConfStream.close();
|
||||
if (!root) {
|
||||
errorSerial<<F("load failed")<<endl;
|
||||
sysConf.setETAG("");
|
||||
// sysConfStream.close();
|
||||
configLocked--;
|
||||
return 0;
|
||||
}
|
||||
infoSerial<<F("Loaded from EEPROM")<<endl;
|
||||
configLocked--;
|
||||
applyConfig();
|
||||
sysConf.loadETAG();
|
||||
//ethClient.stop(); //Refresh MQTT connect to get retained info
|
||||
@@ -1558,6 +1561,7 @@ int loadConfigFromEEPROM()
|
||||
}
|
||||
sysConfStream.close();
|
||||
infoSerial<<F("No stored config")<<endl;
|
||||
configLocked--;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1816,7 +1820,7 @@ if (!sysConf.getServer(configServer,sizeof(configServer)))
|
||||
infoSerial<<F("got Config\n"); delay(500);
|
||||
aJsonFileStream as = aJsonFileStream(configStream);
|
||||
noInterrupts();
|
||||
cleanConf();
|
||||
cleanConf(true);
|
||||
root = aJson.parse(&as);
|
||||
interrupts();
|
||||
hclient.closeStream(configStream); // this is very important -- be sure to close the STREAM
|
||||
@@ -1888,7 +1892,7 @@ if (!sysConf.getServer(configServer,sizeof(configServer)))
|
||||
if (responseStatusCode == 200) {
|
||||
aJsonStream socketStream = aJsonStream(&htclient);
|
||||
debugSerial<<F("Free:")<<freeRam()<<endl;
|
||||
cleanConf();
|
||||
cleanConf(true);
|
||||
debugSerial<<F("Configuration cleaned")<<endl;
|
||||
debugSerial<<F("Free:")<<freeRam()<<endl;
|
||||
//root = aJson.parse((char *) response.c_str());
|
||||
|
||||
@@ -193,9 +193,10 @@ else
|
||||
|
||||
int out_Modbus::Stop()
|
||||
{
|
||||
debugSerial.println("MBUS: De-Init");
|
||||
debugSerial.print("MBUS: De-Init ");
|
||||
debugSerial.println(item->itemArr->name);
|
||||
|
||||
delete store;
|
||||
if (store) delete store;
|
||||
item->setPersistent(NULL);
|
||||
store = NULL;
|
||||
return 1;
|
||||
|
||||
@@ -138,7 +138,8 @@ else
|
||||
|
||||
int out_pid::Stop()
|
||||
{
|
||||
debugSerial.println("PID: De-Init");
|
||||
debugSerial.print(F("PID: De-Init "));
|
||||
debugSerial.println(item->itemArr->name);
|
||||
if (store) delete (store->pid);
|
||||
delete store;
|
||||
item->setPersistent(NULL);
|
||||
|
||||
@@ -20,7 +20,7 @@ void analogWrite(int pin, int val)
|
||||
int out_pwm::Setup()
|
||||
{
|
||||
abstractOut::Setup();
|
||||
debugSerial<<F("PWM-Out #")<<iaddr<<F(" init")<<endl;
|
||||
debugSerial<<F("PWM-Out #")<<iaddr<<F(" ")<<item->itemArr->name<<F(" init")<<endl;
|
||||
if (!item || iaddr) return 0;
|
||||
|
||||
switch (getChanType())
|
||||
@@ -61,7 +61,7 @@ return 1;
|
||||
|
||||
int out_pwm::Stop()
|
||||
{
|
||||
debugSerial<<F("PWM-Out #")<<iaddr<<F(" stop")<<endl;
|
||||
debugSerial<<F("PWM-Out #")<<iaddr<<F(" ")<<item->itemArr->name<<F(" stop")<<endl;
|
||||
|
||||
switch (getChanType())
|
||||
{
|
||||
|
||||
@@ -75,6 +75,7 @@
|
||||
#define WIFI_TIMEOUT 60000UL
|
||||
#define TIMEOUT_RECONNECT 10000UL
|
||||
#define TIMEOUT_REINIT 5000UL
|
||||
#define TIMEOUT_RELOAD 30000UL
|
||||
#define TIMEOUT_RETAIN 8000UL
|
||||
#define INTERVAL_1W 5000UL
|
||||
#define PERIOD_THERMOSTAT_FAILED (600 * 1000UL)
|
||||
|
||||
Reference in New Issue
Block a user