-
Notifications
You must be signed in to change notification settings - Fork 83
/
02_terminal_cli.py
86 lines (71 loc) · 2.89 KB
/
02_terminal_cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""
[TERMINAL WIDGET ESP32 EXAMPLE] =====================================================================================
Environment prepare:
In your Blynk App project:
- add "Terminal" widget,
- bind it to Virtual Pin V2,
- add input line option in widget settings
- Run the App (green triangle in the upper right corner).
- define your auth token for current example
- define SSID and WiFi password that will be used by ESP32 board
- run current example
This started program will call and execute event handler "write_virtual_pin_handler" if new
event comes from terminal app widget.
In App Terminal widget you can type commands.
'help' - info about available commnds
'logo' - prints blynk library ascii logo
'version' - prints blynk library version
'sysinfo' - prints board system info
'ls' - list target board dir. Example: 'ls /lib'.
root dir will be listed if no arguments provided
For any other terminal inputs will be printed error info that provided command is not supported.
=====================================================================================================================
Additional info about blynk you can find by examining such resources:
Downloads, docs, tutorials: https://blynk.io
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Social networks: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
=====================================================================================================================
"""
import blynklib_mp as blynklib
import network
import uos
import utime as time
WIFI_SSID = 'YourWifiSSID'
WIFI_PASS = 'YourWifiPassword'
BLYNK_AUTH = 'YourAuthToken'
print("Connecting to WiFi network '{}'".format(WIFI_SSID))
wifi = network.WLAN(network.STA_IF)
wifi.active(True)
wifi.connect(WIFI_SSID, WIFI_PASS)
while not wifi.isconnected():
time.sleep(1)
print('WiFi connect retry ...')
print('WiFi IP:', wifi.ifconfig()[0])
print("Connecting to Blynk server...")
blynk = blynklib.Blynk(BLYNK_AUTH)
CMD_LIST = ['logo', 'version', 'sysinfo', 'ls']
@blynk.handle_event('write V2')
def write_handler(pin, values):
if values:
in_args = values[0].split(' ')
cmd = in_args[0]
cmd_args = in_args[1:]
if cmd == 'help':
output = ' '.join(CMD_LIST)
elif cmd == CMD_LIST[0]:
output = blynklib.LOGO
elif cmd == CMD_LIST[1]:
output = blynklib.__version__
elif cmd == CMD_LIST[2]:
output = uos.uname()
elif cmd == CMD_LIST[3]:
arg = cmd_args[0] if cmd_args else ''
output = uos.listdir(arg)
else:
output = "[ERR]: Not supported command '{}'".format(values[0])
blynk.virtual_write(pin, output)
blynk.virtual_write(pin, '\n')
while True:
blynk.run()