Set the Wi-Fi name and password, connect to Wi-Fi, and print the connection result to the serial monitor.
from m5stack import *
from m5stack_ui import *
from uiflow import *
import wifiCfg
wifiCfg.doConnect('M5-R&D', '**********')
print(wifiCfg.wlan_sta.isconnected())
Download the Esptouch app on your phone, upload the program to the M5 device, and enter the Wi-Fi password in the Esptouch app. If the serial monitor shows a successful connection and displays the IP address, the device has successfully connected to Wi-Fi and will automatically connect to this Wi-Fi in the future.
wifiCfg.autoConnect(lcdShow=False)
wifiCfg.autoConnect(lcdShow=True)
wifiCfg.reconnect()
wifiCfg.doConnect('', '')
M5Label('label0', x=193, y=67, color=0x000, font=FONT_MONT_14, parent=None)
str(getP2PData())
network.WLAN(network.STA_IF)
wlan.config(essid='', password='', authmode=network.AUTH_OPEN)
essid
: Sets the access point's SSID (network name).password
: Sets the access point's password.authmode
: Sets the access point's authentication mode.wlan.active(True)
str(wlan.scan())
str(wlan.isconnected())
wlan.connect('your_SSID', 'your_PASSWORD')
ssid
: The name of the Wi-Fi network to connect to.password
: The password for the Wi-Fi network.str(wlan.config('mac'))
str(wlan.ifconfig())
str(wlan.status())
wlan.disconnect()
str(1001)
STAT_IDLE
: Wi-Fi idle status. The device is not currently attempting to connect to any Wi-Fi network.STAT_CONNECTING
: Wi-Fi connecting status. The device is attempting to connect to the specified Wi-Fi network.STAT_GOT_IP
: Wi-Fi connected and obtained an IP address. The device has successfully connected to the Wi-Fi network and received an IP address from the DHCP server.smartconfig.set_type(smartconfig.ESPTOUCH)
ESPTOUCH
: Uses the ESPTOUCH protocol for configuration. The Wi-Fi configuration information (SSID and password) is sent to the device via a mobile app, allowing it to connect to the specified Wi-Fi network.
AIRKISS
: Uses the AIRKISS protocol for configuration. AIRKISS is a wireless configuration protocol developed by Tencent, used to send Wi-Fi configuration information to the device.
ESPTOUCH_AIRKISS
: Uses both ESPTOUCH and AIRKISS protocols simultaneously for configuration. The device will listen to both protocols, and the mobile app can use either protocol to send Wi-Fi configuration information. The device will configure itself after receiving the information.
smartconfig.start()
smartconfig.stop()
str(smartconfig.status())
str(smartconfig.get_ssid())
str(smartconfig.get_password())
str(smartconfig.get_phoneip())
str(smartconfig.get_phoneip())