disable all automatic restarts when OTA has started

This commit is contained in:
technyon
2022-07-21 18:31:46 +02:00
parent 2ade696e8b
commit a24bb4b0c2
9 changed files with 35 additions and 7 deletions

View File

@@ -37,6 +37,8 @@ void Network::setupDevice(const NetworkDeviceType hardware)
void Network::initialize()
{
_restartOnDisconnect = _preferences->getBool(preference_restart_on_disconnect);
if(_hostname == "")
{
_hostname = "nukihub";
@@ -102,6 +104,11 @@ int Network::update()
if(!_device->isConnected())
{
if(_restartOnDisconnect && millis() > 60000)
{
ESP.restart();
}
Serial.println(F("Network not connected. Trying reconnect."));
bool success = _device->reconnect();
Serial.println(success ? F("Reconnect successful") : F("Reconnect failed"));
@@ -250,6 +257,12 @@ void Network::setMqttPresencePath(char *path)
strcpy(_mqttPresencePrefix, path);
}
void Network::disableAutoRestarts()
{
_networkTimeout = 0;
_restartOnDisconnect = false;
}
bool Network::isMqttConnected()
{
return _mqttConnected;

View File

@@ -21,6 +21,7 @@ public:
void registerMqttReceiver(MqttReceiver* receiver);
void reconfigureDevice();
void setMqttPresencePath(char* path);
void disableAutoRestarts(); // disable on OTA start
void subscribe(const char* prefix, const char* path);
void publishFloat(const char* prefix, const char* topic, const float value, const uint8_t precision = 2);
@@ -60,6 +61,7 @@ private:
int _networkTimeout = 0;
std::vector<MqttReceiver*> _mqttReceivers;
char* _presenceCsv = nullptr;
bool _restartOnDisconnect = false;
unsigned long _lastConnectedTs = 0;
};

View File

@@ -33,3 +33,8 @@ void Ota::updateFirmware(uint8_t* buf, size_t size)
}
}
}
bool Ota::updateStarted()
{
return _updateStarted;
}

2
Ota.h
View File

@@ -9,6 +9,8 @@ class Ota
public:
void updateFirmware(uint8_t* buf, size_t size);
bool updateStarted();
private:
bool _updateStarted = false;
esp_ota_handle_t otaHandler = 0;

View File

@@ -792,6 +792,7 @@ void WebCfgServer::handleOtaUpload()
}
esp_task_wdt_init(30, false);
_network->disableAutoRestarts();
HTTPUpload& upload = _server.upload();
@@ -828,3 +829,8 @@ void WebCfgServer::sendFontsInterMinCss()
// escaped by https://www.cescaper.com/
_server.send(200, "text/plain", intercss);
}
bool WebCfgServer::otaStarted()
{
return _ota.updateStarted();
}

View File

@@ -27,6 +27,7 @@ public:
void initialize();
void update();
bool otaStarted();
private:
@@ -75,7 +76,6 @@ private:
char _credPassword[31] = {0};
bool _allowRestartToPortal = false;
uint32_t _transferredSize = 0;
bool _otaStart = true;
String _hostname;
String _confirmCode = "----";

View File

@@ -94,6 +94,11 @@ void checkMillisTask(void *pvParameters)
{
delay(30000);
if(webCfgServer->otaStarted())
{
return;
}
// millis() is about to overflow. Restart device to prevent problems with overflow
if(millis() > restartTs)
{

View File

@@ -9,7 +9,6 @@ W5500Device::W5500Device(const String &hostname, Preferences* preferences)
_preferences(preferences)
{
initializeMacAddress(_mac);
_restartOnDisconnect = _preferences->getBool(preference_restart_on_disconnect);
Serial.print("MAC Adress: ");
for(int i=0; i < 6; i++)
@@ -47,10 +46,7 @@ void W5500Device::initialize()
bool W5500Device::reconnect()
{
if(_restartOnDisconnect && millis() > 60000)
{
ESP.restart();
}
_hasDHCPAddress = false;

View File

@@ -31,7 +31,6 @@ private:
int _maintainResult = 0;
bool _hasDHCPAddress = false;
bool _restartOnDisconnect = false;
byte _mac[6];
};