Skip to content

Commit

Permalink
Merge pull request esp8266#1364 from mogorman/master
Browse files Browse the repository at this point in the history
add support for manually selecting ip and port for host side
  • Loading branch information
igrr committed Jan 4, 2016
2 parents ce1b64b + d2a357e commit c52e07a
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions tools/espota.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
#
# Modified since 2015-09-18 from Pascal Gollor (https://github.com/pgollor)
# Modified since 2015-11-09 from Hristo Gochkov (https://github.com/me-no-dev)
# Modified since 2016-01-03 from Matthew O'Gorman (https://githumb.com/mogorman)
#
# This script will push an OTA update to the ESP
# use it like: python espota.py -i <ESP_IP_address> -p <ESP_port> [-a password] -f <sketch.bin>
# use it like: python espota.py -i <ESP_IP_address> -I <Host_IP_address> -p <ESP_port> -P <Host_port> [-a password] -f <sketch.bin>
# Or to upload SPIFFS image:
# python espota.py -i <ESP_IP_address> -p <ESP_port> [-a password] -s -f <spiffs.bin>
# python espota.py -i <ESP_IP_address> -I <Host_IP_address> -p <ESP_port> -P <HOST_port> [-a password] -s -f <spiffs.bin>
#
# Changes
# 2015-09-18:
Expand All @@ -22,6 +23,10 @@
# - Added digest authentication
# - Enchanced error tracking and reporting
#
# Changes
# 2016-01-03:
# - Added more options to parser.
#

from __future__ import print_function
import socket
Expand Down Expand Up @@ -64,11 +69,10 @@ def update_progress(progress):
sys.stderr.write('.')
sys.stderr.flush()

def serve(remoteAddr, remotePort, password, filename, command = FLASH):
def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, command = FLASH):
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serverPort = random.randint(10000,60000)
server_address = ('0.0.0.0', serverPort)
server_address = (localAddr, localPort)
logging.info('Starting on %s:%s', str(server_address[0]), str(server_address[1]))
try:
sock.bind(server_address)
Expand All @@ -82,7 +86,7 @@ def serve(remoteAddr, remotePort, password, filename, command = FLASH):
file_md5 = hashlib.md5(f.read()).hexdigest()
f.close()
logging.info('Upload size: %d', content_size)
message = '%d %d %d %s\n' % (command, serverPort, content_size, file_md5)
message = '%d %d %d %s\n' % (command, localPort, content_size, file_md5)

# Wait for a connection
logging.info('Sending invitation to: %s', remoteAddr)
Expand Down Expand Up @@ -209,12 +213,24 @@ def parser():
help = "ESP8266 IP Address.",
default = False
)
group.add_option("-I", "--host_ip",
dest = "host_ip",
action = "store",
help = "Host IP Address.",
default = "0.0.0.0"
)
group.add_option("-p", "--port",
dest = "esp_port",
type = "int",
help = "ESP8266 ota Port. Default 8266",
default = 8266
)
group.add_option("-P", "--host_port",
dest = "host_port",
type = "int",
help = "Host server ota Port. Default random 10000-60000",
default = random.randint(10000,60000)
)
parser.add_option_group(group)

# auth
Expand Down Expand Up @@ -294,7 +310,7 @@ def main(args):
command = SPIFFS
# end if

return serve(options.esp_ip, options.esp_port, options.auth, options.image, command)
return serve(options.esp_ip, options.host_ip, options.esp_port, options.host_port, options.auth, options.image, command)
# end main


Expand Down

0 comments on commit c52e07a

Please sign in to comment.