diff --git a/CHANGELOG.md b/CHANGELOG.md index f385b74bf..09444e224 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file. ### Breaking Changed ### Changed +- Tasmota OTA scripts now support both unzipped and gzipped file uploads (#17378) ### Fixed - Shutter default motorstop set to 0 (#17403) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 1cc51965b..c0a162589 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -118,6 +118,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm ### Changed - ESP32 Framework (Core) from v2.0.5.3 to v2.0.5.4 (IPv6 support) - TuyaMcu rewrite by btsimonh [#17051](https://github.com/arendst/Tasmota/issues/17051) +- Tasmota OTA scripts now support both unzipped and gzipped file uploads [#17378](https://github.com/arendst/Tasmota/issues/17378) ### Fixed - Shutter default motorstop set to 0 [#17403](https://github.com/arendst/Tasmota/issues/17403) diff --git a/api/upload-tasmota.php b/api/upload-tasmota.php index 9bc204288..8b1504f95 100644 --- a/api/upload-tasmota.php +++ b/api/upload-tasmota.php @@ -42,7 +42,7 @@ $target_file = "tasmota/".$image; $hostname = $_SERVER['SERVER_NAME']; if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) { - if (strpos($target_file, "tasmota32")) { + if (strpos($target_file, "tasmota32") | strpos($target_file, ".gz")) { echo "The file $image has been uploaded to OTA server $hostname. \n"; } else { gzCompressFile($target_file); diff --git a/pio-tools/espupload.py b/pio-tools/espupload.py index fa93ba2bc..8b0993a55 100755 --- a/pio-tools/espupload.py +++ b/pio-tools/espupload.py @@ -36,7 +36,7 @@ import shutil import argparse import requests -#HOST_URL = "domus1:80/api/upload-arduino.php" +# Default URL overwritten by [env] and/or [env:tasmota32_base] upload_port HOST_URL = "otaserver/ota/upload-tasmota.php" def main(args): @@ -57,17 +57,27 @@ def main(args): # end if if not os.path.exists(args.image): - print('Sorry: the file %s does not exist', args.image) + print('Sorry: the file {} does not exist'.format(args.image)) return 2 # end if - # copy firmware.bin to tasmota.bin or tasmota32.bin - tname = os.path.normpath(os.path.dirname(args.image)) - new_filename = tname + os.sep + os.path.basename(tname) + '.bin' - shutil.copy2(args.image, new_filename) + if args.image.find("firmware.bin") != -1: + # Legacy support for $SOURCE + # copy firmware.bin to tasmota.bin or tasmota32.bin + # C:\tmp\.pioenvs\tasmota-theo\firmware.bin + tname = os.path.normpath(os.path.dirname(args.image)) + # C:\tmp\.pioenvs\tasmota-theo\tasmota-theo.bin + upload_file = tname + os.sep + os.path.basename(tname) + '.bin' + shutil.copy2(args.image, upload_file) + else: + # Support for bin_file and bin_gz_file + upload_file = args.image + # end if + +# print('Debug filename in {}, upload {}'.format(args.image, upload_file)) url = 'http://%s' % (args.host_url) - files = {'file': open(new_filename, 'rb')} + files = {'file': open(upload_file, 'rb')} req = requests.post(url, files=files) print(req.text) # end main diff --git a/pio-tools/http-uploader.py b/pio-tools/http-uploader.py index 788c886f2..fafbcfe03 100644 --- a/pio-tools/http-uploader.py +++ b/pio-tools/http-uploader.py @@ -1,13 +1,28 @@ +# Original idea by Pascal Gollor at 2022-12-13 + Import("env") import os +import tasmotapiolib -# pio < 4.0.0 -# from base64 import b64decode -# env.Replace(UPLOADER="pio-tools\espupload.py") -# env.Replace(UPLOADERFLAGS="") -# env.Replace(UPLOADCMD="$UPLOADER -u " + b64decode(ARGUMENTS.get("UPLOAD_PORT")) + " -f $SOURCES") +# You need to specify 'upload_port' in platform_override.ini at '[env]' section -# pio >= 4.0.0 -env.Replace(UPLOADER=os.path.join("pio-tools", "espupload.py")) +# clear upload flags env.Replace(UPLOADERFLAGS="") -env.Replace(UPLOADCMD="$PYTHONEXE $UPLOADER -u $UPLOAD_PORT -f $SOURCES") + +# Use espupload.py which supports both unzipped and zipped binaries +env.Replace(UPLOADER=os.path.join("pio-tools", "espupload.py")) + +# unzipped binary location: build_output\firmware\tasmota-theo.bin +bin_file = tasmotapiolib.get_final_bin_path(env) +# zipped binary location: build_output\firmware\tasmota-theo.bin.gz +bin_gz_file = bin_file.with_suffix(".bin.gz") + +if os.path.exists(bin_gz_file): + # Zipped binary file - build_output\firmware\tasmota-theo.bin.gz + env.Replace(UPLOADCMD="$PYTHONEXE $UPLOADER -u $UPLOAD_PORT -f {}".format(bin_gz_file)) +elif os.path.exists(bin_file): + # Unzipped binary file - build_output\firmware\tasmota-theo.bin + env.Replace(UPLOADCMD="$PYTHONEXE $UPLOADER -u $UPLOAD_PORT -f {}".format(bin_file)) +else: + # Unzipped binary file - C:\tmp\.pioenvs\tasmota-theo\firmware.bin + env.Replace(UPLOADCMD="$PYTHONEXE $UPLOADER -u $UPLOAD_PORT -f $SOURCES")