Skip to content

Commit c209af0

Browse files
committed
add back SmartConfig
1 parent e8d4353 commit c209af0

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/ESP8266WiFi.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extern "C" {
2727
#include "osapi.h"
2828
#include "mem.h"
2929
#include "user_interface.h"
30+
#include "smartconfig.h"
3031
#include "lwip/opt.h"
3132
#include "lwip/err.h"
3233
#include "lwip/dns.h"
@@ -375,6 +376,45 @@ int ESP8266WiFiClass::hostByName(const char* aHostname, IPAddress& aResult)
375376
return (aResult != 0) ? 1 : 0;
376377
}
377378

379+
void ESP8266WiFiClass::beginSmartConfig()
380+
{
381+
if (_smartConfigStarted)
382+
return;
383+
384+
WiFi.mode(WIFI_STA);
385+
386+
_smartConfigStarted = true;
387+
388+
//SC_TYPE_ESPTOUCH use ESPTOUCH for smartconfig, or use SC_TYPE_AIRKISS for AIRKISS
389+
smartconfig_start(SC_TYPE_ESPTOUCH, &ESP8266WiFiClass::_smartConfigDone);
390+
}
391+
392+
void ESP8266WiFiClass::stopSmartConfig()
393+
{
394+
if (!_smartConfigStarted)
395+
return;
396+
397+
smartconfig_stop();
398+
_smartConfigStarted = false;
399+
}
400+
401+
bool ESP8266WiFiClass::smartConfigDone(){
402+
if (!_smartConfigStarted)
403+
return false;
404+
405+
return smartconfig_get_status() == SC_STATUS_LINK_OVER;
406+
}
407+
408+
void ESP8266WiFiClass::_smartConfigDone(void* result)
409+
{
410+
station_config* sta_conf = reinterpret_cast<station_config*>(result);
411+
412+
wifi_station_set_config(sta_conf);
413+
wifi_station_disconnect();
414+
wifi_station_connect();
415+
}
416+
417+
378418
void ESP8266WiFiClass::printDiag(Print& p)
379419
{
380420
const char* modes[] = {"NULL", "STA", "AP", "STA+AP"};

hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/ESP8266WiFi.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,29 @@ class ESP8266WiFiClass
211211
*/
212212
void printDiag(Print& dest);
213213

214+
/*
215+
* Start SmartConfig
216+
*
217+
*/
218+
void beginSmartConfig();
219+
220+
/*
221+
* Query SmartConfig status, to decide when stop config
222+
*
223+
*/
224+
bool smartConfigDone();
225+
226+
void stopSmartConfig();
227+
214228
friend class WiFiClient;
215229
friend class WiFiServer;
216230

217231
protected:
218232
static void _scanDone(void* result, int status);
219233
void * _getScanInfoByIndex(int i);
234+
static void _smartConfigDone(void* result);
235+
bool _smartConfigStarted = false;
236+
220237
static size_t _scanCount;
221238
static void* _scanResult;
222239

hardware/esp8266com/esp8266/platform.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ compiler.S.flags=-c -g -x assembler-with-cpp -MMD
2323
compiler.c.elf.ldscript=eagle.app.v6.ld
2424
compiler.c.elf.flags=-nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" "-T{compiler.c.elf.ldscript}"
2525
compiler.c.elf.cmd=xtensa-lx106-elf-gcc
26-
compiler.c.elf.libs=-lgcc -lm -lhal -lphy -lnet80211 -llwip -lwpa -lmain -lpp
26+
compiler.c.elf.libs=-lgcc -lm -lhal -lphy -lnet80211 -llwip -lwpa -lmain -lpp -lsmartconfig
2727

2828
compiler.cpp.cmd=xtensa-lx106-elf-g++
2929
compiler.cpp.flags=-c -Os -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -std=c++11 -MMD

hardware/tools/esp8266/sdk/ld/eagle.app.v6.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ SECTIONS
154154
*core_esp8266_*.o(.literal*, .text*)
155155
*.cpp.o(.literal*, .text*)
156156
*libm.a:(.literal .text .literal.* .text.*)
157+
*libsmartconfig.a:(.literal .text .literal.* .text.*)
157158
*(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text)
158159
_irom0_text_end = ABSOLUTE(.);
159160
} >irom0_0_seg :irom0_0_phdr

0 commit comments

Comments
 (0)