esp32的wifi连接与esp8266的有区别;
wifi
ESP8266 and ESP32 differ a lot:
ESP8266
- events are captured via
wifi.eventmon.*
:wifi.eventmon.register(event[, function(T)])
wifi.eventmon.STA_CONNECTED
wifi.eventmon.STA_DISCONNECTED
wifi.eventmon.STA_AUTHMODE_CHANGE
wifi.eventmon.STA_GOT_IP
wifi.eventmon.STA_DHCP_TIMEOUT
wifi.eventmon.AP_STACONNECTED
wifi.eventmon.AP_STADISCONNECTED
wifi.eventmon.AP_PROBEREQRECVED
ESP32:
- events are captured via
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 value
ESP32的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这样就不会来回变了;
原文地址:https://www.cnblogs.com/hongwans/p/9104956.html
时间: 2024-11-06 11:26:11