“ESP8266 WiFi”的版本间的差异

来自YFRobotwiki
跳转至: 导航搜索
第1行: 第1行:
  
==<font color="orange" size="+2">'''ESP8266 WiFi 库'''</font><br>==
+
==<font color="orange" size="+2">'''ESP8266 WiFi 库'''</font>==
 +
<br>
  
 
'''The WiFi class initializes the ethernet library and network settings.'''
 
'''The WiFi class initializes the ethernet library and network settings.'''
 +
 +
  
 
- <font color="forestgreen">WiFi.mode()</font>
 
- <font color="forestgreen">WiFi.mode()</font>
: 设置wifi模块工作模式WIFI_AP,WIFI_STA,WIFI_AP_STA
+
 
 +
设置wifi模块工作模式WIFI_AP,WIFI_STA,WIFI_AP_STA
  
 
{| border="0" cellpadding="10" width="100%"
 
{| border="0" cellpadding="10" width="100%"
第13行: 第17行:
  
 
- <font color="forestgreen">WiFi.softAP(ssid,[password],[channel],[ssid_hidden])</font>
 
- <font color="forestgreen">WiFi.softAP(ssid,[password],[channel],[ssid_hidden])</font>
: 设置AP模式参数
+
 
: 参数
+
设置AP模式参数
::ssid:网络名称(最长63字符)
+
参数
::password:密码,至少8个字符,NULL为开放网络(可选参数)
+
:ssid:网络名称(最长63字符)
::channel:通道号,1 - 13(可选参数,缺省情况下为1)
+
:password:密码,至少8个字符,NULL为开放网络(可选参数)
::ssid_hidden:网络是否可见,0为可见网络,1为隐藏网络(可选参数,缺省情况下为0)
+
:channel:通道号,1 - 13(可选参数,缺省情况下为1)
: 返回值:bool
+
:ssid_hidden:网络是否可见,0为可见网络,1为隐藏网络(可选参数,缺省情况下为0)
 +
 
 +
返回值:bool
  
 
- <font color="forestgreen">WiFi.softAPConfig(local_ip,gateway,subnet)</font>
 
- <font color="forestgreen">WiFi.softAPConfig(local_ip,gateway,subnet)</font>
: 配置AP
+
 
: 参数
+
配置AP
::local_ip:ap ip(类型:IPAddress-例192,168,0,1)
+
参数
::gateway:网关ip(类型:IPAddress)
+
:local_ip:ap ip(类型:IPAddress-例192,168,0,1)
::subnet:子网掩码(类型:IPAddress)
+
:gateway:网关ip(类型:IPAddress)
: 返回值:bool
+
:subnet:子网掩码(类型:IPAddress)
 +
 
 +
返回值:bool
  
 
- <font color="forestgreen">WiFi.softAPdisconnect(wifioff)</font>
 
- <font color="forestgreen">WiFi.softAPdisconnect(wifioff)</font>
: 断开网络,关闭AP
+
 
 +
断开网络,关闭AP
  
 
- <font color="forestgreen">WiFi.softAPgetStationNum()</font>
 
- <font color="forestgreen">WiFi.softAPgetStationNum()</font>
:Get the count of the Station / client that are connected to the softAP interface
+
 
 +
Get the count of the Station / client that are connected to the softAP interface
  
 
- <font color="forestgreen">WiFi.softAPIP()</font>
 
- <font color="forestgreen">WiFi.softAPIP()</font>
: 获取IP地址,用于AP模式
+
 
: 回IP 地址
+
获取IP地址,用于AP模式
 +
 
 +
回:IP 地址
  
 
- <font color="forestgreen">WiFi.softAPmacAddress(mac)</font>
 
- <font color="forestgreen">WiFi.softAPmacAddress(mac)</font>
: 获取MAC地址,用于AP模式
+
 
: 返回:uint8_t*
+
获取MAC地址,用于AP模式
 +
 
 +
返回:uint8_t*
  
 
- <font color="forestgreen">WiFi.softAPmacAddress(void)</font>
 
- <font color="forestgreen">WiFi.softAPmacAddress(void)</font>
: 获取MAC地址,用于AP模式
+
 
: 返回:String
+
获取MAC地址,用于AP模式
 +
 
 +
返回:String
 +
 
 
|width="50%" valign="top" align="left"|
 
|width="50%" valign="top" align="left"|
  
第61行: 第78行:
  
 
- <font color="forestgreen">WiFi.begin()</font>
 
- <font color="forestgreen">WiFi.begin()</font>
: 开始wifi连接
+
 
 +
开始wifi连接
  
 
- <font color="forestgreen">WiFi.config(local_ip, gateway, subnet, dns1, dns2)</font>
 
- <font color="forestgreen">WiFi.config(local_ip, gateway, subnet, dns1, dns2)</font>
:Change IP configuration settings disabling the dhcp client
+
 
: 参数
+
Change IP configuration settings disabling the dhcp client
:: local_ip  Static ip configuration
+
参数
:: gateway    Static gateway configuration
+
: local_ip  Static ip configuration
:: subnet    Static Subnet mask
+
: gateway    Static gateway configuration
:: dns1      Static DNS server 1
+
: subnet    Static Subnet mask
:: dns2      Static DNS server 2
+
: dns1      Static DNS server 1
: 返回:bool
+
: dns2      Static DNS server 2
 +
返回:bool
  
 
- <font color="forestgreen">WiFi.reconnect()</font>
 
- <font color="forestgreen">WiFi.reconnect()</font>
:will force a disconnect and then start reconnecting to AP
+
 
: 返回:bool
+
will force a disconnect and then start reconnecting to AP
 +
 
 +
返回:bool
  
 
- <font color="forestgreen">WiFi.disconnect(bool wifioff)</font>
 
- <font color="forestgreen">WiFi.disconnect(bool wifioff)</font>
:Disconnect from the network
+
 
: 返回:bool
+
Disconnect from the network
 +
 
 +
返回:bool
  
 
- <font color="forestgreen">WiFi.isConnected()</font>
 
- <font color="forestgreen">WiFi.isConnected()</font>
: 检查是否已连接
+
 
: 返回:bool
+
检查是否已连接
 +
 
 +
返回:bool
  
 
- <font color="forestgreen">WiFi.setAutoConnect(bool autoConnect)</font>
 
- <font color="forestgreen">WiFi.setAutoConnect(bool autoConnect)</font>
: 设置是否复位自动连接,默认自动连接
+
 
: 返回:bool
+
设置是否复位自动连接,默认自动连接
 +
 
 +
返回:bool
  
 
- <font color="forestgreen">WiFi.setAutoConnect()</font>
 
- <font color="forestgreen">WiFi.setAutoConnect()</font>
: 检查是否设置了复位自动连接
+
 
: 返回:bool
+
检查是否设置了复位自动连接
 +
 
 +
返回:bool
  
 
- <font color="forestgreen">WiFi.setAutoReconnect(bool autoReconnect)</font>
 
- <font color="forestgreen">WiFi.setAutoReconnect(bool autoReconnect)</font>
: 设置当连接断开时是否重新连接
+
 
: 返回:bool
+
设置当连接断开时是否重新连接
 +
 
 +
返回:bool
  
 
- <font color="forestgreen">WiFi.waitForConnectResult()</font>
 
- <font color="forestgreen">WiFi.waitForConnectResult()</font>
: Wait for WiFi connection to reach a result returns the status reached or disconnect if STA is off
+
 
: 返回:连接状态
+
Wait for WiFi connection to reach a result returns the status reached or disconnect if STA is off
::WL_CONNECTED
+
 
::WL_NO_SSID_AVAIL;
+
返回:连接状态
::WL_CONNECT_FAILED;
+
:WL_CONNECTED
::WL_IDLE_STATUS;
+
:WL_NO_SSID_AVAIL;
::WL_DISCONNECTED;
+
:WL_CONNECT_FAILED;
 +
:WL_IDLE_STATUS;
 +
:WL_DISCONNECTED;
  
 
- <font color="forestgreen">WiFi.localIP()</font>
 
- <font color="forestgreen">WiFi.localIP()</font>
: 获取IP地址,用于STA模式
+
 
: 返回:IPAddress
+
获取IP地址,用于STA模式
 +
 
 +
返回:IPAddress
  
 
- <font color="forestgreen">WiFi.macAddress(uint8_t* mac)</font>
 
- <font color="forestgreen">WiFi.macAddress(uint8_t* mac)</font>
: 获取MAC地址,用于STA模式
+
 
 +
获取MAC地址,用于STA模式
 +
 
 +
返回:uint8_t*
  
 
- <font color="forestgreen">WiFi.macAddress(void)</font>
 
- <font color="forestgreen">WiFi.macAddress(void)</font>
: 获取MAC地址,用于STA模式
+
 
 +
获取MAC地址,用于STA模式
 +
 
 +
返回:String
  
 
- <font color="forestgreen">WiFi.subnetMask()</font>
 
- <font color="forestgreen">WiFi.subnetMask()</font>
: Get the interface subnet mask address.
+
 
: 返回:IPAddress
+
Get the interface subnet mask address.
 +
 
 +
返回:IPAddress
  
 
- <font color="forestgreen">WiFi.gatewayIP()</font>
 
- <font color="forestgreen">WiFi.gatewayIP()</font>
: Get the gateway ip address.
+
 
: 返回:IPAddress
+
Get the gateway ip address.
 +
 
 +
返回:IPAddress
  
 
- <font color="forestgreen">WiFi.dnsIP(uint8_t dns_no)</font>
 
- <font color="forestgreen">WiFi.dnsIP(uint8_t dns_no)</font>
: Get the DNS ip address.
+
 
: 返回:IPAddress
+
Get the DNS ip address.
 +
 
 +
返回:IPAddress
  
 
- <font color="forestgreen">WiFi.hostname(void)</font>
 
- <font color="forestgreen">WiFi.hostname(void)</font>
: Get ESP8266 station DHCP hostname
+
 
: 返回:String
+
Get ESP8266 station DHCP hostname
 +
 
 +
返回:String
  
 
- <font color="forestgreen">WiFi.hostname(char* aHostname)</font>
 
- <font color="forestgreen">WiFi.hostname(char* aHostname)</font>
: Set ESP8266 station DHCP hostname
+
 
: 返回:bool
+
Set ESP8266 station DHCP hostname
 +
 
 +
返回:bool
  
 
- <font color="forestgreen">WiFi.hostname(const char* aHostname)</font>
 
- <font color="forestgreen">WiFi.hostname(const char* aHostname)</font>
: Set ESP8266 station DHCP hostname
+
 
: 返回:bool
+
Set ESP8266 station DHCP hostname
 +
 
 +
返回:bool
  
 
- <font color="forestgreen">WiFi.hostname(String aHostname)</font>
 
- <font color="forestgreen">WiFi.hostname(String aHostname)</font>
: Set ESP8266 station DHCP hostname
+
 
: 返回:bool
+
Set ESP8266 station DHCP hostname
 +
 
 +
返回:bool
  
 
- <font color="forestgreen">WiFi.SSID()</font>
 
- <font color="forestgreen">WiFi.SSID()</font>
: 获取当前连接网络的SSID
+
 
: 返回:String
+
 获取当前连接网络的SSID
 +
 
 +
返回:String
  
 
- <font color="forestgreen">WiFi.psk()</font>
 
- <font color="forestgreen">WiFi.psk()</font>
: 获取当前连接网络的共享秘钥
+
 
: 返回:String
+
 获取当前连接网络的共享秘钥
 +
 
 +
返回:String
  
 
- <font color="forestgreen">WiFi.BSSID(void)</font>
 
- <font color="forestgreen">WiFi.BSSID(void)</font>
: Return the current bssid / mac associated with the network if configured
+
 
: 返回:uint8_t*
+
Return the current bssid / mac associated with the network if configured
 +
 
 +
返回:uint8_t*
  
 
- <font color="forestgreen">WiFi.BSSIDstr(void)</font>
 
- <font color="forestgreen">WiFi.BSSIDstr(void)</font>
: Return the current bssid / mac associated with the network if configured
+
 
: 返回:String
+
Return the current bssid / mac associated with the network if configured
 +
 
 +
返回:String
  
 
- <font color="forestgreen">WiFi.RSSI(void)</font>
 
- <font color="forestgreen">WiFi.RSSI(void)</font>
: Return the current network RSSI.
+
 
: 返回:int32_t (RSSI value)
+
Return the current network RSSI.
 +
 
 +
返回:int32_t (RSSI value)
  
 
<font color="deepskyblue" size="+0.5">STA远程配置</font><br>
 
<font color="deepskyblue" size="+0.5">STA远程配置</font><br>
 +
 
- <font color="forestgreen">WiFi.beginWPSConfig(void)</font>
 
- <font color="forestgreen">WiFi.beginWPSConfig(void)</font>
: WPS配置(so far only WPS_TYPE_PBC is supported (SDK 1.2.0))
+
 
: 返回:bool
+
WPS配置(so far only WPS_TYPE_PBC is supported (SDK 1.2.0))
 +
 
 +
返回:bool
  
 
- <font color="forestgreen">WiFi.beginSmartConfig()</font>
 
- <font color="forestgreen">WiFi.beginSmartConfig()</font>
: 开始 SmartConfig
+
 
: 返回:bool
+
 开始 SmartConfig
 +
 
 +
返回:bool
  
 
- <font color="forestgreen">WiFi.stopSmartConfig()</font>
 
- <font color="forestgreen">WiFi.stopSmartConfig()</font>
: 停止 SmartConfig
+
 
: 返回:bool
+
 停止 SmartConfig
 +
 
 +
返回:bool
  
 
- <font color="forestgreen">WiFi.smartConfigDone()</font>
 
- <font color="forestgreen">WiFi.smartConfigDone()</font>
: 查询 SmartConfig 状态,决定何时停止配置
+
 
: 返回:bool
+
 查询 SmartConfig 状态,决定何时停止配置
 +
 
 +
返回:bool
  
 
<br>
 
<br>
第193行: 第267行:
 
:-[[ Server]]
 
:-[[ Server]]
  
:-[[ WiFiServer]]
+
- <font color="forestgreen">WiFiServer(IPAddress addr, uint16_t port)</font>
 +
 
 +
开启服务
 +
 
 +
参数
 +
:addr:ip地址                                                                                                                       
 +
:port:端口
 +
 
 +
- <font color="forestgreen">WiFiServer(uint16_t port)</font>
 +
开启服务
 +
 
 +
参数
 +
 
 +
:port:端口
 +
 
 +
- <font color="forestgreen">WiFi.begin()</font>
 +
 
 +
开始 SmartConfig
  
 
:-[[ begin()]]
 
:-[[ begin()]]
  
 
:-[[ available()]]
 
:-[[ available()]]
 +
- <font color="forestgreen">WiFi.available()</font>
 +
 +
开始 SmartConfig
  
 
:-[[ write()]]
 
:-[[ write()]]

2016年3月25日 (五) 14:19的版本

ESP8266 WiFi 库


The WiFi class initializes the ethernet library and network settings.


- WiFi.mode()

设置wifi模块工作模式WIFI_AP,WIFI_STA,WIFI_AP_STA

ESP8266WiFi AP

- WiFi.softAP(ssid,[password],[channel],[ssid_hidden])

设置AP模式参数 参数

ssid:网络名称(最长63字符)
password:密码,至少8个字符,NULL为开放网络(可选参数)
channel:通道号,1 - 13(可选参数,缺省情况下为1)
ssid_hidden:网络是否可见,0为可见网络,1为隐藏网络(可选参数,缺省情况下为0)

返回值:bool

- WiFi.softAPConfig(local_ip,gateway,subnet)

配置AP 参数

local_ip:ap ip(类型:IPAddress-例192,168,0,1)
gateway:网关ip(类型:IPAddress)
subnet:子网掩码(类型:IPAddress)

返回值:bool

- WiFi.softAPdisconnect(wifioff)

断开网络,关闭AP

- WiFi.softAPgetStationNum()

Get the count of the Station / client that are connected to the softAP interface

- WiFi.softAPIP()

获取IP地址,用于AP模式

返回:IP地址

- WiFi.softAPmacAddress(mac)

获取MAC地址,用于AP模式

返回:uint8_t*

- WiFi.softAPmacAddress(void)

获取MAC地址,用于AP模式

返回:String

ESP8266WiFi STA

WL_CONNECTED

WL_NO_SSID_AVAIL

WL_CONNECT_FAILED

WL_IDLE_STATUS

WL_DISCONNECTED

- WiFi.begin()

开始wifi连接

- WiFi.config(local_ip, gateway, subnet, dns1, dns2)

Change IP configuration settings disabling the dhcp client 参数

local_ip Static ip configuration
gateway Static gateway configuration
subnet Static Subnet mask
dns1 Static DNS server 1
dns2 Static DNS server 2

返回:bool

- WiFi.reconnect()

will force a disconnect and then start reconnecting to AP

返回:bool

- WiFi.disconnect(bool wifioff)

Disconnect from the network

返回:bool

- WiFi.isConnected()

检查是否已连接

返回:bool

- WiFi.setAutoConnect(bool autoConnect)

设置是否复位自动连接,默认自动连接

返回:bool

- WiFi.setAutoConnect()

检查是否设置了复位自动连接

返回:bool

- WiFi.setAutoReconnect(bool autoReconnect)

设置当连接断开时是否重新连接

返回:bool

- WiFi.waitForConnectResult()

Wait for WiFi connection to reach a result returns the status reached or disconnect if STA is off

返回:连接状态

WL_CONNECTED
WL_NO_SSID_AVAIL;
WL_CONNECT_FAILED;
WL_IDLE_STATUS;
WL_DISCONNECTED;

- WiFi.localIP()

获取IP地址,用于STA模式

返回:IPAddress

- WiFi.macAddress(uint8_t* mac)

获取MAC地址,用于STA模式

返回:uint8_t*

- WiFi.macAddress(void)

获取MAC地址,用于STA模式

返回:String

- WiFi.subnetMask()

Get the interface subnet mask address.

返回:IPAddress

- WiFi.gatewayIP()

Get the gateway ip address.

返回:IPAddress

- WiFi.dnsIP(uint8_t dns_no)

Get the DNS ip address.

返回:IPAddress

- WiFi.hostname(void)

Get ESP8266 station DHCP hostname

返回:String

- WiFi.hostname(char* aHostname)

Set ESP8266 station DHCP hostname

返回:bool

- WiFi.hostname(const char* aHostname)

Set ESP8266 station DHCP hostname

返回:bool

- WiFi.hostname(String aHostname)

Set ESP8266 station DHCP hostname

返回:bool

- WiFi.SSID()

获取当前连接网络的SSID

返回:String

- WiFi.psk()

获取当前连接网络的共享秘钥

返回:String

- WiFi.BSSID(void)

Return the current bssid / mac associated with the network if configured

返回:uint8_t*

- WiFi.BSSIDstr(void)

Return the current bssid / mac associated with the network if configured

返回:String

- WiFi.RSSI(void)

Return the current network RSSI.

返回:int32_t (RSSI value)

STA远程配置

- WiFi.beginWPSConfig(void)

WPS配置(so far only WPS_TYPE_PBC is supported (SDK 1.2.0))

返回:bool

- WiFi.beginSmartConfig()

开始 SmartConfig

返回:bool

- WiFi.stopSmartConfig()

停止 SmartConfig

返回:bool

- WiFi.smartConfigDone()

查询 SmartConfig 状态,决定何时停止配置

返回:bool


ESP8266WiFi Server

The Server class creates servers which can send data to and receive data from connected clients (programs running on other computers or devices).

- Server

- WiFiServer(IPAddress addr, uint16_t port)

开启服务

参数

addr:ip地址
port:端口

- WiFiServer(uint16_t port) 开启服务

参数

port:端口

- WiFi.begin()

开始 SmartConfig

- begin()
- available()

- WiFi.available()

开始 SmartConfig

- write()
- print()
- println()


ESP8266WiFi Client

The client class creates clients that can connect to servers and send and receive data.

- Client
- WiFiClient()
- connected()
- connect()
- write()
- print()
- println()
- available()
- read()
- flush()
- stop()



ESP8266WiFi Udp

The UDP class enables UDP message to be sent and received.

-WiFiUDP
-begin()
-available()
-beginPacket()
-endPacket()
-write()
-parsePacket()
-peek()
-read()
-flush()
-stop()
-remoteIP()
-remotePort()




返回ESP8266 Libraries

返回首页

更多建议和问题欢迎反馈至 YFRobot论坛