mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
code style
This commit is contained in:
parent
4b90db41fe
commit
09a7940006
@ -1,23 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
ESP8266WiFi.cpp - WiFi library for esp8266
|
ESP8266WiFi.cpp - WiFi library for esp8266
|
||||||
|
|
||||||
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
|
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
|
||||||
This file is part of the esp8266 core for Arduino environment.
|
This file is part of the esp8266 core for Arduino environment.
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
License as published by the Free Software Foundation; either
|
License as published by the Free Software Foundation; either
|
||||||
version 2.1 of the License, or (at your option) any later version.
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
This library is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
Lesser General Public License for more details.
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free Software
|
License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ESP8266WiFi.h"
|
#include "ESP8266WiFi.h"
|
||||||
|
|
||||||
@ -41,27 +41,20 @@ extern "C" {
|
|||||||
extern "C" void esp_schedule();
|
extern "C" void esp_schedule();
|
||||||
extern "C" void esp_yield();
|
extern "C" void esp_yield();
|
||||||
|
|
||||||
ESP8266WiFiClass::ESP8266WiFiClass()
|
ESP8266WiFiClass::ESP8266WiFiClass() :
|
||||||
: _smartConfigStarted(false)
|
_smartConfigStarted(false), _smartConfigDone(false), _useStaticIp(false), _persistent(true) {
|
||||||
, _smartConfigDone(false)
|
|
||||||
, _useStaticIp(false)
|
|
||||||
, _persistent(true)
|
|
||||||
{
|
|
||||||
uint8 m = wifi_get_opmode();
|
uint8 m = wifi_get_opmode();
|
||||||
_useClientMode = (m & WIFI_STA);
|
_useClientMode = (m & WIFI_STA);
|
||||||
_useApMode = (m & WIFI_AP);
|
_useApMode = (m & WIFI_AP);
|
||||||
wifi_set_event_handler_cb((wifi_event_handler_cb_t)&ESP8266WiFiClass::_eventCallback);
|
wifi_set_event_handler_cb((wifi_event_handler_cb_t) &ESP8266WiFiClass::_eventCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP8266WiFiClass::persistent(bool persistent)
|
void ESP8266WiFiClass::persistent(bool persistent) {
|
||||||
{
|
|
||||||
_persistent = persistent;
|
_persistent = persistent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ESP8266WiFiClass::mode(WiFiMode m) {
|
||||||
void ESP8266WiFiClass::mode(WiFiMode m)
|
if(wifi_get_opmode() == (uint8) m) {
|
||||||
{
|
|
||||||
if(wifi_get_opmode() == (uint8)m) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,19 +73,17 @@ void ESP8266WiFiClass::mode(WiFiMode m)
|
|||||||
_mode(m);
|
_mode(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
WiFiMode ESP8266WiFiClass::getMode()
|
WiFiMode ESP8266WiFiClass::getMode() {
|
||||||
{
|
return (WiFiMode) wifi_get_opmode();
|
||||||
return (WiFiMode)wifi_get_opmode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP8266WiFiClass::_mode(WiFiMode m)
|
void ESP8266WiFiClass::_mode(WiFiMode m) {
|
||||||
{
|
if(wifi_get_opmode() == (uint8) m) {
|
||||||
if(wifi_get_opmode() == (uint8)m) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ETS_UART_INTR_DISABLE();
|
ETS_UART_INTR_DISABLE();
|
||||||
if (_persistent)
|
if(_persistent)
|
||||||
wifi_set_opmode(m);
|
wifi_set_opmode(m);
|
||||||
else
|
else
|
||||||
wifi_set_opmode_current(m);
|
wifi_set_opmode_current(m);
|
||||||
@ -100,36 +91,32 @@ void ESP8266WiFiClass::_mode(WiFiMode m)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool sta_config_equal(const station_config& lhs, const station_config& rhs)
|
static bool sta_config_equal(const station_config& lhs, const station_config& rhs) {
|
||||||
{
|
if(strcmp(reinterpret_cast<const char*>(lhs.ssid), reinterpret_cast<const char*>(rhs.ssid)) != 0)
|
||||||
if (strcmp(reinterpret_cast<const char*>(lhs.ssid), reinterpret_cast<const char*>(rhs.ssid)) != 0)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (strcmp(reinterpret_cast<const char*>(lhs.password), reinterpret_cast<const char*>(rhs.password)) != 0)
|
if(strcmp(reinterpret_cast<const char*>(lhs.password), reinterpret_cast<const char*>(rhs.password)) != 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (lhs.bssid_set) {
|
if(lhs.bssid_set) {
|
||||||
if (!rhs.bssid_set)
|
if(!rhs.bssid_set)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (memcmp(lhs.bssid, rhs.bssid, 6) != 0)
|
if(memcmp(lhs.bssid, rhs.bssid, 6) != 0)
|
||||||
return false;
|
return false;
|
||||||
}
|
} else {
|
||||||
else {
|
if(rhs.bssid_set)
|
||||||
if (rhs.bssid_set)
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ESP8266WiFiClass::begin(char* ssid, char *passphrase, int32_t channel, const uint8_t* bssid)
|
int ESP8266WiFiClass::begin(char* ssid, char *passphrase, int32_t channel, const uint8_t* bssid) {
|
||||||
{
|
|
||||||
return begin((const char*) ssid, (const char*) passphrase, channel, bssid);
|
return begin((const char*) ssid, (const char*) passphrase, channel, bssid);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ESP8266WiFiClass::begin(const char* ssid, const char *passphrase, int32_t channel, const uint8_t* bssid)
|
int ESP8266WiFiClass::begin(const char* ssid, const char *passphrase, int32_t channel, const uint8_t* bssid) {
|
||||||
{
|
|
||||||
_useClientMode = true;
|
_useClientMode = true;
|
||||||
|
|
||||||
if(_useApMode) {
|
if(_useApMode) {
|
||||||
@ -153,13 +140,13 @@ int ESP8266WiFiClass::begin(const char* ssid, const char *passphrase, int32_t ch
|
|||||||
struct station_config conf;
|
struct station_config conf;
|
||||||
strcpy(reinterpret_cast<char*>(conf.ssid), ssid);
|
strcpy(reinterpret_cast<char*>(conf.ssid), ssid);
|
||||||
|
|
||||||
if (passphrase) {
|
if(passphrase) {
|
||||||
strcpy(reinterpret_cast<char*>(conf.password), passphrase);
|
strcpy(reinterpret_cast<char*>(conf.password), passphrase);
|
||||||
} else {
|
} else {
|
||||||
*conf.password = 0;
|
*conf.password = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bssid) {
|
if(bssid) {
|
||||||
conf.bssid_set = 1;
|
conf.bssid_set = 1;
|
||||||
memcpy((void *) &conf.bssid[0], (void *) bssid, 6);
|
memcpy((void *) &conf.bssid[0], (void *) bssid, 6);
|
||||||
} else {
|
} else {
|
||||||
@ -168,13 +155,13 @@ int ESP8266WiFiClass::begin(const char* ssid, const char *passphrase, int32_t ch
|
|||||||
|
|
||||||
struct station_config current_conf;
|
struct station_config current_conf;
|
||||||
wifi_station_get_config(¤t_conf);
|
wifi_station_get_config(¤t_conf);
|
||||||
if (sta_config_equal(current_conf, conf)) {
|
if(sta_config_equal(current_conf, conf)) {
|
||||||
DEBUGV("sta config unchanged");
|
DEBUGV("sta config unchanged");
|
||||||
return status();
|
return status();
|
||||||
}
|
}
|
||||||
|
|
||||||
ETS_UART_INTR_DISABLE();
|
ETS_UART_INTR_DISABLE();
|
||||||
if (_persistent)
|
if(_persistent)
|
||||||
wifi_station_set_config(&conf);
|
wifi_station_set_config(&conf);
|
||||||
else
|
else
|
||||||
wifi_station_set_config_current(&conf);
|
wifi_station_set_config_current(&conf);
|
||||||
@ -190,8 +177,7 @@ int ESP8266WiFiClass::begin(const char* ssid, const char *passphrase, int32_t ch
|
|||||||
return status();
|
return status();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ESP8266WiFiClass::begin()
|
int ESP8266WiFiClass::begin() {
|
||||||
{
|
|
||||||
ETS_UART_INTR_DISABLE();
|
ETS_UART_INTR_DISABLE();
|
||||||
wifi_station_connect();
|
wifi_station_connect();
|
||||||
ETS_UART_INTR_ENABLE();
|
ETS_UART_INTR_ENABLE();
|
||||||
@ -201,18 +187,16 @@ int ESP8266WiFiClass::begin()
|
|||||||
return status();
|
return status();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t ESP8266WiFiClass::waitForConnectResult(){
|
uint8_t ESP8266WiFiClass::waitForConnectResult() {
|
||||||
if ((wifi_get_opmode() & 1) == 0)//1 and 3 have STA enabled
|
if((wifi_get_opmode() & 1) == 0) //1 and 3 have STA enabled
|
||||||
return WL_DISCONNECTED;
|
return WL_DISCONNECTED;
|
||||||
while (status() == WL_DISCONNECTED)
|
while(status() == WL_DISCONNECTED)
|
||||||
delay(100);
|
delay(100);
|
||||||
return status();
|
return status();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// You will have to set the DNS-Server manually later since this will not enable DHCP2
|
// You will have to set the DNS-Server manually later since this will not enable DHCP2
|
||||||
void ESP8266WiFiClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet)
|
void ESP8266WiFiClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet) {
|
||||||
{
|
|
||||||
struct ip_info info;
|
struct ip_info info;
|
||||||
info.ip.addr = static_cast<uint32_t>(local_ip);
|
info.ip.addr = static_cast<uint32_t>(local_ip);
|
||||||
info.gw.addr = static_cast<uint32_t>(gateway);
|
info.gw.addr = static_cast<uint32_t>(gateway);
|
||||||
@ -224,8 +208,7 @@ void ESP8266WiFiClass::config(IPAddress local_ip, IPAddress gateway, IPAddress s
|
|||||||
_useStaticIp = true;
|
_useStaticIp = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP8266WiFiClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns)
|
void ESP8266WiFiClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns) {
|
||||||
{
|
|
||||||
struct ip_info info;
|
struct ip_info info;
|
||||||
info.ip.addr = static_cast<uint32_t>(local_ip);
|
info.ip.addr = static_cast<uint32_t>(local_ip);
|
||||||
info.gw.addr = static_cast<uint32_t>(gateway);
|
info.gw.addr = static_cast<uint32_t>(gateway);
|
||||||
@ -237,18 +220,17 @@ void ESP8266WiFiClass::config(IPAddress local_ip, IPAddress gateway, IPAddress s
|
|||||||
// Set DNS-Server
|
// Set DNS-Server
|
||||||
ip_addr_t d;
|
ip_addr_t d;
|
||||||
d.addr = static_cast<uint32_t>(dns);
|
d.addr = static_cast<uint32_t>(dns);
|
||||||
dns_setserver(0,&d);
|
dns_setserver(0, &d);
|
||||||
|
|
||||||
_useStaticIp = true;
|
_useStaticIp = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ESP8266WiFiClass::softAPdisconnect(bool wifioff)
|
int ESP8266WiFiClass::softAPdisconnect(bool wifioff) {
|
||||||
{
|
|
||||||
struct softap_config conf;
|
struct softap_config conf;
|
||||||
*conf.ssid = 0;
|
*conf.ssid = 0;
|
||||||
*conf.password = 0;
|
*conf.password = 0;
|
||||||
ETS_UART_INTR_DISABLE();
|
ETS_UART_INTR_DISABLE();
|
||||||
if (_persistent)
|
if(_persistent)
|
||||||
wifi_softap_set_config(&conf);
|
wifi_softap_set_config(&conf);
|
||||||
else
|
else
|
||||||
wifi_softap_set_config_current(&conf);
|
wifi_softap_set_config_current(&conf);
|
||||||
@ -257,7 +239,7 @@ int ESP8266WiFiClass::softAPdisconnect(bool wifioff)
|
|||||||
if(wifioff) {
|
if(wifioff) {
|
||||||
_useApMode = false;
|
_useApMode = false;
|
||||||
|
|
||||||
if( _useClientMode) {
|
if(_useClientMode) {
|
||||||
// turn on STA
|
// turn on STA
|
||||||
_mode(WIFI_STA);
|
_mode(WIFI_STA);
|
||||||
} else {
|
} else {
|
||||||
@ -269,13 +251,12 @@ int ESP8266WiFiClass::softAPdisconnect(bool wifioff)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ESP8266WiFiClass::disconnect(bool wifioff)
|
int ESP8266WiFiClass::disconnect(bool wifioff) {
|
||||||
{
|
|
||||||
struct station_config conf;
|
struct station_config conf;
|
||||||
*conf.ssid = 0;
|
*conf.ssid = 0;
|
||||||
*conf.password = 0;
|
*conf.password = 0;
|
||||||
ETS_UART_INTR_DISABLE();
|
ETS_UART_INTR_DISABLE();
|
||||||
if (_persistent)
|
if(_persistent)
|
||||||
wifi_station_set_config(&conf);
|
wifi_station_set_config(&conf);
|
||||||
else
|
else
|
||||||
wifi_station_set_config_current(&conf);
|
wifi_station_set_config_current(&conf);
|
||||||
@ -297,28 +278,23 @@ int ESP8266WiFiClass::disconnect(bool wifioff)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool softap_config_equal(const softap_config& lhs, const softap_config& rhs)
|
static bool softap_config_equal(const softap_config& lhs, const softap_config& rhs) {
|
||||||
{
|
if(strcmp(reinterpret_cast<const char*>(lhs.ssid), reinterpret_cast<const char*>(rhs.ssid)) != 0)
|
||||||
if (strcmp(reinterpret_cast<const char*>(lhs.ssid), reinterpret_cast<const char*>(rhs.ssid)) != 0)
|
|
||||||
return false;
|
return false;
|
||||||
if (strcmp(reinterpret_cast<const char*>(lhs.password), reinterpret_cast<const char*>(rhs.password)) != 0)
|
if(strcmp(reinterpret_cast<const char*>(lhs.password), reinterpret_cast<const char*>(rhs.password)) != 0)
|
||||||
return false;
|
return false;
|
||||||
if (lhs.channel != rhs.channel)
|
if(lhs.channel != rhs.channel)
|
||||||
return false;
|
return false;
|
||||||
if (lhs.ssid_hidden != rhs.ssid_hidden)
|
if(lhs.ssid_hidden != rhs.ssid_hidden)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ESP8266WiFiClass::softAP(const char* ssid) {
|
||||||
void ESP8266WiFiClass::softAP(const char* ssid)
|
|
||||||
{
|
|
||||||
softAP(ssid, 0);
|
softAP(ssid, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ESP8266WiFiClass::softAP(const char* ssid, const char* passphrase, int channel, int ssid_hidden) {
|
||||||
void ESP8266WiFiClass::softAP(const char* ssid, const char* passphrase, int channel, int ssid_hidden)
|
|
||||||
{
|
|
||||||
_useApMode = true;
|
_useApMode = true;
|
||||||
if(_useClientMode) {
|
if(_useClientMode) {
|
||||||
// turn on AP+STA mode
|
// turn on AP+STA mode
|
||||||
@ -347,35 +323,30 @@ void ESP8266WiFiClass::softAP(const char* ssid, const char* passphrase, int chan
|
|||||||
conf.max_connection = 4;
|
conf.max_connection = 4;
|
||||||
conf.beacon_interval = 100;
|
conf.beacon_interval = 100;
|
||||||
|
|
||||||
if (!passphrase || strlen(passphrase) == 0)
|
if(!passphrase || strlen(passphrase) == 0) {
|
||||||
{
|
|
||||||
conf.authmode = AUTH_OPEN;
|
conf.authmode = AUTH_OPEN;
|
||||||
*conf.password = 0;
|
*conf.password = 0;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
conf.authmode = AUTH_WPA2_PSK;
|
conf.authmode = AUTH_WPA2_PSK;
|
||||||
strcpy(reinterpret_cast<char*>(conf.password), passphrase);
|
strcpy(reinterpret_cast<char*>(conf.password), passphrase);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct softap_config conf_current;
|
struct softap_config conf_current;
|
||||||
wifi_softap_get_config(&conf_current);
|
wifi_softap_get_config(&conf_current);
|
||||||
if (softap_config_equal(conf, conf_current))
|
if(softap_config_equal(conf, conf_current)) {
|
||||||
{
|
|
||||||
DEBUGV("softap config unchanged");
|
DEBUGV("softap config unchanged");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ETS_UART_INTR_DISABLE();
|
ETS_UART_INTR_DISABLE();
|
||||||
if (_persistent)
|
if(_persistent)
|
||||||
wifi_softap_set_config(&conf);
|
wifi_softap_set_config(&conf);
|
||||||
else
|
else
|
||||||
wifi_softap_set_config_current(&conf);
|
wifi_softap_set_config_current(&conf);
|
||||||
ETS_UART_INTR_ENABLE();
|
ETS_UART_INTR_ENABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP8266WiFiClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet)
|
void ESP8266WiFiClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet) {
|
||||||
{
|
|
||||||
struct ip_info info;
|
struct ip_info info;
|
||||||
info.ip.addr = static_cast<uint32_t>(local_ip);
|
info.ip.addr = static_cast<uint32_t>(local_ip);
|
||||||
info.gw.addr = static_cast<uint32_t>(gateway);
|
info.gw.addr = static_cast<uint32_t>(gateway);
|
||||||
@ -385,142 +356,120 @@ void ESP8266WiFiClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPAdd
|
|||||||
wifi_softap_dhcps_start();
|
wifi_softap_dhcps_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* ESP8266WiFiClass::macAddress(uint8_t* mac)
|
uint8_t* ESP8266WiFiClass::macAddress(uint8_t* mac) {
|
||||||
{
|
|
||||||
wifi_get_macaddr(STATION_IF, mac);
|
wifi_get_macaddr(STATION_IF, mac);
|
||||||
return mac;
|
return mac;
|
||||||
}
|
}
|
||||||
|
|
||||||
String ESP8266WiFiClass::macAddress(void)
|
String ESP8266WiFiClass::macAddress(void) {
|
||||||
{
|
|
||||||
uint8_t mac[6];
|
uint8_t mac[6];
|
||||||
char macStr[18] = {0};
|
char macStr[18] = { 0 };
|
||||||
wifi_get_macaddr(STATION_IF, mac);
|
wifi_get_macaddr(STATION_IF, mac);
|
||||||
|
|
||||||
sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
return String(macStr);
|
return String(macStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* ESP8266WiFiClass::softAPmacAddress(uint8_t* mac)
|
uint8_t* ESP8266WiFiClass::softAPmacAddress(uint8_t* mac) {
|
||||||
{
|
|
||||||
wifi_get_macaddr(SOFTAP_IF, mac);
|
wifi_get_macaddr(SOFTAP_IF, mac);
|
||||||
return mac;
|
return mac;
|
||||||
}
|
}
|
||||||
|
|
||||||
String ESP8266WiFiClass::softAPmacAddress(void)
|
String ESP8266WiFiClass::softAPmacAddress(void) {
|
||||||
{
|
|
||||||
uint8_t mac[6];
|
uint8_t mac[6];
|
||||||
char macStr[18] = {0};
|
char macStr[18] = { 0 };
|
||||||
wifi_get_macaddr(SOFTAP_IF, mac);
|
wifi_get_macaddr(SOFTAP_IF, mac);
|
||||||
|
|
||||||
sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
return String(macStr);
|
return String(macStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
IPAddress ESP8266WiFiClass::localIP()
|
IPAddress ESP8266WiFiClass::localIP() {
|
||||||
{
|
|
||||||
struct ip_info ip;
|
struct ip_info ip;
|
||||||
wifi_get_ip_info(STATION_IF, &ip);
|
wifi_get_ip_info(STATION_IF, &ip);
|
||||||
return IPAddress(ip.ip.addr);
|
return IPAddress(ip.ip.addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
IPAddress ESP8266WiFiClass::softAPIP()
|
IPAddress ESP8266WiFiClass::softAPIP() {
|
||||||
{
|
|
||||||
struct ip_info ip;
|
struct ip_info ip;
|
||||||
wifi_get_ip_info(SOFTAP_IF, &ip);
|
wifi_get_ip_info(SOFTAP_IF, &ip);
|
||||||
return IPAddress(ip.ip.addr);
|
return IPAddress(ip.ip.addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
IPAddress ESP8266WiFiClass::subnetMask()
|
IPAddress ESP8266WiFiClass::subnetMask() {
|
||||||
{
|
|
||||||
struct ip_info ip;
|
struct ip_info ip;
|
||||||
wifi_get_ip_info(STATION_IF, &ip);
|
wifi_get_ip_info(STATION_IF, &ip);
|
||||||
return IPAddress(ip.netmask.addr);
|
return IPAddress(ip.netmask.addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
IPAddress ESP8266WiFiClass::gatewayIP()
|
IPAddress ESP8266WiFiClass::gatewayIP() {
|
||||||
{
|
|
||||||
struct ip_info ip;
|
struct ip_info ip;
|
||||||
wifi_get_ip_info(STATION_IF, &ip);
|
wifi_get_ip_info(STATION_IF, &ip);
|
||||||
return IPAddress(ip.gw.addr);
|
return IPAddress(ip.gw.addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
IPAddress ESP8266WiFiClass::dnsIP(int dns_no)
|
IPAddress ESP8266WiFiClass::dnsIP(int dns_no) {
|
||||||
{
|
|
||||||
ip_addr_t dns_ip = dns_getserver(dns_no);
|
ip_addr_t dns_ip = dns_getserver(dns_no);
|
||||||
return IPAddress(dns_ip.addr);
|
return IPAddress(dns_ip.addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
String ESP8266WiFiClass::SSID() const
|
String ESP8266WiFiClass::SSID() const {
|
||||||
{
|
|
||||||
static struct station_config conf;
|
static struct station_config conf;
|
||||||
wifi_station_get_config(&conf);
|
wifi_station_get_config(&conf);
|
||||||
return String(reinterpret_cast<char*>(conf.ssid));
|
return String(reinterpret_cast<char*>(conf.ssid));
|
||||||
}
|
}
|
||||||
|
|
||||||
String ESP8266WiFiClass::psk() const
|
String ESP8266WiFiClass::psk() const {
|
||||||
{
|
|
||||||
static struct station_config conf;
|
static struct station_config conf;
|
||||||
wifi_station_get_config(&conf);
|
wifi_station_get_config(&conf);
|
||||||
return String(reinterpret_cast<char*>(conf.password));
|
return String(reinterpret_cast<char*>(conf.password));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* ESP8266WiFiClass::BSSID(void)
|
uint8_t* ESP8266WiFiClass::BSSID(void) {
|
||||||
{
|
|
||||||
static struct station_config conf;
|
static struct station_config conf;
|
||||||
wifi_station_get_config(&conf);
|
wifi_station_get_config(&conf);
|
||||||
return reinterpret_cast<uint8_t*>(conf.bssid);
|
return reinterpret_cast<uint8_t*>(conf.bssid);
|
||||||
}
|
}
|
||||||
|
|
||||||
String ESP8266WiFiClass::BSSIDstr(void)
|
String ESP8266WiFiClass::BSSIDstr(void) {
|
||||||
{
|
|
||||||
static struct station_config conf;
|
static struct station_config conf;
|
||||||
char mac[18] = {0};
|
char mac[18] = { 0 };
|
||||||
wifi_station_get_config(&conf);
|
wifi_station_get_config(&conf);
|
||||||
sprintf(mac,"%02X:%02X:%02X:%02X:%02X:%02X", conf.bssid[0], conf.bssid[1], conf.bssid[2], conf.bssid[3], conf.bssid[4], conf.bssid[5]);
|
sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X", conf.bssid[0], conf.bssid[1], conf.bssid[2], conf.bssid[3], conf.bssid[4], conf.bssid[5]);
|
||||||
return String(mac);
|
return String(mac);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t ESP8266WiFiClass::channel(void) {
|
int32_t ESP8266WiFiClass::channel(void) {
|
||||||
return wifi_get_channel();
|
return wifi_get_channel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t ESP8266WiFiClass::RSSI(void) {
|
int32_t ESP8266WiFiClass::RSSI(void) {
|
||||||
return wifi_station_get_rssi();
|
return wifi_station_get_rssi();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C"
|
extern "C" {
|
||||||
{
|
typedef STAILQ_HEAD(, bss_info)
|
||||||
typedef STAILQ_HEAD(, bss_info) bss_info_head_t;
|
bss_info_head_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP8266WiFiClass::_scanDone(void* result, int status)
|
void ESP8266WiFiClass::_scanDone(void* result, int status) {
|
||||||
{
|
if(status != OK) {
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
ESP8266WiFiClass::_scanCount = 0;
|
ESP8266WiFiClass::_scanCount = 0;
|
||||||
ESP8266WiFiClass::_scanResult = 0;
|
ESP8266WiFiClass::_scanResult = 0;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
bss_info_head_t* head = reinterpret_cast<bss_info_head_t*>(result);
|
bss_info_head_t* head = reinterpret_cast<bss_info_head_t*>(result);
|
||||||
|
|
||||||
for (bss_info* it = STAILQ_FIRST(head); it; it = STAILQ_NEXT(it, next), ++i);
|
for(bss_info* it = STAILQ_FIRST(head); it; it = STAILQ_NEXT(it, next), ++i)
|
||||||
|
;
|
||||||
ESP8266WiFiClass::_scanCount = i;
|
ESP8266WiFiClass::_scanCount = i;
|
||||||
if (i == 0)
|
if(i == 0) {
|
||||||
{
|
|
||||||
ESP8266WiFiClass::_scanResult = 0;
|
ESP8266WiFiClass::_scanResult = 0;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
bss_info* copied_info = new bss_info[i];
|
bss_info* copied_info = new bss_info[i];
|
||||||
i = 0;
|
i = 0;
|
||||||
for (bss_info* it = STAILQ_FIRST(head); it; it = STAILQ_NEXT(it, next), ++i)
|
for(bss_info* it = STAILQ_FIRST(head); it; it = STAILQ_NEXT(it, next), ++i) {
|
||||||
{
|
|
||||||
memcpy(copied_info + i, it, sizeof(bss_info));
|
memcpy(copied_info + i, it, sizeof(bss_info));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -550,10 +499,8 @@ int8_t ESP8266WiFiClass::scanComplete() {
|
|||||||
return WIFI_SCAN_FAILED;
|
return WIFI_SCAN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP8266WiFiClass::scanDelete()
|
void ESP8266WiFiClass::scanDelete() {
|
||||||
{
|
if(ESP8266WiFiClass::_scanResult) {
|
||||||
if (ESP8266WiFiClass::_scanResult)
|
|
||||||
{
|
|
||||||
delete[] reinterpret_cast<bss_info*>(ESP8266WiFiClass::_scanResult);
|
delete[] reinterpret_cast<bss_info*>(ESP8266WiFiClass::_scanResult);
|
||||||
ESP8266WiFiClass::_scanResult = 0;
|
ESP8266WiFiClass::_scanResult = 0;
|
||||||
ESP8266WiFiClass::_scanCount = 0;
|
ESP8266WiFiClass::_scanCount = 0;
|
||||||
@ -561,8 +508,7 @@ void ESP8266WiFiClass::scanDelete()
|
|||||||
_scanComplete = false;
|
_scanComplete = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t ESP8266WiFiClass::scanNetworks(bool async, bool show_hidden)
|
int8_t ESP8266WiFiClass::scanNetworks(bool async, bool show_hidden) {
|
||||||
{
|
|
||||||
if(ESP8266WiFiClass::_scanStarted) {
|
if(ESP8266WiFiClass::_scanStarted) {
|
||||||
return WIFI_SCAN_RUNNING;
|
return WIFI_SCAN_RUNNING;
|
||||||
}
|
}
|
||||||
@ -578,8 +524,7 @@ int8_t ESP8266WiFiClass::scanNetworks(bool async, bool show_hidden)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int status = wifi_station_get_connect_status();
|
int status = wifi_station_get_connect_status();
|
||||||
if (status != STATION_GOT_IP && status != STATION_IDLE)
|
if(status != STATION_GOT_IP && status != STATION_IDLE) {
|
||||||
{
|
|
||||||
disconnect();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,142 +552,126 @@ int8_t ESP8266WiFiClass::scanNetworks(bool async, bool show_hidden)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void * ESP8266WiFiClass::_getScanInfoByIndex(int i)
|
void * ESP8266WiFiClass::_getScanInfoByIndex(int i) {
|
||||||
{
|
if(!ESP8266WiFiClass::_scanResult || (size_t) i > ESP8266WiFiClass::_scanCount) {
|
||||||
if (!ESP8266WiFiClass::_scanResult || (size_t)i > ESP8266WiFiClass::_scanCount)
|
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return reinterpret_cast<bss_info*>(ESP8266WiFiClass::_scanResult) + i;
|
return reinterpret_cast<bss_info*>(ESP8266WiFiClass::_scanResult) + i;
|
||||||
}
|
}
|
||||||
|
|
||||||
String ESP8266WiFiClass::SSID(uint8_t i)
|
String ESP8266WiFiClass::SSID(uint8_t i) {
|
||||||
{
|
|
||||||
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
|
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
|
||||||
if (!it)
|
if(!it)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
return String(reinterpret_cast<const char*>(it->ssid));
|
return String(reinterpret_cast<const char*>(it->ssid));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t * ESP8266WiFiClass::BSSID(uint8_t i)
|
uint8_t * ESP8266WiFiClass::BSSID(uint8_t i) {
|
||||||
{
|
|
||||||
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
|
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
|
||||||
if (!it)
|
if(!it)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return it->bssid;
|
return it->bssid;
|
||||||
}
|
}
|
||||||
|
|
||||||
String ESP8266WiFiClass::BSSIDstr(uint8_t i)
|
String ESP8266WiFiClass::BSSIDstr(uint8_t i) {
|
||||||
{
|
char mac[18] = { 0 };
|
||||||
char mac[18] = {0};
|
|
||||||
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
|
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
|
||||||
if (!it)
|
if(!it)
|
||||||
return String("");
|
return String("");
|
||||||
|
|
||||||
sprintf(mac,"%02X:%02X:%02X:%02X:%02X:%02X", it->bssid[0], it->bssid[1], it->bssid[2], it->bssid[3], it->bssid[4], it->bssid[5]);
|
sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X", it->bssid[0], it->bssid[1], it->bssid[2], it->bssid[3], it->bssid[4], it->bssid[5]);
|
||||||
return String(mac);
|
return String(mac);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ESP8266WiFiClass::channel(uint8_t i)
|
int32_t ESP8266WiFiClass::channel(uint8_t i) {
|
||||||
{
|
|
||||||
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
|
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
|
||||||
if (!it)
|
if(!it)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return it->channel;
|
return it->channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ESP8266WiFiClass::isHidden(uint8_t i)
|
bool ESP8266WiFiClass::isHidden(uint8_t i) {
|
||||||
{
|
|
||||||
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
|
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
|
||||||
if (!it)
|
if(!it)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return (it->is_hidden != 0);
|
return (it->is_hidden != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ESP8266WiFiClass::getNetworkInfo(uint8_t i, String &ssid, uint8_t &encType, int32_t &rssi, uint8_t* &bssid, int32_t &channel, bool &isHidden)
|
bool ESP8266WiFiClass::getNetworkInfo(uint8_t i, String &ssid, uint8_t &encType, int32_t &rssi, uint8_t* &bssid, int32_t &channel, bool &isHidden) {
|
||||||
{
|
|
||||||
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
|
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
|
||||||
if (!it)
|
if(!it)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ssid = (const char*)it->ssid;
|
ssid = (const char*) it->ssid;
|
||||||
encType = encryptionType(i);
|
encType = encryptionType(i);
|
||||||
rssi = it->rssi;
|
rssi = it->rssi;
|
||||||
bssid = it->bssid; // move ptr
|
bssid = it->bssid; // move ptr
|
||||||
channel = it->channel;
|
channel = it->channel;
|
||||||
isHidden = (it->is_hidden != 0);
|
isHidden = (it->is_hidden != 0);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ESP8266WiFiClass::RSSI(uint8_t i)
|
int32_t ESP8266WiFiClass::RSSI(uint8_t i) {
|
||||||
{
|
|
||||||
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
|
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
|
||||||
if (!it)
|
if(!it)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return it->rssi;
|
return it->rssi;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t ESP8266WiFiClass::encryptionType(uint8_t i)
|
uint8_t ESP8266WiFiClass::encryptionType(uint8_t i) {
|
||||||
{
|
|
||||||
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
|
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
|
||||||
if (!it)
|
if(!it)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
int authmode = it->authmode;
|
int authmode = it->authmode;
|
||||||
if (authmode == AUTH_OPEN)
|
if(authmode == AUTH_OPEN)
|
||||||
return ENC_TYPE_NONE;
|
return ENC_TYPE_NONE;
|
||||||
if (authmode == AUTH_WEP)
|
if(authmode == AUTH_WEP)
|
||||||
return ENC_TYPE_WEP;
|
return ENC_TYPE_WEP;
|
||||||
if (authmode == AUTH_WPA_PSK)
|
if(authmode == AUTH_WPA_PSK)
|
||||||
return ENC_TYPE_TKIP;
|
return ENC_TYPE_TKIP;
|
||||||
if (authmode == AUTH_WPA2_PSK)
|
if(authmode == AUTH_WPA2_PSK)
|
||||||
return ENC_TYPE_CCMP;
|
return ENC_TYPE_CCMP;
|
||||||
if (authmode == AUTH_WPA_WPA2_PSK)
|
if(authmode == AUTH_WPA_WPA2_PSK)
|
||||||
return ENC_TYPE_AUTO;
|
return ENC_TYPE_AUTO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_status_t ESP8266WiFiClass::status()
|
wl_status_t ESP8266WiFiClass::status() {
|
||||||
{
|
|
||||||
int status = wifi_station_get_connect_status();
|
int status = wifi_station_get_connect_status();
|
||||||
|
|
||||||
if (status == STATION_GOT_IP)
|
if(status == STATION_GOT_IP)
|
||||||
return WL_CONNECTED;
|
return WL_CONNECTED;
|
||||||
else if (status == STATION_NO_AP_FOUND)
|
else if(status == STATION_NO_AP_FOUND)
|
||||||
return WL_NO_SSID_AVAIL;
|
return WL_NO_SSID_AVAIL;
|
||||||
else if (status == STATION_CONNECT_FAIL || status == STATION_WRONG_PASSWORD)
|
else if(status == STATION_CONNECT_FAIL || status == STATION_WRONG_PASSWORD)
|
||||||
return WL_CONNECT_FAILED;
|
return WL_CONNECT_FAILED;
|
||||||
else if (status == STATION_IDLE)
|
else if(status == STATION_IDLE)
|
||||||
return WL_IDLE_STATUS;
|
return WL_IDLE_STATUS;
|
||||||
else
|
else
|
||||||
return WL_DISCONNECTED;
|
return WL_DISCONNECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wifi_dns_found_callback(const char *name, ip_addr_t *ipaddr, void *callback_arg)
|
void wifi_dns_found_callback(const char *name, ip_addr_t *ipaddr, void *callback_arg) {
|
||||||
{
|
if(ipaddr)
|
||||||
if (ipaddr)
|
|
||||||
(*reinterpret_cast<IPAddress*>(callback_arg)) = ipaddr->addr;
|
(*reinterpret_cast<IPAddress*>(callback_arg)) = ipaddr->addr;
|
||||||
esp_schedule(); // resume the hostByName function
|
esp_schedule(); // resume the hostByName function
|
||||||
}
|
}
|
||||||
|
|
||||||
int ESP8266WiFiClass::hostByName(const char* aHostname, IPAddress& aResult)
|
int ESP8266WiFiClass::hostByName(const char* aHostname, IPAddress& aResult) {
|
||||||
{
|
|
||||||
ip_addr_t addr;
|
ip_addr_t addr;
|
||||||
aResult = static_cast<uint32_t>(0);
|
aResult = static_cast<uint32_t>(0);
|
||||||
err_t err = dns_gethostbyname(aHostname, &addr, &wifi_dns_found_callback, &aResult);
|
err_t err = dns_gethostbyname(aHostname, &addr, &wifi_dns_found_callback, &aResult);
|
||||||
if (err == ERR_OK)
|
if(err == ERR_OK) {
|
||||||
{
|
|
||||||
aResult = addr.addr;
|
aResult = addr.addr;
|
||||||
}
|
} else if(err == ERR_INPROGRESS) {
|
||||||
else if (err == ERR_INPROGRESS)
|
|
||||||
{
|
|
||||||
esp_yield();
|
esp_yield();
|
||||||
// will return here when dns_found_callback fires
|
// will return here when dns_found_callback fires
|
||||||
}
|
}
|
||||||
@ -771,13 +700,12 @@ bool ESP8266WiFiClass::hostname(String aHostname) {
|
|||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
|
|
||||||
void wifi_wps_status_cb(wps_cb_status status)
|
void wifi_wps_status_cb(wps_cb_status status) {
|
||||||
{
|
|
||||||
DEBUGV("wps cb status: %d\r\n", status);
|
DEBUGV("wps cb status: %d\r\n", status);
|
||||||
switch (status) {
|
switch(status) {
|
||||||
case WPS_CB_ST_SUCCESS:
|
case WPS_CB_ST_SUCCESS:
|
||||||
if(!wifi_wps_disable()) {
|
if(!wifi_wps_disable()) {
|
||||||
DEBUGV("wps disable failed\n");
|
DEBUGV("wps disable failed\n");
|
||||||
}
|
}
|
||||||
wifi_station_connect();
|
wifi_station_connect();
|
||||||
break;
|
break;
|
||||||
@ -800,13 +728,13 @@ bool ESP8266WiFiClass::beginWPSConfig(void) {
|
|||||||
|
|
||||||
_useClientMode = true;
|
_useClientMode = true;
|
||||||
|
|
||||||
if(_useApMode) {
|
if(_useApMode) {
|
||||||
// turn on AP+STA mode
|
// turn on AP+STA mode
|
||||||
_mode(WIFI_AP_STA);
|
_mode(WIFI_AP_STA);
|
||||||
} else {
|
} else {
|
||||||
// turn on STA mode
|
// turn on STA mode
|
||||||
_mode(WIFI_STA);
|
_mode(WIFI_STA);
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnect();
|
disconnect();
|
||||||
|
|
||||||
@ -841,11 +769,8 @@ bool ESP8266WiFiClass::beginWPSConfig(void) {
|
|||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
|
|
||||||
|
void ESP8266WiFiClass::beginSmartConfig() {
|
||||||
|
if(_smartConfigStarted)
|
||||||
void ESP8266WiFiClass::beginSmartConfig()
|
|
||||||
{
|
|
||||||
if (_smartConfigStarted)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(_useApMode) {
|
if(_useApMode) {
|
||||||
@ -863,27 +788,24 @@ void ESP8266WiFiClass::beginSmartConfig()
|
|||||||
smartconfig_start(reinterpret_cast<sc_callback_t>(&ESP8266WiFiClass::_smartConfigCallback), 1);
|
smartconfig_start(reinterpret_cast<sc_callback_t>(&ESP8266WiFiClass::_smartConfigCallback), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP8266WiFiClass::stopSmartConfig()
|
void ESP8266WiFiClass::stopSmartConfig() {
|
||||||
{
|
if(!_smartConfigStarted)
|
||||||
if (!_smartConfigStarted)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
smartconfig_stop();
|
smartconfig_stop();
|
||||||
_smartConfigStarted = false;
|
_smartConfigStarted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ESP8266WiFiClass::smartConfigDone()
|
bool ESP8266WiFiClass::smartConfigDone() {
|
||||||
{
|
if(!_smartConfigStarted)
|
||||||
if (!_smartConfigStarted)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return _smartConfigDone;
|
return _smartConfigDone;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP8266WiFiClass::_smartConfigCallback(uint32_t st, void* result)
|
void ESP8266WiFiClass::_smartConfigCallback(uint32_t st, void* result) {
|
||||||
{
|
|
||||||
sc_status status = (sc_status) st;
|
sc_status status = (sc_status) st;
|
||||||
if (status == SC_STATUS_LINK) {
|
if(status == SC_STATUS_LINK) {
|
||||||
station_config* sta_conf = reinterpret_cast<station_config*>(result);
|
station_config* sta_conf = reinterpret_cast<station_config*>(result);
|
||||||
|
|
||||||
wifi_station_set_config(sta_conf);
|
wifi_station_set_config(sta_conf);
|
||||||
@ -891,13 +813,11 @@ void ESP8266WiFiClass::_smartConfigCallback(uint32_t st, void* result)
|
|||||||
wifi_station_connect();
|
wifi_station_connect();
|
||||||
|
|
||||||
WiFi._smartConfigDone = true;
|
WiFi._smartConfigDone = true;
|
||||||
}
|
} else if(status == SC_STATUS_LINK_OVER) {
|
||||||
else if (status == SC_STATUS_LINK_OVER) {
|
|
||||||
WiFi.stopSmartConfig();
|
WiFi.stopSmartConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -906,7 +826,7 @@ void ESP8266WiFiClass::_smartConfigCallback(uint32_t st, void* result)
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
bool ESP8266WiFiClass::setSleepMode(WiFiSleepType_t type) {
|
bool ESP8266WiFiClass::setSleepMode(WiFiSleepType_t type) {
|
||||||
return wifi_set_sleep_type((sleep_type_t)type);
|
return wifi_set_sleep_type((sleep_type_t) type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -914,7 +834,7 @@ bool ESP8266WiFiClass::setSleepMode(WiFiSleepType_t type) {
|
|||||||
* @return sleep_type_t
|
* @return sleep_type_t
|
||||||
*/
|
*/
|
||||||
WiFiSleepType_t ESP8266WiFiClass::getSleepMode() {
|
WiFiSleepType_t ESP8266WiFiClass::getSleepMode() {
|
||||||
return (WiFiSleepType_t)wifi_get_sleep_type();
|
return (WiFiSleepType_t) wifi_get_sleep_type();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -923,7 +843,7 @@ WiFiSleepType_t ESP8266WiFiClass::getSleepMode() {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
bool ESP8266WiFiClass::setPhyMode(WiFiPhyMode_t mode) {
|
bool ESP8266WiFiClass::setPhyMode(WiFiPhyMode_t mode) {
|
||||||
return wifi_set_phy_mode((phy_mode_t)mode);
|
return wifi_set_phy_mode((phy_mode_t) mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -931,28 +851,26 @@ bool ESP8266WiFiClass::setPhyMode(WiFiPhyMode_t mode) {
|
|||||||
* @return phy_mode_t
|
* @return phy_mode_t
|
||||||
*/
|
*/
|
||||||
WiFiPhyMode_t ESP8266WiFiClass::getPhyMode() {
|
WiFiPhyMode_t ESP8266WiFiClass::getPhyMode() {
|
||||||
return (WiFiPhyMode_t)wifi_get_phy_mode();
|
return (WiFiPhyMode_t) wifi_get_phy_mode();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
|
|
||||||
void ESP8266WiFiClass::_eventCallback(void* arg)
|
void ESP8266WiFiClass::_eventCallback(void* arg) {
|
||||||
{
|
|
||||||
System_Event_t* event = reinterpret_cast<System_Event_t*>(arg);
|
System_Event_t* event = reinterpret_cast<System_Event_t*>(arg);
|
||||||
DEBUGV("wifi evt: %d\r\n", event->event);
|
DEBUGV("wifi evt: %d\r\n", event->event);
|
||||||
|
|
||||||
if (event->event == EVENT_STAMODE_DISCONNECTED) {
|
if(event->event == EVENT_STAMODE_DISCONNECTED) {
|
||||||
WiFiClient::stopAll();
|
WiFiClient::stopAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP8266WiFiClass::printDiag(Print& p)
|
void ESP8266WiFiClass::printDiag(Print& p) {
|
||||||
{
|
const char* modes[] = { "NULL", "STA", "AP", "STA+AP" };
|
||||||
const char* modes[] = {"NULL", "STA", "AP", "STA+AP"};
|
|
||||||
p.print("Mode: ");
|
p.print("Mode: ");
|
||||||
p.println(modes[wifi_get_opmode()]);
|
p.println(modes[wifi_get_opmode()]);
|
||||||
|
|
||||||
const char* phymodes[] = {"", "B", "G", "N"};
|
const char* phymodes[] = { "", "B", "G", "N" };
|
||||||
p.print("PHY mode: ");
|
p.print("PHY mode: ");
|
||||||
p.println(phymodes[(int) wifi_get_phy_mode()]);
|
p.println(phymodes[(int) wifi_get_phy_mode()]);
|
||||||
|
|
||||||
@ -995,5 +913,4 @@ bool ESP8266WiFiClass::_scanComplete = false;
|
|||||||
size_t ESP8266WiFiClass::_scanCount = 0;
|
size_t ESP8266WiFiClass::_scanCount = 0;
|
||||||
void* ESP8266WiFiClass::_scanResult = 0;
|
void* ESP8266WiFiClass::_scanResult = 0;
|
||||||
|
|
||||||
|
|
||||||
ESP8266WiFiClass WiFi;
|
ESP8266WiFiClass WiFi;
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
ESP8266WiFi.h - esp8266 Wifi support.
|
ESP8266WiFi.h - esp8266 Wifi support.
|
||||||
Based on WiFi.h from Ardiono WiFi shield library.
|
Based on WiFi.h from Ardiono WiFi shield library.
|
||||||
Copyright (c) 2011-2014 Arduino. All right reserved.
|
Copyright (c) 2011-2014 Arduino. All right reserved.
|
||||||
Modified by Ivan Grokhotkov, December 2014
|
Modified by Ivan Grokhotkov, December 2014
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
License as published by the Free Software Foundation; either
|
License as published by the Free Software Foundation; either
|
||||||
version 2.1 of the License, or (at your option) any later version.
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
This library is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
Lesser General Public License for more details.
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free Software
|
License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef WiFi_h
|
#ifndef WiFi_h
|
||||||
#define WiFi_h
|
#define WiFi_h
|
||||||
@ -25,7 +25,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "include/wl_definitions.h"
|
#include "include/wl_definitions.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "IPAddress.h"
|
#include "IPAddress.h"
|
||||||
@ -36,11 +36,12 @@ extern "C" {
|
|||||||
#define WIFI_SCAN_RUNNING (-1)
|
#define WIFI_SCAN_RUNNING (-1)
|
||||||
#define WIFI_SCAN_FAILED (-2)
|
#define WIFI_SCAN_FAILED (-2)
|
||||||
|
|
||||||
|
|
||||||
// Note:
|
// Note:
|
||||||
// this enums need to be in sync with the SDK!
|
// this enums need to be in sync with the SDK!
|
||||||
|
|
||||||
enum WiFiMode { WIFI_OFF = 0, WIFI_STA = 1, WIFI_AP = 2, WIFI_AP_STA = 3 };
|
enum WiFiMode {
|
||||||
|
WIFI_OFF = 0, WIFI_STA = 1, WIFI_AP = 2, WIFI_AP_STA = 3
|
||||||
|
};
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
WIFI_PHY_MODE_11B = 1, WIFI_PHY_MODE_11G = 2, WIFI_PHY_MODE_11N = 3
|
WIFI_PHY_MODE_11B = 1, WIFI_PHY_MODE_11G = 2, WIFI_PHY_MODE_11N = 3
|
||||||
@ -50,390 +51,375 @@ typedef enum {
|
|||||||
WIFI_NONE_SLEEP = 0, WIFI_LIGHT_SLEEP = 2, WIFI_MODEM_SLEEP = 3
|
WIFI_NONE_SLEEP = 0, WIFI_LIGHT_SLEEP = 2, WIFI_MODEM_SLEEP = 3
|
||||||
} WiFiSleepType_t;
|
} WiFiSleepType_t;
|
||||||
|
|
||||||
|
class ESP8266WiFiClass {
|
||||||
|
public:
|
||||||
|
|
||||||
class ESP8266WiFiClass
|
ESP8266WiFiClass();
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
ESP8266WiFiClass();
|
void persistent(bool persistent);
|
||||||
|
|
||||||
void persistent(bool persistent);
|
void mode(WiFiMode);
|
||||||
|
WiFiMode getMode();
|
||||||
|
|
||||||
void mode(WiFiMode);
|
/**
|
||||||
WiFiMode getMode();
|
* Start Wifi connection
|
||||||
|
* if passphrase is set the most secure supported mode will be automatically selected
|
||||||
|
* @param ssid const char* Pointer to the SSID string.
|
||||||
|
* @param passphrase const char * Optional. Passphrase. Valid characters in a passphrase must be between ASCII 32-126 (decimal).
|
||||||
|
* @param bssid uint8_t[6] Optional. BSSID / MAC of AP
|
||||||
|
* @param channel Optional. Channel of AP
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int begin(const char* ssid, const char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL);
|
||||||
|
int begin(char* ssid, char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL);
|
||||||
|
|
||||||
/**
|
// Use sdk config to connect.
|
||||||
* Start Wifi connection
|
int begin();
|
||||||
* if passphrase is set the most secure supported mode will be automatically selected
|
|
||||||
* @param ssid const char* Pointer to the SSID string.
|
|
||||||
* @param passphrase const char * Optional. Passphrase. Valid characters in a passphrase must be between ASCII 32-126 (decimal).
|
|
||||||
* @param bssid uint8_t[6] Optional. BSSID / MAC of AP
|
|
||||||
* @param channel Optional. Channel of AP
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
int begin(const char* ssid, const char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL);
|
|
||||||
int begin(char* ssid, char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL);
|
|
||||||
|
|
||||||
// Use sdk config to connect.
|
/* Wait for Wifi connection to reach a result
|
||||||
int begin();
|
* returns the status reached or disconnect if STA is off
|
||||||
|
*/
|
||||||
|
uint8_t waitForConnectResult();
|
||||||
|
|
||||||
|
/* Set up an open access point
|
||||||
|
*
|
||||||
|
* param ssid: Pointer to the SSID string.
|
||||||
|
*/
|
||||||
|
void softAP(const char* ssid);
|
||||||
|
|
||||||
/* Wait for Wifi connection to reach a result
|
/* Set up a WPA2-secured access point
|
||||||
* returns the status reached or disconnect if STA is off
|
*
|
||||||
*/
|
* param ssid: Pointer to the SSID string.
|
||||||
uint8_t waitForConnectResult();
|
* param passphrase: Pointer to passphrase, 8 characters min.
|
||||||
|
* param channel: WiFi channel number, 1 - 13.
|
||||||
|
* param ssid_hidden: Network cloaking? 0 = broadcast SSID, 1 = hide SSID
|
||||||
|
*/
|
||||||
|
void softAP(const char* ssid, const char* passphrase, int channel = 1, int ssid_hidden = 0);
|
||||||
|
|
||||||
/* Set up an open access point
|
/* Change Ip configuration settings disabling the dhcp client
|
||||||
*
|
*
|
||||||
* param ssid: Pointer to the SSID string.
|
* param local_ip: Static ip configuration
|
||||||
*/
|
* param gateway: Static gateway configuration
|
||||||
void softAP(const char* ssid);
|
* param subnet: Static Subnet mask
|
||||||
|
*/
|
||||||
|
void config(IPAddress local_ip, IPAddress gateway, IPAddress subnet);
|
||||||
|
|
||||||
|
/* Change Ip configuration settings disabling the dhcp client
|
||||||
|
*
|
||||||
|
* param local_ip: Static ip configuration
|
||||||
|
* param gateway: Static gateway configuration
|
||||||
|
* param subnet: Static Subnet mask
|
||||||
|
* param dns: Defined DNS
|
||||||
|
*/
|
||||||
|
void config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns);
|
||||||
|
|
||||||
/* Set up a WPA2-secured access point
|
/* Configure access point
|
||||||
*
|
*
|
||||||
* param ssid: Pointer to the SSID string.
|
* param local_ip: access point IP
|
||||||
* param passphrase: Pointer to passphrase, 8 characters min.
|
* param gateway: gateway IP
|
||||||
* param channel: WiFi channel number, 1 - 13.
|
* param subnet: subnet mask
|
||||||
* param ssid_hidden: Network cloaking? 0 = broadcast SSID, 1 = hide SSID
|
*/
|
||||||
*/
|
void softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet);
|
||||||
void softAP(const char* ssid, const char* passphrase, int channel = 1, int ssid_hidden = 0);
|
|
||||||
|
|
||||||
/* Change Ip configuration settings disabling the dhcp client
|
/*
|
||||||
*
|
* Disconnect from the network (close AP)
|
||||||
* param local_ip: Static ip configuration
|
*
|
||||||
* param gateway: Static gateway configuration
|
* return: one value of wl_status_t enum
|
||||||
* param subnet: Static Subnet mask
|
*/
|
||||||
*/
|
int softAPdisconnect(bool wifioff = false);
|
||||||
void config(IPAddress local_ip, IPAddress gateway, IPAddress subnet);
|
|
||||||
|
|
||||||
/* Change Ip configuration settings disabling the dhcp client
|
/*
|
||||||
*
|
* Disconnect from the network
|
||||||
* param local_ip: Static ip configuration
|
*
|
||||||
* param gateway: Static gateway configuration
|
* return: one value of wl_status_t enum
|
||||||
* param subnet: Static Subnet mask
|
*/
|
||||||
* param dns: Defined DNS
|
int disconnect(bool wifioff = false);
|
||||||
*/
|
|
||||||
void config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns);
|
|
||||||
|
|
||||||
/* Configure access point
|
/*
|
||||||
*
|
* Get the station interface MAC address.
|
||||||
* param local_ip: access point IP
|
*
|
||||||
* param gateway: gateway IP
|
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
|
||||||
* param subnet: subnet mask
|
* return: String
|
||||||
*/
|
*/
|
||||||
void softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet);
|
uint8_t* macAddress(uint8_t* mac);
|
||||||
|
String macAddress(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Disconnect from the network (close AP)
|
* Get the softAP interface MAC address.
|
||||||
*
|
*
|
||||||
* return: one value of wl_status_t enum
|
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
|
||||||
*/
|
* return: String
|
||||||
int softAPdisconnect(bool wifioff = false);
|
*/
|
||||||
|
uint8_t* softAPmacAddress(uint8_t* mac);
|
||||||
|
String softAPmacAddress(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Disconnect from the network
|
* Get the station interface IP address.
|
||||||
*
|
*
|
||||||
* return: one value of wl_status_t enum
|
* return: Ip address value
|
||||||
*/
|
*/
|
||||||
int disconnect(bool wifioff = false);
|
IPAddress localIP();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the station interface MAC address.
|
* Get the softAP interface IP address.
|
||||||
*
|
*
|
||||||
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
|
* return: Ip address value
|
||||||
* return: String
|
*/
|
||||||
*/
|
IPAddress softAPIP();
|
||||||
uint8_t* macAddress(uint8_t* mac);
|
|
||||||
String macAddress(void);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the softAP interface MAC address.
|
* Get the interface subnet mask address.
|
||||||
*
|
*
|
||||||
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
|
* return: subnet mask address value
|
||||||
* return: String
|
*/
|
||||||
*/
|
IPAddress subnetMask();
|
||||||
uint8_t* softAPmacAddress(uint8_t* mac);
|
|
||||||
String softAPmacAddress(void);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the station interface IP address.
|
* Get the gateway ip address.
|
||||||
*
|
*
|
||||||
* return: Ip address value
|
* return: gateway ip address value
|
||||||
*/
|
*/
|
||||||
IPAddress localIP();
|
IPAddress gatewayIP();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the softAP interface IP address.
|
* Get the DNS ip address.
|
||||||
*
|
*
|
||||||
* return: Ip address value
|
* return: DNS ip address value
|
||||||
*/
|
*/
|
||||||
IPAddress softAPIP();
|
IPAddress dnsIP(int dns_no = 0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the interface subnet mask address.
|
* Return the current SSID associated with the network
|
||||||
*
|
*
|
||||||
* return: subnet mask address value
|
* return: ssid string
|
||||||
*/
|
*/
|
||||||
IPAddress subnetMask();
|
String SSID() const;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the gateway ip address.
|
* Return the current pre shared key associated with the network
|
||||||
*
|
*
|
||||||
* return: gateway ip address value
|
* return: psk string
|
||||||
*/
|
*/
|
||||||
IPAddress gatewayIP();
|
String psk() const;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the DNS ip address.
|
* Return the current bssid / mac associated with the network if configured
|
||||||
*
|
*
|
||||||
* return: DNS ip address value
|
* return: bssid uint8_t *
|
||||||
*/
|
*/
|
||||||
IPAddress dnsIP(int dns_no = 0);
|
uint8_t *BSSID(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the current SSID associated with the network
|
* Return the current bssid / mac associated with the network if configured
|
||||||
*
|
*
|
||||||
* return: ssid string
|
* return: bssid string
|
||||||
*/
|
*/
|
||||||
String SSID() const;
|
String BSSIDstr(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the current pre shared key associated with the network
|
* Return the current channel associated with the network
|
||||||
*
|
*
|
||||||
* return: psk string
|
* return: channel
|
||||||
*/
|
*/
|
||||||
String psk() const;
|
int32_t channel(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the current bssid / mac associated with the network if configured
|
* Return the current network RSSI.
|
||||||
*
|
*
|
||||||
* return: bssid uint8_t *
|
* return: RSSI value
|
||||||
*/
|
*/
|
||||||
uint8_t *BSSID(void);
|
|
||||||
|
|
||||||
/*
|
int32_t RSSI();
|
||||||
* Return the current bssid / mac associated with the network if configured
|
|
||||||
*
|
|
||||||
* return: bssid string
|
|
||||||
*/
|
|
||||||
String BSSIDstr(void);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the current channel associated with the network
|
* called to get the scan state in Async mode
|
||||||
*
|
*
|
||||||
* return: channel
|
* return -1 if scan not fin
|
||||||
*/
|
* return -2 if scan not triggered
|
||||||
int32_t channel(void);
|
*/
|
||||||
|
int8_t scanComplete();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the current network RSSI.
|
* delete last scan result from RAM
|
||||||
*
|
*/
|
||||||
* return: RSSI value
|
void scanDelete();
|
||||||
*/
|
|
||||||
|
|
||||||
int32_t RSSI();
|
/*
|
||||||
|
* Start scan WiFi networks available
|
||||||
|
*
|
||||||
|
* return: Number of discovered networks
|
||||||
|
*/
|
||||||
|
int8_t scanNetworks(bool async = false, bool show_hidden = false);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the SSID discovered during the network scan.
|
||||||
|
*
|
||||||
|
* param networkItem: specify from which network item want to get the information
|
||||||
|
*
|
||||||
|
* return: ssid string of the specified item on the networks scanned list
|
||||||
|
*/
|
||||||
|
String SSID(uint8_t networkItem);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* called to get the scan state in Async mode
|
* Return the encryption type of the networks discovered during the scanNetworks
|
||||||
*
|
*
|
||||||
* return -1 if scan not fin
|
* param networkItem: specify from which network item want to get the information
|
||||||
* return -2 if scan not triggered
|
*
|
||||||
*/
|
* return: encryption type (enum wl_enc_type) of the specified item on the networks scanned list
|
||||||
int8_t scanComplete();
|
*/
|
||||||
|
uint8_t encryptionType(uint8_t networkItem);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* delete last scan result from RAM
|
* Return the RSSI of the networks discovered during the scanNetworks
|
||||||
*/
|
*
|
||||||
void scanDelete();
|
* param networkItem: specify from which network item want to get the information
|
||||||
|
*
|
||||||
|
* return: signed value of RSSI of the specified item on the networks scanned list
|
||||||
|
*/
|
||||||
|
int32_t RSSI(uint8_t networkItem);
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Start scan WiFi networks available
|
* return MAC / BSSID of scanned wifi
|
||||||
*
|
* @param networkItem specify from which network item want to get the information
|
||||||
* return: Number of discovered networks
|
* @return uint8_t * MAC / BSSID of scanned wifi
|
||||||
*/
|
*/
|
||||||
int8_t scanNetworks(bool async = false, bool show_hidden = false);
|
uint8_t * BSSID(uint8_t networkItem);
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Return the SSID discovered during the network scan.
|
* return MAC / BSSID of scanned wifi
|
||||||
*
|
* @param networkItem specify from which network item want to get the information
|
||||||
* param networkItem: specify from which network item want to get the information
|
* @return String MAC / BSSID of scanned wifi
|
||||||
*
|
*/
|
||||||
* return: ssid string of the specified item on the networks scanned list
|
String BSSIDstr(uint8_t networkItem);
|
||||||
*/
|
|
||||||
String SSID(uint8_t networkItem);
|
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Return the encryption type of the networks discovered during the scanNetworks
|
* return channel of scanned wifi
|
||||||
*
|
* @param networkItem specify from which network item want to get the information
|
||||||
* param networkItem: specify from which network item want to get the information
|
* @return uint32_t channel of scanned wifi
|
||||||
*
|
*/
|
||||||
* return: encryption type (enum wl_enc_type) of the specified item on the networks scanned list
|
int32_t channel(uint8_t networkItem);
|
||||||
*/
|
|
||||||
uint8_t encryptionType(uint8_t networkItem);
|
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Return the RSSI of the networks discovered during the scanNetworks
|
* return if the scanned wifi is Hidden (no SSID)
|
||||||
*
|
* @param networkItem specify from which network item want to get the information
|
||||||
* param networkItem: specify from which network item want to get the information
|
* @return bool (true == hidden)
|
||||||
*
|
*/
|
||||||
* return: signed value of RSSI of the specified item on the networks scanned list
|
bool isHidden(uint8_t networkItem);
|
||||||
*/
|
|
||||||
int32_t RSSI(uint8_t networkItem);
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loads all infos from a scanned wifi in to the ptr parameters
|
||||||
|
* @param networkItem uint8_t
|
||||||
|
* @param ssid const char**
|
||||||
|
* @param encryptionType uint8_t *
|
||||||
|
* @param RSSI int32_t *
|
||||||
|
* @param BSSID uint8_t **
|
||||||
|
* @param channel int32_t *
|
||||||
|
* @param isHidden bool *
|
||||||
|
* @return (true if ok)
|
||||||
|
*/
|
||||||
|
bool getNetworkInfo(uint8_t networkItem, String &ssid, uint8_t &encryptionType, int32_t &RSSI, uint8_t* &BSSID, int32_t &channel, bool &isHidden);
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* return MAC / BSSID of scanned wifi
|
* Return Connection status.
|
||||||
* @param networkItem specify from which network item want to get the information
|
*
|
||||||
* @return uint8_t * MAC / BSSID of scanned wifi
|
* return: one of the value defined in wl_status_t
|
||||||
*/
|
*/
|
||||||
uint8_t * BSSID(uint8_t networkItem);
|
wl_status_t status();
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* return MAC / BSSID of scanned wifi
|
* Resolve the given hostname to an IP address.
|
||||||
* @param networkItem specify from which network item want to get the information
|
* param aHostname: Name to be resolved
|
||||||
* @return String MAC / BSSID of scanned wifi
|
* param aResult: IPAddress structure to store the returned IP address
|
||||||
*/
|
* result: 1 if aIPAddrString was successfully converted to an IP address,
|
||||||
String BSSIDstr(uint8_t networkItem);
|
* else error code
|
||||||
|
*/
|
||||||
|
int hostByName(const char* aHostname, IPAddress& aResult);
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* return channel of scanned wifi
|
* Get ESP8266 station DHCP hostname
|
||||||
* @param networkItem specify from which network item want to get the information
|
*/
|
||||||
* @return uint32_t channel of scanned wifi
|
String hostname(void);
|
||||||
*/
|
|
||||||
int32_t channel(uint8_t networkItem);
|
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* return if the scanned wifi is Hidden (no SSID)
|
* Set ESP8266 station DHCP hostname
|
||||||
* @param networkItem specify from which network item want to get the information
|
* hostname, max length:32
|
||||||
* @return bool (true == hidden)
|
*/
|
||||||
*/
|
bool hostname(char* aHostname);bool hostname(const char* aHostname);bool hostname(String aHostname);
|
||||||
bool isHidden(uint8_t networkItem);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* loads all infos from a scanned wifi in to the ptr parameters
|
* WPS config
|
||||||
* @param networkItem uint8_t
|
* so far only WPS_TYPE_PBC is supported (SDK 1.2.0)
|
||||||
* @param ssid const char**
|
*/
|
||||||
* @param encryptionType uint8_t *
|
bool beginWPSConfig(void);
|
||||||
* @param RSSI int32_t *
|
|
||||||
* @param BSSID uint8_t **
|
|
||||||
* @param channel int32_t *
|
|
||||||
* @param isHidden bool *
|
|
||||||
* @return (true if ok)
|
|
||||||
*/
|
|
||||||
bool getNetworkInfo(uint8_t networkItem, String &ssid, uint8_t &encryptionType, int32_t &RSSI, uint8_t* &BSSID, int32_t &channel, bool &isHidden);
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Output WiFi settings to an object derived from Print interface (like Serial).
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void printDiag(Print& dest);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return Connection status.
|
* Start SmartConfig
|
||||||
*
|
*
|
||||||
* return: one of the value defined in wl_status_t
|
*/
|
||||||
*/
|
void beginSmartConfig();
|
||||||
wl_status_t status();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Resolve the given hostname to an IP address.
|
* Query SmartConfig status, to decide when stop config
|
||||||
* param aHostname: Name to be resolved
|
*
|
||||||
* param aResult: IPAddress structure to store the returned IP address
|
*/
|
||||||
* result: 1 if aIPAddrString was successfully converted to an IP address,
|
bool smartConfigDone();
|
||||||
* else error code
|
|
||||||
*/
|
|
||||||
int hostByName(const char* aHostname, IPAddress& aResult);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get ESP8266 station DHCP hostname
|
* Stop SmartConfig
|
||||||
*/
|
*
|
||||||
String hostname(void);
|
*/
|
||||||
|
void stopSmartConfig();
|
||||||
|
|
||||||
/*
|
friend class WiFiClient;
|
||||||
* Set ESP8266 station DHCP hostname
|
friend class WiFiServer;
|
||||||
* hostname, max length:32
|
|
||||||
*/
|
|
||||||
bool hostname(char* aHostname);
|
|
||||||
bool hostname(const char* aHostname);
|
|
||||||
bool hostname(String aHostname);
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set Sleep mode
|
||||||
|
* @param type WiFiPhyMode_t
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
bool setSleepMode(WiFiSleepType_t type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WPS config
|
* get Sleep mode
|
||||||
* so far only WPS_TYPE_PBC is supported (SDK 1.2.0)
|
* @return sleep_type_t
|
||||||
*/
|
*/
|
||||||
bool beginWPSConfig(void);
|
WiFiSleepType_t getSleepMode();
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Output WiFi settings to an object derived from Print interface (like Serial).
|
* set phy Mode
|
||||||
*
|
* @param mode phy_mode_t
|
||||||
*/
|
* @return bool
|
||||||
void printDiag(Print& dest);
|
*/
|
||||||
|
bool setPhyMode(WiFiPhyMode_t mode);
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Start SmartConfig
|
* get phy Mode
|
||||||
*
|
* @return phy_mode_t
|
||||||
*/
|
*/
|
||||||
void beginSmartConfig();
|
WiFiPhyMode_t getPhyMode();
|
||||||
|
|
||||||
/*
|
protected:
|
||||||
* Query SmartConfig status, to decide when stop config
|
void _mode(WiFiMode);
|
||||||
*
|
static void _scanDone(void* result, int status);
|
||||||
*/
|
void * _getScanInfoByIndex(int i);
|
||||||
bool smartConfigDone();
|
static void _smartConfigCallback(uint32_t status, void* result);
|
||||||
|
static void _eventCallback(void *event);bool _smartConfigStarted;bool _smartConfigDone;
|
||||||
|
|
||||||
/*
|
bool _useApMode;bool _useClientMode;bool _useStaticIp;bool _persistent;
|
||||||
* Stop SmartConfig
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void stopSmartConfig();
|
|
||||||
|
|
||||||
friend class WiFiClient;
|
static bool _scanAsync;
|
||||||
friend class WiFiServer;
|
static bool _scanStarted;
|
||||||
|
static bool _scanComplete;
|
||||||
|
|
||||||
/**
|
static size_t _scanCount;
|
||||||
* set Sleep mode
|
static void* _scanResult;
|
||||||
* @param type WiFiPhyMode_t
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
bool setSleepMode(WiFiSleepType_t type);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get Sleep mode
|
|
||||||
* @return sleep_type_t
|
|
||||||
*/
|
|
||||||
WiFiSleepType_t getSleepMode();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set phy Mode
|
|
||||||
* @param mode phy_mode_t
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
bool setPhyMode(WiFiPhyMode_t mode);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get phy Mode
|
|
||||||
* @return phy_mode_t
|
|
||||||
*/
|
|
||||||
WiFiPhyMode_t getPhyMode();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void _mode(WiFiMode);
|
|
||||||
static void _scanDone(void* result, int status);
|
|
||||||
void * _getScanInfoByIndex(int i);
|
|
||||||
static void _smartConfigCallback(uint32_t status, void* result);
|
|
||||||
static void _eventCallback(void *event);
|
|
||||||
bool _smartConfigStarted;
|
|
||||||
bool _smartConfigDone;
|
|
||||||
|
|
||||||
bool _useApMode;
|
|
||||||
bool _useClientMode;
|
|
||||||
bool _useStaticIp;
|
|
||||||
bool _persistent;
|
|
||||||
|
|
||||||
static bool _scanAsync;
|
|
||||||
static bool _scanStarted;
|
|
||||||
static bool _scanComplete;
|
|
||||||
|
|
||||||
static size_t _scanCount;
|
|
||||||
static void* _scanResult;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user