AutoConnectUpdate API
Only for AutoConnect
The following AutoConnectUpdate API are valid only for AutoConnect; they are not available for AutoConnectCore.
Constructor¶
AutoConnectUpdate¶
AutoConnectUpdate(const String& host, const uint16_t port, const String& uri, const int timeout, const uint8_t ledOn)
- Parameters
- hostUpdate server address. Specifies IP address or FQDN.
- portSpecifies HTTP port for the updating process. The default assumes
AUTOCONNECT_UPDATE_PORT
defined in theAutoConnectDefs.h
header file. - uriSpecifies a URI on the update server that has deployed available binary sketch files.
- timeoutSpecifies the maximum response time for the update server. The default assumes
AUTOCONNECT_UPDATE_TIMEOUT
in theAutoConnectDefs.h
header file.- ledOnActive signal to light the LED ticker during the update. Specifies HIGH or LOW
The AutoConnectUpdate class inherits from the ESP8266HTTPUpdate (HTTPUpdate for ESP32) class.
Public member functions¶
attach¶
void AutoConnectUpdate::attach(AutoConnect& portal)
Attaches the AutoConnectUpdate to the AutoConnect which constitutes the bedrock of the update process. This function creates a dialog page for the update operation as an instance of AutoConnectAux and participates in the AutoConnect menu.
- Parameter
- portalSpecifies a reference to the AutoConnect instance to attach.
disable¶
void AutoConnectUpdate::disable(const bool activate)
Disable the Update item in AutoConnect menu. The AutoConnect::disable function only hides the Update item from the menu, and the AutoConnectUpdate class is still active with the parameter condition. You can use the AutoConnectUpdate::enable function to appear it again in the menu.
- Parameter
- activateIf specified the true then the Update item will be displayed on the AutoConnect menu and OTA update will be available during the WiFi status is WL_CONNECTED. For the false, the OTA update feature is disabled.
enable¶
void AutoConnectUpdate::enable(void)
Makes AutoConnectUpdate class available by incorporating the OTA update function into the AutoConnect menu. In ordinarily, the AutoConnectUpdate class becomes available by just calling the AutoConnectUpdate::attach function.
handleUpdate¶
void AutoConnectUpdate::handleUpdate(void)
Performs the update process. This function is called by AutoConnect::handleClient when AutoConnectUpdate is enabled. In many cases, sketches do not need to call this function on purpose.
isEnabled¶
bool AutoConnectUpdate::isEnabled(void)
Returns whether AutoConnectUpdate is enabled.
rebootOnUpdate¶
void AutoConnectUpdate::rebootOnUpdate(bool reboot)
Specifies whether or not to automatically restart the module as a result of the successful completion of the update process.
- Parameter
- rebootIf specified the true then the ESP module will reboot after the updating successfully completed. For the false, The module does not reboot automatically. The uploaded new firmware remains in the updating stage of the flash on the ESP module.
The boot process during the next start turn of the module by reset will copy the updated firmware to the actual program area and a new sketch program will start. The default value is true.
This function inherits from the ESP8266HTTPUpdate (HTTPUpdate for ESP32) class.
onEnd¶
void AutoConnectUpdate::onEnd(HTTPUpdateEndCB fn)
- Parameter
- fnA function called when the update has been finished.
This function inherits from the ESP8266HTTPUpdate (HTTPUpdate for ESP32) class.
An fn specifies the function called when the update has been finished. Its prototype declaration is defined as HTTPUpdateEndCB.
using HTTPUpdateEndCB = std::function<void()>;
onError¶
void AutoConnectUpdate::onError(HTTPUpdateErrorCB fn)
Register the exit routine that is called when some error occurred. For the ESP32 platform, this function is only available in ESP32 Arduino core 2.0.0 or later.
- Parameter
- fnA function called when some updating error occurs.
This function inherits from the ESP8266HTTPUpdate (HTTPUpdate for ESP32) class.
An fn specifies the function called when the some error occurred. Its prototype declaration is defined as HTTPUpdateErrorCB.
using HTTPUpdateErrorCB = std::function<void(int error)>;
- Parameter
- errorError code of the Update. It is defined in the ESP8266HTTPClient class, ESP8266HTTPUpdate class or the HTTPUpdate class of the Arduino core for each platform.
onProgress¶
void AutoConnectUpdate::onProgress(HTTPUpdateProgressCB fn)
Register the exit routine that is called during the update progress. For the ESP32 platform, this function is only available in ESP32 Arduino core 2.0.0 or later.
- Parameter
- fnA function called during the updating progress.
This function inherits from the ESP8266HTTPUpdate (HTTPUpdate for ESP32) class.
An fn specifies the function called during the updating progress. Its prototype declaration is defined as HTTPUpdateProgressCB.
Updating Progress bar will not available
AutoConnectUpdate uses the onProgress exit to update the progress bar on a web page during updating. If the user sketch registers its own exit routine with the onProgress function, AutoConnectUpdate's progress bar on the web page will not be updated.
using HTTPUpdateProgressCB = std::function<void(int amount, int size)>;
- Parameters
- amountTotal amount of bytes received.
- sizeBlock size of current send.
onStart¶
void AutoConnectUpdate::onStart(HTTPUpdateStartCB fn)
Register the on-start exit routine that is called only once when the update has been started. For the ESP32 platform, this function is only available in ESP32 Arduino core 2.0.0 or later.
- Parameter
- fnA function called at the update start.
This function inherits from the ESP8266HTTPUpdate (HTTPUpdate for ESP32) class.
An fn specifies the function called when the OTA starts. Its prototype declaration is defined as HTTPUpdateStartCB.
using HTTPUpdateStartCB = std::function<void()>;
setLedPin¶
void AutoConnectUpdate::setLedPin(int ledPin, uint8_t ledOn)
Sets the port and the ON signal level of the externally connected LED that should act as a ticker during the update process.
- Parameter
- ledPinSpecifies the PIN connected external LED for the ticker. The default assumes
AUTOCONNECT_TICKER_PORT
defined in theAutoConnectDefs.h
header file and it is derived from the board-specific LED_BUILTIN. By default, the AutoConnectUpdate class does not use the ticker for boards without the LED_BUILTIN definition. If you connect the ticker LED externally, you need to specify the PIN using the setLedPin function. - ledOnSpecifies the the ON signal level of the LED PIN port. It is HIGH or LOW.
This function inherits from the ESP8266HTTPUpdate (HTTPUpdate for ESP32) class.
status¶
AC_UPDATESTATUS_t AutoConnectUpdate::status(void)
Returns the update process status transition indicator as an enumerated value of the AC_UPDATESTATUS_t type that indicates the process status of the AutoConnectUpdate class.
- Return value
- One of the enumerated values indicating the status of the Update class as follows:
-
- UPDATE_RESET : Update process ended, need to reset.
- UPDATE_IDLE : Update process has not started.
- UPDATE_START : Update process has been started.
- UPDATE_PROGRESS : Update process has been started.
- UPDATE_SUCCESS : Update successfully completed.
- UPDATE_NOAVAIL : No available update.
- UPDATE_FAIL : Update failed.
Public member variables¶
host¶
Update server address. Specifies IP address or FQDN.
- Type
- String
port¶
HTTP port for the updating process.
- Type
- StringThe default assumes
AUTOCONNECT_UPDATE_PORT
defined in theAutoConnectDefs.h
header file.
uri¶
URI on the update server that has deployed available binary sketch files.
- Type
- String