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