Skip to content

Commit 8ffff8b

Browse files
committed
Change Tasmota OTA scripts
Change Tasmota OTA scripts now support both unzipped and gzipped file uploads (#17378)
1 parent b2d3921 commit 8ffff8b

File tree

5 files changed

+43
-16
lines changed

5 files changed

+43
-16
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
99
### Breaking Changed
1010

1111
### Changed
12+
- Tasmota OTA scripts now support both unzipped and gzipped file uploads (#17378)
1213

1314
### Fixed
1415
- Shutter default motorstop set to 0 (#17403)

RELEASENOTES.md

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm
118118
### Changed
119119
- ESP32 Framework (Core) from v2.0.5.3 to v2.0.5.4 (IPv6 support)
120120
- TuyaMcu rewrite by btsimonh [#17051](https://github.com/arendst/Tasmota/issues/17051)
121+
- Tasmota OTA scripts now support both unzipped and gzipped file uploads [#17378](https://github.com/arendst/Tasmota/issues/17378)
121122

122123
### Fixed
123124
- Shutter default motorstop set to 0 [#17403](https://github.com/arendst/Tasmota/issues/17403)

api/upload-tasmota.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function gzCompressFile($source, $level = 9){
4242
$hostname = $_SERVER['SERVER_NAME'];
4343

4444
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
45-
if (strpos($target_file, "tasmota32")) {
45+
if (strpos($target_file, "tasmota32") | strpos($target_file, ".gz")) {
4646
echo "The file $image has been uploaded to OTA server $hostname. \n";
4747
} else {
4848
gzCompressFile($target_file);

pio-tools/espupload.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import argparse
3737
import requests
3838

39-
#HOST_URL = "domus1:80/api/upload-arduino.php"
39+
# Default URL overwritten by [env] and/or [env:tasmota32_base] upload_port
4040
HOST_URL = "otaserver/ota/upload-tasmota.php"
4141

4242
def main(args):
@@ -57,17 +57,27 @@ def main(args):
5757
# end if
5858

5959
if not os.path.exists(args.image):
60-
print('Sorry: the file %s does not exist', args.image)
60+
print('Sorry: the file {} does not exist'.format(args.image))
6161
return 2
6262
# end if
6363

64-
# copy firmware.bin to tasmota.bin or tasmota32.bin
65-
tname = os.path.normpath(os.path.dirname(args.image))
66-
new_filename = tname + os.sep + os.path.basename(tname) + '.bin'
67-
shutil.copy2(args.image, new_filename)
64+
if args.image.find("firmware.bin") != -1:
65+
# Legacy support for $SOURCE
66+
# copy firmware.bin to tasmota.bin or tasmota32.bin
67+
# C:\tmp\.pioenvs\tasmota-theo\firmware.bin
68+
tname = os.path.normpath(os.path.dirname(args.image))
69+
# C:\tmp\.pioenvs\tasmota-theo\tasmota-theo.bin
70+
upload_file = tname + os.sep + os.path.basename(tname) + '.bin'
71+
shutil.copy2(args.image, upload_file)
72+
else:
73+
# Support for bin_file and bin_gz_file
74+
upload_file = args.image
75+
# end if
76+
77+
# print('Debug filename in {}, upload {}'.format(args.image, upload_file))
6878

6979
url = 'http://%s' % (args.host_url)
70-
files = {'file': open(new_filename, 'rb')}
80+
files = {'file': open(upload_file, 'rb')}
7181
req = requests.post(url, files=files)
7282
print(req.text)
7383
# end main

pio-tools/http-uploader.py

+23-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1+
# Original idea by Pascal Gollor at 2022-12-13
2+
13
Import("env")
24
import os
5+
import tasmotapiolib
36

4-
# pio < 4.0.0
5-
# from base64 import b64decode
6-
# env.Replace(UPLOADER="pio-tools\espupload.py")
7-
# env.Replace(UPLOADERFLAGS="")
8-
# env.Replace(UPLOADCMD="$UPLOADER -u " + b64decode(ARGUMENTS.get("UPLOAD_PORT")) + " -f $SOURCES")
7+
# You need to specify 'upload_port' in platform_override.ini at '[env]' section
98

10-
# pio >= 4.0.0
11-
env.Replace(UPLOADER=os.path.join("pio-tools", "espupload.py"))
9+
# clear upload flags
1210
env.Replace(UPLOADERFLAGS="")
13-
env.Replace(UPLOADCMD="$PYTHONEXE $UPLOADER -u $UPLOAD_PORT -f $SOURCES")
11+
12+
# Use espupload.py which supports both unzipped and zipped binaries
13+
env.Replace(UPLOADER=os.path.join("pio-tools", "espupload.py"))
14+
15+
# unzipped binary location: build_output\firmware\tasmota-theo.bin
16+
bin_file = tasmotapiolib.get_final_bin_path(env)
17+
# zipped binary location: build_output\firmware\tasmota-theo.bin.gz
18+
bin_gz_file = bin_file.with_suffix(".bin.gz")
19+
20+
if os.path.exists(bin_gz_file):
21+
# Zipped binary file - build_output\firmware\tasmota-theo.bin.gz
22+
env.Replace(UPLOADCMD="$PYTHONEXE $UPLOADER -u $UPLOAD_PORT -f {}".format(bin_gz_file))
23+
elif os.path.exists(bin_file):
24+
# Unzipped binary file - build_output\firmware\tasmota-theo.bin
25+
env.Replace(UPLOADCMD="$PYTHONEXE $UPLOADER -u $UPLOAD_PORT -f {}".format(bin_file))
26+
else:
27+
# Unzipped binary file - C:\tmp\.pioenvs\tasmota-theo\firmware.bin
28+
env.Replace(UPLOADCMD="$PYTHONEXE $UPLOADER -u $UPLOAD_PORT -f $SOURCES")

0 commit comments

Comments
 (0)