@johnnycubides/micropython-esp32-plugin-catalejo-editor 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/micropython-esp32/README.md +3 -0
- package/micropython-esp32/commands.d.ts +3 -3
- package/micropython-esp32/esp32-libs/esp32-c3-mini/boot.py +14 -0
- package/micropython-esp32/esp32-libs/esp32-c3-mini/webrepl_cfg.py +1 -0
- package/micropython-esp32/esp32-libs/esp32-c3-mini/wifi.py +135 -0
- package/micropython-esp32/esp32-libs/esp32-c3-mini/wifi_config.py +11 -0
- package/micropython-esp32/esp32-libs/esp32-c3-oled-mini/boot.py +14 -0
- package/micropython-esp32/esp32-libs/esp32-c3-oled-mini/display.py +67 -0
- package/micropython-esp32/esp32-libs/esp32-c3-oled-mini/ssd1306.py +164 -0
- package/micropython-esp32/esp32-libs/esp32-c3-oled-mini/webrepl_cfg.py +1 -0
- package/micropython-esp32/esp32-libs/esp32-c3-oled-mini/wifi.py +135 -0
- package/micropython-esp32/esp32-libs/esp32-c3-oled-mini/wifi_config.py +11 -0
- package/micropython-esp32/esp32-libs/esp32-s3-zero/boot.py +14 -0
- package/micropython-esp32/esp32-libs/esp32-s3-zero/webrepl_cfg.py +1 -0
- package/micropython-esp32/esp32-libs/esp32-s3-zero/wifi.py +135 -0
- package/micropython-esp32/esp32-libs/esp32-s3-zero/wifi_config.py +11 -0
- package/micropython-esp32/esp32-libs/esp32-wroom-devkit/boot.py +14 -0
- package/micropython-esp32/esp32-libs/esp32-wroom-devkit/webrepl_cfg.py +1 -0
- package/micropython-esp32/esp32-libs/esp32-wroom-devkit/wifi.py +135 -0
- package/micropython-esp32/esp32-libs/esp32-wroom-devkit/wifi_config.py +11 -0
- package/micropython-esp32/lang.d.ts +60 -1
- package/micropython-esp32/micropython.es.js +330 -178
- package/micropython-esp32/micropython.umd.js +14 -14
- package/micropython-esp32/plugin.json +1 -1
- package/micropython-esp32/upy-websockect.d.ts +30 -2
- package/package.json +1 -1
- package/micropython-esp32/esp32-libs/boot.py +0 -13
- package/micropython-esp32/esp32-libs/wifi.py +0 -77
- package/micropython-esp32/esp32-libs/wifi_config_esp32c3mini.py +0 -14
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
try:
|
|
2
|
+
import display
|
|
3
|
+
except ImportError:
|
|
4
|
+
display = None
|
|
5
|
+
|
|
6
|
+
AP_PASS = '87654321'
|
|
7
|
+
|
|
8
|
+
def scr(*lines, inv=None):
|
|
9
|
+
# Complemento OLED: muestra en pantalla lo mismo que se imprime por serial
|
|
10
|
+
if display:
|
|
11
|
+
display.show(*lines, inv=inv)
|
|
12
|
+
|
|
13
|
+
def ip_lines(ip):
|
|
14
|
+
return display.ip_lines(ip) if display else [ip]
|
|
15
|
+
|
|
16
|
+
def status_txt(network, st):
|
|
17
|
+
# Máximo 7 caracteres: se muestra como 'X <motivo>' en una fila de 9
|
|
18
|
+
names = {
|
|
19
|
+
getattr(network, 'STAT_NO_AP_FOUND', -1): 'sin red',
|
|
20
|
+
getattr(network, 'STAT_WRONG_PASSWORD', -2): 'clave?', # también CONNECTION_FAIL
|
|
21
|
+
getattr(network, 'STAT_HANDSHAKE_TIMEOUT', -3): 'enlace',
|
|
22
|
+
getattr(network, 'STAT_BEACON_TIMEOUT', -4): 'enlace',
|
|
23
|
+
getattr(network, 'STAT_CONNECTING', -5): 'timeout',
|
|
24
|
+
}
|
|
25
|
+
return names.get(st, 'st:' + str(st))
|
|
26
|
+
|
|
27
|
+
def do_ap():
|
|
28
|
+
import network
|
|
29
|
+
ap_if = network.WLAN(network.AP_IF)
|
|
30
|
+
mac = ''.join('%02x' % b for b in ap_if.config('mac'))[-5:]
|
|
31
|
+
if not network.WLAN(network.AP_IF).active() and not network.WLAN(network.STA_IF).isconnected():
|
|
32
|
+
print("Config...")
|
|
33
|
+
ap_if.config(essid='Catalejo-'+mac, authmode=3, password=AP_PASS)
|
|
34
|
+
ap_if.active(True)
|
|
35
|
+
print('WiFi name: ' + 'Catalejo-' + mac)
|
|
36
|
+
print('PASS: ' + AP_PASS)
|
|
37
|
+
scr('AP:', 'Catalejo-' + mac, AP_PASS)
|
|
38
|
+
|
|
39
|
+
def led_ctr(led, state):
|
|
40
|
+
if led:
|
|
41
|
+
if state != None:
|
|
42
|
+
led.value(state)
|
|
43
|
+
else:
|
|
44
|
+
led.value(not led.value())
|
|
45
|
+
|
|
46
|
+
def but_ctr(but, logic):
|
|
47
|
+
if but:
|
|
48
|
+
return but.value() == logic
|
|
49
|
+
else:
|
|
50
|
+
return False
|
|
51
|
+
|
|
52
|
+
def removeMain():
|
|
53
|
+
try:
|
|
54
|
+
from machine import Pin
|
|
55
|
+
import wifi_config
|
|
56
|
+
import time
|
|
57
|
+
scr('Catalejo', 'arrancando')
|
|
58
|
+
if wifi_config.BUT != None and wifi_config.LBUT != None:
|
|
59
|
+
led = Pin(wifi_config.LED, Pin.OUT)
|
|
60
|
+
but = Pin(wifi_config.BUT, Pin.IN)
|
|
61
|
+
time.sleep(1.5)
|
|
62
|
+
ret_but = but_ctr(but, wifi_config.LBUT)
|
|
63
|
+
if ret_but:
|
|
64
|
+
import os
|
|
65
|
+
os.remove("main.py")
|
|
66
|
+
led_ctr(led, not wifi_config.LLED)
|
|
67
|
+
print("main.py removed")
|
|
68
|
+
scr('Catalejo', 'main.py', 'borrado')
|
|
69
|
+
except OSError as e:
|
|
70
|
+
print(e)
|
|
71
|
+
|
|
72
|
+
def do_sta_connect():
|
|
73
|
+
import network
|
|
74
|
+
import wifi_config
|
|
75
|
+
if not wifi_config.SSID or not wifi_config.PASS or not wifi_config.ATTE:
|
|
76
|
+
return
|
|
77
|
+
wlan = network.WLAN(network.STA_IF)
|
|
78
|
+
mac = ''.join('%02x' % b for b in network.WLAN(network.AP_IF).config('mac'))[-5:]
|
|
79
|
+
wlan.active(True)
|
|
80
|
+
# Placas ESP32-C3 con antena chip (0.42" OLED, Super Mini) no conectan a potencia máxima
|
|
81
|
+
txp = getattr(wifi_config, 'TXP', None)
|
|
82
|
+
if txp != None:
|
|
83
|
+
try:
|
|
84
|
+
# Rango válido 2 - 21 dBm; el chip usa escalones 2, 5, 7, 8.5, 11, 13, 14, 15, 16.5, 18, 20
|
|
85
|
+
wlan.config(txpower=txp)
|
|
86
|
+
except (OSError, ValueError) as e:
|
|
87
|
+
print('TXP invalido (2-21 dBm):', txp, e)
|
|
88
|
+
from machine import Pin
|
|
89
|
+
import time
|
|
90
|
+
led = None
|
|
91
|
+
but = None
|
|
92
|
+
ret_but = None
|
|
93
|
+
if wifi_config.LED != None and wifi_config.LLED != None:
|
|
94
|
+
led = Pin(wifi_config.LED, Pin.OUT)
|
|
95
|
+
if wifi_config.BUT != None and wifi_config.LBUT != None:
|
|
96
|
+
but = Pin(wifi_config.BUT, Pin.IN)
|
|
97
|
+
led_ctr(led, wifi_config.LLED)
|
|
98
|
+
time.sleep(0.5)
|
|
99
|
+
ret_but = but_ctr(but, wifi_config.LBUT)
|
|
100
|
+
if not wlan.isconnected():
|
|
101
|
+
print('Connecting to network...')
|
|
102
|
+
wlan.connect(wifi_config.SSID, wifi_config.PASS)
|
|
103
|
+
attemps = 0
|
|
104
|
+
while not wlan.isconnected() and attemps < wifi_config.ATTE:
|
|
105
|
+
scr('STA...', wifi_config.SSID[:9], '%d/%d' % (attemps + 1, wifi_config.ATTE))
|
|
106
|
+
led_ctr(led, wifi_config.LLED)
|
|
107
|
+
time.sleep(0.1)
|
|
108
|
+
led_ctr(led, not wifi_config.LLED)
|
|
109
|
+
time.sleep(0.9)
|
|
110
|
+
attemps += 1
|
|
111
|
+
if wlan.isconnected():
|
|
112
|
+
led_ctr(led, wifi_config.LLED)
|
|
113
|
+
ip = wlan.ifconfig()[0]
|
|
114
|
+
print("IP STA: ", ip)
|
|
115
|
+
print("Dev: catalejo-" + mac)
|
|
116
|
+
scr('STA OK', ip_lines(ip), 'Dev:' + mac)
|
|
117
|
+
if ret_but :
|
|
118
|
+
scr('IP STA:', ip_lines(ip), 'Dev:' + mac, 'Btn:salir')
|
|
119
|
+
time.sleep(3)
|
|
120
|
+
while not but_ctr(but, wifi_config.LBUT):
|
|
121
|
+
led_ctr(led, None)
|
|
122
|
+
print("IP STA: ", ip)
|
|
123
|
+
print("Dev: catalejo-" + mac)
|
|
124
|
+
time.sleep(1)
|
|
125
|
+
scr('STA OK', ip_lines(ip), 'Dev:' + mac)
|
|
126
|
+
if not wifi_config.AP:
|
|
127
|
+
network.WLAN(network.AP_IF).active(False)
|
|
128
|
+
print("AP_IF off")
|
|
129
|
+
scr('STA OK', ip_lines(ip), 'Dev:' + mac, 'AP off')
|
|
130
|
+
else:
|
|
131
|
+
st = wlan.status()
|
|
132
|
+
wlan.active(False)
|
|
133
|
+
led_ctr(led, not wifi_config.LLED)
|
|
134
|
+
print("Don't connect how a STA, status:", st)
|
|
135
|
+
scr('X ' + status_txt(network, st), 'AP:', 'Catalejo-' + mac, AP_PASS, inv=0)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
SSID = None # vacío en el paquete: la red se configura en cada placa
|
|
2
|
+
PASS = None # vacío en el paquete: la red se configura en cada placa
|
|
3
|
+
ATTE = 15
|
|
4
|
+
TXP = None # potencia por defecto (20 dBm); probar 8.5 si no conecta
|
|
5
|
+
AP = False
|
|
6
|
+
LED = 2
|
|
7
|
+
LLED = 0
|
|
8
|
+
BUT = 0
|
|
9
|
+
LBUT = 0
|
|
10
|
+
OLED_SDA = None # sin pantalla OLED
|
|
11
|
+
OLED_SCL = None
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# This file is executed on every boot (including wake-boot from deepsleep)
|
|
2
|
+
# import esp
|
|
3
|
+
# esp.osdebug(None)
|
|
4
|
+
# import webrepl
|
|
5
|
+
# webrepl.start()
|
|
6
|
+
|
|
7
|
+
import webrepl
|
|
8
|
+
from wifi import do_ap, do_sta_connect, removeMain
|
|
9
|
+
|
|
10
|
+
removeMain()
|
|
11
|
+
webrepl.start()
|
|
12
|
+
do_ap()
|
|
13
|
+
do_sta_connect()
|
|
14
|
+
gc.collect()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
PASS = '0000'
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
try:
|
|
2
|
+
import display
|
|
3
|
+
except ImportError:
|
|
4
|
+
display = None
|
|
5
|
+
|
|
6
|
+
AP_PASS = '87654321'
|
|
7
|
+
|
|
8
|
+
def scr(*lines, inv=None):
|
|
9
|
+
# Complemento OLED: muestra en pantalla lo mismo que se imprime por serial
|
|
10
|
+
if display:
|
|
11
|
+
display.show(*lines, inv=inv)
|
|
12
|
+
|
|
13
|
+
def ip_lines(ip):
|
|
14
|
+
return display.ip_lines(ip) if display else [ip]
|
|
15
|
+
|
|
16
|
+
def status_txt(network, st):
|
|
17
|
+
# Máximo 7 caracteres: se muestra como 'X <motivo>' en una fila de 9
|
|
18
|
+
names = {
|
|
19
|
+
getattr(network, 'STAT_NO_AP_FOUND', -1): 'sin red',
|
|
20
|
+
getattr(network, 'STAT_WRONG_PASSWORD', -2): 'clave?', # también CONNECTION_FAIL
|
|
21
|
+
getattr(network, 'STAT_HANDSHAKE_TIMEOUT', -3): 'enlace',
|
|
22
|
+
getattr(network, 'STAT_BEACON_TIMEOUT', -4): 'enlace',
|
|
23
|
+
getattr(network, 'STAT_CONNECTING', -5): 'timeout',
|
|
24
|
+
}
|
|
25
|
+
return names.get(st, 'st:' + str(st))
|
|
26
|
+
|
|
27
|
+
def do_ap():
|
|
28
|
+
import network
|
|
29
|
+
ap_if = network.WLAN(network.AP_IF)
|
|
30
|
+
mac = ''.join('%02x' % b for b in ap_if.config('mac'))[-5:]
|
|
31
|
+
if not network.WLAN(network.AP_IF).active() and not network.WLAN(network.STA_IF).isconnected():
|
|
32
|
+
print("Config...")
|
|
33
|
+
ap_if.config(essid='Catalejo-'+mac, authmode=3, password=AP_PASS)
|
|
34
|
+
ap_if.active(True)
|
|
35
|
+
print('WiFi name: ' + 'Catalejo-' + mac)
|
|
36
|
+
print('PASS: ' + AP_PASS)
|
|
37
|
+
scr('AP:', 'Catalejo-' + mac, AP_PASS)
|
|
38
|
+
|
|
39
|
+
def led_ctr(led, state):
|
|
40
|
+
if led:
|
|
41
|
+
if state != None:
|
|
42
|
+
led.value(state)
|
|
43
|
+
else:
|
|
44
|
+
led.value(not led.value())
|
|
45
|
+
|
|
46
|
+
def but_ctr(but, logic):
|
|
47
|
+
if but:
|
|
48
|
+
return but.value() == logic
|
|
49
|
+
else:
|
|
50
|
+
return False
|
|
51
|
+
|
|
52
|
+
def removeMain():
|
|
53
|
+
try:
|
|
54
|
+
from machine import Pin
|
|
55
|
+
import wifi_config
|
|
56
|
+
import time
|
|
57
|
+
scr('Catalejo', 'arrancando')
|
|
58
|
+
if wifi_config.BUT != None and wifi_config.LBUT != None:
|
|
59
|
+
led = Pin(wifi_config.LED, Pin.OUT)
|
|
60
|
+
but = Pin(wifi_config.BUT, Pin.IN)
|
|
61
|
+
time.sleep(1.5)
|
|
62
|
+
ret_but = but_ctr(but, wifi_config.LBUT)
|
|
63
|
+
if ret_but:
|
|
64
|
+
import os
|
|
65
|
+
os.remove("main.py")
|
|
66
|
+
led_ctr(led, not wifi_config.LLED)
|
|
67
|
+
print("main.py removed")
|
|
68
|
+
scr('Catalejo', 'main.py', 'borrado')
|
|
69
|
+
except OSError as e:
|
|
70
|
+
print(e)
|
|
71
|
+
|
|
72
|
+
def do_sta_connect():
|
|
73
|
+
import network
|
|
74
|
+
import wifi_config
|
|
75
|
+
if not wifi_config.SSID or not wifi_config.PASS or not wifi_config.ATTE:
|
|
76
|
+
return
|
|
77
|
+
wlan = network.WLAN(network.STA_IF)
|
|
78
|
+
mac = ''.join('%02x' % b for b in network.WLAN(network.AP_IF).config('mac'))[-5:]
|
|
79
|
+
wlan.active(True)
|
|
80
|
+
# Placas ESP32-C3 con antena chip (0.42" OLED, Super Mini) no conectan a potencia máxima
|
|
81
|
+
txp = getattr(wifi_config, 'TXP', None)
|
|
82
|
+
if txp != None:
|
|
83
|
+
try:
|
|
84
|
+
# Rango válido 2 - 21 dBm; el chip usa escalones 2, 5, 7, 8.5, 11, 13, 14, 15, 16.5, 18, 20
|
|
85
|
+
wlan.config(txpower=txp)
|
|
86
|
+
except (OSError, ValueError) as e:
|
|
87
|
+
print('TXP invalido (2-21 dBm):', txp, e)
|
|
88
|
+
from machine import Pin
|
|
89
|
+
import time
|
|
90
|
+
led = None
|
|
91
|
+
but = None
|
|
92
|
+
ret_but = None
|
|
93
|
+
if wifi_config.LED != None and wifi_config.LLED != None:
|
|
94
|
+
led = Pin(wifi_config.LED, Pin.OUT)
|
|
95
|
+
if wifi_config.BUT != None and wifi_config.LBUT != None:
|
|
96
|
+
but = Pin(wifi_config.BUT, Pin.IN)
|
|
97
|
+
led_ctr(led, wifi_config.LLED)
|
|
98
|
+
time.sleep(0.5)
|
|
99
|
+
ret_but = but_ctr(but, wifi_config.LBUT)
|
|
100
|
+
if not wlan.isconnected():
|
|
101
|
+
print('Connecting to network...')
|
|
102
|
+
wlan.connect(wifi_config.SSID, wifi_config.PASS)
|
|
103
|
+
attemps = 0
|
|
104
|
+
while not wlan.isconnected() and attemps < wifi_config.ATTE:
|
|
105
|
+
scr('STA...', wifi_config.SSID[:9], '%d/%d' % (attemps + 1, wifi_config.ATTE))
|
|
106
|
+
led_ctr(led, wifi_config.LLED)
|
|
107
|
+
time.sleep(0.1)
|
|
108
|
+
led_ctr(led, not wifi_config.LLED)
|
|
109
|
+
time.sleep(0.9)
|
|
110
|
+
attemps += 1
|
|
111
|
+
if wlan.isconnected():
|
|
112
|
+
led_ctr(led, wifi_config.LLED)
|
|
113
|
+
ip = wlan.ifconfig()[0]
|
|
114
|
+
print("IP STA: ", ip)
|
|
115
|
+
print("Dev: catalejo-" + mac)
|
|
116
|
+
scr('STA OK', ip_lines(ip), 'Dev:' + mac)
|
|
117
|
+
if ret_but :
|
|
118
|
+
scr('IP STA:', ip_lines(ip), 'Dev:' + mac, 'Btn:salir')
|
|
119
|
+
time.sleep(3)
|
|
120
|
+
while not but_ctr(but, wifi_config.LBUT):
|
|
121
|
+
led_ctr(led, None)
|
|
122
|
+
print("IP STA: ", ip)
|
|
123
|
+
print("Dev: catalejo-" + mac)
|
|
124
|
+
time.sleep(1)
|
|
125
|
+
scr('STA OK', ip_lines(ip), 'Dev:' + mac)
|
|
126
|
+
if not wifi_config.AP:
|
|
127
|
+
network.WLAN(network.AP_IF).active(False)
|
|
128
|
+
print("AP_IF off")
|
|
129
|
+
scr('STA OK', ip_lines(ip), 'Dev:' + mac, 'AP off')
|
|
130
|
+
else:
|
|
131
|
+
st = wlan.status()
|
|
132
|
+
wlan.active(False)
|
|
133
|
+
led_ctr(led, not wifi_config.LLED)
|
|
134
|
+
print("Don't connect how a STA, status:", st)
|
|
135
|
+
scr('X ' + status_txt(network, st), 'AP:', 'Catalejo-' + mac, AP_PASS, inv=0)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
SSID = None # vacío en el paquete: la red se configura en cada placa
|
|
2
|
+
PASS = None # vacío en el paquete: la red se configura en cada placa
|
|
3
|
+
ATTE = 15
|
|
4
|
+
TXP = None # antena PCB: potencia por defecto (20 dBm)
|
|
5
|
+
AP = False
|
|
6
|
+
LED = 2
|
|
7
|
+
LLED = 0
|
|
8
|
+
BUT = 0
|
|
9
|
+
LBUT = 0
|
|
10
|
+
OLED_SDA = None # sin pantalla OLED
|
|
11
|
+
OLED_SCL = None
|
|
@@ -41,5 +41,64 @@ declare const dialogLabelCommands: {
|
|
|
41
41
|
};
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
|
+
/** Mensajes de la conexión con la placa por WiFi (WebREPL) */
|
|
45
|
+
declare const webreplLang: {
|
|
46
|
+
sendOk: {
|
|
47
|
+
en: string;
|
|
48
|
+
es: string;
|
|
49
|
+
};
|
|
50
|
+
sendFailed: {
|
|
51
|
+
en: string;
|
|
52
|
+
es: string;
|
|
53
|
+
};
|
|
54
|
+
resetOk: {
|
|
55
|
+
en: string;
|
|
56
|
+
es: string;
|
|
57
|
+
};
|
|
58
|
+
resetFailed: {
|
|
59
|
+
en: string;
|
|
60
|
+
es: string;
|
|
61
|
+
};
|
|
62
|
+
runOk: {
|
|
63
|
+
en: string;
|
|
64
|
+
es: string;
|
|
65
|
+
};
|
|
66
|
+
runFailed: {
|
|
67
|
+
en: string;
|
|
68
|
+
es: string;
|
|
69
|
+
};
|
|
70
|
+
noIp: {
|
|
71
|
+
en: string;
|
|
72
|
+
es: string;
|
|
73
|
+
};
|
|
74
|
+
noContent: {
|
|
75
|
+
en: string;
|
|
76
|
+
es: string;
|
|
77
|
+
};
|
|
78
|
+
connect: {
|
|
79
|
+
en: string;
|
|
80
|
+
es: string;
|
|
81
|
+
};
|
|
82
|
+
closed: {
|
|
83
|
+
en: string;
|
|
84
|
+
es: string;
|
|
85
|
+
};
|
|
86
|
+
timeout: {
|
|
87
|
+
en: string;
|
|
88
|
+
es: string;
|
|
89
|
+
};
|
|
90
|
+
accessDenied: {
|
|
91
|
+
en: string;
|
|
92
|
+
es: string;
|
|
93
|
+
};
|
|
94
|
+
filename: {
|
|
95
|
+
en: string;
|
|
96
|
+
es: string;
|
|
97
|
+
};
|
|
98
|
+
rejected: {
|
|
99
|
+
en: string;
|
|
100
|
+
es: string;
|
|
101
|
+
};
|
|
102
|
+
};
|
|
44
103
|
export declare function getTextFromLang(object: any, lang: LANG): string;
|
|
45
|
-
export { itemsToolBarLang, dialogLabelCommands, };
|
|
104
|
+
export { itemsToolBarLang, dialogLabelCommands, webreplLang, };
|