8000 Added raw HW esp32 example · blynkkk/lib-python@a95c61c · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on May 7, 2025. It is now read-only.

Commit a95c61c

Browse files
committed
Added raw HW esp32 example
1 parent 5110fad commit a95c61c

File tree

2 files changed

+87
-1
lines changed

2 files changed

+87
-1
lines changed

examples/06_terminal_widget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363

6464
# last command in example - just to show error handling
6565
# for certain HW can be added specific commands. 'gpio readall' on PI3b for example
66-
ALLOWED_COMMANDS_LIST = ['ls', 'lsusb', 'ip a', 'ip abc'] # '
66+
ALLOWED_COMMANDS_LIST = ['ls', 'lsusb', 'ip a', 'ip abc']
6767

6868
blynk = blynklib.Blynk(BLYNK_AUTH)
6969

examples/esp32/02_terminal_cli.py

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

0 commit comments

Comments
 (0)
0