Added channel to SSID with Config NEW

pull/41/head
Hieromon Ikasamo 6 years ago
parent a5f7135393
commit 8bf37ed398
  1. 23
      src/AutoConnect.cpp
  2. 2
      src/AutoConnect.h
  3. 33
      src/AutoConnectPage.cpp

@ -53,6 +53,7 @@ void AutoConnect::_initialize() {
_currentPageElement = nullptr; _currentPageElement = nullptr;
_menuTitle = String(F(AUTOCONNECT_MENU_TITLE)); _menuTitle = String(F(AUTOCONNECT_MENU_TITLE));
_connectTimeout = AUTOCONNECT_TIMEOUT; _connectTimeout = AUTOCONNECT_TIMEOUT;
_scanCount = 0;
memset(&_credential, 0x00, sizeof(struct station_config)); memset(&_credential, 0x00, sizeof(struct station_config));
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
_disconnectEventId = -1; // The member available for ESP32 only _disconnectEventId = -1; // The member available for ESP32 only
@ -95,10 +96,7 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long
_connectTimeout = timeout; _connectTimeout = timeout;
// Start WiFi connection with station mode. // Start WiFi connection with station mode.
#if defined(ARDUINO_ARCH_ESP32) WiFi.softAPdisconnect(true);
WiFi.softAPdisconnect(false);
#endif
WiFi.enableAP(false);
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
delay(100); delay(100);
@ -446,8 +444,9 @@ void AutoConnect::handleRequest() {
_disconnectWiFi(true); _disconnectWiFi(true);
// An attempt to establish a new AP. // An attempt to establish a new AP.
AC_DBG("Request for %s\n", reinterpret_cast<const char*>(_credential.ssid)); int32_t ch = _connectCh == 0 ? _apConfig.channel : _connectCh;
WiFi.begin(reinterpret_cast<const char*>(_credential.ssid), reinterpret_cast<const char*>(_credential.password), _apConfig.channel); AC_DBG("Request(%d) for %s\n", (int)ch, reinterpret_cast<const char*>(_credential.ssid));
WiFi.begin(reinterpret_cast<const char*>(_credential.ssid), reinterpret_cast<const char*>(_credential.password), ch);
if (_waitForConnect(_connectTimeout) == WL_CONNECTED) { if (_waitForConnect(_connectTimeout) == WL_CONNECTED) {
if (WiFi.BSSID() != NULL) { if (WiFi.BSSID() != NULL) {
memcpy(_credential.bssid, WiFi.BSSID(), sizeof(station_config::bssid)); memcpy(_credential.bssid, WiFi.BSSID(), sizeof(station_config::bssid));
@ -491,7 +490,7 @@ void AutoConnect::handleRequest() {
if (_rfDisconnect) { if (_rfDisconnect) {
// Disconnect from the current AP. // Disconnect from the current AP.
_waitForEndTransmission(); // _waitForEndTransmission();
_stopPortal(); _stopPortal();
_disconnectWiFi(false); _disconnectWiFi(false);
while (WiFi.status() == WL_CONNECTED) { while (WiFi.status() == WL_CONNECTED) {
@ -706,6 +705,16 @@ String AutoConnect::_induceConnect(PageArgument& args) {
strncpy(reinterpret_cast<char*>(_credential.password), args.arg(AUTOCONNECT_PARAMID_PASS).c_str(), sizeof(_credential.password)); strncpy(reinterpret_cast<char*>(_credential.password), args.arg(AUTOCONNECT_PARAMID_PASS).c_str(), sizeof(_credential.password));
} }
// Determine the connection channel based on the scan result.
_connectCh = 0;
for (uint8_t nn = 0; nn < _scanCount; nn++) {
String ssid = WiFi.SSID(nn);
if (!strcmp(ssid.c_str(), reinterpret_cast<const char*>(_credential.ssid))) {
_connectCh = WiFi.channel(nn);
break;
}
}
// Turn on the trigger to start WiFi.begin(). // Turn on the trigger to start WiFi.begin().
_rfConnect = true; _rfConnect = true;

@ -263,6 +263,8 @@ class AutoConnect {
AutoConnectConfig _apConfig; AutoConnectConfig _apConfig;
struct station_config _credential; struct station_config _credential;
uint8_t _hiddenSSIDCount; uint8_t _hiddenSSIDCount;
int16_t _scanCount;
uint8_t _connectCh;
unsigned long _connectTimeout; unsigned long _connectTimeout;
unsigned long _portalAccessPeriod; unsigned long _portalAccessPeriod;

@ -40,8 +40,9 @@ const char AutoConnect::_CSS_BASE[] PROGMEM = {
"}" "}"
".base-panel>*>label{" ".base-panel>*>label{"
"display:inline-block;" "display:inline-block;"
"width:3.0em;" "font-size:0.9em;"
"text-align:right;" "margin-left:10px;"
"text-align:left;"
"}" "}"
"input{" "input{"
"-moz-appearance:none;" "-moz-appearance:none;"
@ -119,10 +120,10 @@ const char AutoConnect::_CSS_UL[] PROGMEM = {
const char AutoConnect::_CSS_ICON_LOCK[] PROGMEM = { const char AutoConnect::_CSS_ICON_LOCK[] PROGMEM = {
".img-lock{" ".img-lock{"
"display:inline-block;" "display:inline-block;"
"width:24px;" "width:22px;"
"height:24px;" "height:22px;"
"margin-left:12px;" "margin-top:14px;"
"vertical-align:middle;" "float:right;"
"background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAB1ElEQVRIibWVu0scURTGf3d2drBQFAWbbRQVCwuVLIZdi2gnWIiF/4GtKyuJGAJh8mgTcU0T8T8ICC6kiIVu44gvtFEQQWwsbExQJGHXmZtiZsOyzCN3Vz+4cDjfvec7j7l3QAF95onRZ54YKmdE1IbnS0c9mnAyAjkBxDy3LRHrjtRyu7OD52HntTAyvbw/HxP2hkCearrRb2WSCSuTTGi60S+QpzFhbwznDl/VVMHw0sF7hEjFbW2qkB38lfp8nNDipWcATil+uDM3cDWyeNRSijnfkHJnezb5Vkkgvbg3IOXD2e1ts93S+icnkZOAVaalZK3YQMa4L+pC6L1WduhYSeCf0PLBdxzOjZ93Lwvm6APAiLmlF1ubPiHotmaS41ExQjH0ZbfNM1NAFpgD0lVcICIrANqAVaAd+AFIYAy4BqaBG+Wsq5AH3vgk8xpYrzf4KLAZwhe8PYEIvQe4vc6H8Hnc2dQs0AFchvAXQGdEDF8s4A5TZS34BQqqQNaS1WMI3KD4WUbNoBJfce9CO7BSr4BfBe8A21vmUwh0VdjdTyHwscL+UK+AHxoD7FDoAX6/Cnpxn4ay/egCjcCL/w1chkqLakLQ/6ABhT57uAd+Vzv/Ara3iY6fK4WxAAAAAElFTkSuQmCC) no-repeat;" "background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAB1ElEQVRIibWVu0scURTGf3d2drBQFAWbbRQVCwuVLIZdi2gnWIiF/4GtKyuJGAJh8mgTcU0T8T8ICC6kiIVu44gvtFEQQWwsbExQJGHXmZtiZsOyzCN3Vz+4cDjfvec7j7l3QAF95onRZ54YKmdE1IbnS0c9mnAyAjkBxDy3LRHrjtRyu7OD52HntTAyvbw/HxP2hkCearrRb2WSCSuTTGi60S+QpzFhbwznDl/VVMHw0sF7hEjFbW2qkB38lfp8nNDipWcATil+uDM3cDWyeNRSijnfkHJnezb5Vkkgvbg3IOXD2e1ts93S+icnkZOAVaalZK3YQMa4L+pC6L1WduhYSeCf0PLBdxzOjZ93Lwvm6APAiLmlF1ubPiHotmaS41ExQjH0ZbfNM1NAFpgD0lVcICIrANqAVaAd+AFIYAy4BqaBG+Wsq5AH3vgk8xpYrzf4KLAZwhe8PYEIvQe4vc6H8Hnc2dQs0AFchvAXQGdEDF8s4A5TZS34BQqqQNaS1WMI3KD4WUbNoBJfce9CO7BSr4BfBe8A21vmUwh0VdjdTyHwscL+UK+AHxoD7FDoAX6/Cnpxn4ay/egCjcCL/w1chkqLakLQ/6ABhT57uAd+Vzv/Ara3iY6fK4WxAAAAAElFTkSuQmCC) no-repeat;"
"}" "}"
}; };
@ -141,7 +142,7 @@ const char AutoConnect::_CSS_INPUT_BUTTON[] PROGMEM = {
"input[type=\"button\"]{" "input[type=\"button\"]{"
"background-color:#1b5e20;" "background-color:#1b5e20;"
"border-color:#1b5e20;" "border-color:#1b5e20;"
"width:16em;" "width:15em;"
"}" "}"
".aux-page input[type=\"button\"]{" ".aux-page input[type=\"button\"]{"
"font-weight:normal;" "font-weight:normal;"
@ -514,7 +515,7 @@ const char AutoConnect::_ELM_MENU_PRE[] PROGMEM = {
"<ul class=\"luxbar-navigation\">" "<ul class=\"luxbar-navigation\">"
"<li class=\"luxbar-header\">" "<li class=\"luxbar-header\">"
"<a href=\"" AUTOCONNECT_URI "\" class=\"luxbar-brand\">MENU_TITLE</a>" "<a href=\"" AUTOCONNECT_URI "\" class=\"luxbar-brand\">MENU_TITLE</a>"
"<label class=\"luxbar-hamburger luxbar-hamburger-doublespin\" id=\"luxbar-hamburger\" for=\"luxbar-checkbox\"><span></span></label>" "<label class=\"luxbar-hamburger luxbar-hamburger-doublespin\" id=\"luxbar-hamburger\" for=\"luxbar-checkbox\"></label>"
"</li>" "</li>"
"<li class=\"luxbar-item\"><a href=\"" AUTOCONNECT_URI_CONFIG "\">Configure new AP</a></li>" "<li class=\"luxbar-item\"><a href=\"" AUTOCONNECT_URI_CONFIG "\">Configure new AP</a></li>"
"<li class=\"luxbar-item\"><a href=\"" AUTOCONNECT_URI_OPEN "\">Open SSIDs</a></li>" "<li class=\"luxbar-item\"><a href=\"" AUTOCONNECT_URI_OPEN "\">Open SSIDs</a></li>"
@ -1097,13 +1098,13 @@ String AutoConnect::_token_LIST_SSID(PageArgument& args) {
String ssidList = String(""); String ssidList = String("");
_hiddenSSIDCount = 0; _hiddenSSIDCount = 0;
WiFi.scanDelete(); WiFi.scanDelete();
int8_t nn = WiFi.scanNetworks(false, true); _scanCount = WiFi.scanNetworks(false, true);
AC_DBG("%d network(s) found\n", (int)nn); AC_DBG("%d network(s) found\n", (int)_scanCount);
for (uint8_t i = 0; i < nn; i++) { for (uint8_t i = 0; i < _scanCount; i++) {
String ssid = WiFi.SSID(i); String ssid = WiFi.SSID(i);
if (ssid.length() > 0) { if (ssid.length() > 0) {
ssidList += String(F("<input type=\"button\" onClick=\"document.getElementById('ssid').value=this.getAttribute('value');document.getElementById('passphrase').focus()\" value=\"")) + ssid + String("\">"); ssidList += String(F("<input type=\"button\" onClick=\"document.getElementById('ssid').value=this.getAttribute('value');document.getElementById('passphrase').focus()\" value=\"")) + ssid + String("\">");
ssidList += String(F("<label>")) + String(AutoConnect::_toWiFiQuality(WiFi.RSSI(i))) + String(F("&#037;</label>")); ssidList += String(F("<label>")) + String(AutoConnect::_toWiFiQuality(WiFi.RSSI(i))) + String(F("&#037;&ensp;Ch.")) + String(WiFi.channel(i)) + String(F("</label>"));
if (WiFi.encryptionType(i) != ENC_TYPE_NONE) if (WiFi.encryptionType(i) != ENC_TYPE_NONE)
ssidList += String(F("<span class=\"img-lock\"></span>")); ssidList += String(F("<span class=\"img-lock\"></span>"));
ssidList += String(F("<br>")); ssidList += String(F("<br>"));
@ -1125,12 +1126,11 @@ String AutoConnect::_token_OPEN_SSID(PageArgument& args) {
struct station_config entry; struct station_config entry;
String ssidList; String ssidList;
String rssiSym; String rssiSym;
int16_t wn;
uint8_t creEntries = credit.entries(); uint8_t creEntries = credit.entries();
if (creEntries > 0) { if (creEntries > 0) {
ssidList = String(""); ssidList = String("");
wn = WiFi.scanNetworks(false, true); _scanCount = WiFi.scanNetworks(false, true);
} }
else else
ssidList = String(F("<p><b>No saved credentials.</b></p>")); ssidList = String(F("<p><b>No saved credentials.</b></p>"));
@ -1140,9 +1140,10 @@ String AutoConnect::_token_OPEN_SSID(PageArgument& args) {
AC_DBG("A credential #%d loaded\n", (int)i); AC_DBG("A credential #%d loaded\n", (int)i);
ssidList += String(F("<input id=\"sb\" type=\"submit\" name=\"" AUTOCONNECT_PARAMID_CRED "\" value=\"")) + String(reinterpret_cast<char*>(entry.ssid)) + String(F("\"><label>")); ssidList += String(F("<input id=\"sb\" type=\"submit\" name=\"" AUTOCONNECT_PARAMID_CRED "\" value=\"")) + String(reinterpret_cast<char*>(entry.ssid)) + String(F("\"><label>"));
rssiSym = String(F("N/A</label>")); rssiSym = String(F("N/A</label>"));
for (int8_t sc = 0; sc < wn; sc++) { for (int8_t sc = 0; sc < (int8_t)_scanCount; sc++) {
if (!memcmp(entry.bssid, WiFi.BSSID(sc), sizeof(station_config::bssid))) { if (!memcmp(entry.bssid, WiFi.BSSID(sc), sizeof(station_config::bssid))) {
rssiSym = String(AutoConnect::_toWiFiQuality(WiFi.RSSI(sc))) + String(F("&#037;</label>")); _connectCh = WiFi.channel(sc);
rssiSym = String(AutoConnect::_toWiFiQuality(WiFi.RSSI(sc))) + String(F("&#037;&ensp;Ch.")) + String(_connectCh) + String(F("</label>"));
if (WiFi.encryptionType(sc) != ENC_TYPE_NONE) if (WiFi.encryptionType(sc) != ENC_TYPE_NONE)
rssiSym += String(F("<span class=\"img-lock\"></span>")); rssiSym += String(F("<span class=\"img-lock\"></span>"));
break; break;

Loading…
Cancel
Save