diff --git a/MicroPython_BUILD/components/micropython/esp32/modules/inisetup.py b/MicroPython_BUILD/components/micropython/esp32/modules/inisetup.py
index d672580..ee57bf3 100644
--- a/MicroPython_BUILD/components/micropython/esp32/modules/inisetup.py
+++ b/MicroPython_BUILD/components/micropython/esp32/modules/inisetup.py
@@ -7,10 +7,10 @@ def setup():
# This file is executed on every boot (including wake-boot from deepsleep)
import sys
sys.path[1] = '/flash/lib'
+from m5stack import lcd, speaker, buttonA, buttonB, buttonC
# ---------- M5Cloud ------------
if True:
- from m5stack import lcd, buttonA, buttonB
if buttonB.isPressed():
lcd.println('On: OFF-LINE Mode', color=lcd.ORANGE)
else:
diff --git a/MicroPython_BUILD/components/micropython/esp32/modules/wificonfig.py b/MicroPython_BUILD/components/micropython/esp32/modules/wificonfig.py
index 15cd2a5..2aadd2c 100644
--- a/MicroPython_BUILD/components/micropython/esp32/modules/wificonfig.py
+++ b/MicroPython_BUILD/components/micropython/esp32/modules/wificonfig.py
@@ -1,11 +1,11 @@
-import network, json, ubinascii, time, machine, socket
-from m5stack import lcd
-
-wlan_sta = network.WLAN(network.STA_IF); wlan_sta.active(True)
-# scanlist = wlan_sta.scan()
-# node_id = ubinascii.hexlify(machine.unique_id())
-# ssid_name= "M5Stack-"+node_id[-6:].decode('utf-8')
+from m5stack import lcd, node_id
+import network, ubinascii, machine
+import ujson as json
+import utime as time
+import usocket as socket
+wlan_sta = network.WLAN(network.STA_IF);
+wlan_ap = network.WLAN(network.AP_IF)
def do_connect(ntwrk_ssid, netwrk_pass):
if not wlan_sta.isconnected():
@@ -14,33 +14,43 @@ def do_connect(ntwrk_ssid, netwrk_pass):
wlan_sta.active(True)
wlan_sta.connect(ntwrk_ssid, netwrk_pass)
lcd.print('Connecting.')
- a=0
- while not wlan_sta.isconnected() | (a > 150) :
+ a = 0
+ while not wlan_sta.isconnected() | (a > 100) :
time.sleep(0.2)
- a+=1
+ a += 1
print('.', end='')
- lcd.print('.')
+ lcd.print('.', wrap=True)
if wlan_sta.isconnected():
print('\nConnected. Network config:', wlan_sta.ifconfig())
lcd.println("Connected! \r\nNetwork config:\r\n"+wlan_sta.ifconfig()[0]+', '+wlan_sta.ifconfig()[3])
return (True)
- else :
+ else:
print('\nProblem. Not Connected to :'+ntwrk_ssid)
lcd.println('Problem. Not Connected to :'+ntwrk_ssid)
return (False)
+def save_wifi(ssid, password):
+ try:
+ wifidata = {}
+ wifidata['ssid'] = ssid
+ wifidata['password'] = password
+ with open("config.json", "r") as fo:
+ cfg = fo.read()
+ with open("config.json", "w") as fo:
+ cfg = json.loads(cfg)
+ cfg['wifi'] = wifidata
+ fo.write(json.dumps(cfg))
+ except:
+ with open("config.json", "w") as fo:
+ cfg = {}
+ cfg['wifi'] = wifidata
+ fo.write(json.dumps(cfg))
+
+
def _httpHanderRoot(httpClient, httpResponse) :
response_header = """\
-
-
M5Stack Setup
-
-
- 
- WiFi Setup
-
"""
+
content = response_header + response_variable + response_footer
# print('content:')
# print(content)
@@ -71,44 +76,24 @@ def _httpHanderConfig(httpClient, httpResponse) :
ssid = formData["ssid"]
password = formData["password"]
print(formData)
+ content = ''
+ is_connected = False
+
+ if do_connect(ssid, password):
+ is_connected = True
+ save_wifi(ssid, password)
+ content = """^_^ WiFi connection success
Reset device now ...
"""
+ else:
+ content = """×_× WiFi connection failed
Click here return configure page.
"""
- content = """\
-
-
-
-
- M5Stack Setup
-
-
- Connecting WiFi %s ...
- Device reset...
-
-
- """ % (ssid)
- # """ % (escape(firstname), escape(lastname))
httpResponse.WriteResponseOk( headers = None,
contentType = "text/html",
contentCharset = "UTF-8",
content = content )
- if do_connect(ssid, password):
- try:
- wifidata = {}
- wifidata['ssid'] = ssid
- wifidata['password'] = password
-
- with open("config.json", "r") as fo:
- cfg = fo.read()
-
- with open("config.json", "w") as fo:
- cfg = json.loads(cfg)
- cfg['wifi'] = wifidata
- fo.write(json.dumps(cfg))
- except:
- with open("config.json", "w") as fo:
- cfg = {}
- cfg['wifi'] = wifidata
- fo.write(json.dumps(cfg))
+ if is_connected:
+ time.sleep(3)
+ wlan_ap.active(False)
machine.reset()
@@ -118,15 +103,24 @@ routeHandlers = [
( "/configure", "GET", _httpHanderConfig )
]
-# webserver.Start(threaded=True)
+
+# def wlan_ap_cb(info):
+# # [WiFi] event: 15 (Station connected to soft-AP)
+# event = info[0]
+# if event == 15:
+# # lcd.clear(lcd.WHITE)
+# lcd.image(0,0, '/flash/img/qrcode_192.jpg')
+# lcd.qrcode('http://192.168.4.1', 126, 17, 175)
+
def webserver_start():
- wlan_ap = network.WLAN(network.AP_IF)
- wlan_ap.active(False)
+ # wlan_ap.eventCB(wlan_ap_cb)
wlan_ap.active(True)
- node_id = ubinascii.hexlify(machine.unique_id())
- ssid_name= "M5Stack-"+node_id[-6:].decode('utf-8')
- wlan_ap.config(essid=ssid_name)
+ # node_id = ubinascii.hexlify(machine.unique_id())
+ ssid_name= "M5Stack-"+node_id[-4:]
+ # lcd.font(lcd.FONT_Comic, transparent=True)
+ # lcd.print(ssid_name, 135, 190, lcd.RED)
+ wlan_ap.config(essid=ssid_name, authmode=network.AUTH_OPEN)
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
print('WiFi AP WebServer Start!')
print('Connect to Wifi ssid:'+ssid_name)
diff --git a/MicroPython_BUILD/components/micropython/esp32/modules_examples/wificonfig.py b/MicroPython_BUILD/components/micropython/esp32/modules_examples/wificonfig.py
new file mode 100644
index 0000000..15cd2a5
--- /dev/null
+++ b/MicroPython_BUILD/components/micropython/esp32/modules_examples/wificonfig.py
@@ -0,0 +1,141 @@
+import network, json, ubinascii, time, machine, socket
+from m5stack import lcd
+
+wlan_sta = network.WLAN(network.STA_IF); wlan_sta.active(True)
+# scanlist = wlan_sta.scan()
+# node_id = ubinascii.hexlify(machine.unique_id())
+# ssid_name= "M5Stack-"+node_id[-6:].decode('utf-8')
+
+
+def do_connect(ntwrk_ssid, netwrk_pass):
+ if not wlan_sta.isconnected():
+ print('M5Stack Core try to connect WiFi: SSID:'+ntwrk_ssid+' PASSWD:'+netwrk_pass+' network...')
+ lcd.println('M5Stack Core try to connect WiFi: \r\nWiFi SSID:'+ntwrk_ssid+' \t\nPASSWD:'+netwrk_pass)
+ wlan_sta.active(True)
+ wlan_sta.connect(ntwrk_ssid, netwrk_pass)
+ lcd.print('Connecting.')
+ a=0
+ while not wlan_sta.isconnected() | (a > 150) :
+ time.sleep(0.2)
+ a+=1
+ print('.', end='')
+ lcd.print('.')
+ if wlan_sta.isconnected():
+ print('\nConnected. Network config:', wlan_sta.ifconfig())
+ lcd.println("Connected! \r\nNetwork config:\r\n"+wlan_sta.ifconfig()[0]+', '+wlan_sta.ifconfig()[3])
+ return (True)
+ else :
+ print('\nProblem. Not Connected to :'+ntwrk_ssid)
+ lcd.println('Problem. Not Connected to :'+ntwrk_ssid)
+ return (False)
+
+
+def _httpHanderRoot(httpClient, httpResponse) :
+ response_header = """\
+
+ M5Stack Setup
+
+
+ 
+ WiFi Setup
+
+
+ """
+ content = response_header + response_variable + response_footer
+ # print('content:')
+ # print(content)
+ httpResponse.WriteResponseOk( headers = None,
+ contentType = "text/html",
+ contentCharset = "UTF-8",
+ content = content )
+
+
+def _httpHanderConfig(httpClient, httpResponse) :
+ formData = httpClient.GetRequestQueryParams()
+ ssid = formData["ssid"]
+ password = formData["password"]
+ print(formData)
+
+ content = """\
+
+
+
+
+ M5Stack Setup
+
+
+ Connecting WiFi %s ...
+ Device reset...
+
+
+ """ % (ssid)
+ # """ % (escape(firstname), escape(lastname))
+ httpResponse.WriteResponseOk( headers = None,
+ contentType = "text/html",
+ contentCharset = "UTF-8",
+ content = content )
+
+ if do_connect(ssid, password):
+ try:
+ wifidata = {}
+ wifidata['ssid'] = ssid
+ wifidata['password'] = password
+
+ with open("config.json", "r") as fo:
+ cfg = fo.read()
+
+ with open("config.json", "w") as fo:
+ cfg = json.loads(cfg)
+ cfg['wifi'] = wifidata
+ fo.write(json.dumps(cfg))
+ except:
+ with open("config.json", "w") as fo:
+ cfg = {}
+ cfg['wifi'] = wifidata
+ fo.write(json.dumps(cfg))
+ machine.reset()
+
+
+routeHandlers = [
+ ( "/", "GET", _httpHanderRoot ),
+ ( "/wifi", "GET", _httpHanderRoot ),
+ ( "/configure", "GET", _httpHanderConfig )
+]
+
+# webserver.Start(threaded=True)
+
+def webserver_start():
+ wlan_ap = network.WLAN(network.AP_IF)
+ wlan_ap.active(False)
+ wlan_ap.active(True)
+ node_id = ubinascii.hexlify(machine.unique_id())
+ ssid_name= "M5Stack-"+node_id[-6:].decode('utf-8')
+ wlan_ap.config(essid=ssid_name)
+ addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
+ print('WiFi AP WebServer Start!')
+ print('Connect to Wifi ssid:'+ssid_name)
+ print('And connect to esp via your web browser (like 192.168.4.1)')
+ print('listening on', addr)
+ lcd.println(b'Connect to Wifi ssid:'+ssid_name)
+ lcd.println('via your web browser: 192.168.4.1')
+ lcd.println('listening on'+str(addr))
+
+ from microWebSrv import MicroWebSrv
+ webserver = MicroWebSrv(routeHandlers=routeHandlers)
+ webserver.Start(threaded=False)
diff --git a/MicroPython_BUILD/firmware/esp32/MicroPython.bin b/MicroPython_BUILD/firmware/esp32/MicroPython.bin
index 849afaa..c73bd45 100644
Binary files a/MicroPython_BUILD/firmware/esp32/MicroPython.bin and b/MicroPython_BUILD/firmware/esp32/MicroPython.bin differ
diff --git a/MicroPython_BUILD/firmware/esp32/partitions_mpy.bin b/MicroPython_BUILD/firmware/esp32/partitions_mpy.bin
index 18f066a..94e7dda 100644
Binary files a/MicroPython_BUILD/firmware/esp32/partitions_mpy.bin and b/MicroPython_BUILD/firmware/esp32/partitions_mpy.bin differ
diff --git a/MicroPython_BUILD/firmware/esp32/partitions_mpy.csv b/MicroPython_BUILD/firmware/esp32/partitions_mpy.csv
index f95ae70..1f782a7 100644
--- a/MicroPython_BUILD/firmware/esp32/partitions_mpy.csv
+++ b/MicroPython_BUILD/firmware/esp32/partitions_mpy.csv
@@ -5,5 +5,5 @@
# -------------------------------------------------------
nvs, data, nvs, 0x9000, 24K,
phy_init, data, phy, 0xf000, 4K,
-MicroPython, app, factory, 0x10000, 1024K,
-internalfs, data, spiffs, , 3008K,
+MicroPython, app, factory, 0x10000, 1664K,
+internalfs, data, spiffs, , 2368K,
diff --git a/MicroPython_BUILD/firmware/esp32/sdkconfig b/MicroPython_BUILD/firmware/esp32/sdkconfig
index 2816197..686211c 100644
--- a/MicroPython_BUILD/firmware/esp32/sdkconfig
+++ b/MicroPython_BUILD/firmware/esp32/sdkconfig
@@ -101,9 +101,21 @@ CONFIG_MICROPY_STACK_SIZE=20
CONFIG_MICROPY_HEAP_SIZE=96
CONFIG_MICROPY_THREAD_MAX_THREADS=4
CONFIG_MICROPY_THREAD_STACK_SIZE=4
-CONFIG_MICROPY_USE_TELNET=
+CONFIG_MICROPY_USE_TELNET=y
CONFIG_MICROPY_USE_WEBSERVER=
-CONFIG_MICROPY_USE_FTPSERVER=
+CONFIG_MICROPY_USE_FTPSERVER=y
+
+#
+# FTP Server Configuration
+#
+CONFIG_FTPSERVER_LOG_LEVEL=1
+CONFIG_FTPSERVER_LOG_LEVEL0=
+CONFIG_FTPSERVER_LOG_LEVEL1=y
+CONFIG_FTPSERVER_LOG_LEVEL2=
+CONFIG_FTPSERVER_LOG_LEVEL3=
+CONFIG_FTPSERVER_LOG_LEVEL4=
+CONFIG_MICROPY_FTPSERVER_TIMEOUT=300
+CONFIG_MICROPY_FTPSERVER_BUFFER_SIZE=1024
#
# Modules
diff --git a/MicroPython_BUILD/firmware/esp32_psram/MicroPython.bin b/MicroPython_BUILD/firmware/esp32_psram/MicroPython.bin
index ea02d33..2b9e442 100644
Binary files a/MicroPython_BUILD/firmware/esp32_psram/MicroPython.bin and b/MicroPython_BUILD/firmware/esp32_psram/MicroPython.bin differ
diff --git a/MicroPython_BUILD/firmware/esp32_psram/bootloader/bootloader.bin b/MicroPython_BUILD/firmware/esp32_psram/bootloader/bootloader.bin
index e5f1ab0..8271b0b 100644
Binary files a/MicroPython_BUILD/firmware/esp32_psram/bootloader/bootloader.bin and b/MicroPython_BUILD/firmware/esp32_psram/bootloader/bootloader.bin differ
diff --git a/MicroPython_BUILD/firmware/esp32_psram/firmware.bin b/MicroPython_BUILD/firmware/esp32_psram/firmware.bin
index 98a2a41..1191f4a 100644
Binary files a/MicroPython_BUILD/firmware/esp32_psram/firmware.bin and b/MicroPython_BUILD/firmware/esp32_psram/firmware.bin differ
diff --git a/MicroPython_BUILD/firmware/esp32_psram/partitions_mpy.csv b/MicroPython_BUILD/firmware/esp32_psram/partitions_mpy.csv
index e3cf707..02fe64b 100644
--- a/MicroPython_BUILD/firmware/esp32_psram/partitions_mpy.csv
+++ b/MicroPython_BUILD/firmware/esp32_psram/partitions_mpy.csv
@@ -5,10 +5,5 @@
# -------------------------------------------------------
nvs, data, nvs, 0x9000, 24K,
phy_init, data, phy, 0xf000, 4K,
-<<<<<<< HEAD
MicroPython, app, factory, 0x10000, 1792K,
internalfs, data, spiffs, , 2240K,
-=======
-MicroPython, app, factory, 0x10000, 1536K,
-internalfs, data, spiffs, , 1024K,
->>>>>>> master
diff --git a/MicroPython_BUILD/firmware/esp32_psram/sdkconfig b/MicroPython_BUILD/firmware/esp32_psram/sdkconfig
index fcb7909..c7e7f4a 100644
--- a/MicroPython_BUILD/firmware/esp32_psram/sdkconfig
+++ b/MicroPython_BUILD/firmware/esp32_psram/sdkconfig
@@ -19,14 +19,9 @@ CONFIG_LOG_BOOTLOADER_LEVEL_WARN=y
CONFIG_LOG_BOOTLOADER_LEVEL_INFO=
CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG=
CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE=
-<<<<<<< HEAD
CONFIG_LOG_BOOTLOADER_LEVEL=2
-CONFIG_BOOTLOADER_VDDSDIO_BOOST=y
-=======
-CONFIG_LOG_BOOTLOADER_LEVEL=3
CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_8V=
CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V=y
->>>>>>> master
#
# Security features
@@ -84,17 +79,17 @@ CONFIG_MONITOR_BAUD=115200
#
CONFIG_MICROPY_HW_BOARD_NAME="M5Stack"
CONFIG_MICROPY_HW_MCU_NAME="ESP32"
-CONFIG_MICROPY_TIMEZONE="GMT0BST"
+CONFIG_MICROPY_TIMEZONE="UTC-8"
CONFIG_MICROPY_USE_OTA=
CONFIG_BOOT_SET_LED=-1
#
# System settings
#
-CONFIG_MICRO_PY_LOG_LEVEL=2
+CONFIG_MICRO_PY_LOG_LEVEL=1
CONFIG_MICRO_PY_LOG_LEVEL0=
-CONFIG_MICRO_PY_LOG_LEVEL1=
-CONFIG_MICRO_PY_LOG_LEVEL2=y
+CONFIG_MICRO_PY_LOG_LEVEL1=y
+CONFIG_MICRO_PY_LOG_LEVEL2=
CONFIG_MICRO_PY_LOG_LEVEL3=
CONFIG_MICRO_PY_LOG_LEVEL4=
CONFIG_MICRO_PY_LOG_LEVEL5=
@@ -102,7 +97,7 @@ CONFIG_MICROPY_RX_BUFFER_SIZE=1080
CONFIG_MICROPY_USE_TASK_WDT=y
CONFIG_MICROPY_USE_BOTH_CORES=
CONFIG_MICROPY_TASK_PRIORITY=5
-CONFIG_MICROPY_STACK_SIZE=32
+CONFIG_MICROPY_STACK_SIZE=20
CONFIG_MICROPY_HEAP_SIZE=3072
CONFIG_MICROPY_THREAD_MAX_THREADS=6
CONFIG_MICROPY_THREAD_STACK_SIZE=6
@@ -136,14 +131,14 @@ CONFIG_MICROPY_USE_MDNS=y
CONFIG_MICROPY_USE_CURL=y
CONFIG_MICROPY_USE_CURL_TLS=y
CONFIG_MICROPY_USE_CURLFTP=
-CONFIG_MICROPY_USE_SSH=y
+CONFIG_MICROPY_USE_SSH=
CONFIG_MICROPY_USE_MQTT=y
#
# MQTT Configuration
#
CONFIG_MQTT_PROTOCOL_311=y
-CONFIG_MQTT_PRIORITY=5
+CONFIG_MQTT_PRIORITY=4
CONFIG_MQTT_BUFFER_SIZE_BYTE=2048
CONFIG_MQTT_MAX_PAYLOAD_SIZE=4094
CONFIG_MQTT_LOG_LEVEL=1
@@ -457,12 +452,12 @@ CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y
# Log output
#
CONFIG_LOG_DEFAULT_LEVEL_NONE=
-CONFIG_LOG_DEFAULT_LEVEL_ERROR=
-CONFIG_LOG_DEFAULT_LEVEL_WARN=y
+CONFIG_LOG_DEFAULT_LEVEL_ERROR=y
+CONFIG_LOG_DEFAULT_LEVEL_WARN=
CONFIG_LOG_DEFAULT_LEVEL_INFO=
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=
CONFIG_LOG_DEFAULT_LEVEL_VERBOSE=
-CONFIG_LOG_DEFAULT_LEVEL=2
+CONFIG_LOG_DEFAULT_LEVEL=1
CONFIG_LOG_COLORS=y
#