Skip to main content

Control MicroPython with your own code

Project description

Code style: black

MPyCntrl

Control MicroPython with your own coding

Drop in architecture with pttydev

can be used with minor changes with pttydev

don't forget to use ptty.waitready() after open()

pttydev sample code sample_pttydev.py

Code

sample code is in the github repo here sample.py

installation

mpycntrl can be installed with pip from here mpycntrl

What's new ?

Check CHANGELOG for latest ongoing, or upcoming news

sync project folders

with a sync file (e.g. mpycntrl_sync.json) it is possible to sync a complete project from local disk to a device.

sync will first create the folder structure, and the hash copy the files.

# use a different timeout e.g. 0.7 sec when syncing larger files

python3 -m mpycntrl -sync-all mpycntrl_sync.json -to 0.7


# but usually omit timeout (and sync larger files separately)

python3 -m mpycntrl -sync-all mpycntrl_sync.json 


# just copy (without hash compare), creates also folders

python3 -m mpycntrl -put-all mpycntrl_sync.json 

refer to mpycntrl_sync.json to see the structure. internally it uses glob for including and excluding files.

cmd line

display all available cmd line options with -h

usage: python3 -m mpycntrl [DEVICE-PARAMETER] [options]

Control MicroPython via cmd line

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show version info and exit
  -timeout TIMEOUT, -to TIMEOUT
                        timeout in sec to use (default: 0.35)
  -trace, -t            display trace info (default: False)
  -debug, -d            display debug info (default: False)
  -showtime             display execution time (default: False)
  -follow, -f           don't exit, keep following the output of MicroPython
                        (default: False)
  -maxretry MAXRETRY, -max MAXRETRY
                        max number of retries to connect (default: 3)
  -blocksize BLOCKSIZE, -bs BLOCKSIZE
                        blocksize during file transfer (default: 512)
  -reconnect RECONNECT_AFTER
                        reconnect delay when connection breaks (default: 1)
  -translate, -tr       translate response as string where possible (default:
                        False)
  -eval EVAL, -exe EVAL, -run EVAL, -e EVAL
                        send source code to MicroPython and execute
  -reset, -r            reset MicroPython by sending cntrl + D, soft restart
  -hardreset, -R        hard reset MicroPython
  -cntrlc, -c           send break cntrl + C
  -meminfo, -i          get memory info
  -ls [PATH]            list directory
  -ll [PATH]            long list directory as json with stat_result. refer to
                        os.stat() for more details
  -rm PATH              remove file
  -mkdir PATH, -mk PATH
                        create folders including sub folders, returns array of
                        tupels which dirs where created. returns false if
                        directory is already existing
  -rmdir PATH, -rd PATH
                        remove folder and all containing files and sub folders
  -get PATH [PATH ...]  get file from MicroPython
  -put PATH [PATH ...]  put file on MicroPhyton
  -stat FILE            get stat info for a file
  -hash FILE            get hash value for a file
  -hashcopy PATH, -hcp PATH, -hashcp PATH
                        put file on MicroPhyton if hashes are different
  -put-all sync_file    one way copy to device. creates folder and copy files.
                        no deletion of device files/ folders.
  -sync-all sync_file   one way copy / sync to device. creates folder and hash
                        copy files. no deletion of device files/ folders.
  -sync sync_file       one way copy / sync to device. hash copy files. no
                        creation folders.
  -wlan WLAN_SSID_PASSWD WLAN_SSID_PASSWD
                        WLAN ssid, and password to connect to
  -wlan-state CMD_WLAN_ACIVE
                        WLAN state on/off.
  -wlan-ifconfig, -wlan-if
                        WLAN ifconfig

PTTY:
  websocket parameter

  -host IP, -ip IP      ip adress to use (default: None)
  -hostport PORT, -ipport PORT, -ipp PORT
                        ip port to use (default: 8266)
  -passwd PASSWD, -pass PASSWD, -pwd PASSWD
                        password to use (default: 123456)
  -ipdelay DELAY        delay for writing 255 byte blocks (default: 0.5)

TTY:
  serial parameter

  -port PORT, -p PORT   port/device to use (default: /dev/ttyUSB0)
  -baud BAUD, -b BAUD   baud rate to use (default: 115200)
  -bytesize BYTESIZE, -cs BYTESIZE
                        bytesize to use (default: 8)
  -parity {N,E,O}       parity to use (default: N)
  -stopbits STOPBITS    stopbits to use (default: 1)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mpycntrl-0.0.10.tar.gz (26.4 kB view hashes)

Uploaded source

Built Distribution

mpycntrl-0.0.10-py3-none-any.whl (26.3 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page