mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-10 14:42:08 +03:00
Fix upload progress and randomize the server port
randomization is good in cases where the previous port is not yet released by the OS or the server hangs On OS X it's very noticeable if you need to OTA twice in a short time.
This commit is contained in:
parent
0213dc34ff
commit
d1235f0204
@ -30,18 +30,19 @@ import os
|
|||||||
import optparse
|
import optparse
|
||||||
import logging
|
import logging
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import random
|
||||||
|
|
||||||
# Commands
|
# Commands
|
||||||
FLASH = 0
|
FLASH = 0
|
||||||
SPIFFS = 100
|
SPIFFS = 100
|
||||||
AUTH = 200
|
AUTH = 200
|
||||||
PROGRESS = 0
|
PROGRESS = False
|
||||||
# update_progress() : Displays or updates a console progress bar
|
# update_progress() : Displays or updates a console progress bar
|
||||||
## Accepts a float between 0 and 1. Any int will be converted to a float.
|
## Accepts a float between 0 and 1. Any int will be converted to a float.
|
||||||
## A value under 0 represents a 'halt'.
|
## A value under 0 represents a 'halt'.
|
||||||
## A value at 1 or bigger represents 100%
|
## A value at 1 or bigger represents 100%
|
||||||
def update_progress(progress):
|
def update_progress(progress):
|
||||||
if (PROGRESS == 1):
|
if (PROGRESS):
|
||||||
barLength = 60 # Modify this to change the length of the progress bar
|
barLength = 60 # Modify this to change the length of the progress bar
|
||||||
status = ""
|
status = ""
|
||||||
if isinstance(progress, int):
|
if isinstance(progress, int):
|
||||||
@ -66,7 +67,7 @@ def update_progress(progress):
|
|||||||
def serve(remoteAddr, remotePort, password, filename, command = FLASH):
|
def serve(remoteAddr, remotePort, password, filename, command = FLASH):
|
||||||
# Create a TCP/IP socket
|
# Create a TCP/IP socket
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
serverPort = 48266
|
serverPort = random.randint(10000,60000)
|
||||||
server_address = ('0.0.0.0', serverPort)
|
server_address = ('0.0.0.0', serverPort)
|
||||||
logging.info('Starting on %s:%s', str(server_address[0]), str(server_address[1]))
|
logging.info('Starting on %s:%s', str(server_address[0]), str(server_address[1]))
|
||||||
try:
|
try:
|
||||||
@ -141,11 +142,11 @@ def serve(remoteAddr, remotePort, password, filename, command = FLASH):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
f = open(filename, "rb")
|
f = open(filename, "rb")
|
||||||
if (PROGRESS == 0):
|
if (PROGRESS):
|
||||||
|
update_progress(0)
|
||||||
|
else:
|
||||||
sys.stderr.write('Uploading')
|
sys.stderr.write('Uploading')
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
else:
|
|
||||||
update_progress(0)
|
|
||||||
offset = 0
|
offset = 0
|
||||||
while True:
|
while True:
|
||||||
chunk = f.read(1460)
|
chunk = f.read(1460)
|
||||||
@ -280,8 +281,8 @@ def main(args):
|
|||||||
logging.debug("Options: %s", str(options))
|
logging.debug("Options: %s", str(options))
|
||||||
|
|
||||||
# check options
|
# check options
|
||||||
if (options.progress):
|
global PROGRESS
|
||||||
PROGRESS = 1
|
PROGRESS = options.progress
|
||||||
if (not options.esp_ip or not options.image):
|
if (not options.esp_ip or not options.image):
|
||||||
logging.critical("Not enough arguments.")
|
logging.critical("Not enough arguments.")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user