Skip to content

Commit

Permalink
add progress option for espota.py and fix typo in ArduinoOTA
Browse files Browse the repository at this point in the history
  • Loading branch information
Me No Dev committed Nov 11, 2015
1 parent 3c14656 commit 18f0a99
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
2 changes: 1 addition & 1 deletion libraries/ArduinoOTA/ArduinoOTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void ArduinoOTAClass::begin() {

if (!_hostname.length()) {
char tmp[15];
sprintf(tmp, "esp8266-%02x", ESP.getChipId());
sprintf(tmp, "esp8266-%06x", ESP.getChipId());
_hostname = tmp;
}
if (!_port) {
Expand Down
48 changes: 43 additions & 5 deletions tools/espota.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,33 @@
FLASH = 0
SPIFFS = 100
AUTH = 200

PROGRESS = 0
# update_progress() : Displays or updates a console progress bar
## Accepts a float between 0 and 1. Any int will be converted to a float.
## A value under 0 represents a 'halt'.
## A value at 1 or bigger represents 100%
def update_progress(progress):
if (PROGRESS == 1):
barLength = 60 # Modify this to change the length of the progress bar
status = ""
if isinstance(progress, int):
progress = float(progress)
if not isinstance(progress, float):
progress = 0
status = "error: progress var must be float\r\n"
if progress < 0:
progress = 0
status = "Halt...\r\n"
if progress >= 1:
progress = 1
status = "Done...\r\n"
block = int(round(barLength*progress))
text = "\rUploading: [{0}] {1}% {2}".format( "="*block + " "*(barLength-block), int(progress*100), status)
sys.stderr.write(text)
sys.stderr.flush()
else:
sys.stderr.write('.')
sys.stderr.flush()

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

try:
f = open(filename, "rb")
sys.stderr.write('Uploading')
sys.stderr.flush()
if (PROGRESS == 0):
sys.stderr.write('Uploading')
sys.stderr.flush()
else:
update_progress(0)
offset = 0
while True:
chunk = f.read(1460)
if not chunk: break
sys.stderr.write('.')
sys.stderr.flush()
offset += len(chunk)
update_progress(offset/float(content_size))
connection.settimeout(10)
try:
connection.sendall(chunk)
Expand Down Expand Up @@ -220,6 +250,12 @@ def parser():
action = "store_true",
default = False
)
group.add_option("-r", "--progress",
dest = "progress",
help = "Show progress output. Does not work for ArduinoIDE",
action = "store_true",
default = False
)
parser.add_option_group(group)

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

# check options
if (options.progress):
PROGRESS = 1
if (not options.esp_ip or not options.image):
logging.critical("Not enough arguments.")

Expand Down

0 comments on commit 18f0a99

Please sign in to comment.