Skip to content

Commit

Permalink
Add WiFi scan task
Browse files Browse the repository at this point in the history
  • Loading branch information
nochkin committed Jan 11, 2025
1 parent b1fe71a commit ab0568a
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/common_tasks_esp32.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
void ws2812_task(void *task);
void led_task(void *task);
void info_task(void *task);
void wifi_task(void *task);
26 changes: 26 additions & 0 deletions src/common_tasks_esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <Arduino.h>
#include <FastLED.h>
#include <WiFi.h>

void ws2812_task(void *task) {
uint8_t led_pin = (uint32_t)task & 0xff;
Expand Down Expand Up @@ -69,4 +70,29 @@ void info_task(void *task) {
vTaskDelete(NULL);
}

void wifi_task(void *task) {
log_d("WiFi task");

WiFi.mode(WIFI_STA);
WiFi.disconnect();

vTaskDelay(pdMS_TO_TICKS(1000));
int16_t count = WiFi.scanNetworks();
if (count == 0) {
log_v("No WiFI APs found");
} else {
for (int16_t ii=0; ii<count; ii++) {
log_v("%02d: %s (%d dBm) %s [BSSID: %s]",
ii+1,
WiFi.SSID(ii).c_str(),
WiFi.RSSI(ii),
WiFi.encryptionType(ii) == WIFI_AUTH_OPEN ? "Open" : "Protected",
WiFi.BSSIDstr(ii).c_str()
);
}
}

vTaskDelete(NULL);
}

#endif
1 change: 1 addition & 0 deletions src/main_esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

void setup_custom() {
xTaskCreate(info_task, "info", CONFIG_ARDUINO_LOOP_STACK_SIZE, NULL, 10, NULL);
xTaskCreate(wifi_task, "wifi", CONFIG_ARDUINO_LOOP_STACK_SIZE, NULL, 10, NULL);
}

void loop_custom() {
Expand Down
3 changes: 2 additions & 1 deletion src/main_esp32_tdisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class LGFX_TDisplay : public lgfx::LGFX_Device
LGFX_TDisplay tft;
uint32_t lv_width = LV_HOR_RES;
uint32_t lv_height = LV_VER_RES;
uint8_t disp_buf[240 * 50 * sizeof(lv_color_t)];
uint8_t disp_buf[240 * 15 * sizeof(lv_color_t)];

static void disp_flush(lv_display_t *disp, const lv_area_t *area, unsigned char *color_p) {
uint32_t w = lv_area_get_width(area);
Expand Down Expand Up @@ -137,6 +137,7 @@ void setup_custom() {
// lv_demo_benchmark();

xTaskCreate(info_task, "info", CONFIG_ARDUINO_LOOP_STACK_SIZE, NULL, 10, NULL);
xTaskCreate(wifi_task, "wifi", CONFIG_ARDUINO_LOOP_STACK_SIZE, NULL, 10, NULL);
xTaskCreate(loop_task, "loop", CONFIG_ARDUINO_LOOP_STACK_SIZE, NULL, 10, NULL);
}

Expand Down
1 change: 1 addition & 0 deletions src/main_esp32c3_supermini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

void setup_custom() {
xTaskCreate(info_task, "info", CONFIG_ARDUINO_LOOP_STACK_SIZE, NULL, 10, NULL);
xTaskCreate(wifi_task, "wifi", CONFIG_ARDUINO_LOOP_STACK_SIZE, NULL, 10, NULL);
xTaskCreate(led_task, "led", CONFIG_ARDUINO_LOOP_STACK_SIZE, (void*)MY_LED_PIN, 10, NULL);
}

Expand Down
1 change: 1 addition & 0 deletions src/main_esp32c6_supermini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

void setup_custom() {
xTaskCreate(info_task, "info", CONFIG_ARDUINO_LOOP_STACK_SIZE, NULL, 10, NULL);
xTaskCreate(wifi_task, "wifi", CONFIG_ARDUINO_LOOP_STACK_SIZE, NULL, 10, NULL);
xTaskCreate(ws2812_task, "ws2812", CONFIG_ARDUINO_LOOP_STACK_SIZE, (void*)MY_WS2812_PIN, 10, NULL);
}

Expand Down
1 change: 1 addition & 0 deletions src/main_esp32s3_n16r8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

void setup_custom() {
xTaskCreate(info_task, "info", CONFIG_ARDUINO_LOOP_STACK_SIZE, NULL, 10, NULL);
xTaskCreate(wifi_task, "wifi", CONFIG_ARDUINO_LOOP_STACK_SIZE, NULL, 10, NULL);
xTaskCreate(ws2812_task, "ws2812", CONFIG_ARDUINO_LOOP_STACK_SIZE, (void*)MY_WS2812_PIN, 10, NULL);
}

Expand Down
1 change: 1 addition & 0 deletions src/main_esp32s3_n8r2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

void setup_custom() {
xTaskCreate(info_task, "info", CONFIG_ARDUINO_LOOP_STACK_SIZE, NULL, 10, NULL);
xTaskCreate(wifi_task, "wifi", CONFIG_ARDUINO_LOOP_STACK_SIZE, NULL, 10, NULL);
xTaskCreate(ws2812_task, "ws2812", CONFIG_ARDUINO_LOOP_STACK_SIZE, (void*)MY_WS2812_PIN, 10, NULL);
}

Expand Down
1 change: 1 addition & 0 deletions src/main_esp32s3_supermini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

void setup_custom() {
xTaskCreate(info_task, "info", CONFIG_ARDUINO_LOOP_STACK_SIZE, NULL, 10, NULL);
xTaskCreate(wifi_task, "wifi", CONFIG_ARDUINO_LOOP_STACK_SIZE, NULL, 10, NULL);
xTaskCreate(ws2812_task, "ws2812", CONFIG_ARDUINO_LOOP_STACK_SIZE, (void*)MY_WS2812_PIN, 10, NULL);
}

Expand Down

0 comments on commit ab0568a

Please sign in to comment.