|
@ -25,7 +25,7 @@ void _wifiConfigure() { |
|
|
#endif
|
|
|
#endif
|
|
|
jw.setConnectTimeout(WIFI_CONNECT_TIMEOUT); |
|
|
jw.setConnectTimeout(WIFI_CONNECT_TIMEOUT); |
|
|
wifiReconnectCheck(); |
|
|
wifiReconnectCheck(); |
|
|
jw.setAPMode(WIFI_AP_MODE); |
|
|
|
|
|
|
|
|
jw.enableAPFailsafe(true); |
|
|
jw.cleanNetworks(); |
|
|
jw.cleanNetworks(); |
|
|
|
|
|
|
|
|
// If system is flagged unstable we do not init wifi networks
|
|
|
// If system is flagged unstable we do not init wifi networks
|
|
@ -196,6 +196,31 @@ void _wifiInject() { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void _wifiWPS(justwifi_messages_t code, char * parameter) { |
|
|
|
|
|
|
|
|
|
|
|
if (MESSAGE_WPS_SUCCESS == code) { |
|
|
|
|
|
|
|
|
|
|
|
String ssid = WiFi.SSID(); |
|
|
|
|
|
String pass = WiFi.psk(); |
|
|
|
|
|
|
|
|
|
|
|
// Look for the same SSID
|
|
|
|
|
|
uint8_t count = 0; |
|
|
|
|
|
while (count < WIFI_MAX_NETWORKS) { |
|
|
|
|
|
if (!hasSetting("ssid", count)) break; |
|
|
|
|
|
if (getSetting("ssid", count).equals(ssid)) break; |
|
|
|
|
|
count++; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If we have reached the max we overwrite the first one
|
|
|
|
|
|
if (WIFI_MAX_NETWORKS == count) count = 0; |
|
|
|
|
|
|
|
|
|
|
|
setSetting("ssid", count, ssid); |
|
|
|
|
|
setSetting("pass", count, pass); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
#if WIFI_AP_CAPTIVE
|
|
|
#if WIFI_AP_CAPTIVE
|
|
|
|
|
|
|
|
|
#include "DNSServer.h"
|
|
|
#include "DNSServer.h"
|
|
@ -223,6 +248,8 @@ void _wifiCaptivePortal(justwifi_messages_t code, char * parameter) { |
|
|
|
|
|
|
|
|
void _wifiDebug(justwifi_messages_t code, char * parameter) { |
|
|
void _wifiDebug(justwifi_messages_t code, char * parameter) { |
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
if (code == MESSAGE_SCANNING) { |
|
|
if (code == MESSAGE_SCANNING) { |
|
|
DEBUG_MSG_P(PSTR("[WIFI] Scanning\n")); |
|
|
DEBUG_MSG_P(PSTR("[WIFI] Scanning\n")); |
|
|
} |
|
|
} |
|
@ -243,6 +270,8 @@ void _wifiDebug(justwifi_messages_t code, char * parameter) { |
|
|
DEBUG_MSG_P(PSTR("[WIFI] %s\n"), parameter); |
|
|
DEBUG_MSG_P(PSTR("[WIFI] %s\n"), parameter); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
if (code == MESSAGE_CONNECTING) { |
|
|
if (code == MESSAGE_CONNECTING) { |
|
|
DEBUG_MSG_P(PSTR("[WIFI] Connecting to %s\n"), parameter); |
|
|
DEBUG_MSG_P(PSTR("[WIFI] Connecting to %s\n"), parameter); |
|
|
} |
|
|
} |
|
@ -259,22 +288,38 @@ void _wifiDebug(justwifi_messages_t code, char * parameter) { |
|
|
wifiStatus(); |
|
|
wifiStatus(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (code == MESSAGE_ACCESSPOINT_CREATED) { |
|
|
|
|
|
wifiStatus(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (code == MESSAGE_DISCONNECTED) { |
|
|
if (code == MESSAGE_DISCONNECTED) { |
|
|
DEBUG_MSG_P(PSTR("[WIFI] Disconnected\n")); |
|
|
DEBUG_MSG_P(PSTR("[WIFI] Disconnected\n")); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
if (code == MESSAGE_ACCESSPOINT_CREATING) { |
|
|
if (code == MESSAGE_ACCESSPOINT_CREATING) { |
|
|
DEBUG_MSG_P(PSTR("[WIFI] Creating access point\n")); |
|
|
DEBUG_MSG_P(PSTR("[WIFI] Creating access point\n")); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (code == MESSAGE_ACCESSPOINT_CREATED) { |
|
|
|
|
|
wifiStatus(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (code == MESSAGE_ACCESSPOINT_FAILED) { |
|
|
if (code == MESSAGE_ACCESSPOINT_FAILED) { |
|
|
DEBUG_MSG_P(PSTR("[WIFI] Could not create access point\n")); |
|
|
DEBUG_MSG_P(PSTR("[WIFI] Could not create access point\n")); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
if (code == MESSAGE_WPS_START) { |
|
|
|
|
|
DEBUG_MSG_P(PSTR("[WIFI] WPS started\n")); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (code == MESSAGE_WPS_SUCCESS) { |
|
|
|
|
|
DEBUG_MSG_P(PSTR("[WIFI] WPS succeded!\n")); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (code == MESSAGE_WPS_ERROR) { |
|
|
|
|
|
DEBUG_MSG_P(PSTR("[WIFI] WPS failed\n")); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#endif // DEBUG_SUPPORT
|
|
|
#endif // DEBUG_SUPPORT
|
|
@ -298,6 +343,11 @@ void _wifiInitCommands() { |
|
|
DEBUG_MSG_P(PSTR("+OK\n")); |
|
|
DEBUG_MSG_P(PSTR("+OK\n")); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
settingsRegisterCommand(F("WIFI.WPS"), [](Embedis* e) { |
|
|
|
|
|
jw.startWPS(); |
|
|
|
|
|
DEBUG_MSG_P(PSTR("+OK\n")); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
settingsRegisterCommand(F("WIFI.SCAN"), [](Embedis* e) { |
|
|
settingsRegisterCommand(F("WIFI.SCAN"), [](Embedis* e) { |
|
|
_wifiScan(); |
|
|
_wifiScan(); |
|
|
DEBUG_MSG_P(PSTR("+OK\n")); |
|
|
DEBUG_MSG_P(PSTR("+OK\n")); |
|
@ -445,6 +495,7 @@ void wifiSetup() { |
|
|
_wifiConfigure(); |
|
|
_wifiConfigure(); |
|
|
|
|
|
|
|
|
// Message callbacks
|
|
|
// Message callbacks
|
|
|
|
|
|
wifiRegister(_wifiWPS); |
|
|
#if WIFI_AP_CAPTIVE
|
|
|
#if WIFI_AP_CAPTIVE
|
|
|
wifiRegister(_wifiCaptivePortal); |
|
|
wifiRegister(_wifiCaptivePortal); |
|
|
#endif
|
|
|
#endif
|
|
|