documentation checked and edit

for all files in lib folder
This commit is contained in:
2023-10-12 18:45:12 +02:00
parent 61a95e4601
commit db74898b72
41 changed files with 1030 additions and 569 deletions
+13 -13
View File
@@ -21,18 +21,18 @@ Network::Network(const char *ssid, const char *passphrase)
this->init(ssid, passphrase);
}
Network::Network(const char *ssid, const char *passphrase, NetworkAdresses adresses)
: adresses{adresses}
Network::Network(const char *ssid, const char *passphrase, NetworkAddresses adresses)
: addresses{adresses}
{
if (!WiFiGenericClass::mode(WIFI_AP_STA))
{
std::cout << "Network::connectWiFi failed WiFi.mode" << std::endl;
}
if (!WiFi.config(this->adresses.localIP,
this->adresses.gateway,
this->adresses.subnet,
this->adresses.dnsServer))
if (!WiFi.config(this->addresses.localIP,
this->addresses.gateway,
this->addresses.subnet,
this->addresses.dnsServer))
{
std::cout << "STA Failed to configure" << std::endl;
}
@@ -45,7 +45,7 @@ Network::~Network()
delete mqttClient;
}
bool Network::activateEspNow(recieveCallbackPtr reci, sendCallbackPtr send)
bool Network::activateEspNow(receiveCallbackPtr reci, sendCallbackPtr send)
{
if (esp_now_init() != ESP_OK)
{
@@ -76,7 +76,7 @@ bool Network::activateMqtt(const char *user, const char *passphrase)
this->mqttPassphrase = passphrase;
this->mqttClient = new PubSubClient(this->wifiClient);
this->mqttClient->setServer(this->adresses.mqttServer, this->adresses.mqttPort);
this->mqttClient->setServer(this->addresses.mqttServer, this->addresses.mqttPort);
this->mqttClient->setSocketTimeout(1);
if (this->wifiConnected)
@@ -116,7 +116,7 @@ uint8_t Network::getCurrentChannel()
void Network::runAsChild()
{
if (!this->initSucessful)
if (!this->initSuccessful)
{
return;
}
@@ -154,21 +154,21 @@ void Network::init(const char *ssid, const char *passphrase)
void Network::checkWifi()
{
if ((WiFiSTAClass::status() != WL_CONNECTED) && (millis() - this->lastWifiRecoonectAttemp >= Network::wifiReconnectDelay))
if ((WiFiSTAClass::status() != WL_CONNECTED) && (millis() - this->lastWifiReconnectAttempt >= Network::wifiReconnectDelay))
{
std::cout << "Reconnecting to WiFi..." << std::endl;
WiFi.disconnect();
this->wifiConnected = WiFi.reconnect();
this->lastWifiRecoonectAttemp = millis();
this->lastWifiReconnectAttempt = millis();
}
}
void Network::checkMqtt()
{
if (!this->mqttClient->connected() && millis() - this->lastMqttReconnectAttemp > Network::mqttReconnectDelay)
if (!this->mqttClient->connected() && millis() - this->lastMqttReconnectAttempt > Network::mqttReconnectDelay)
{
this->mqttConnected = this->connectMqtt();
this->lastMqttReconnectAttemp = millis();
this->lastMqttReconnectAttempt = millis();
}
if (this->mqttConnected)
+59 -8
View File
@@ -20,10 +20,20 @@
#include <esp_now.h>
#include <esp_wifi.h>
typedef void (*recieveCallbackPtr)(const uint8_t *mac, const uint8_t *incomingData, int len);
/**
* @brief Typedef to easy handle the receive Callback
*/
typedef void (*receiveCallbackPtr)(const uint8_t *mac, const uint8_t *incomingData, int len);
/**
* @brief Typedef to easy handle the send Callback
*/
typedef void (*sendCallbackPtr)(const uint8_t *mac_addr, esp_now_send_status_t status);
struct NetworkAdresses
/**
* @brief A Struct to hold all network addresses
*/
struct NetworkAddresses
{
IPAddress localIP;
IPAddress gateway;
@@ -33,17 +43,58 @@ struct NetworkAdresses
uint16_t mqttPort = 1883;
};
/**
* @brief A class to manage the wireless connections
*/
class Network : public Component
{
public:
/**
* @brief Construct a new Network object
*
* With this constructor the esp gets its ip from a Dhcp server
*
* @param ssid
* @param passphrase
*/
Network(const char *ssid, const char *passphrase);
Network(const char *ssid, const char *passphrase, NetworkAdresses adresses);
/**
* @brief Construct a new Network object
*
* This constructor is used for a static ip setup
*
* @param ssid
* @param passphrase
* @param addresses
*/
Network(const char *ssid, const char *passphrase, NetworkAddresses addresses);
~Network();
bool activateEspNow(recieveCallbackPtr reci, sendCallbackPtr send);
/**
* @brief Activate ESP-NOW to communicate with the remote Control
*
* @param receive
* @param send
* @return true
* @return false
*/
bool activateEspNow(receiveCallbackPtr receive, sendCallbackPtr send);
/**
* @brief Activate MQTT to send debug messages
*
* @param user
* @param passphrase
* @return true
* @return false
*/
bool activateMqtt(const char *user = nullptr, const char *passphrase = nullptr);
/**
* @brief Print the current used IPs
*/
const void printIPs();
bool isWifiConnected() const { return this->wifiConnected; }
@@ -61,11 +112,11 @@ private:
void checkMqtt();
bool connectMqtt();
NetworkAdresses adresses;
NetworkAddresses addresses;
WiFiClient wifiClient;
PubSubClient *mqttClient = nullptr;
bool initSucessful = false;
bool initSuccessful = false;
bool wifiConnected = false;
bool mqttConnected = false;
@@ -73,8 +124,8 @@ private:
const char *mqttPassphrase = nullptr;
uint8_t broadcastAddress[6] = {0xC8, 0xC9, 0xA3, 0xC8, 0x57, 0x10};
uint32_t lastWifiRecoonectAttemp = 0;
uint32_t lastMqttReconnectAttemp = 0;
uint32_t lastWifiReconnectAttempt = 0;
uint32_t lastMqttReconnectAttempt = 0;
static constexpr uint8_t wifiConnectTimeout = 20;
static constexpr uint16_t wifiConnectLoopTime = 500;