2024-06-11 23:57:39 +02:00
|
|
|
OTA Update via HTTP Request
|
|
|
|
===========================
|
2024-06-06 04:35:31 +02:00
|
|
|
|
|
|
|
.. seo::
|
|
|
|
:description: Instructions for setting up Over-The-Air (OTA) updates for ESPs to download firmwares remotely by HTTP.
|
|
|
|
:image: system-update.svg
|
|
|
|
|
2024-06-10 02:36:21 +02:00
|
|
|
The OTA (Over The Air) via HTTP Request update component allows your devices to install updated firmware on their own.
|
2024-06-06 04:35:31 +02:00
|
|
|
To use it, in your device's configuration, you specify a URL from which the device will download the binary
|
|
|
|
file (firmware). To trigger the update, an ESPHome :ref:`action <config-action>` is used which initiates the
|
|
|
|
download and installation of the new firmware. Once complete, the device is rebooted, invoking the new firmware.
|
|
|
|
|
|
|
|
Since the device functions as an HTTP(S) client, it can be on a foreign network or behind a firewall. This mechanism
|
|
|
|
is primarily useful with either standalone or MQTT-only devices.
|
|
|
|
|
2024-06-10 02:36:21 +02:00
|
|
|
To use this platform, the :doc:`http_request` component must be present in your configuration.
|
|
|
|
|
2024-06-06 04:35:31 +02:00
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
# Example configuration entry
|
|
|
|
ota:
|
|
|
|
- platform: http_request
|
|
|
|
|
|
|
|
Configuration variables:
|
|
|
|
------------------------
|
|
|
|
|
2024-06-21 08:36:52 +02:00
|
|
|
- All :ref:`automations <automation>` supported by :doc:`/components/ota/index`.
|
2024-06-06 04:35:31 +02:00
|
|
|
|
|
|
|
.. _ota_http_request-flash_action:
|
|
|
|
|
2024-06-10 02:36:21 +02:00
|
|
|
``ota.http_request.flash`` Action
|
2024-06-06 04:35:31 +02:00
|
|
|
---------------------------------
|
|
|
|
|
2024-06-10 02:36:21 +02:00
|
|
|
This action triggers the download and installation of the updated firmware from the configured URL. As it's an
|
|
|
|
ESPHome :ref:`action <config-action>`, it may be used in any ESPHome :ref:`automation(s) <automation>`.
|
2024-06-06 04:35:31 +02:00
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
on_...:
|
|
|
|
then:
|
2024-06-10 02:36:21 +02:00
|
|
|
- ota.http_request.flash:
|
2024-06-06 04:35:31 +02:00
|
|
|
md5_url: http://example.com/firmware.md5
|
2024-06-18 05:25:29 +02:00
|
|
|
url: https://example.com/firmware.ota.bin
|
2024-06-06 04:35:31 +02:00
|
|
|
- logger.log: "This message should be not displayed because the device reboots"
|
|
|
|
|
|
|
|
Configuration variables:
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
- **md5** (*Optional*, string, :ref:`templatable <config-templatable>`): The
|
|
|
|
`MD5sum <https://en.wikipedia.org/wiki/Md5sum>`_ of the firmware file pointed to by ``url`` (below). May not be used
|
|
|
|
with ``md5_url`` (below); must be specified if ``md5_url`` is not.
|
|
|
|
- **md5_url** (*Optional*, string, :ref:`templatable <config-templatable>`): The URL of the file containing an
|
|
|
|
`MD5sum <https://en.wikipedia.org/wiki/Md5sum>`_ of the firmware file pointed to by ``url`` (below). May not be used
|
|
|
|
with ``md5`` (above); must be specified if ``md5`` is not.
|
|
|
|
- **url** (**Required**, string, :ref:`templatable <config-templatable>`): The URL of the binary file containing the
|
|
|
|
(new) firmware to be installed.
|
|
|
|
- **username** (*Optional*, string, :ref:`templatable <config-templatable>`): The username to use for HTTP basic
|
|
|
|
authentication.
|
|
|
|
- **password** (*Optional*, string, :ref:`templatable <config-templatable>`): The password to use for HTTP basic
|
|
|
|
authentication.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
2024-06-18 05:25:29 +02:00
|
|
|
- You can obtain the ``firmware.ota.bin`` file from either:
|
2024-06-10 02:36:21 +02:00
|
|
|
|
2024-06-18 05:25:29 +02:00
|
|
|
- **ESPHome dashboard** (HA add-on): download in *"OTA format"* (formerly "legacy format")
|
|
|
|
- **ESPHome CLI**: the directory ``.esphome/build/project/.pioenvs/project/firmware.ota.bin``
|
2024-06-10 02:36:21 +02:00
|
|
|
|
|
|
|
...where *"project"* is the name of your ESPHome device/project.
|
|
|
|
|
2024-06-18 05:25:29 +02:00
|
|
|
You **cannot** use ``firmware.factory.bin`` or *"Factory format"* (formerly "Modern format") with this component.
|
2024-06-10 02:36:21 +02:00
|
|
|
|
2024-06-06 04:35:31 +02:00
|
|
|
- ``username`` and ``password`` must be `URL-encoded <https://en.wikipedia.org/wiki/Percent-encoding>`_ if they
|
|
|
|
include special characters.
|
|
|
|
|
|
|
|
- The `MD5sum <https://en.wikipedia.org/wiki/Md5sum>`_ of the firmware binary file is an ASCII file (also known
|
|
|
|
as "plain text", typically found in files with a ``.txt`` extension) consisting of 32 lowercase hexadecimal
|
|
|
|
characters. It can be obtained and saved to a file with the following command(s):
|
|
|
|
|
|
|
|
- On macOS:
|
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
2024-06-18 05:25:29 +02:00
|
|
|
md5 -q firmware.ota.bin > firmware.md5
|
2024-06-06 04:35:31 +02:00
|
|
|
|
|
|
|
- On most Linux distributions:
|
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
2024-06-18 05:25:29 +02:00
|
|
|
md5sum firmware.ota.bin > firmware.md5
|
2024-06-06 04:35:31 +02:00
|
|
|
|
|
|
|
- On Windows/PowerShell:
|
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
2024-06-18 05:25:29 +02:00
|
|
|
(Get-FileHash -Path firmware.ota.bin -Algorithm md5).Hash.ToLower() | Out-File -FilePath firmware.md5 -Encoding ASCII
|
2024-06-06 04:35:31 +02:00
|
|
|
|
2024-06-18 05:25:29 +02:00
|
|
|
This will generate the MD5 hash of the ``firmware.ota.bin`` file and write the resulting hash value to the
|
2024-06-06 04:35:31 +02:00
|
|
|
``firmware.md5`` file. The ``md5_url`` configuration variable should point to this file on the web server.
|
|
|
|
It is used by the OTA updating mechanism to ensure the integrity of the (new) firmware as it is installed.
|
|
|
|
|
|
|
|
**If, for any reason, the MD5sum provided does not match the MD5sum computed as the firmware is installed, the
|
|
|
|
device will continue to use the original firmware and the new firmware is discarded.**
|
|
|
|
|
|
|
|
See Also
|
|
|
|
--------
|
|
|
|
|
2024-06-21 08:36:52 +02:00
|
|
|
- :apiref:`ota/ota_component.h`
|
|
|
|
- :doc:`/components/ota/index`
|
|
|
|
- :doc:`/components/ota/esphome`
|
|
|
|
- :doc:`/components/safe_mode`
|
2024-06-06 04:35:31 +02:00
|
|
|
- :ghedit:`Edit`
|