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;
_menuTitle = String(F(AUTOCONNECT_MENU_TITLE));
_connectTimeout = AUTOCONNECT_TIMEOUT;
_scanCount = 0;
memset(&_credential, 0x00, sizeof(struct station_config));
#ifdef ARDUINO_ARCH_ESP32
_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;
// Start WiFi connection with station mode.
#if defined(ARDUINO_ARCH_ESP32)
WiFi.softAPdisconnect(false);
#endif
WiFi.enableAP(false);
WiFi.softAPdisconnect(true);
WiFi.mode(WIFI_STA);
delay(100);
@ -446,8 +444,9 @@ void AutoConnect::handleRequest() {
_disconnectWiFi(true);
// An attempt to establish a new AP.
AC_DBG("Request for %s\n", reinterpret_cast<const char*>(_credential.ssid));
WiFi.begin(reinterpret_cast<const char*>(_credential.ssid), reinterpret_cast<const char*>(_credential.password), _apConfig.channel);
int32_t ch = _connectCh == 0 ? _apConfig.channel : _connectCh;
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 (WiFi.BSSID() != NULL) {
memcpy(_credential.bssid, WiFi.BSSID(), sizeof(station_config::bssid));
@ -491,7 +490,7 @@ void AutoConnect::handleRequest() {
if (_rfDisconnect) {
// Disconnect from the current AP.
_waitForEndTransmission();
// _waitForEndTransmission();
_stopPortal();
_disconnectWiFi(false);
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));
}
// 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().
_rfConnect = true;

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

@ -40,8 +40,9 @@ const char AutoConnect::_CSS_BASE[] PROGMEM = {
"}"
".base-panel>*>label{"
"display:inline-block;"
"width:3.0em;"
"text-align:right;"
"font-size:0.9em;"
"margin-left:10px;"
"text-align:left;"
"}"
"input{"
"-moz-appearance:none;"
@ -119,10 +120,10 @@ const char AutoConnect::_CSS_UL[] PROGMEM = {
const char AutoConnect::_CSS_ICON_LOCK[] PROGMEM = {
".img-lock{"
"display:inline-block;"
"width:24px;"
"height:24px;"
"margin-left:12px;"
"vertical-align:middle;"
"width:22px;"
"height:22px;"
"margin-top:14px;"
"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;"
"}"
};
@ -141,7 +142,7 @@ const char AutoConnect::_CSS_INPUT_BUTTON[] PROGMEM = {
"input[type=\"button\"]{"
"background-color:#1b5e20;"
"border-color:#1b5e20;"
"width:16em;"
"width:15em;"
"}"
".aux-page input[type=\"button\"]{"
"font-weight:normal;"
@ -514,7 +515,7 @@ const char AutoConnect::_ELM_MENU_PRE[] PROGMEM = {
"<ul class=\"luxbar-navigation\">"
"<li class=\"luxbar-header\">"
"<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 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>"
@ -1097,13 +1098,13 @@ String AutoConnect::_token_LIST_SSID(PageArgument& args) {
String ssidList = String("");
_hiddenSSIDCount = 0;
WiFi.scanDelete();
int8_t nn = WiFi.scanNetworks(false, true);
AC_DBG("%d network(s) found\n", (int)nn);
for (uint8_t i = 0; i < nn; i++) {
_scanCount = WiFi.scanNetworks(false, true);
AC_DBG("%d network(s) found\n", (int)_scanCount);
for (uint8_t i = 0; i < _scanCount; i++) {
String ssid = WiFi.SSID(i);
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("<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)
ssidList += String(F("<span class=\"img-lock\"></span>"));
ssidList += String(F("<br>"));
@ -1125,12 +1126,11 @@ String AutoConnect::_token_OPEN_SSID(PageArgument& args) {
struct station_config entry;
String ssidList;
String rssiSym;
int16_t wn;
uint8_t creEntries = credit.entries();
if (creEntries > 0) {
ssidList = String("");
wn = WiFi.scanNetworks(false, true);
_scanCount = WiFi.scanNetworks(false, true);
}
else
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);
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>"));
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))) {
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)
rssiSym += String(F("<span class=\"img-lock\"></span>"));
break;

Loading…
Cancel
Save