- I am using ESP32-WROOM-32E (16MB flash). And I am using Arduino IDE for firmware development.
- While updating the Firmware via OTA the Wi-Fi connection gets interrupted due to a network issue. The device gets hang-in that state for 45 minutes (nearly 1 hour) and then restarted automatically & starts to work on the previous firmware.
- Is there any way to exit from that hanging state by doing any changes coding-wise or in the library?
I have attached the coding & output screenshots below. Could you suggest any points to overcome this?
#include <WiFi.h>
#include <otadrive_esp.h>
/*Wi-fi credentials details-in which our device was connected to..*/
const char* cSsid = "Washing_Machine";
const char* cPassword = "Test@123";
/*OTA mode - Timer variables*/
unsigned long otaUpdateStartTime = 0;
unsigned long otatimerDelay = 5; // By default 5 minutes was given for updating the firmware
unsigned long otaInterval;;
String otaApiKey = "668e0b8d-f416-4072-ace1-6147d57cad4f";
String firmwareVersion = "v@1.1.1";
void onUpdateProgress(int progress, int totalt);
void onUpdateProgress(int progress, int totalt)
{
static int last = 0;
int progressPercent = (100 * progress) / totalt;
Serial.print("*");
if (last != progressPercent && progressPercent % 10 == 0)
{
//print every 10%
Serial.printf("%d", progressPercent);
if (WiFi.status() == WL_CONNECTED)
{
Serial.println("Wi_Fi Connected!");
}
else
{
Serial.println("Wi-Fi Connection Timeout");
}
}
last = progressPercent;
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
WiFiEnable();
OtaDriveInit();
}
void loop() {
// put your main code here, to run repeatedly:
if ((WiFi.status() == WL_CONNECTED))
{
/* Firmware update is not possible when the RTOS is in run condition*/
OtaDrivecheck();
}
else {
Serial.println("WiFi disconnected...Trying to Connect Again!");
WiFiEnable();
}
}
void WiFiEnable(void)
{
unsigned long wifiLastTimeout = millis();
//Wi-Fi in Station mode
WiFi.mode(WIFI_STA);
// Connect to WiFi network
WiFi.begin(cSsid, cPassword);
Serial.print("Connecting");
// Waiting for connection
while ((WiFi.status() != WL_CONNECTED) && ( millis() - wifiLastTimeout <= 30000)) {
delay(500);
Serial.print(".");
}
if (WiFi.status() != WL_CONNECTED)
{
Serial.println("Wi_Fi Connection Timeout!");
}
else
{
Serial.println("");
Serial.print("Connected to ");
Serial.println(cSsid);
}
}
/*To disconnect the Wi-Fi*/
void WiFiDisable(void)
{
WiFi.disconnect();
Serial.println("Wi-Fi is disabled");
}
/*Over The Air Firmware Update initialization*/
void OtaDriveInit(void)
{
/*Set the information of Registered device's API key in the OTA drive..*/
OTADRIVE.setInfo(otaApiKey, firmwareVersion);
OTADRIVE.onUpdateFirmwareProgress(onUpdateProgress);
Serial.printf("OTA Drive Frimware Version:%s\n", firmwareVersion);
Serial.print("OtaDrive MAC address:");
Serial.println(OTADRIVE.getChipId());
}
/*OTA Firmware update check if the device is in Firmware update mode*/
void OtaDrivecheck(void)
{
if (WiFi.status() == WL_CONNECTED)
{
/*Check and update the new version every 10 seconds if it connected to Wi-fi*/
if (OTADRIVE.timeTick(60))
{
// retrive firmware info from OTAdrive server
updateInfo inf = OTADRIVE.updateFirmwareInfo();
Serial.printf("\nfirmware info: %s ,%dBytes\n%s\n",
inf.version.c_str(), inf.size, inf.available ? "New version available" : "No newer version");
// update firmware if newer available
if (inf.available)
{
OTADRIVE.updateFirmware();
}
}
}
else
{
Serial.println("Wi-Fi not Connected");
WiFiEnable(); //For Trying to Reconnect with the Wi-Fi, if it is disconnect in between after the sometime
}
unsigned long otaInterval = otatimerDelay * 60000;
if ((millis() - otaUpdateStartTime) > otaInterval)
{
Serial.println("OTA update Interval is Exceeded");
Serial.println("Restarting...");
delay(1000);
ESP.restart();
}
}
Serial port Log:
11:53:24.990 -> ⸮⸮0ND)!
11:53:24.990 -> Jʄ嫦⸮b⸮⸮1⸮⸮Connecting............................................................Wi_Fi Connection Timeout!
11:53:55.382 -> OTA Drive Frimware Version:v@1.1.0
11:53:55.382 -> OtaDrive MAC address:24146757ddc4
11:53:55.476 -> WiFi disconnected...Trying to Connect Again!
11:53:55.476 -> Connecting............................................................Wi_Fi Connection Timeout!
11:54:25.402 -> WiFi disconnected...Trying to Connect Again!
11:54:25.450 -> Connecting...........................
11:54:38.871 -> Connected to Washing_Machine
11:54:39.626 ->
11:54:39.626 -> firmware info: ,0Bytes
11:54:39.626 -> No newer version
11:55:39.742 ->
11:55:39.742 -> firmware info: 1.1.1 ,743840Bytes
11:55:39.742 -> New version available
11:55:42.464 -> ********************10Wi_Fi Connected!
11:55:46.913 -> ******************20Wi_Fi Connected!
11:55:50.800 -> ***OTA update Interval is Exceeded
12:36:29.075 -> Restarting...
12:36:30.039 -> ⸮⸮⸮⸮L⸮1⸮)⸮⸮⸮)⸮⸮9⸮!թConnecting............................................................Wi_Fi Connection Timeout!
12:37:00.455 -> OTA Drive Frimware Version:v@1.1.0
12:37:00.455 -> OtaDrive MAC address:24146757ddc4
12:37:00.551 -> WiFi disconnected...Trying to Connect Again!
12:37:00.551 -> Connecting............................................................Wi_Fi Connection Timeout!
12:37:30.450 -> WiFi disconnected...Trying to Connect Again!
12:37:30.498 -> Connecting............................................................Wi_Fi Connection Timeout!
12:38:00.469 -> WiFi disconnected...Trying to Connect Again!