Jędrzej Wyzgała
Jędrzej Wyzgała

Reputation: 43

Rshell on windows freezes randomly while sending files to ESP32 running micropython via rsync or cp

I'm having trouble copying files to ESP32 device running micropython via rshell (remote micropython shell). The problem seems to occur randomly. Sometimes I manage to successfuly send all files (like 20 of them) with rsync and sometimes I cannot even copy one file with cp. There is no error message and script doesn't crash, it just stops working and freezes the console. I've tried with and without -a parameter (I'm sending only .py files). The last thing printed with debug is code to be run on microcontroller below and it just stops there. I didn't find any pattern. I've tried using some other esp32 device and other windows PC. Same results. I even tried lowering default 32 buffer to 16, no improvement. The worst thing is that is sometimes works fine and I cannot get constant results (even bad). It stops on random files, not always the same one.

Rsync command (with --mirror parameter) is very helpful and I could not just copy all files by hand.

EDIT: just tested on mac and it works fine. I guess it's just problem on windows...

Adding /pyboard/protocol/parser.py
----- About to send 2269 bytes of code to the pyboard -----
def recv_file_from_host(src_file, dst_filename, filesize, dst_mode='wb'):
"""Function which runs on the pyboard. Matches up with send_file_to_remote."""
import sys
import ubinascii
import os
if False:
    try:
        import pyb
        usb = pyb.USB_VCP()
    except:
        try:
            import machine
            usb = machine.USB_VCP()
        except:
            usb = None
    if usb and usb.isconnected():
        # We don't want 0x03 bytes in the data to be interpreted as a Control-C
        # This gets reset each time the REPL runs a line, so we don't need to
        # worry about resetting it ourselves
        usb.setinterrupt(-1)
try:
    with open(dst_filename, dst_mode) as dst_file:
        bytes_remaining = filesize
        if not False:
            bytes_remaining *= 2  # hexlify makes each byte into 2
        buf_size = 32
        write_buf = bytearray(buf_size)
        read_buf = bytearray(buf_size)
        while bytes_remaining > 0:
            # Send back an ack as a form of flow control
            sys.stdout.write('\x06')
            read_size = min(bytes_remaining, buf_size)
            buf_remaining = read_size
            buf_index = 0
            while buf_remaining > 0:
                if False:
                    bytes_read = sys.stdin.buffer.readinto(read_buf, read_size)
                else:
                    bytes_read = sys.stdin.readinto(read_buf, read_size)
                if bytes_read > 0:
                    write_buf[buf_index:bytes_read] = read_buf[0:bytes_read]
                    buf_index += bytes_read
                    buf_remaining -= bytes_read
            if False:
                dst_file.write(write_buf[0:read_size])
            else:
                dst_file.write(ubinascii.unhexlify(write_buf[0:read_size]))
            if hasattr(os, 'sync'):
                os.sync()
            bytes_remaining -= read_size
    return True
except:
    return False
output = recv_file_from_host(None, '/protocol/parser.py', 1467)
if output is None:
print("None")
else:
print(output)

-----

Upvotes: 2

Views: 498

Answers (1)

Mark
Mark

Reputation: 1

I had the same problem , when trying

    C:\> cp src\main.py /pyboard/

the cmd freezes. When I copied using the following

    C:\> cp src/main.py /pyboard/

There where no issues, so maybe rshell has some problems when there are "\" in the path

Upvotes: 0

Related Questions