mirror of
https://github.com/0xFEEDC0DE64/arduino-esp32.git
synced 2025-07-05 14:56:32 +02:00
Add smartConfig support (#136)
* smartConfig support * fixed bug, added example * added _smartConfigDone = ture * changed example name, added explanation
This commit is contained in:
@ -40,6 +40,7 @@ extern "C" {
|
||||
#include <lwip/ip_addr.h>
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/dns.h"
|
||||
#include <esp_smartconfig.h>
|
||||
}
|
||||
|
||||
extern "C" void esp_schedule();
|
||||
@ -498,3 +499,64 @@ IPv6Address WiFiSTAClass::localIPv6()
|
||||
}
|
||||
return IPv6Address(addr.addr);
|
||||
}
|
||||
|
||||
|
||||
bool WiFiSTAClass::_smartConfigStarted = false;
|
||||
bool WiFiSTAClass::_smartConfigDone = false;
|
||||
|
||||
|
||||
bool WiFiSTAClass::beginSmartConfig() {
|
||||
if (_smartConfigStarted) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!WiFi.mode(WIFI_STA)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
esp_err_t err;
|
||||
err = esp_smartconfig_start(reinterpret_cast<sc_callback_t>(&WiFiSTAClass::_smartConfigCallback), 1);
|
||||
if (err == ESP_OK) {
|
||||
_smartConfigStarted = true;
|
||||
_smartConfigDone = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WiFiSTAClass::stopSmartConfig() {
|
||||
if (!_smartConfigStarted) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (esp_smartconfig_stop() == ESP_OK) {
|
||||
_smartConfigStarted = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WiFiSTAClass::smartConfigDone() {
|
||||
if (!_smartConfigStarted) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return _smartConfigDone;
|
||||
}
|
||||
|
||||
void WiFiSTAClass::_smartConfigCallback(uint32_t st, void* result) {
|
||||
smartconfig_status_t status = (smartconfig_status_t) st;
|
||||
if (status == SC_STATUS_LINK) {
|
||||
wifi_sta_config_t *sta_conf = reinterpret_cast<wifi_sta_config_t *>(result);
|
||||
|
||||
esp_wifi_set_config(WIFI_IF_AP, (wifi_config_t *)sta_conf);
|
||||
esp_wifi_disconnect();
|
||||
esp_wifi_connect();
|
||||
|
||||
_smartConfigDone = true;
|
||||
} else if (status == SC_STATUS_LINK_OVER) {
|
||||
WiFi.stopSmartConfig();
|
||||
}
|
||||
}
|
||||
|
@ -85,6 +85,16 @@ protected:
|
||||
static wl_status_t _status;
|
||||
static bool _useStaticIp;
|
||||
|
||||
public:
|
||||
bool beginSmartConfig();
|
||||
bool stopSmartConfig();
|
||||
bool smartConfigDone();
|
||||
|
||||
protected:
|
||||
static bool _smartConfigStarted;
|
||||
static bool _smartConfigDone;
|
||||
static void _smartConfigCallback(uint32_t status, void* result);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user