Skip to content

Commit e179a01

Browse files
committed
add function begin without any parameters and add functin psk to return current pre shared kex form sdk config
1 parent 6102e78 commit e179a01

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

hardware/esp8266com/esp8266/libraries/ESP8266WiFi/keywords.txt

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ localIP KEYWORD2
4141
subnetMask KEYWORD2
4242
gatewayIP KEYWORD2
4343
SSID KEYWORD2
44+
psk KEYWORD2
4445
BSSID KEYWORD2
4546
RSSI KEYWORD2
4647
encryptionType KEYWORD2

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

+18
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,17 @@ int ESP8266WiFiClass::begin(const char* ssid, const char *passphrase, int32_t ch
145145
return status();
146146
}
147147

148+
int ESP8266WiFiClass::begin()
149+
{
150+
ETS_UART_INTR_DISABLE();
151+
wifi_station_connect();
152+
ETS_UART_INTR_ENABLE();
153+
154+
if(!_useStaticIp)
155+
wifi_station_dhcpc_start();
156+
return status();
157+
}
158+
148159
uint8_t ESP8266WiFiClass::waitForConnectResult(){
149160
if ((wifi_get_opmode() & 1) == 0)//1 and 3 have STA enabled
150161
return WL_DISCONNECTED;
@@ -366,6 +377,13 @@ char* ESP8266WiFiClass::SSID()
366377
return reinterpret_cast<char*>(conf.ssid);
367378
}
368379

380+
const char* ESP8266WiFiClass::psk()
381+
{
382+
static struct station_config conf;
383+
wifi_station_get_config(&conf);
384+
return reinterpret_cast<const char*>(conf.password);
385+
}
386+
369387
uint8_t* ESP8266WiFiClass::BSSID(void)
370388
{
371389
static struct station_config conf;

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

+10
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class ESP8266WiFiClass
5858
int begin(const char* ssid, const char *passphrase = NULL, int32_t channel = 0, uint8_t bssid[6] = NULL);
5959
int begin(char* ssid, char *passphrase = NULL, int32_t channel = 0, uint8_t bssid[6] = NULL);
6060

61+
// Use sdk config to connect.
62+
int begin();
63+
6164

6265
/* Wait for Wifi connection to reach a result
6366
* returns the status reached or disconnect if STA is off
@@ -172,6 +175,13 @@ class ESP8266WiFiClass
172175
*/
173176
char* SSID();
174177

178+
/*
179+
* Return the current pre shared key associated with the network
180+
*
181+
* return: psk string
182+
*/
183+
const char* psk();
184+
175185
/*
176186
* Return the current bssid / mac associated with the network if configured
177187
*

0 commit comments

Comments
 (0)