esp32的wifi连接与esp8266的有区别;
ESP8266 and ESP32 differ a lot:
ESP8266
wifi.eventmon.*:
wifi.eventmon.register(event[, function(T)])
wifi.eventmon.STA_CONNECTEDwifi.eventmon.STA_DISCONNECTEDwifi.eventmon.STA_AUTHMODE_CHANGEwifi.eventmon.STA_GOT_IPwifi.eventmon.STA_DHCP_TIMEOUTwifi.eventmon.AP_STACONNECTEDwifi.eventmon.AP_STADISCONNECTEDwifi.eventmon.AP_PROBEREQRECVEDESP32:
wifi.on()
wifi.ap.on(event, callback)
event:
start: no additional infostop: no additional infosta_connected: information about the client that connected:mac: the MAC addressid: assigned station id (AID)disconnected: information about disconnecting clientmac: the MAC addressprobe_req: information about the probing clientfrom: MAC address of the probing clientrssi: Received Signal Strength Indicator valueESP32的WiFi函数

我只列出esp32的代码
print("系统启动了") gpio.config({ gpio=2, dir=gpio.OUT }) gpio.write(2,1) print("设置wifi工作模式 连接到WiFi路由器时") wifi.mode(wifi.STATION,true) print("启动wifi") wifi.start() print("连接访问点(将配置保存到flash中)") station_cfg={} station_cfg.ssid="xz220" station_cfg.pwd="www.kyhmy.com" wifi.sta.config(station_cfg, true) print("连接") wifi.sta.connect() print("获取MAC") print(wifi.sta.getmac())
比较有意思的是,我没有发现获取IP的方法,可能是官方取消了

只能登陆路由器查看板子获取到的ip地址了

我给板子绑定了固定ip这样就不会来回变了;
野路子学习esp32(十) NodeMcu-WIFi@a.宏万
原文:https://www.cnblogs.com/hongwans/p/9104956.html