mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-04 02:09:30 +02:00
mDNS controlled by run-time variable
This commit is contained in:
parent
5f8eedbacb
commit
efdbbff916
3 changed files with 28 additions and 24 deletions
|
@ -28,15 +28,10 @@
|
||||||
#error \
|
#error \
|
||||||
"Initial setup not completed, USER_SECRETS.h is missing. Please rename the file USER_SECRETS.TEMPLATE.h to USER_SECRETS.h and fill in the required credentials. This file is ignored by version control to keep sensitive information private."
|
"Initial setup not completed, USER_SECRETS.h is missing. Please rename the file USER_SECRETS.TEMPLATE.h to USER_SECRETS.h and fill in the required credentials. This file is ignored by version control to keep sensitive information private."
|
||||||
#endif
|
#endif
|
||||||
|
#include "src/devboard/mqtt/mqtt.h"
|
||||||
#include "src/devboard/webserver/webserver.h"
|
#include "src/devboard/webserver/webserver.h"
|
||||||
#include "src/devboard/wifi/wifi.h"
|
#include "src/devboard/wifi/wifi.h"
|
||||||
|
|
||||||
#ifdef MDNSRESPONDER
|
|
||||||
#include <ESPmDNS.h>
|
|
||||||
#endif // MDNSRESONDER
|
|
||||||
|
|
||||||
#include "src/devboard/mqtt/mqtt.h"
|
|
||||||
|
|
||||||
#ifdef PERIODIC_BMS_RESET_AT
|
#ifdef PERIODIC_BMS_RESET_AT
|
||||||
#include "src/devboard/utils/ntp_time.h"
|
#include "src/devboard/utils/ntp_time.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -183,9 +178,9 @@ void connectivity_loop(void*) {
|
||||||
init_webserver();
|
init_webserver();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MDNSRESPONDER
|
if (mdns_enabled) {
|
||||||
init_mDNS();
|
init_mDNS();
|
||||||
#endif
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
START_TIME_MEASUREMENT(wifi);
|
START_TIME_MEASUREMENT(wifi);
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
|
#include <ESPmDNS.h>
|
||||||
#include "../../include.h"
|
#include "../../include.h"
|
||||||
#include "../utils/events.h"
|
#include "../utils/events.h"
|
||||||
|
|
||||||
#ifdef WIFI
|
#if defined(WIFI) || defined(WEBSERVER)
|
||||||
const bool wifi_enabled_default = true;
|
const bool wifi_enabled_default = true;
|
||||||
#else
|
#else
|
||||||
const bool wifi_enabled_default = false;
|
const bool wifi_enabled_default = false;
|
||||||
|
@ -10,6 +11,21 @@ const bool wifi_enabled_default = false;
|
||||||
|
|
||||||
bool wifi_enabled = wifi_enabled_default;
|
bool wifi_enabled = wifi_enabled_default;
|
||||||
|
|
||||||
|
#ifdef WIFIAP
|
||||||
|
const bool wifiap_enabled_default = true;
|
||||||
|
#else
|
||||||
|
const bool wifiap_enabled_default = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool wifiap_enabled = wifiap_enabled_default;
|
||||||
|
|
||||||
|
#ifdef MDNSRESPONDER
|
||||||
|
const bool mdns_enabled_default = true;
|
||||||
|
#else
|
||||||
|
const bool mdns_enabled_default = false;
|
||||||
|
#endif
|
||||||
|
bool mdns_enabled = mdns_enabled_default;
|
||||||
|
|
||||||
// Configuration Parameters
|
// Configuration Parameters
|
||||||
static const uint16_t WIFI_CHECK_INTERVAL = 2000; // 1 seconds normal check interval when last connected
|
static const uint16_t WIFI_CHECK_INTERVAL = 2000; // 1 seconds normal check interval when last connected
|
||||||
static const uint16_t STEP_WIFI_CHECK_INTERVAL = 2000; // 3 seconds wait step increase in checks for normal reconnects
|
static const uint16_t STEP_WIFI_CHECK_INTERVAL = 2000; // 3 seconds wait step increase in checks for normal reconnects
|
||||||
|
@ -36,12 +52,12 @@ static bool connected_once = false;
|
||||||
|
|
||||||
void init_WiFi() {
|
void init_WiFi() {
|
||||||
|
|
||||||
#ifdef WIFIAP
|
if (!wifiap_enabled) {
|
||||||
WiFi.mode(WIFI_AP_STA); // Simultaneous WiFi AP and Router connection
|
WiFi.mode(WIFI_AP_STA); // Simultaneous WiFi AP and Router connection
|
||||||
init_WiFi_AP();
|
init_WiFi_AP();
|
||||||
#else
|
} else {
|
||||||
WiFi.mode(WIFI_STA); // Only Router connection
|
WiFi.mode(WIFI_AP); // Only AP mode
|
||||||
#endif // WIFIAP
|
}
|
||||||
|
|
||||||
// Set WiFi to auto reconnect
|
// Set WiFi to auto reconnect
|
||||||
WiFi.setAutoReconnect(true);
|
WiFi.setAutoReconnect(true);
|
||||||
|
@ -183,7 +199,6 @@ void onWifiDisconnect(WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||||
//normal reconnect retry start at first 2 seconds
|
//normal reconnect retry start at first 2 seconds
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MDNSRESPONDER
|
|
||||||
// Initialise mDNS
|
// Initialise mDNS
|
||||||
void init_mDNS() {
|
void init_mDNS() {
|
||||||
// Calulate the host name using the last two chars from the MAC address so each one is likely unique on a network.
|
// Calulate the host name using the last two chars from the MAC address so each one is likely unique on a network.
|
||||||
|
@ -201,9 +216,7 @@ void init_mDNS() {
|
||||||
MDNS.addService("battery_emulator", "tcp", 80);
|
MDNS.addService("battery_emulator", "tcp", 80);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // MDNSRESPONDER
|
|
||||||
|
|
||||||
#ifdef WIFIAP
|
|
||||||
void init_WiFi_AP() {
|
void init_WiFi_AP() {
|
||||||
#ifdef DEBUG_LOG
|
#ifdef DEBUG_LOG
|
||||||
logging.println("Creating Access Point: " + String(ssidAP));
|
logging.println("Creating Access Point: " + String(ssidAP));
|
||||||
|
@ -217,4 +230,3 @@ void init_WiFi_AP() {
|
||||||
logging.println(IP.toString());
|
logging.println(IP.toString());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif // WIFIAP
|
|
||||||
|
|
|
@ -5,10 +5,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "../../include.h"
|
#include "../../include.h"
|
||||||
|
|
||||||
#ifdef MDNSRESPONDER
|
|
||||||
#include <ESPmDNS.h>
|
|
||||||
#endif // MDNSRESONDER
|
|
||||||
|
|
||||||
extern std::string ssid;
|
extern std::string ssid;
|
||||||
extern std::string password;
|
extern std::string password;
|
||||||
extern const uint8_t wifi_channel;
|
extern const uint8_t wifi_channel;
|
||||||
|
@ -29,5 +25,6 @@ void init_WiFi_AP();
|
||||||
void init_mDNS();
|
void init_mDNS();
|
||||||
|
|
||||||
extern bool wifi_enabled;
|
extern bool wifi_enabled;
|
||||||
|
extern bool mdns_enabled;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue