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
@ -41,26 +41,19 @@ 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,13 +73,11 @@ 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;
|
||||||
}
|
}
|
||||||
@ -100,8 +91,7 @@ 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;
|
||||||
|
|
||||||
@ -114,8 +104,7 @@ static bool sta_config_equal(const station_config& lhs, const station_config& rh
|
|||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
@ -123,13 +112,11 @@ static bool sta_config_equal(const station_config& lhs, const station_config& rh
|
|||||||
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) {
|
||||||
@ -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();
|
||||||
@ -209,10 +195,8 @@ uint8_t ESP8266WiFiClass::waitForConnectResult(){
|
|||||||
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);
|
||||||
@ -242,8 +225,7 @@ void ESP8266WiFiClass::config(IPAddress local_ip, IPAddress gateway, IPAddress s
|
|||||||
_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;
|
||||||
@ -269,8 +251,7 @@ 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;
|
||||||
@ -297,8 +278,7 @@ 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)
|
||||||
@ -310,15 +290,11 @@ static bool softap_config_equal(const softap_config& lhs, const softap_config& r
|
|||||||
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,21 +323,17 @@ 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;
|
||||||
}
|
}
|
||||||
@ -374,8 +346,7 @@ void ESP8266WiFiClass::softAP(const char* ssid, const char* passphrase, int chan
|
|||||||
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,14 +356,12 @@ 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);
|
||||||
@ -401,14 +370,12 @@ String ESP8266WiFiClass::macAddress(void)
|
|||||||
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);
|
||||||
@ -417,63 +384,54 @@ String ESP8266WiFiClass::softAPmacAddress(void)
|
|||||||
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);
|
||||||
@ -481,46 +439,37 @@ String ESP8266WiFiClass::BSSIDstr(void)
|
|||||||
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,18 +552,15 @@ 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 "";
|
||||||
@ -626,8 +568,7 @@ String ESP8266WiFiClass::SSID(uint8_t i)
|
|||||||
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;
|
||||||
@ -635,8 +576,7 @@ uint8_t * ESP8266WiFiClass::BSSID(uint8_t i)
|
|||||||
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)
|
||||||
@ -646,8 +586,7 @@ String ESP8266WiFiClass::BSSIDstr(uint8_t i)
|
|||||||
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;
|
||||||
@ -655,8 +594,7 @@ int32_t ESP8266WiFiClass::channel(uint8_t i)
|
|||||||
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;
|
||||||
@ -664,8 +602,7 @@ bool ESP8266WiFiClass::isHidden(uint8_t i)
|
|||||||
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;
|
||||||
@ -680,8 +617,7 @@ bool ESP8266WiFiClass::getNetworkInfo(uint8_t i, String &ssid, uint8_t &encType,
|
|||||||
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;
|
||||||
@ -689,8 +625,7 @@ int32_t ESP8266WiFiClass::RSSI(uint8_t i)
|
|||||||
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;
|
||||||
@ -709,8 +644,7 @@ uint8_t ESP8266WiFiClass::encryptionType(uint8_t i)
|
|||||||
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)
|
||||||
@ -725,24 +659,19 @@ wl_status_t ESP8266WiFiClass::status()
|
|||||||
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,8 +700,7 @@ 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:
|
||||||
@ -841,10 +769,7 @@ bool ESP8266WiFiClass::beginWPSConfig(void) {
|
|||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
|
|
||||||
|
void ESP8266WiFiClass::beginSmartConfig() {
|
||||||
|
|
||||||
void ESP8266WiFiClass::beginSmartConfig()
|
|
||||||
{
|
|
||||||
if(_smartConfigStarted)
|
if(_smartConfigStarted)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -863,8 +788,7 @@ 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;
|
||||||
|
|
||||||
@ -872,16 +796,14 @@ void ESP8266WiFiClass::stopSmartConfig()
|
|||||||
_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);
|
||||||
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -936,8 +856,7 @@ WiFiPhyMode_t ESP8266WiFiClass::getPhyMode() {
|
|||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
@ -946,8 +865,7 @@ void ESP8266WiFiClass::_eventCallback(void* arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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()]);
|
||||||
@ -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;
|
||||||
|
@ -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,9 +51,7 @@ 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 {
|
||||||
class ESP8266WiFiClass
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ESP8266WiFiClass();
|
ESP8266WiFiClass();
|
||||||
@ -77,7 +76,6 @@ public:
|
|||||||
// Use sdk config to connect.
|
// Use sdk config to connect.
|
||||||
int begin();
|
int begin();
|
||||||
|
|
||||||
|
|
||||||
/* Wait for Wifi connection to reach a result
|
/* Wait for Wifi connection to reach a result
|
||||||
* returns the status reached or disconnect if STA is off
|
* returns the status reached or disconnect if STA is off
|
||||||
*/
|
*/
|
||||||
@ -89,7 +87,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
void softAP(const char* ssid);
|
void softAP(const char* ssid);
|
||||||
|
|
||||||
|
|
||||||
/* Set up a WPA2-secured access point
|
/* Set up a WPA2-secured access point
|
||||||
*
|
*
|
||||||
* param ssid: Pointer to the SSID string.
|
* param ssid: Pointer to the SSID string.
|
||||||
@ -234,7 +231,6 @@ public:
|
|||||||
|
|
||||||
int32_t RSSI();
|
int32_t RSSI();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* called to get the scan state in Async mode
|
* called to get the scan state in Async mode
|
||||||
*
|
*
|
||||||
@ -282,7 +278,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
int32_t RSSI(uint8_t networkItem);
|
int32_t RSSI(uint8_t networkItem);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return MAC / BSSID of scanned wifi
|
* 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
|
||||||
@ -324,7 +319,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool getNetworkInfo(uint8_t networkItem, String &ssid, uint8_t &encryptionType, int32_t &RSSI, uint8_t* &BSSID, int32_t &channel, bool &isHidden);
|
bool getNetworkInfo(uint8_t networkItem, String &ssid, uint8_t &encryptionType, int32_t &RSSI, uint8_t* &BSSID, int32_t &channel, bool &isHidden);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return Connection status.
|
* Return Connection status.
|
||||||
*
|
*
|
||||||
@ -350,10 +344,7 @@ public:
|
|||||||
* Set ESP8266 station DHCP hostname
|
* Set ESP8266 station DHCP hostname
|
||||||
* hostname, max length:32
|
* hostname, max length:32
|
||||||
*/
|
*/
|
||||||
bool hostname(char* aHostname);
|
bool hostname(char* aHostname);bool hostname(const char* aHostname);bool hostname(String aHostname);
|
||||||
bool hostname(const char* aHostname);
|
|
||||||
bool hostname(String aHostname);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WPS config
|
* WPS config
|
||||||
@ -419,14 +410,9 @@ protected:
|
|||||||
static void _scanDone(void* result, int status);
|
static void _scanDone(void* result, int status);
|
||||||
void * _getScanInfoByIndex(int i);
|
void * _getScanInfoByIndex(int i);
|
||||||
static void _smartConfigCallback(uint32_t status, void* result);
|
static void _smartConfigCallback(uint32_t status, void* result);
|
||||||
static void _eventCallback(void *event);
|
static void _eventCallback(void *event);bool _smartConfigStarted;bool _smartConfigDone;
|
||||||
bool _smartConfigStarted;
|
|
||||||
bool _smartConfigDone;
|
|
||||||
|
|
||||||
bool _useApMode;
|
bool _useApMode;bool _useClientMode;bool _useStaticIp;bool _persistent;
|
||||||
bool _useClientMode;
|
|
||||||
bool _useStaticIp;
|
|
||||||
bool _persistent;
|
|
||||||
|
|
||||||
static bool _scanAsync;
|
static bool _scanAsync;
|
||||||
static bool _scanStarted;
|
static bool _scanStarted;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user