disable all automatic restarts when OTA has started
This commit is contained in:
13
Network.cpp
13
Network.cpp
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
5
Ota.cpp
5
Ota.cpp
@@ -33,3 +33,8 @@ void Ota::updateFirmware(uint8_t* buf, size_t size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Ota::updateStarted()
|
||||
{
|
||||
return _updateStarted;
|
||||
}
|
||||
|
||||
2
Ota.h
2
Ota.h
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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 = "----";
|
||||
|
||||
5
main.cpp
5
main.cpp
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ private:
|
||||
|
||||
int _maintainResult = 0;
|
||||
bool _hasDHCPAddress = false;
|
||||
bool _restartOnDisconnect = false;
|
||||
|
||||
byte _mac[6];
|
||||
};
|
||||
Reference in New Issue
Block a user