Skip to content

Commit 1ae367d

Browse files
ethanlczskylarCai
authored andcommitted
add uilite demos for HaaS EDU K1 and M5StackCore2
Signed-off-by: ethan.lcz <[email protected]>
1 parent 0c3bb1c commit 1ae367d

File tree

188 files changed

+9625
-50
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+9625
-50
lines changed

components/netmgr/src/netmgr_wifi.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ static int wifi_recvmsg_task()
307307

308308
static void wifi_connect_failed_cb(uint32_t event_id, const void *param, void *context)
309309
{
310-
NETMGR_WIFI_LOGE("%s:%d err=%d\n", __func__, __LINE__, event_id);
310+
NETMGR_WIFI_LOGI("%s:%d err=%d\n", __func__, __LINE__, event_id);
311311
if(event_id == RET_WIFI_INVALID_PASSWORD) {
312312
g_handshake_failed_retry = NETMGR_WIFI_HANDSHAKE_FAILED_MAX_RETRY;
313313
//netmgr_stat_chg_event(m, NOTIFY_WIFI_HANDSHAKE_FAILED, param);
@@ -980,10 +980,10 @@ static int read_config_value(char** pos, const char* obj,int* line, netmgr_wifi_
980980
*pos = pos_end;
981981
NETMGR_WIFI_LOGI("%s:%d len :%d %s ", __func__, __LINE__, len, pos_start);
982982
if(strncmp(obj,"ssid", 4) == 0) {
983-
int contain_chinese = ssid_contain_chinese_check(config->ssid);
984983
strncpy(config->ssid, pos_start, len);
985984
config->ssid[len]='\0';
986985
NETMGR_WIFI_LOGI("%s:%d ssid=%s\n", __func__, __LINE__, config->ssid);
986+
int contain_chinese = ssid_contain_chinese_check(config->ssid);
987987
if((1 == contain_chinese) && (0 != string_convert((uint8_t *)config->gbk_ssid, MAX_SSID_SIZE, (uint8_t *)config->ssid, strlen(config->ssid), UTF8_TO_GBK))) {
988988
config->contain_chinese = true;
989989
} else {
@@ -1122,7 +1122,7 @@ static int get_wifi_config(const char *name, netmgr_wifi_ap_config_t* saved_ap_c
11221122

11231123
fd = open(name, O_RDONLY);
11241124
if(fd < 0) {
1125-
NETMGR_WIFI_LOGE("%s:%d open %s failed:%s\n", __func__, __LINE__, name, strerror(errno));
1125+
NETMGR_WIFI_LOGI("%s:%d open %s failed:%s\n", __func__, __LINE__, name, strerror(errno));
11261126
return -1;
11271127
}
11281128

@@ -1227,9 +1227,10 @@ static void wifi_activation_report_task()
12271227
#ifdef MICROPY_PY_CHANNEL_ENABLE
12281228
static void py_app_ota_handle(void* arg)
12291229
{
1230-
printf("save wifi info to kv and start ota channel\n");
1230+
NETMGR_WIFI_LOGD("save wifi info to kv and start ota channel\n");
12311231
extern int save_ssid_and_password(char *ssid, char *passwd);
12321232
save_ssid_and_password(_amp_ssid, _amp_password);
1233+
usleep(1000 * 1000);
12331234
extern int on_get_url(char *url);
12341235
extern int check_channel_enable(void);
12351236
if(check_channel_enable() == 0)
@@ -2202,7 +2203,7 @@ static int wifi_start_sta(netmgr_hdl_t hdl, netmgr_conn_t *conn, const char *ssi
22022203
if((conn->state == CONN_STATE_DISCONNECTED) ||
22032204
(conn->state == CONN_STATE_CONNECTING)) {
22042205
int ret = 0;
2205-
NETMGR_WIFI_LOGE("%s:%d start wifi\n", __func__, __LINE__);
2206+
NETMGR_WIFI_LOGI("%s:%d start wifi\n", __func__, __LINE__);
22062207
ret = ioctl(hdl, WIFI_DEV_CMD_CONNECT, &type);
22072208
if(ret != 0) {
22082209
NETMGR_WIFI_LOGE("%s:%d wifi connect failed=%d\n", __func__, __LINE__, ret);
@@ -2418,9 +2419,9 @@ int netmgr_wifi_connect(netmgr_hdl_t hdl, netmgr_wifi_params_t *params)
24182419
/* get wifi config */
24192420
if(-1 == get_wifi_config(NETMGR_WIFI_TEMP_CONF, saved_ap_conf, READ_SPECIFIC_CONFIG)) {
24202421
if(-1 == get_wifi_config(NETMGR_WIFI_CONF, saved_ap_conf, READ_SPECIFIC_CONFIG)) {
2421-
NETMGR_WIFI_LOGE("%s:%d no temp config found\n", __func__, __LINE__);
2422+
NETMGR_WIFI_LOGI("%s:%d no temp config found\n", __func__, __LINE__);
24222423
} else {
2423-
NETMGR_WIFI_LOGE("%s:%d no config found\n", __func__, __LINE__);
2424+
NETMGR_WIFI_LOGI("%s:%d no config found\n", __func__, __LINE__);
24242425
}
24252426
}
24262427
}
@@ -3040,7 +3041,7 @@ int netmgr_wifi_get_config(netmgr_hdl_t hdl, netmgr_wifi_config_t* config)
30403041
memset(config, 0, sizeof(netmgr_wifi_ap_config_t));
30413042
if(-1 == get_wifi_config(NETMGR_WIFI_TEMP_CONF, config, READ_ALL_CONFIG)) {
30423043
if(-1 == get_wifi_config(NETMGR_WIFI_CONF, config, READ_ALL_CONFIG)) {
3043-
NETMGR_WIFI_LOGE("%s:%d no config found\n", __func__, __LINE__);
3044+
NETMGR_WIFI_LOGI("%s:%d no config found\n", __func__, __LINE__);
30443045
return -1;
30453046
}
30463047
}
@@ -3457,7 +3458,7 @@ static void handle_netmgr_wifi_help_cmd()
34573458
NETMGR_WIFI_LOGI("netmgr -t wifi -s\n");
34583459
NETMGR_WIFI_LOGI("netmgr -t wifi -p\n");
34593460
NETMGR_WIFI_LOGI("netmgr -t wifi -r\n");
3460-
NETMGR_WIFI_LOGI("netmgr -t wifi -w network={\\nssid=\"xxxxxx\"\\npassword=\"xxxxxxxx\"\\nchannel=\"1\"\\n}\\n");
3461+
NETMGR_WIFI_LOGI("netmgr -t wifi -w network={\\nssid=\"apple\"\\npassword=\"aos123456\"\\nchannel=\"1\"\\n}\\n");
34613462
NETMGR_WIFI_LOGI("netmgr -t wifi -d\n");
34623463
NETMGR_WIFI_LOGI("netmgr -t wifi -n 0\n");
34633464
NETMGR_WIFI_LOGI("netmgr -t wifi -e\n");

components/py_engine/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@page py_engine py_engine
22

3-
[更正文档](https://gitee.com/alios-things/py_engine/edit/master/README.md) &emsp;&emsp;&emsp;&emsp; [贡献说明](https://help.aliyun.com/document_detail/302301.html)
3+
[更正文档](https://gitee.com/alios-things/py_engine/edit/rel_3.3.0/README.md) &emsp;&emsp;&emsp;&emsp; [贡献说明](https://help.aliyun.com/document_detail/302301.html)
44

55
# 概述
66
py_engine (Python轻应用引擎) 以MicroPython为基础打造而成.可以快速实现IoT场景连云、控端、AI等最常见功能。快速上手文档和编程接口请参考[Python轻应用编程参考](https://g.alicdn.com/HaaSAI/PythonDoc/quickstart/index.html)
@@ -80,7 +80,7 @@ def_config:
8080
8181
```yaml
8282
depends:
83-
- py_engine: master # helloworld_demo中引入py_engine组件
83+
- py_engine: dev_aos # helloworld_demo中引入py_engine组件
8484
```
8585
8686
## 步骤3 下载组件

components/py_engine/adapter/esp32/boards/M5STACK_CORE2/sdkconfig.board

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,11 @@ CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA=y
4747

4848
# 配置MBEDTLS 使用外部内存
4949
CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC=y
50+
51+
# m5stackcore2 和nodemcu32s的wifi和lwip的配置保持一致,减少20KB内存
52+
CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=4
53+
CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=16
54+
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=8
55+
CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=8
56+
CONFIG_LWIP_TCP_RECVMBOX_SIZE=8
57+
CONFIG_LWIP_UDP_RECVMBOX_SIZE=8

components/py_engine/adapter/esp32/fs/boot.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ def _connect_wifi():
2121
if bt_disabled != "no":
2222
uos.plussys_mm()
2323

24+
2425
channel = kv.get('app_upgrade_channel')
25-
if channel == "disable":
26-
pass
27-
else:
26+
if channel == "enable":
2827
import online_upgrade
2928
online_upgrade.on(_on_get_url)
3029
try:
@@ -34,6 +33,14 @@ def _connect_wifi():
3433
print(e)
3534

3635

36+
app_upgrade = kv.get('_amp_app_upgrade')
37+
if app_upgrade == "enable":
38+
print("App is being upgraded. It will take about 10 seconds.")
39+
execfile('/lib/appUpgrade.py')
40+
kv.remove('_amp_app_upgrade')
41+
print("App upgrade finished.")
42+
43+
3744

3845

3946

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import uos as os
2+
import uerrno as errno
3+
import ujson as json
4+
import uzlib
5+
import upip_utarfile as tarfile
6+
import gc
7+
import time
8+
import ussl
9+
import usocket
10+
import kv
11+
import network
12+
import time
13+
14+
file_buf = bytearray(128)
15+
16+
def install_pkg(package_url, install_path):
17+
gzdict_sz = 16 + 15
18+
f1 = url_open(package_url)
19+
if(isinstance(f1, (str, bytes, bytearray)) == True):
20+
return f1
21+
try:
22+
f2 = uzlib.DecompIO(f1, gzdict_sz)
23+
f3 = tarfile.TarFile(fileobj=f2)
24+
install_tar(f3, install_path)
25+
except Exception as e:
26+
print(e)
27+
return("UNTAR_FILE_FAIL")
28+
finally:
29+
f1.close()
30+
del f3
31+
del f2
32+
gc.collect()
33+
34+
return 'SUCCESS'
35+
36+
37+
38+
def download_save_file(file_url, fname):
39+
global file_buf
40+
f1 = url_open(file_url)
41+
42+
if(isinstance(f1, (str, bytes, bytearray)) == True):
43+
return f1
44+
45+
_makedirs(fname)
46+
with open(fname, "wb") as outf:
47+
while True:
48+
sz = f1.readinto(file_buf)
49+
if not sz:
50+
break
51+
outf.write(file_buf, sz)
52+
outf.close()
53+
f1.close()
54+
del f1
55+
return 'SUCCESS'
56+
57+
58+
def url_open(url):
59+
proto, _, host, urlpath = url.split('/', 3)
60+
try:
61+
port = 443
62+
if ":" in host:
63+
host, port = host.split(":")
64+
port = int(port)
65+
ai = usocket.getaddrinfo(host, port, 0, usocket.SOCK_STREAM)
66+
except OSError as e:
67+
print("Error:", "Unable to resolve %s (no Internet?)" % host, e)
68+
return 'HOST_RESOLVED_FAIL'
69+
ai = ai[0]
70+
s = usocket.socket(ai[0], ai[1], ai[2])
71+
try:
72+
s.connect(ai[-1])
73+
if proto == "https:":
74+
s = ussl.wrap_socket(s, server_hostname=host)
75+
s.write("GET /%s HTTP/1.0\r\nHost: %s:%s\r\n\r\n" % (urlpath, host, port))
76+
l = s.readline()
77+
protover, status, msg = l.split(None, 2)
78+
if status != b"200":
79+
if status == b"404" or status == b"301":
80+
return("Package not found")
81+
else:
82+
print("status is {}".format(status))
83+
return(status)
84+
while True:
85+
l = s.readline()
86+
if not l:
87+
return("Unexpected EOF in HTTP headers")
88+
if l == b'\r\n':
89+
break
90+
except Exception as e:
91+
s.close()
92+
print(e)
93+
return('SOCKET_ERROR')
94+
return s
95+
96+
97+
def _makedirs(name, mode=0o777):
98+
ret = False
99+
s = ""
100+
comps = name.rstrip("/").split("/")[:-1]
101+
if comps[0] == "":
102+
s = "/"
103+
for c in comps:
104+
if s and s[-1] != "/":
105+
s += "/"
106+
s += c
107+
try:
108+
os.mkdir(s)
109+
ret = True
110+
except OSError as e:
111+
if e.args[0] != errno.EEXIST and e.args[0] != errno.EISDIR:
112+
print(e)
113+
ret = False
114+
return ret
115+
116+
117+
def install_tar(f, prefix):
118+
for info in f:
119+
fname = info.name
120+
#try:
121+
#fname = fname[fname.index("/") + 1:]
122+
#except ValueError:
123+
#fname = ""
124+
outfname = prefix + fname
125+
if info.type != tarfile.DIRTYPE:
126+
_makedirs(outfname)
127+
subf = f.extractfile(info)
128+
save_file(outfname, subf)
129+
130+
def save_file(fname, subf):
131+
global file_buf
132+
with open(fname, "wb") as outf:
133+
while True:
134+
sz = subf.readinto(file_buf)
135+
if not sz:
136+
break
137+
outf.write(file_buf, sz)
138+
outf.close()
139+
140+
#download_save_file(url,"/data/pyamp/main.py")
141+
142+
def connect_wifi(ssid,passwd):
143+
sta_if = network.WLAN(network.STA_IF)
144+
sta_if.active(True)
145+
sta_if.scan()
146+
sta_if.connect(ssid,passwd)
147+
time.sleep(5)
148+
return sta_if.isconnected()
149+
150+
if __name__ == "__main__":
151+
ssid = kv.get('_amp_wifi_ssid')
152+
passwd = kv.get('_amp_wifi_passwd')
153+
if isinstance(ssid,str) and isinstance(passwd,str):
154+
if connect_wifi(ssid,passwd):
155+
url = kv.get('_amp_pyapp_url')
156+
if isinstance(url,str):
157+
install_pkg(url,"/data/pyamp/")
158+
kv.remove('_amp_pyapp_url')

0 commit comments

Comments
 (0)