Skip to content

Commit

Permalink
Change Tasmota OTA scripts
Browse files Browse the repository at this point in the history
Change Tasmota OTA scripts now support both unzipped and gzipped file uploads (#17378)
  • Loading branch information
arendst committed Dec 21, 2022
1 parent b2d3921 commit 8ffff8b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion api/upload-tasmota.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function gzCompressFile($source, $level = 9){
$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);
Expand Down
24 changes: 17 additions & 7 deletions pio-tools/espupload.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
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):
Expand All @@ -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
Expand Down
31 changes: 23 additions & 8 deletions pio-tools/http-uploader.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 8ffff8b

Please sign in to comment.