Skip to content

Commit 02cfda3

Browse files
committed
improving the scanning functionality
1 parent 0db3052 commit 02cfda3

File tree

8 files changed

+41
-23
lines changed

8 files changed

+41
-23
lines changed

components/web_server/www/html/js/functions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
---
3-
var version="1.0.0_beta",
3+
var version="1.1.0",
44
sL = getE('spinner-container'),
55
notification = getE("notification"),
66
themeColor = getComputedStyle(document.body),

components/web_server/www/html/js/scan.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ var table = document.getElementsByTagName('table')[0],
44
networkInfo = getE('networksFound'),
55
scanInfo = getE('spinner-container'),
66
apMAC = getE('apMAC'),
7-
startStopScan = getE('startStopScan'),
87
selectAll = getE('selectAll'),
98
ssid = getE("ssid"),
109
password = getE("password"),
@@ -13,13 +12,16 @@ var table = document.getElementsByTagName('table')[0],
1312
selectedApElement = -1,
1413
previousCall = new Date().getTime(),
1514
url = window.location.href,
16-
wifiIndicator, securityState, res;
15+
wifiIndicator, securityState,
16+
scanning = false, res;
1717

1818
function toggleScan(onoff) {
1919
if (onoff) {
2020
showLoading("hide");
21+
scanning = false;
2122
} else {
2223
showLoading();
24+
scanning = true;
2325
}
2426
}
2527

@@ -54,10 +56,11 @@ function getStatus(enc, hid) {
5456
return buff
5557
}
5658
function scan() {
59+
if (scanning) return;
5760
toggleScan(false);
5861
getResponse('{% if jekyll.environment == "development" %}APScanResults.json{% else %}data/APScanResults.json{% endif %}', function (responseText, status) {
59-
6062
try {
63+
if (responseText == "false") return setTimeout(function () { scanning = false;scan(); }, 1000);
6164
res = JSON.parse(responseText);
6265
log("RESPONSE ~ ", res, true)
6366
notify();
@@ -66,6 +69,7 @@ function scan() {
6669
log("INVALID ~ ", responseText, false)
6770
console.error(err)
6871
notify('{% t scan.messages.E0 %} (E0)');
72+
scanning = false;
6973
return
7074
}
7175
res.aps = res.aps.sort(compare);
@@ -148,15 +152,15 @@ function connect() {
148152
if (responseText == "true") {
149153
indicate(true);
150154
restart(true);
151-
notify("{% t scan.messages.E2 %} (E2)",2000);
155+
notify("{% t scan.messages.E2 %} (E2)", 2000);
152156
} else {
153157
indicate(false);
154158
notify("{% t scan.messages.E3 %} (E3)");
155159
}
156-
},function(){
160+
}, function () {
157161
ndicate(false);
158162
notify("{% t scan.messages.E4 %} (E4)");
159-
},null,"POST");
163+
}, null, "POST");
160164
}
161165

162166

-3 Bytes
Binary file not shown.
43 Bytes
Binary file not shown.

components/wifi_handler/wifi_event_handler.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,28 @@ static const char *TAG = "wifi_event_handler";
2828
EventGroupHandle_t wifi_event_group;
2929
const int WIFI_CONNECTED_BIT = BIT0;
3030

31+
#define WIFI_RETRY_COUNT 3
32+
#define WIFI_RETRY_DELAY_MAX 8000
33+
static int wifi_retry_count = 0;
34+
3135
void wifi_retry_handler(void)
3236
{
33-
ESP_LOGI(TAG, "Retrying WiFi connection");
34-
// Retry the WiFi connection
35-
esp_wifi_scan_stop();
36-
esp_wifi_disconnect();
37-
esp_wifi_connect();
38-
xEventGroupClearBits(wifi_event_group, WIFI_CONNECTED_BIT);
37+
if (wifi_retry_count < WIFI_RETRY_COUNT)
38+
{
39+
ESP_LOGI(TAG, "Retrying WiFi connection (%d/%d)", wifi_retry_count + 1, WIFI_RETRY_COUNT);
40+
esp_wifi_scan_stop();
41+
esp_wifi_disconnect();
42+
esp_wifi_connect();
43+
wifi_retry_count++;
44+
}
45+
else
46+
{
47+
vTaskDelay(WIFI_RETRY_DELAY_MAX / portTICK_PERIOD_MS);
48+
ESP_LOGW(TAG, "Maximum number of WiFi connection retries reached (%d)", WIFI_RETRY_COUNT);
49+
wifi_retry_count = 0;
50+
wifi_retry_handler();
51+
}
3952
}
40-
41-
//-----------------------------------------------------------------------------
42-
// Disconnect handler for wifi connection
4353
static void wifi_disconnect_handler(const uint8_t reason)
4454
{
4555
switch (reason)

components/wifi_handler/wifi_handler.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ char *wifi_scan_handler(void)
3737
.scan_type = WIFI_SCAN_TYPE_ACTIVE,
3838
};
3939
printf("Start scanning...\n");
40-
ESP_ERROR_CHECK(esp_wifi_scan_start(&scan_config, true));
41-
printf(" completed!\n");
40+
esp_err_t err = esp_wifi_scan_start(&scan_config, true);
41+
if (err != ESP_OK)
42+
{
43+
return "false";
44+
printf("scanning Failed!\n");
45+
}
46+
printf("scanning completed!\n");
4247
// Get the number of access points found
4348

4449
uint16_t ap_num;

components/wifi_handler/wifi_init.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,7 @@ void wifi_init()
127127
// Enable DNS (offer) for dhcp server
128128
dhcps_offer_t dhcps_dns_value = OFFER_DNS;
129129
dhcps_set_option_info(6, &dhcps_dns_value, sizeof(dhcps_dns_value));
130-
131-
xEventGroupWaitBits(wifi_event_group, WIFI_CONNECTED_BIT,
132-
pdFALSE, pdTRUE, JOIN_TIMEOUT_MS / portTICK_PERIOD_MS);
133-
// vTaskDelay(2000 / portTICK_PERIOD_MS);
130+
134131
ESP_ERROR_CHECK(esp_wifi_start());
135132

136133
if (strlen(ssid) > 0)
@@ -142,6 +139,8 @@ void wifi_init()
142139
{
143140
ESP_LOGI(TAG, "wifi_init_ap with default finished.");
144141
}
142+
xEventGroupWaitBits(wifi_event_group, WIFI_CONNECTED_BIT,
143+
pdFALSE, pdFALSE, JOIN_TIMEOUT_MS / portTICK_PERIOD_MS);
145144
}
146145

147146
//-----------------------------------------------------------------------------

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
[extra_script_settings]
13-
version = 1.0.0_beta ; Set the version to the project
13+
version = 1.1.0 ; Set the version to the project
1414
merge_to_single_bin = 1 ; (0 = disable) Enable the conversion of a multiple bins to single bin file of 0x0 format
1515

1616

0 commit comments

Comments
 (0)