89 lines
2.2 KiB
C++
89 lines
2.2 KiB
C++
/*
|
|
* SPDX-FileCopyrightText: 2023 Sascha Nitsch (@grumpydevelop@contentnation.net) https://contentnation.net/en/grumpydevelop
|
|
*
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*/
|
|
|
|
#ifndef WLANMANAGER_H_
|
|
#define WLANMANAGER_H_
|
|
#include <DNSServer.h>
|
|
|
|
/**
|
|
* \class WLANManager
|
|
* \brief manager for and connecting to WLAN
|
|
*/
|
|
class WLANManager {
|
|
public:
|
|
/// \brief constructor
|
|
WLANManager();
|
|
|
|
/// \brief set SSID and password
|
|
/// \param ssid SSID to set
|
|
/// \param password password to set
|
|
void setSSID(const char* ssid, const char* password);
|
|
|
|
/// \brief load config from given file
|
|
/// \param filename file name of config file
|
|
void loadConfigFromFile(const char* filename);
|
|
|
|
/// \brief start WLAN
|
|
void start();
|
|
|
|
/// \brief set mode to access point (true) or client (false)
|
|
/// \param isAccessPoint true if we are an access point
|
|
void setAccessPoint(bool isAccessPoint);
|
|
|
|
/// \brief are we an access point?
|
|
/// \return true if we are
|
|
bool isAccessPoint() const;
|
|
|
|
/// \brief save configuration
|
|
/// \param filename filename of config file
|
|
void save(const char* filename);
|
|
|
|
/// \brief connect to an access point
|
|
/// \param ssid ssid of AP
|
|
/// \param pass password of AP
|
|
/// \param callbal function to be called if connected
|
|
/// \retval true on success
|
|
bool connectToAp(const char* ssid, const char* pass, std::function<void()> callback);
|
|
|
|
/// \brief get SSID
|
|
/// \return current SSID
|
|
const char* getSSID() const;
|
|
|
|
/// \brief open access point
|
|
void openAP();
|
|
|
|
/// \brief internal loop, need to be called from main loop
|
|
void loop();
|
|
|
|
/// \brief get current IP
|
|
/// \return current IP
|
|
uint32_t getIP() const;
|
|
|
|
private:
|
|
/// \brief parse input and search for next semicolon
|
|
/// \param start start offset. Input string will be modified
|
|
/// \return pointer to char after semicolor or NULL if not found
|
|
char* nextSemi(char* start);
|
|
|
|
/// \brief wait for connection to access point
|
|
/// \return WLAN status
|
|
uint8_t waitForConnectResult();
|
|
|
|
/// pointer to our dns server
|
|
DNSServer* m_dnsServer;
|
|
|
|
/// are we an access point
|
|
bool m_isAccessPoint;
|
|
|
|
/// our ssid
|
|
char m_ssid[64];
|
|
|
|
// our password
|
|
char m_password[64];
|
|
};
|
|
|
|
#endif // WLANMANAGER_H_
|