Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions webrepl_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def help(rc=0):
print("%s - Perform remote file operations using MicroPython WebREPL protocol" % exename)
print("Arguments:")
print(" [-p password] <host>:<remote_file> <local_file> - Copy remote file to local file")
print(" [-p password] <local_file> <host>:<remote_file> - Copy local file to remote file")
print(" [-p password] [-r/--reset] <local_file> <host>:<remote_file> - Copy local file to remote file and optionally reset after")
print("Examples:")
print(" %s script.py 192.168.4.1:/another_name.py" % exename)
print(" %s script.py 192.168.4.1:/app/" % exename)
Expand All @@ -191,7 +191,7 @@ def parse_remote(remote):


def main():
if len(sys.argv) not in (3, 5):
if len(sys.argv) not in (3, 4, 5, 6):
help(1)

passwd = None
Expand All @@ -200,6 +200,12 @@ def main():
sys.argv.pop(i)
passwd = sys.argv.pop(i)
break
do_reset = False
for i in range(len(sys.argv)):
if sys.argv[i] == '--reset' or sys.argv[i] == '-r' :
sys.argv.pop(i)
do_reset = True
break

if not passwd:
import getpass
Expand Down Expand Up @@ -250,9 +256,21 @@ def main():
get_file(ws, dst_file, src_file)
elif op == "put":
put_file(ws, src_file, dst_file)
if do_reset:
print('Resetting...')
# ws.write only sends binary data, so we need to instead send the
# appropriate header for "text" data to send control characters
text_hdr = struct.pack(">BB", 0x81, 1)
s.send(text_hdr)
s.send(b'\x03') #ctrl-c to interrupt whatever might be happening
#print(s.recv(1000))
s.send(text_hdr)
s.send(b'\x04') #ctrl-d
#print(s.recv(1000))


s.close()


if __name__ == "__main__":
main()
main()