network is now a component
This commit is contained in:
@@ -1,107 +0,0 @@
|
||||
/**
|
||||
* @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 <esp_now.h>
|
||||
#include <esp_wifi.h>
|
||||
|
||||
#include "networkConfig.h"
|
||||
|
||||
typedef void (*recieveCallbackPtr) (const uint8_t * mac, const uint8_t *incomingData, int len);
|
||||
typedef void (*sendCallbackPtr) (const uint8_t *mac_addr, esp_now_send_status_t status);
|
||||
|
||||
/**
|
||||
* @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();
|
||||
static bool connectEspNow(recieveCallbackPtr reci, sendCallbackPtr send);
|
||||
static uint8_t getCurrentChannel();
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
* @return true if connected
|
||||
* @return false if not connected
|
||||
*/
|
||||
static bool checkMQTT();
|
||||
static bool initMQTT();
|
||||
|
||||
/**
|
||||
* @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();
|
||||
static const uint8_t * getBroadcastAddress() { return broadcastAddress; }
|
||||
|
||||
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 int32_t getWiFiChannel(const char *ssid);
|
||||
|
||||
static esp_now_peer_info_t peerInfo;
|
||||
static uint8_t broadcastAddress[6];
|
||||
|
||||
static IPAddress local_IP;
|
||||
static IPAddress gateway;
|
||||
static IPAddress subnet;
|
||||
static IPAddress mqtt_server;
|
||||
static IPAddress dnsServer;
|
||||
|
||||
static WiFiClient wifi_client;
|
||||
static PubSubClient* mqtt_client;
|
||||
};
|
||||
|
||||
#endif // NETWORK_H
|
||||
+33
-80
@@ -12,94 +12,47 @@
|
||||
*
|
||||
*/
|
||||
|
||||
// General config
|
||||
#define MQTT_TIME_RECONNECT 2500
|
||||
|
||||
/**
|
||||
* @brief Wlan connect timeout
|
||||
*
|
||||
* This number multiplied by WLAN_CONNECT_LOOP_TIME is the
|
||||
* timeout in milliseconds.
|
||||
*/
|
||||
#define WLAN_CONNECT_TIMEOUT 20
|
||||
|
||||
/**
|
||||
* @brief Wlan connect loop time
|
||||
*
|
||||
* The time in milliseconds until the next connection attempt.
|
||||
*/
|
||||
#define WLAN_CONNECT_LOOP_TIME 500
|
||||
#define WLAN_DNS_SERVER "8.8.8.8"
|
||||
#define ESP_NOW_CONTROLER_MAC {0xC8, 0xC9, 0xA3, 0xC8, 0x57, 0x10}
|
||||
|
||||
#define NTRIP_RTK2GO
|
||||
|
||||
// NTRIP config NRW
|
||||
#ifdef NTRIP_NRW
|
||||
#define NTRIP_HOST "www.sapos-nw-ntrip.de"
|
||||
#define NTRIP_PORT 2101
|
||||
#define NTRIP_MOUNT_POINT "VRS_3_3G_NW"
|
||||
#define NTRIP_USER "nw-916771"
|
||||
#define NTRIP_PASSWORD "Schalke#246"
|
||||
#endif // NTRIP_NRW
|
||||
|
||||
// NTRIP config NS
|
||||
#ifdef NTRIP_NS
|
||||
#define NTRIP_HOST "openservice-sapos.niedersachsen.de"
|
||||
#define NTRIP_PORT 2101
|
||||
#define NTRIP_MOUNT_POINT "VRS_3_2G_NI"
|
||||
#define NTRIP_USER "ni_FHDo01"
|
||||
#define NTRIP_PASSWORD "ALdx-1-3e49"
|
||||
#endif // NTRIP_NS
|
||||
|
||||
// NTRIP config RTK2Go
|
||||
#ifdef NTRIP_RTK2GO
|
||||
#define NTRIP_HOST "rtk2go.com"
|
||||
#define NTRIP_PORT 2101
|
||||
#define NTRIP_MOUNT_POINT "GER-Dortmund"
|
||||
#define NTRIP_USER "alklein1@gmx.de"
|
||||
#define NTRIP_PASSWORD "none"
|
||||
#endif // NTRIP_RTK2GO
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define HOTSPOT
|
||||
|
||||
//Network config Hotspot
|
||||
#ifdef HOTSPOT
|
||||
#define WLAN_SSID "Kleiax Handy"
|
||||
#define WLAN_PASSWORD "12345677"
|
||||
#define WLAN_IP "192.168.43.4"
|
||||
#define WLAN_SUBNETMASK "255.255.128.0"
|
||||
#define WLAN_GATEWAY "192.168.43.1"
|
||||
// Only for defines reasons
|
||||
#define MQTT_SERVER "172.22.64.216"
|
||||
#define MQTT_PORT 1883
|
||||
namespace NetworkConfig {
|
||||
const char ssid[] = "Kleiax Handy";
|
||||
const char password[] = "12345677";
|
||||
const char ip[] = "192.168.43.4";
|
||||
const char subnet[] = "255.255.255.0";
|
||||
const char gateway[] = "192.168.43.1";
|
||||
const char dns[] = "8.8.8.8";
|
||||
const bool mqtt = false;
|
||||
}
|
||||
#endif //HOTSPOT
|
||||
|
||||
//Network config Rhede
|
||||
#ifdef RHEDE
|
||||
#define WLAN_SSID "LebennigHuus"
|
||||
#define WLAN_PASSWORD "Punica-699"
|
||||
#define WLAN_IP "192.168.11.4"
|
||||
#define WLAN_SUBNETMASK "255.255.128.0"
|
||||
#define WLAN_GATEWAY "192.168.0.1"
|
||||
#define MQTT
|
||||
#define MQTT_SERVER "192.168.1.7"
|
||||
#define MQTT_PORT 1883
|
||||
#define MQTT_AUTH
|
||||
#define MQTT_USER "kleiax"
|
||||
#define MQTT_PASSWORD "p?{$_~5%hBM7wrcFkr55KWr#"
|
||||
namespace NetworkConfig {
|
||||
const char ssid[] = "LebennigHuus";
|
||||
const char password[] = "Punica-699";
|
||||
const char ip[] = "192.168.11.4";
|
||||
const char subnet[] = "255.255.128.0";
|
||||
const char gateway[] = "192.168.0.1";
|
||||
const char dns[] = "8.8.8.8";
|
||||
const bool mqtt = true;
|
||||
}
|
||||
#endif //RHEDE
|
||||
|
||||
//Network config Doro
|
||||
#ifdef DORO
|
||||
#define WLAN_SSID "Tuedelkram"
|
||||
#define WLAN_PASSWORD "3Kaesehoch!"
|
||||
#define WLAN_IP "192.168.178.4"
|
||||
#define WLAN_SUBNETMASK "255.255.255.0"
|
||||
#define WLAN_GATEWAY "192.168.178.1"
|
||||
// Only for defines reasons
|
||||
#define MQTT_SERVER "172.22.64.216"
|
||||
#define MQTT_PORT 1883
|
||||
#endif //DORO
|
||||
namespace MqttConfig {
|
||||
const char server[] = "192.168.1.7";
|
||||
const uint16_t port = 1883;
|
||||
const char user[] = "kleiax";
|
||||
const char password[] = "p?{$_~5%hBM7wrcFkr55KWr#";
|
||||
}
|
||||
|
||||
namespace NtripConfig {
|
||||
const char host[] = "rtk2go.com";
|
||||
const uint16_t port = 2101;
|
||||
const char mountPoint[] = "GER-Dortmund";
|
||||
// const char mountPoint[] = "GER-Papenburg";
|
||||
const char user[] = "alklein1@gmx.de";
|
||||
const char password[] = "none";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user