91 lines
2.1 KiB
C++
91 lines
2.1 KiB
C++
/**
|
|
* @file network.h
|
|
* @author Alexander Klein (alex@kleiax.de)
|
|
* @brief Contains the Network class.
|
|
* @version 0.1
|
|
* @date 2021-12-14
|
|
*
|
|
* @copyright Copyright (c) 2021
|
|
*
|
|
*/
|
|
|
|
#ifndef NETWORK_H
|
|
#define NETWORK_H
|
|
|
|
#include <iostream>
|
|
#include <WiFi.h>
|
|
#include <PubSubClient.h>
|
|
|
|
#include "networkConfig.h"
|
|
|
|
/**
|
|
* @brief This class handles all network stuff
|
|
*
|
|
* This class only inherits static functions and members and use
|
|
* only the configuration data is given by networkConfig.h
|
|
*
|
|
*/
|
|
class Network {
|
|
public:
|
|
/**
|
|
* @brief Set the all IPs needed by this class
|
|
*/
|
|
static void setIps();
|
|
|
|
/**
|
|
* @brief Establish a connection to the WiFi.
|
|
*
|
|
* @return true Wifi is connected
|
|
* @return false Timeout
|
|
*/
|
|
static bool connectWifi();
|
|
|
|
/**
|
|
* @brief Set all general settings to connect to a broker.
|
|
*/
|
|
static void setupMQTT();
|
|
|
|
/**
|
|
* @brief Checks if mqtt is still connected
|
|
*
|
|
* If mqtt is not connect, this function try a reconnect
|
|
* with the function connectMQTT. This function should be
|
|
* called every mainloop.
|
|
*/
|
|
static void checkMQTT();
|
|
|
|
/**
|
|
* @brief Checks if WiFi is still connected
|
|
*
|
|
* If WiFi is not connected, this function try a reconnect.
|
|
* This function should be called every mainloop.
|
|
*/
|
|
static void checkWiFi();
|
|
|
|
/**
|
|
* @brief Get the Mqtt Client object
|
|
*
|
|
* @return PubSubClient*
|
|
*/
|
|
static PubSubClient* getMqttClient();
|
|
|
|
private:
|
|
/**
|
|
* @brief Tries a connect to the broker
|
|
*
|
|
* @return true if the connect attemp was successful
|
|
* @return false if the connect attemp was unsuccessful
|
|
*/
|
|
static bool connectMQTT();
|
|
|
|
static IPAddress local_IP;
|
|
static IPAddress gateway;
|
|
static IPAddress subnet;
|
|
static IPAddress mqtt_server;
|
|
|
|
static WiFiClient wifi_client;
|
|
static PubSubClient* mqtt_client;
|
|
};
|
|
|
|
#endif // NETWORK_H
|