def create_websocket(addr): s = socket.socket() s.connect(addr) #s = s.makefile("rwb") websocket_helper.client_handshake(s) ws = websocket(s) return ws
def main(): if len(sys.argv) != 3: help(1) if ":" in sys.argv[1] and ":" in sys.argv[2]: error("Operations on 2 remote files are not supported") if ":" not in sys.argv[1] and ":" not in sys.argv[2]: error("One remote file is required") if ":" in sys.argv[1]: op = "get" host, port, src_file = parse_remote(sys.argv[1]) dst_file = sys.argv[2] if os.path.isdir(dst_file): basename = src_file.rsplit("/", 1)[-1] dst_file += "/" + basename else: op = "put" host, port, dst_file = parse_remote(sys.argv[2]) src_file = sys.argv[1] if dst_file[-1] == "/": basename = src_file.rsplit("/", 1)[-1] dst_file += basename if 1: print(op, host, port) print(src_file, "->", dst_file) s = socket.socket() ai = socket.getaddrinfo(host, port) addr = ai[0][4] s.connect(addr) #s = s.makefile("rwb") websocket_helper.client_handshake(s) ws = websocket(s) import getpass passwd = getpass.getpass() login(ws, passwd) print("Remote WebREPL version:", get_ver(ws)) # Set websocket to send data marked as "binary" ws.ioctl(9, 2) if op == "get": get_file(ws, dst_file, src_file) elif op == "put": put_file(ws, src_file, dst_file) s.close()
def main(): print("Uploading src") s = socket.socket() ai = socket.getaddrinfo(TARGET_IP, TARGET_PORT) addr = ai[0][4] print (addr) s.connect(addr) #s = s.makefile("rwb") websocket_helper.client_handshake(s) ws = websocket(s) login(ws, TARGET_PASS) print("Remote WebREPL version:", get_ver(ws)) # Now commands can be sent and files can be uploaded send_cmd(ws,"\x03") # Break currently running program if any send_cmd(ws,"import os") send_cmd(ws,"import machine") thisFileDir = os.path.dirname(os.path.abspath(__file__)) srcDir = os.path.join(thisFileDir,'..', 'src') rootDir = os.listdir(srcDir) # Go through source and look for folders # For each folder in src # Send create folder command # Send go to folder command # Put all files from folder in target folder # Return to previous folder # For the rest of the files just upload in root for item in rootDir: fullPath = os.path.join(srcDir,item) print(fullPath) if os.path.isdir(fullPath): cmd = "os.mkdir('%s')"%item send_cmd(ws,cmd) cmd = "os.chdir('%s')"%item send_cmd(ws,cmd) subDir = os.listdir(fullPath) for subItem in subDir: subFullPath = os.path.join(fullPath,subItem) print(subFullPath) put_file(ws, subFullPath, subItem) cmd = "os.chdir('..')" send_cmd(ws,cmd) else: put_file(ws, fullPath, item) cmd = "machine.reset()" send_cmd(ws,cmd) # Nothing can be done after this s.close()
import socket host = "192.168.98.37" port = "8266" passwd = "1234" # establish connection with esp s = socket.socket() ai = socket.getaddrinfo(host, port) addr = ai[0][4] print('Connecting to address ' + str(addr[0]) + ":" + str(addr[1])) s.connect(addr) #s = s.makefile("rwb") print('Connected') websocket_helper.client_handshake(s) ws = websocket(s) print('Authenticating...') webrepl.login(ws, passwd) print('Successfully authenticated:') print("Remote WebREPL version:", webrepl.get_ver(ws)) # Set websocket to send data marked as "binary" ws.ioctl(9, 2) def uploadSource(filename, subdir): import webrepl_cli as webrepl src_file = parentDir + '/' + subdir + '/' + filename print('Sending ' + src_file + ' to device..')