Created
June 11, 2015 15:31
-
-
Save igrr/d35ab8446922179dc58c to your computer and use it in GitHub Desktop.
ESP8266 Arduino OTA test script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/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' | |
sent = sock2.sendto(message, remote_address) | |
while True: | |
# Wait for a connection | |
print >>sys.stderr, 'waiting for a 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)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dont upload SPIFF! [CRITICAL]: Not enough arguments.
but all arguments set! -s spiff.bin , ip and etc
upload only firmware!