added wifi disable

This commit is contained in:
Martin Brodbeck 2023-01-04 10:17:06 +01:00
parent 710f1e815f
commit 36575884f3
2 changed files with 14 additions and 6 deletions

View file

@ -113,7 +113,7 @@ std::vector<WasteDate> 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);
}

View file

@ -21,8 +21,10 @@ struct WasteDate {
std::vector<WasteDate> 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);