Page 1 of 1

problem with ampy, one code can't be sent

Posted: Fri Jan 26, 2018 12:54 pm
by ghusson
Hello, I try to send code here under. But ampy ends in error.
Version used : ampy, version 1.0.3
Do you have an idea ?
Thank you.

Error :

Code: Select all

ampy --port /dev/ttyUSB0 --baud=115200 put tools.py 
Traceback (most recent call last):
  File "/usr/local/bin/ampy", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/ampy/cli.py", line 213, in put
    board_files.put(remote, infile.read())
  File "/usr/local/lib/python2.7/dist-packages/ampy/files.py", line 137, in put
    self._pyboard.exec_("f = open('{0}', 'wb')".format(filename))
  File "/usr/local/lib/python2.7/dist-packages/ampy/pyboard.py", line 263, in exec_
    ret, ret_err = self.exec_raw(command)
  File "/usr/local/lib/python2.7/dist-packages/ampy/pyboard.py", line 254, in exec_raw
    self.exec_raw_no_follow(command);
  File "/usr/local/lib/python2.7/dist-packages/ampy/pyboard.py", line 251, in exec_raw_no_follow
    raise PyboardError('could not exec command')
ampy.pyboard.PyboardError: could not exec command


Code :

Code: Select all



def print_memory_usage():
    import gc
    mem_used = gc.mem_alloc()
    mem_free = gc.mem_free()
    mem_total = mem_used + mem_free
    used_percent = round((100 * mem_used) / mem_total)
    mem_used_kilo = round(mem_used / 1000)
    mem_free_kilo = round(mem_free / 1000)
    mem_total_kilo = round(mem_total / 1000)
    print(str(used_percent) + "% of heap memory used (" + str(mem_used_kilo) + "kB /" + str(mem_total_kilo) + "kB - " + str(mem_free_kilo) + "kB free).")
    # 59% of heap memory used (56kB /96kB - 40kB free).


def print_filesystem_usage():
    import uos
    import math
    fs_path = '/'
    statvfs = uos.statvfs(fs_path)
    fs_fragment_size_bytes = statvfs[1]
    fs_block_size_bytes = statvfs[0]
    fs_size_kb = round((fs_fragment_size_bytes / 1000) * statvfs[2])
    fs_user_size_free_kb = round((fs_block_size_bytes / 1000 ) * statvfs[4])
    fs_user_size_used_kb = fs_size_kb - fs_user_size_free_kb
    fs_used_percent = math.ceil((fs_user_size_used_kb * 100) / fs_size_kb)
    print(str(fs_used_percent) + "% of \"" + fs_path + "\" FS used (" + str(fs_user_size_used_kb) + "kB /" + str(fs_size_kb) + "kB - " + str(fs_user_size_used_kb) + "kB free).")
    # 1% of "/lib" FS used (5kB /2073kB - 5kB free).


def print_os_uname():
    import uos
    print(uos.uname())


def print_loaded_modules_list():
    import sys
    loaded_modules_list = ", ".join(sys.modules.keys())
    print("Loaded modules: " + loaded_modules_list)


def print_info():
    print_os_uname()
    print_loaded_modules_list()
    print_filesystem_usage()
    print_memory_usage()


Re: problem with ampy, one code can't be sent

Posted: Fri Jan 26, 2018 9:18 pm
by cefn
I get this when the console is already busy running something (e.g. is not showing chevrons like >>>).

This happens when for example you have a main.py which launches and takes over execution, preventing ampy from intervening via the console.

I find a workaround is to run GNU screen and connect to the device (also Putty and Miniterm can work). Then I run CTRL+C or whatever else is required to get it back to a clean micropython shell.

Once it is waiting there with a clean micropython shell I can exit screen, (CTRL+A then K), which leaves the serial device free, but the console in the correct state.

After this, ampy should run correctly.

Keep in mind that resetting brings back the same problem, as main.py is running afresh, unless you take the opportunity to remove it while you have control via ampy. Also any serial stuff being printed out by a background routine or OS level error, will also mess with Ampy. I have needed to interactively call esp.osdebug(None) to recover things before now.

Re: problem with ampy, one code can't be sent

Posted: Mon Jan 29, 2018 11:00 am
by ghusson
Indeed I know all that, but thank you to remember that.
I think I had no task printing some things and that my line was clear.
Anyway, I now use Loboris integrated framework with his FTP server, thus I don't have this problem anymore :-)
Thank you,
Gautier.