From 36575884f3d16518be3b801b8cb50cf7180df453 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Wed, 4 Jan 2023 10:17:06 +0100 Subject: [PATCH] added wifi disable --- src/utils.cpp | 14 ++++++++++---- src/utils.h | 6 ++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/utils.cpp b/src/utils.cpp index 4a79de0..9311ff3 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -113,7 +113,7 @@ std::vector parseCsv(const std::string &csv) { return wasteDates; } -int wifi_setup_impl(uint32_t country, const string &ssid, const string &pw, bool firstTry) { +int wifi_setup(uint32_t country, const string &ssid, const string &pw, bool firstTry) { if (firstTry) { if (cyw43_arch_init_with_country(country)) { return 1; @@ -159,7 +159,7 @@ int wifi_setup_impl(uint32_t country, const string &ssid, const string &pw, bool return status; } -void wifi_setup() { +void wifi_enable() { const string ssid{"Apis cerana"}; const string pw{"2JkJEh2vptVT"}; const uint32_t country{CYW43_COUNTRY_GERMANY}; @@ -168,15 +168,21 @@ void wifi_setup() { int res = -1; do { if (firstTry) { - res = wifi_setup_impl(country, ssid, pw, true); + res = wifi_setup(country, ssid, pw, true); firstTry = false; } else { #ifdef DEBUG printf("Setting up connection failed. Trying again after 5 sec...\n"); #endif sleep_ms(5000); - res = wifi_setup_impl(country, ssid, pw, false); + res = wifi_setup(country, ssid, pw, false); } } while (res != CYW43_LINK_UP); } + +void wifi_disable() { + + cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0); + cyw43_wifi_leave(&cyw43_state, CYW43_ITF_STA); +} \ No newline at end of file diff --git a/src/utils.h b/src/utils.h index 79aa0b5..2c54569 100644 --- a/src/utils.h +++ b/src/utils.h @@ -21,8 +21,10 @@ struct WasteDate { std::vector parseCsv(const std::string &csv); -static int wifi_setup_impl(uint32_t country, const std::string &ssid, const std::string &pw, +static int wifi_setup(uint32_t country, const std::string &ssid, const std::string &pw, bool firstTry = true); -void wifi_setup(); +void wifi_enable(); + +void wifi_disable(); bool isDST(int8_t day, int8_t month, int8_t dow); \ No newline at end of file