Upload file selector on esp-idf only

This commit is contained in:
Edward Firmo
2024-01-11 00:52:56 +01:00
parent 06b0ccfd10
commit c642da6c3c
8 changed files with 84 additions and 29 deletions

View File

@@ -188,7 +188,7 @@ These files are considerably bigger, as the fonts requires more memory, but it s
### 6. Improved TFT transfer ### 6. Improved TFT transfer
#### TFT file selectors #### TFT file selectors (`ESP-IDF` framework required)
We still working on the Upload TFT engine to make it easier for new and for experienced users. We still working on the Upload TFT engine to make it easier for new and for experienced users.
Now, together with the **Update TFT Display** button, you will find also **Update TFT Display - Model** and **Update TFT Display - Branch** (disabled by default) Now, together with the **Update TFT Display** button, you will find also **Update TFT Display - Model** and **Update TFT Display - Branch** (disabled by default)
where you can select the different model you are using and the upload URL will be automatically adjusted to donwload the file directly from the repository on GitHub, where you can select the different model you are using and the upload URL will be automatically adjusted to donwload the file directly from the repository on GitHub,

View File

@@ -65,6 +65,20 @@ display:
tft_url: ${nextion_update_url} tft_url: ${nextion_update_url}
exit_reparse_on_start: true exit_reparse_on_start: true
esphome:
on_boot:
- priority: 601.0
then:
- lambda: |-
// Hide TFT file selectors when using arduino
#ifdef ARDUINO
tft_file_branch->set_internal(true);
tft_file_model->set_internal(true);
#elif defined(ESP_PLATFORM)
tft_file_branch->set_internal(false);
tft_file_model->set_internal(false);
#endif
globals: globals:
- id: baud_rate_original - id: baud_rate_original
type: uint type: uint
@@ -217,7 +231,11 @@ script:
then: then:
- delay: 2s - delay: 2s
- lambda: |- - lambda: |-
static const char *const TAG = "addon_upload_tft.script.set_tft_file"; #ifdef ARDUINO
static const char *const TAG = "addon_upload_tft.script.set_tft_file.arduino";
#elif defined(ESP_PLATFORM)
static const char *const TAG = "addon_upload_tft.script.set_tft_file.esp_idf";
#endif
std::string branch = tft_file_branch->state; std::string branch = tft_file_branch->state;
std::string model = tft_file_model->state; std::string model = tft_file_model->state;
ESP_LOGD(TAG, "TFT URL set:"); ESP_LOGD(TAG, "TFT URL set:");
@@ -231,6 +249,9 @@ script:
if (id(is_uploading_tft)) if (id(is_uploading_tft))
ESP_LOGW(TAG, " TFT Upload in progress."); ESP_LOGW(TAG, " TFT Upload in progress.");
else { else {
#ifdef ARDUINO
std::string url = "${nextion_update_url}";
#elif defined(ESP_PLATFORM)
std::string url; std::string url;
std::string file_name; std::string file_name;
if (model == "NSPanel Blank") file_name = "nspanel_blank.tft"; if (model == "NSPanel Blank") file_name = "nspanel_blank.tft";
@@ -251,6 +272,7 @@ script:
url = url.substr(0, endPos + 1); url = url.substr(0, endPos + 1);
} }
} }
#endif
ESP_LOGD(TAG, " Full URL: %s", url.c_str()); ESP_LOGD(TAG, " Full URL: %s", url.c_str());
id(tft_url) = url; id(tft_url) = url;
@@ -308,6 +330,27 @@ script:
// Upload URL // Upload URL
ESP_LOGD(TAG, " Upload URL: %s", url.c_str()); ESP_LOGD(TAG, " Upload URL: %s", url.c_str());
#ifdef ARDUINO
auto startsWith = [](const std::string& str, const std::string& prefix) -> bool {
if (str.length() < prefix.length()) return false;
std::string lowerStr = str.substr(0, prefix.length());
std::transform(lowerStr.begin(), lowerStr.end(), lowerStr.begin(),
[](unsigned char c){ return std::tolower(c); });
std::string lowerPrefix = prefix;
std::transform(lowerPrefix.begin(), lowerPrefix.end(), lowerPrefix.begin(),
[](unsigned char c){ return std::tolower(c); });
return lowerStr == lowerPrefix;
};
if (startsWith(url, "https")) {
ESP_LOGE(TAG, "HTTPS is not supported by Arduino framework.");
ESP_LOGE(TAG, "This transfer will most likely fail.");
ESP_LOGE(TAG, "Please use HTTP instead.");
}
#endif
disp1->set_tft_url(url.c_str()); disp1->set_tft_url(url.c_str());
nextion_uart_command->execute("bkcmd=3"); nextion_uart_command->execute("bkcmd=3");
@@ -1237,7 +1280,7 @@ select:
initial_option: "main" initial_option: "main"
optimistic: true optimistic: true
restore_value: true restore_value: true
internal: false internal: true
entity_category: config entity_category: config
disabled_by_default: true disabled_by_default: true
icon: mdi:file-sync icon: mdi:file-sync
@@ -1259,7 +1302,7 @@ select:
initial_option: "Use nextion_update_url" initial_option: "Use nextion_update_url"
optimistic: true optimistic: true
restore_value: true restore_value: true
internal: false internal: true
entity_category: config entity_category: config
disabled_by_default: false disabled_by_default: false
icon: mdi:file-sync icon: mdi:file-sync

View File

@@ -63,6 +63,8 @@ esphome:
name: esphome.NSPanel_HA_Blueprint name: esphome.NSPanel_HA_Blueprint
version: "${version}" version: "${version}"
on_boot: on_boot:
- priority: 602.0
then:
- text_sensor.template.publish: - text_sensor.template.publish:
id: firmware_url id: firmware_url
state: https://raw.githubusercontent.com/Blackymas/NSPanel_HA_Blueprint/main/nspanel_esphome_prebuilt.bin state: https://raw.githubusercontent.com/Blackymas/NSPanel_HA_Blueprint/main/nspanel_esphome_prebuilt.bin

View File

@@ -27,8 +27,6 @@ substitutions:
wifi_ssid: !secret wifi_ssid wifi_ssid: !secret wifi_ssid
wifi_password: !secret wifi_password wifi_password: !secret wifi_password
nextion_update_url: "http://homeassistant.local:8123/local/nspanel_us.tft"
# Add-on configuration (if needed) # Add-on configuration (if needed)
## Add-on climate ## Add-on climate
heater_relay: "1" # Possible values: "1" or "2" heater_relay: "1" # Possible values: "1" or "2"
@@ -96,8 +94,6 @@ substitutions:
wifi_ssid: !secret wifi_ssid wifi_ssid: !secret wifi_ssid
wifi_password: !secret wifi_password wifi_password: !secret wifi_password
nextion_update_url: "http://homeassistant.local:8123/local/nspanel_us.tft"
# Add-on configuration (if needed) # Add-on configuration (if needed)
## Add-on climate ## Add-on climate
cooler_relay: "1" # Possible values: "1" or "2" cooler_relay: "1" # Possible values: "1" or "2"
@@ -140,8 +136,6 @@ substitutions:
wifi_ssid: !secret wifi_ssid wifi_ssid: !secret wifi_ssid
wifi_password: !secret wifi_password wifi_password: !secret wifi_password
nextion_update_url: "http://homeassistant.local:8123/local/nspanel_us.tft"
# Add-on configuration (if needed) # Add-on configuration (if needed)
## Add-on climate ## Add-on climate
heater_relay: "1" # Possible values: "1" or "2" heater_relay: "1" # Possible values: "1" or "2"
@@ -184,8 +178,6 @@ substitutions:
wifi_ssid: !secret wifi_ssid wifi_ssid: !secret wifi_ssid
wifi_password: !secret wifi_password wifi_password: !secret wifi_password
nextion_update_url: "http://homeassistant.local:8123/local/nspanel_us.tft"
# Add-on configuration (if needed) # Add-on configuration (if needed)
## Add-on climate ## Add-on climate
heater_relay: "1" # Possible values: "1" or "2" heater_relay: "1" # Possible values: "1" or "2"

View File

@@ -59,8 +59,6 @@ substitutions:
wifi_ssid: !secret wifi_ssid wifi_ssid: !secret wifi_ssid
wifi_password: !secret wifi_password wifi_password: !secret wifi_password
nextion_update_url: "http://homeassistant.local:8123/local/nspanel_us.tft"
# Add-on configuration (if needed) # Add-on configuration (if needed)
## Add-on climate ## Add-on climate
# heater_relay: "1" # Possible values: "1" or "2" # heater_relay: "1" # Possible values: "1" or "2"

View File

@@ -93,7 +93,7 @@ Follow these steps to add a new device in the ESPHome Dashboard:
device_name: "YOUR_NSPANEL_NAME" device_name: "YOUR_NSPANEL_NAME"
wifi_ssid: !secret wifi_ssid wifi_ssid: !secret wifi_ssid
wifi_password: !secret wifi_password wifi_password: !secret wifi_password
nextion_update_url: "http://homeassistant.local:8123/local/nspanel_eu.tft" nextion_update_url: "http://homeassistant.local:8123/local/nspanel_eu.tft" # Optional for `esp-idf` framework
# Add-on configuration (if needed) # Add-on configuration (if needed)
# heater_relay: "1" # Possible values: "1" or "2" # heater_relay: "1" # Possible values: "1" or "2"
@@ -125,7 +125,8 @@ Follow these steps to add a new device in the ESPHome Dashboard:
![Edit Settings](pics/ha_esphome_dashboard_new_device_06b.png) ![Edit Settings](pics/ha_esphome_dashboard_new_device_06b.png)
10. For Wi-Fi credentials, use `!secret` for added security or input them directly. 10. For Wi-Fi credentials, use `!secret` for added security or input them directly.
Learn about secrets in ESPHome: [Home Assistant Secrets in ESPHome](https://www.youtube.com/watch?v=eW4vKDeHh7Y). Learn about secrets in ESPHome: [Home Assistant Secrets in ESPHome](https://www.youtube.com/watch?v=eW4vKDeHh7Y).
11. Optionally, adjust `nextion_update_url` to the URL of a TFT file hosted on an HTTP or HTTPS server, ensuring that the file is accessible to the NSPanel. 11. (Optionally when using `esp-idf`) Adjust `nextion_update_url` to the URL of a TFT file hosted on an HTTP or HTTPS server,
ensuring that the file is accessible to the NSPanel.
This URL will be used by ESPHome to download the TFT file to your panel. This URL will be used by ESPHome to download the TFT file to your panel.
For more information on hosting the TFT file and setting up the URL, see the [Upload TFT](#upload-tft) section. For more information on hosting the TFT file and setting up the URL, see the [Upload TFT](#upload-tft) section.

View File

@@ -4,15 +4,24 @@ The NSPanel consist in a ESP32 board (the panel itself, controlling the relays,
This Nextion display have an independent controller which also requires a firmware and its settings (the basic layout), and this is done by an `.tft` file. This Nextion display have an independent controller which also requires a firmware and its settings (the basic layout), and this is done by an `.tft` file.
When you get your panel from Sonoff, their `tft` file is installed in the Nextion display and using a called "Reparse mode", which makes a bit challenging to replace the `tft` file when using ESPHome and then, we highly recoment you using `nspanel_blank.tft`, which is just a fraction of the size of a regular `tft` and will make the first `tft` replacement much easier. You can find this file under the folder [`custom_configuration`](/custom_configuration). When you get your panel from Sonoff, their `tft` file is installed in the Nextion display and using a called "Reparse mode",
which makes a bit challenging to replace the `tft` file when using ESPHome and then, we highly recoment you using `nspanel_blank.tft`,
which is just a fraction of the size of a regular `tft` and will make the first `tft` replacement much easier.
You can find this file under the folder [`custom_configuration`](/custom_configuration).
Once NSPanel's original `tft` is replaced, is much easier to install a new `tft` with ESPHome, so you can go directly to the final file (either `nspanel_eu.tft`, `nspanel_us.tft` or `nspanel_us_land.tft`). Once NSPanel's original `tft` is replaced, is much easier to install a new `tft` with ESPHome,
so you can go directly to the final file (either `nspanel_eu.tft`, `nspanel_us.tft` or `nspanel_us_land.tft`).
For more datails on how to install the first `tft` file, specially if your panel still displaying the original Sonoff screen, please refeer to the Wiki where you will find the doc ["Common Issues TFT Upload"](/wiki/(EN)-Common-Issues-TFT-Upload). For more datails on how to install the first `tft` file, specially if your panel still displaying the original Sonoff screen,
please refeer to the Wiki where you will find the doc ["Common Issues TFT Upload"](/wiki/(EN)-Common-Issues-TFT-Upload).
## How to install a different `tft` file? ## How to install a different `tft` file?
### v4.2 or later and `esp-idf` framework
Just go to your devices's page (under **Settings** > **Devices and Services** > **ESPHome**), select your **Upload TFT display - Model** and then press **Upload TFT display**.
### Older versions or `arduino` framework
On your ESPHome settings, you have entered a url for `nextion_update_url`, in the substitutions, like this: On your ESPHome settings, you have entered a url for `nextion_update_url`, in the substitutions, like this:
```yaml ```yaml
@@ -49,32 +58,42 @@ esp32:
This url will indicate where your panel will look for the `tft` file when you click the "Upload TFT" button (under device's page) or call the service `esphome.xxxxx_upload_tft`. This url will indicate where your panel will look for the `tft` file when you click the "Upload TFT" button (under device's page) or call the service `esphome.xxxxx_upload_tft`.
The most popular way to switch between the `nspanel_blank.tft` and `nspanel_xx.tft` is replacing the URL on the ESPHome settings and flashing the device again, however, you can also do this calling the service `esphome.xxxxx_upload_tft_url` adding the URL of the alternative file as a parameter. It's up to you, as both ways will give the same result. The most popular way to switch between the `nspanel_blank.tft` and `nspanel_xx.tft` is replacing the URL on the ESPHome settings and flashing the device again,
however, you can also do this calling the service `esphome.xxxxx_upload_tft_url` adding the URL of the alternative file as a parameter.
It's up to you, as both ways will give the same result.
## What to do after installing `nspanel_blank.tft`? ## What to do after installing `nspanel_blank.tft`?
![image](https://github.com/Blackymas/NSPanel_HA_Blueprint/assets/94725493/3b0bb950-4857-4c22-a53a-062d09f315dc) ![image](https://github.com/Blackymas/NSPanel_HA_Blueprint/assets/94725493/3b0bb950-4857-4c22-a53a-062d09f315dc)
Once you have sucessfully installed any of the `tft` files from this project, the `nspanel_blank.tft` file shouldn't be necessary anymore and you should be able to always install the final `tft` file. Once you have sucessfully installed any of the `tft` files from this project,
the `nspanel_blank.tft` file shouldn't be necessary anymore and you should be able to always install the final `tft` file.
### v4.2 or later and `esp-idf` framework
Just go to your devices's page (under **Settings** > **Devices and Services** > **ESPHome**), select your **Upload TFT display - Model** and then press **Upload TFT display**.
### Older versions or `arduino` framework
Make sure you have one of the following final TFT files in your local http server (typically Home Assistant on ***www*** folder): Make sure you have one of the following final TFT files in your local http server (typically Home Assistant on ***www*** folder):
- [`nspanel_eu.tft`](../nspanel_eu.tft) - [`nspanel_eu.tft`](../nspanel_eu.tft)
- [`nspanel_us.tft`](../nspanel_us.tft) - [`nspanel_us.tft`](../nspanel_us.tft)
- [`nspanel_us_land.tft`](../nspanel_us_land.tft) - [`nspanel_us_land.tft`](../nspanel_us_land.tft)
Now Flash your panel with `nextion_update_url` pointing to one of the final TFT files and press **Upload TFT** in the device's page (**Settings** > **Devices & Services** > **ESPHome**). Now Flash your panel with `nextion_update_url` pointing to one of the final TFT files and
press **Upload TFT** in the device's page (**Settings** > **Devices & Services** > **ESPHome**).
## Additional Tips and Resources ## Additional Tips and Resources
We have an useful guide for [troubleshooting TFT transfer issues](tft_upload.md). Please take a look there first. We have an useful guide for [troubleshooting TFT transfer issues](tft_upload.md).
Please take a look there first.
After troubleshooting, if issues persist, consult the [Issues](/Blackymas/NSPanel_HA_Blueprint/issues) and feel free to create a new one asking for more personalized assistance. After troubleshooting, if issues persist, consult the [Issues](/Blackymas/NSPanel_HA_Blueprint/issues) and feel free to create a new one asking for more personalized assistance.
Please share as much info as possible, like: Please share as much info as possible, like:
1. Describing (or a picture of) what is in your screen 1. Describing (or a picture of) what is in your screen
2. Are updating from a previous version of this same project, or coming from another NSPanel customization (which one?) or customizing for the first time a panel with original Sonoff settings? 2. Are updating from a previous version of this same project,
or coming from another NSPanel customization (which one?)
or customizing for the first time a panel with original Sonoff settings?
3. Please share the ESPHome logs from when your panel starts to the moment the upload fails. 3. Please share the ESPHome logs from when your panel starts to the moment the upload fails.
4. Describe what you have already tried. 4. Describe what you have already tried.
## Important note ## Important note
Remember, these steps are a guideline and might vary slightly based on your specific setup and previously installed system. Remember, these steps are a guideline and might vary slightly based on your specific setup and previously installed system.

Binary file not shown.