mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-13 13:01:55 +03:00
Initial Upload From IDE
For Test ONLY
This commit is contained in:
committed by
Ivan Grokhotkov
parent
a82796f83f
commit
dc9072b94b
67
tools/espota.py
Executable file
67
tools/espota.py
Executable file
@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# this script will push an OTA update to the ESP
|
||||
#
|
||||
# use it like: python ota_server.py <ESP_IP_address> <sketch.bin>
|
||||
#
|
||||
# on the ESP side you need code like this: https://gist.github.com/igrr/43d5c52328e955bb6b09 to handle the update
|
||||
#
|
||||
|
||||
import socket
|
||||
import sys
|
||||
import os
|
||||
|
||||
def serve(remoteAddr, filename):
|
||||
# Create a TCP/IP socket
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
serverPort = 48266
|
||||
server_address = ('0.0.0.0', serverPort)
|
||||
print >>sys.stderr, 'starting up on %s port %s' % server_address
|
||||
sock.bind(server_address)
|
||||
sock.listen(1)
|
||||
|
||||
sock2 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
remote_address = (remoteAddr, 8266)
|
||||
content_size = os.path.getsize(filename)
|
||||
print >>sys.stderr, 'upload size: %d' % content_size
|
||||
message = '%d %d %d\n' % (0, serverPort, content_size)
|
||||
print >>sys.stderr, 'sending invitation %s' % message
|
||||
sent = sock2.sendto(message, remote_address)
|
||||
sent = sock2.sendto(message, remote_address)
|
||||
sent = sock2.sendto(message, remote_address)
|
||||
|
||||
|
||||
while True:
|
||||
# Wait for a connection
|
||||
print >>sys.stderr, 'waiting for connection'
|
||||
connection, client_address = sock.accept()
|
||||
try:
|
||||
print >>sys.stderr, 'connection from', client_address
|
||||
|
||||
print >>sys.stderr, 'opening file %s' % filename
|
||||
f = open(filename, "rb")
|
||||
|
||||
while True:
|
||||
chunk = f.read(4096)
|
||||
if not chunk:
|
||||
break
|
||||
|
||||
print >>sys.stderr, 'sending %d' % len(chunk)
|
||||
connection.sendall(chunk)
|
||||
|
||||
print >>sys.stderr, 'done!'
|
||||
return 0
|
||||
|
||||
finally:
|
||||
connection.close()
|
||||
f.close()
|
||||
return 1
|
||||
|
||||
def main(args):
|
||||
return serve(args[1], args[2])
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
||||
|
Reference in New Issue
Block a user