admin管理员组

文章数量:1530914

1、简介

Wi-Fi设备有两种模式:

1.Access Point(AP) 模式,此为无线接入点,家里的光猫就是结合WiFi和internet路由功能的AP。

2.Station(STA)模式,此为 无线终端,连接到AP的装置,手机,电脑等需要联网的设备都是工作在STA模式。

2、官方文档

Quick reference for the ESP32 — MicroPython latest documentation

3、micropython实战

import network
import time
from socket import *
wlan = network.WLAN(network.STA_IF)   //创建一个网络对象,并将其设置在STA模式
wlan.active(True)                     //激活wlan
if not wlan.isconnected():
    print('connecting to network...')
    wlan.connect('lig', '15601')            //这里写你自己的WIFI名称  密码
    while not wlan.isconnected():
         pass
print('network config:', wlan.ifconfig())
udp_socket=socket(AF_INET,SOCK_DGRAM)
dest_addr=('192.168.8.116',8080)            //这里写你自己网络调试助手上显示的IP地址和端口
send_data='hello_world'
udp_socket.sendto(send_data.encode('utf-8'),dest_addr)

使用的网络调试助手下载链接:http://free.cmsoft/download/cmsoft/assistant/netassist5.0.2.zip

截图如下:

打开端口,运行上面的程序 ,如果能在网络调试助手上面观察到发送的字符。

则说明通信ok!本节试验成功! 

参考:ESP32学习(3)——连接WIFI_esp32连接wifi-CSDN博客

本文标签: wifi