|
1 | 1 | # MIT License |
2 | 2 | # |
3 | | -# Copyright (c) 2020 Carlos Gil Gonzalez |
| 3 | +# Copyright (c) 2020 - 2022 Carlos Gil Gonzalez |
4 | 4 | # |
5 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
6 | 6 | # of this software and associated documentation files (the "Software"), to deal |
|
20 | 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
21 | 21 | # SOFTWARE. |
22 | 22 |
|
23 | | -""" |
24 | | -Python lib to interface with micropython devices through WebREPL protocol or |
25 | | -through Serial connection. |
26 | | -
|
27 | | -Example usage: |
28 | | -
|
29 | | -WIRELESS DEVICE (WebREPL) |
30 | | - >>> from upydevice import W_UPYDEVICE |
31 | | -# Setup and configurate a device : |
32 | | - >>> esp32 = W_UPYDEVICE('192.168.1.56', 'mypass') # (target_ip, password) |
33 | | -# Send command: |
34 | | - >>> esp32.cmd('led.on()') |
35 | | - >>> esp32.cmd("uos.listdir('/')") |
36 | | - ['boot.py', 'webrepl_cfg.py', 'main.py'] # this output is stored in [upydevice].output |
37 | | - >>> esp32.output |
38 | | - ['boot.py', 'webrepl_cfg.py', 'main.py'] |
39 | | - >>> esp32.cmd('foo()') |
40 | | - >>> esp32.cmd('x = [1,2,3];my_var = len(x);print(my_var)') |
41 | | - 3 |
42 | | -# Soft Reset: |
43 | | - >>> esp32.reset() |
44 | | - Rebooting device... |
45 | | -
|
46 | | - ### closed ### |
47 | | -
|
48 | | - Done! |
49 | | -
|
50 | | -SERIAL DEVICE (Picocom, Pyserial) |
51 | | - >>> from upydevice import S_UPYDEVICE |
52 | | -# Setup and configurate a device : |
53 | | - >>> esp32 = S_UPYDEVICE('/dev/tty.SLAB_USBtoUART', 1000, 115200) # defaults (serial_port, timeout=1000, baudrate=9600) |
54 | | -# Send command: |
55 | | - >>> esp32.cmd('led.on()') |
56 | | - >>> esp32.cmd("uos.listdir('/')") |
57 | | - ['boot.py', 'webrepl_cfg.py', 'main.py'] # this output is stored in [upydevice].output |
58 | | - >>> esp32.output |
59 | | - ['boot.py', 'webrepl_cfg.py', 'main.py'] |
60 | | - >>> esp32.cmd('foo()') |
61 | | - >>> esp32.cmd('x = [1,2,3];my_var = len(x);print(my_var)') |
62 | | - 3 |
63 | | -# Soft Reset: |
64 | | - >>> esp32.reset() |
65 | | - Rebooting device... |
66 | | - Done! |
67 | | -
|
68 | | -PYBOARD (Picocom, Pyserial) |
69 | | - >>> from upydevice import PYBOARD |
70 | | -# Setup and configurate a device : |
71 | | - pyboard = PYBOARD('/dev/tty.usbmodem3370377430372') # defaults (serial_port, timeout=1000, baudrate=9600) |
72 | | -# Send command: |
73 | | - >>> pyboard.cmd('pyb.LED(1).toggle()',timeout=100) |
74 | | - >>> pyboard.cmd("import uos;uos.listdir('/flash')") |
75 | | - ['main.py', 'pybcdc.inf', 'README.txt', 'boot.py', '.fseventsd', '.Trashes'] # this output is stored in [upydevice].output |
76 | | - >>> pyboard.output |
77 | | - ['main.py', 'pybcdc.inf', 'README.txt', 'boot.py', '.fseventsd', '.Trashes'] |
78 | | - >>> pyboard.cmd('foo()') |
79 | | - >>> pyboard.cmd('x = [1,2,3];my_var = len(x);print(my_var)') |
80 | | - 3 |
81 | | -# Soft Reset: |
82 | | - >>> pyboard.reset() |
83 | | - Rebooting pyboard... |
84 | | - Done! |
85 | | -
|
86 | | -GROUP (to send commands to several devices at a time) |
87 | | -# Setup and configurate the devices : |
88 | | - >>> from upydevice import W_UPYDEVICE, PYBOARD, GROUP |
89 | | -# PYBOARD |
90 | | - >>> pyboard = PYBOARD('/dev/tty.usbmodem387E386731342') |
91 | | -# ESP32 |
92 | | - >>> esp32_A = W_UPYDEVICE('192.168.1.53', 'mypass') |
93 | | - >>> esp32_B = W_UPYDEVICE('192.168.1.40', 'mypass') |
94 | | -
|
95 | | -# Setup and configurate the group: |
96 | | - >>> my_group = GROUP([esp32_A, esp32_B, pyboard]) |
97 | | -
|
98 | | -# Each upydevice has a name attribute that can be set at creation momment or after |
99 | | -# pyboard = PYBOARD('/dev/tty.usbmodem387E386731342', name='my_pyboard_1'); or pyboard.name = 'my_pyboard_1') |
100 | | -# If not set an automatic name will be set as 'upydev_class'+'ip or serial port' |
101 | | -
|
102 | | -# Send command: |
103 | | - >>> my_group.cmd('import machine;import ubinascii;ubinascii.hexlify(machine.unique_id())') |
104 | | - Sending command to wupydev_53 |
105 | | - b'30aea4233564' |
106 | | -
|
107 | | - Sending command to wupydev_40 |
108 | | - b'807d3a809b30' |
109 | | -
|
110 | | - Sending command to pyboard_tty.usbmodem387E386731342 |
111 | | - b'33004e000351343134383038' |
112 | | -
|
113 | | -# There is an option to silent the group messages with group_silent = True, and or each device ouput with device_silent=True |
114 | | -
|
115 | | -# Output is stored in group output attribute: |
116 | | - >>> my_group.output |
117 | | - {'wupydev_53': b'30aea4233564', 'wupydev_40': b'807d3a809b30', 'pyboard_tty.usbmodem387E386731342': b'33004e000351343134383038'} |
118 | | -
|
119 | | -# Send command parallel mode **: (experimental mode, may not work 100% of the times, depends on the connection quality (for wireless devices)) |
120 | | - >>> my_group.cmd_p('6*12') |
121 | | - Sending command to: wupydev_53, wupydev_40, pyboard_tty.usbmodem387E386731342 |
122 | | - 72 |
123 | | -
|
124 | | -
|
125 | | - 72 |
126 | | -
|
127 | | - 72 |
128 | | -
|
129 | | - Done! |
130 | | -# To see which ouput corresponds to which device use 'id=True' parameter: |
131 | | -
|
132 | | - >>> my_group.cmd_p('ubinascii.hexlify(machine.unique_id())', id=True) |
133 | | - Sending command to: wupydev_53, wupydev_40, pyboard_tty.usbmodem387E386731342 |
134 | | - pyboard_tty.usbmodem387E386731342:b'33004e000351343134383038' |
135 | | - pyboard_tty.usbmodem387E386731342: |
136 | | - pyboard_tty.usbmodem387E386731342: |
137 | | - wupydev_40:b'807d3a809b30' |
138 | | - wupydev_53:b'30aea4233564' |
139 | | - wupydev_40: |
140 | | - wupydev_53: |
141 | | - Done! |
142 | | - >>> |
143 | | - >>> my_group.output |
144 | | - {'wupydev_53': b'30aea4233564', 'wupydev_40': b'807d3a809b30', 'pyboard_tty.usbmodem387E386731342': b'33004e000351343134383038'} |
145 | | -
|
146 | | -To see more info read the DOCS at the github repo. |
147 | | -""" |
148 | | - |
149 | 23 | from .upydevice import * |
150 | 24 | name = 'upydevice' |
151 | | -__version__ = '0.3.7' |
| 25 | +__version__ = '0.3.8' |
0 commit comments