31 lines
937 B
C++
31 lines
937 B
C++
// Two files from firmware/src/hw, reproduced verbatim: WiFiMgr.hpp (the
|
|
// interface) and WiFiMgr.cpp (the implementation). The boundary is marked.
|
|
// WiFiMgr.hpp — the interface the rest of the firmware depends on
|
|
// WiFiMgr.hpp
|
|
#pragma once
|
|
#include <Arduino.h>
|
|
|
|
namespace WiFiMgr {
|
|
bool connectHome(const char* ssid, const char* psk, uint32_t timeoutMs = 15000);
|
|
void disconnect();
|
|
}
|
|
// WiFiMgr.cpp — the only translation unit that includes <WiFi.h>
|
|
// WiFiMgr.cpp
|
|
#include "WiFiMgr.hpp"
|
|
#include <WiFi.h> // ESP32 WiFi
|
|
|
|
namespace WiFiMgr {
|
|
bool connectHome(const char* ssid, const char* psk, uint32_t timeoutMs) {
|
|
WiFi.mode(WIFI_STA);
|
|
WiFi.begin(ssid, psk);
|
|
uint32_t t0 = millis();
|
|
while (WiFi.status() != WL_CONNECTED && millis() - t0 < timeoutMs) {
|
|
delay(200);
|
|
}
|
|
return WiFi.status() == WL_CONNECTED;
|
|
}
|
|
void disconnect() {
|
|
WiFi.disconnect(true, true);
|
|
WiFi.mode(WIFI_OFF);
|
|
}
|
|
} |