mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-25 20:26:41 +00:00
oobe ScanNetworks and fix wifiValidateSsid
This commit is contained in:
parent
b8bdcaf710
commit
ca920eff2d
@ -311,6 +311,7 @@ bool oobeSetup()
|
|||||||
char pass[32];
|
char pass[32];
|
||||||
|
|
||||||
if(wifiShowAP(ssid, pass)) {
|
if(wifiShowAP(ssid, pass)) {
|
||||||
|
WiFi.scanNetworks(true);
|
||||||
haspDevice.set_backlight_level(255);
|
haspDevice.set_backlight_level(255);
|
||||||
oobeSetupQR(ssid, pass);
|
oobeSetupQR(ssid, pass);
|
||||||
oobeSetupSsid();
|
oobeSetupSsid();
|
||||||
@ -339,6 +340,7 @@ void oobeFakeSetup(const char*, const char*)
|
|||||||
char ssid[32] = "HASP-ABCDEF";
|
char ssid[32] = "HASP-ABCDEF";
|
||||||
char pass[32] = "haspadmin";
|
char pass[32] = "haspadmin";
|
||||||
|
|
||||||
|
WiFi.scanNetworks(true);
|
||||||
haspDevice.set_backlight_level(255);
|
haspDevice.set_backlight_level(255);
|
||||||
oobeSetupQR(ssid, pass);
|
oobeSetupQR(ssid, pass);
|
||||||
oobeSetupSsid();
|
oobeSetupSsid();
|
||||||
|
@ -294,6 +294,20 @@ static void wifi_callback(system_event_id_t event, system_event_info_t info)
|
|||||||
case SYSTEM_EVENT_STA_GOT_IP:
|
case SYSTEM_EVENT_STA_GOT_IP:
|
||||||
wifiConnected(IPAddress(info.got_ip.ip_info.ip.addr));
|
wifiConnected(IPAddress(info.got_ip.ip_info.ip.addr));
|
||||||
break;
|
break;
|
||||||
|
case SYSTEM_EVENT_SCAN_DONE: {
|
||||||
|
uint16_t count = WiFi.scanComplete();
|
||||||
|
for(int i = 0; i < count; ++i) {
|
||||||
|
// Print SSID and RSSI for each network found
|
||||||
|
Serial.print(i + 1);
|
||||||
|
Serial.print(": ");
|
||||||
|
Serial.print(WiFi.SSID(i));
|
||||||
|
Serial.print(" (");
|
||||||
|
Serial.print(WiFi.RSSI(i));
|
||||||
|
Serial.print(")");
|
||||||
|
Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " " : "*");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case SYSTEM_EVENT_STA_DISCONNECTED:
|
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||||
wifiDisconnected((const char*)info.disconnected.ssid, info.disconnected.reason);
|
wifiDisconnected((const char*)info.disconnected.ssid, info.disconnected.reason);
|
||||||
// NTP.stop(); // NTP sync can be disabled to avoid sync errors
|
// NTP.stop(); // NTP sync can be disabled to avoid sync errors
|
||||||
@ -467,9 +481,9 @@ bool wifiEvery5Seconds()
|
|||||||
bool wifiValidateSsid(const char* ssid, const char* pass)
|
bool wifiValidateSsid(const char* ssid, const char* pass)
|
||||||
{
|
{
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
WiFi.begin(wifiSsid, wifiPassword, WIFI_ALL_CHANNEL_SCAN);
|
WiFi.begin(ssid, pass, WIFI_ALL_CHANNEL_SCAN);
|
||||||
#else
|
#else
|
||||||
WiFi.begin(wifiSsid, wifiPassword);
|
WiFi.begin(ssid, pass);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t attempt = 0;
|
uint8_t attempt = 0;
|
||||||
@ -480,13 +494,13 @@ bool wifiValidateSsid(const char* ssid, const char* pass)
|
|||||||
char espIp[16];
|
char espIp[16];
|
||||||
memset(espIp, 0, sizeof(espIp));
|
memset(espIp, 0, sizeof(espIp));
|
||||||
snprintf_P(espIp, sizeof(espIp), PSTR("%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]);
|
snprintf_P(espIp, sizeof(espIp), PSTR("%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]);
|
||||||
while(attempt < 15 && (WiFi.status() != WL_CONNECTED || String(espIp) == F("0.0.0.0"))) {
|
while(attempt < 30 && (WiFi.status() != WL_CONNECTED || String(espIp) == F("0.0.0.0"))) {
|
||||||
#else
|
#else
|
||||||
while(attempt < 15 && (WiFi.status() != WL_CONNECTED || WiFi.localIP().toString() == F("0.0.0.0"))) {
|
while(attempt < 30 && (WiFi.status() != WL_CONNECTED || WiFi.localIP().toString() == F("0.0.0.0"))) {
|
||||||
#endif
|
#endif
|
||||||
attempt++;
|
attempt++;
|
||||||
LOG_INFO(TAG_WIFI, F(D_WIFI_CONNECTING_TO "... %u"), wifiSsid, attempt);
|
LOG_INFO(TAG_WIFI, F(D_WIFI_CONNECTING_TO "... %u"), ssid, attempt);
|
||||||
delay(500);
|
delay(250);
|
||||||
}
|
}
|
||||||
#if defined(STM32F4xx)
|
#if defined(STM32F4xx)
|
||||||
LOG_INFO(TAG_WIFI, F(D_NETWORK_IP_ADDRESS_RECEIVED), espIp);
|
LOG_INFO(TAG_WIFI, F(D_NETWORK_IP_ADDRESS_RECEIVED), espIp);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user