Skip to content

Commit 18f0a99

Browse files
author
Me No Dev
committed
add progress option for espota.py and fix typo in ArduinoOTA
1 parent 3c14656 commit 18f0a99

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

libraries/ArduinoOTA/ArduinoOTA.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void ArduinoOTAClass::begin() {
6363

6464
if (!_hostname.length()) {
6565
char tmp[15];
66-
sprintf(tmp, "esp8266-%02x", ESP.getChipId());
66+
sprintf(tmp, "esp8266-%06x", ESP.getChipId());
6767
_hostname = tmp;
6868
}
6969
if (!_port) {

tools/espota.py

+43-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,33 @@
3535
FLASH = 0
3636
SPIFFS = 100
3737
AUTH = 200
38-
38+
PROGRESS = 0
39+
# update_progress() : Displays or updates a console progress bar
40+
## Accepts a float between 0 and 1. Any int will be converted to a float.
41+
## A value under 0 represents a 'halt'.
42+
## A value at 1 or bigger represents 100%
43+
def update_progress(progress):
44+
if (PROGRESS == 1):
45+
barLength = 60 # Modify this to change the length of the progress bar
46+
status = ""
47+
if isinstance(progress, int):
48+
progress = float(progress)
49+
if not isinstance(progress, float):
50+
progress = 0
51+
status = "error: progress var must be float\r\n"
52+
if progress < 0:
53+
progress = 0
54+
status = "Halt...\r\n"
55+
if progress >= 1:
56+
progress = 1
57+
status = "Done...\r\n"
58+
block = int(round(barLength*progress))
59+
text = "\rUploading: [{0}] {1}% {2}".format( "="*block + " "*(barLength-block), int(progress*100), status)
60+
sys.stderr.write(text)
61+
sys.stderr.flush()
62+
else:
63+
sys.stderr.write('.')
64+
sys.stderr.flush()
3965

4066
def serve(remoteAddr, remotePort, password, filename, command = FLASH):
4167
# Create a TCP/IP socket
@@ -115,13 +141,17 @@ def serve(remoteAddr, remotePort, password, filename, command = FLASH):
115141

116142
try:
117143
f = open(filename, "rb")
118-
sys.stderr.write('Uploading')
119-
sys.stderr.flush()
144+
if (PROGRESS == 0):
145+
sys.stderr.write('Uploading')
146+
sys.stderr.flush()
147+
else:
148+
update_progress(0)
149+
offset = 0
120150
while True:
121151
chunk = f.read(1460)
122152
if not chunk: break
123-
sys.stderr.write('.')
124-
sys.stderr.flush()
153+
offset += len(chunk)
154+
update_progress(offset/float(content_size))
125155
connection.settimeout(10)
126156
try:
127157
connection.sendall(chunk)
@@ -220,6 +250,12 @@ def parser():
220250
action = "store_true",
221251
default = False
222252
)
253+
group.add_option("-r", "--progress",
254+
dest = "progress",
255+
help = "Show progress output. Does not work for ArduinoIDE",
256+
action = "store_true",
257+
default = False
258+
)
223259
parser.add_option_group(group)
224260

225261
(options, args) = parser.parse_args()
@@ -244,6 +280,8 @@ def main(args):
244280
logging.debug("Options: %s", str(options))
245281

246282
# check options
283+
if (options.progress):
284+
PROGRESS = 1
247285
if (not options.esp_ip or not options.image):
248286
logging.critical("Not enough arguments.")
249287

0 commit comments

Comments
 (0)