Skip to content

Commit c52e07a

Browse files
committed
Merge pull request esp8266#1364 from mogorman/master
add support for manually selecting ip and port for host side
2 parents ce1b64b + d2a357e commit c52e07a

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

tools/espota.py

+23-7
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
#
66
# Modified since 2015-09-18 from Pascal Gollor (https://github.com/pgollor)
77
# Modified since 2015-11-09 from Hristo Gochkov (https://github.com/me-no-dev)
8+
# Modified since 2016-01-03 from Matthew O'Gorman (https://githumb.com/mogorman)
89
#
910
# This script will push an OTA update to the ESP
10-
# use it like: python espota.py -i <ESP_IP_address> -p <ESP_port> [-a password] -f <sketch.bin>
11+
# 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>
1112
# Or to upload SPIFFS image:
12-
# python espota.py -i <ESP_IP_address> -p <ESP_port> [-a password] -s -f <spiffs.bin>
13+
# python espota.py -i <ESP_IP_address> -I <Host_IP_address> -p <ESP_port> -P <HOST_port> [-a password] -s -f <spiffs.bin>
1314
#
1415
# Changes
1516
# 2015-09-18:
@@ -22,6 +23,10 @@
2223
# - Added digest authentication
2324
# - Enchanced error tracking and reporting
2425
#
26+
# Changes
27+
# 2016-01-03:
28+
# - Added more options to parser.
29+
#
2530

2631
from __future__ import print_function
2732
import socket
@@ -64,11 +69,10 @@ def update_progress(progress):
6469
sys.stderr.write('.')
6570
sys.stderr.flush()
6671

67-
def serve(remoteAddr, remotePort, password, filename, command = FLASH):
72+
def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, command = FLASH):
6873
# Create a TCP/IP socket
6974
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
70-
serverPort = random.randint(10000,60000)
71-
server_address = ('0.0.0.0', serverPort)
75+
server_address = (localAddr, localPort)
7276
logging.info('Starting on %s:%s', str(server_address[0]), str(server_address[1]))
7377
try:
7478
sock.bind(server_address)
@@ -82,7 +86,7 @@ def serve(remoteAddr, remotePort, password, filename, command = FLASH):
8286
file_md5 = hashlib.md5(f.read()).hexdigest()
8387
f.close()
8488
logging.info('Upload size: %d', content_size)
85-
message = '%d %d %d %s\n' % (command, serverPort, content_size, file_md5)
89+
message = '%d %d %d %s\n' % (command, localPort, content_size, file_md5)
8690

8791
# Wait for a connection
8892
logging.info('Sending invitation to: %s', remoteAddr)
@@ -209,12 +213,24 @@ def parser():
209213
help = "ESP8266 IP Address.",
210214
default = False
211215
)
216+
group.add_option("-I", "--host_ip",
217+
dest = "host_ip",
218+
action = "store",
219+
help = "Host IP Address.",
220+
default = "0.0.0.0"
221+
)
212222
group.add_option("-p", "--port",
213223
dest = "esp_port",
214224
type = "int",
215225
help = "ESP8266 ota Port. Default 8266",
216226
default = 8266
217227
)
228+
group.add_option("-P", "--host_port",
229+
dest = "host_port",
230+
type = "int",
231+
help = "Host server ota Port. Default random 10000-60000",
232+
default = random.randint(10000,60000)
233+
)
218234
parser.add_option_group(group)
219235

220236
# auth
@@ -294,7 +310,7 @@ def main(args):
294310
command = SPIFFS
295311
# end if
296312

297-
return serve(options.esp_ip, options.esp_port, options.auth, options.image, command)
313+
return serve(options.esp_ip, options.host_ip, options.esp_port, options.host_port, options.auth, options.image, command)
298314
# end main
299315

300316

0 commit comments

Comments
 (0)