1 Star 0 Fork 2

admin/esp32-gps-micropython

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
wifi.py 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
hui-shao 提交于 2021-11-24 17:28 +08:00 . [format] format wifi.py
import network
import time
# import socket
class WIFI:
port = 10000 # 端口号
wlan = None # wlan
listenSocket = None # 套接字
def __init__(self, _ssid: str, _passwd: str):
self.ssid = _ssid
self.passwd = _passwd
self.status = "[WIFI] No Connection."
self.ip = "0.0.0.0"
# 连接WiFi
def connect(self) -> bool:
self.wlan = network.WLAN(network.STA_IF)
self.wlan.active(True) # 激活网络
self.wlan.disconnect() # 断开WiFi连接
self.wlan.connect(self.ssid, self.passwd) # 连接WiFi
i = 1
while 1: # 等待连接
if self.wlan.ifconfig()[0] == "0.0.0.0":
time.sleep(1)
i += 1
elif i >= 60:
self.status = "[WIFI] Time Out."
print(self.status)
return False
else:
self.ip = str(self.wlan.ifconfig()[0])
self.status = "[WIFI] {}".format(self.ip)
print(self.status)
return True
def disconnect(self):
self.wlan.disconnect()
self.status = "[WIFI] Disconnected."
if __name__ == '__main__':
W = WIFI("mmcblk0p7", "66661111")
W.connect()
print(W.status)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cehx_0/esp32-gps.git
git@gitee.com:cehx_0/esp32-gps.git
cehx_0
esp32-gps
esp32-gps-micropython
master

搜索帮助