Removed Ethernet, added default WiFi (mikrotik AP) and fixed various Clock bugs.
This commit is contained in:
@@ -524,14 +524,14 @@ void CommandHandler::handleSetRtcTimeCommand(JsonVariant contents, const Message
|
|||||||
|
|
||||||
// Verify the time was set correctly by reading it back
|
// Verify the time was set correctly by reading it back
|
||||||
unsigned long verifyTime = _timeKeeper->getTime();
|
unsigned long verifyTime = _timeKeeper->getTime();
|
||||||
if (verifyTime > 0 && abs((long)verifyTime - (long)timestamp) < 5) { // Allow 5 second tolerance
|
if (verifyTime > 0 && abs((long)verifyTime - (long)localTimestamp) < 5) { // Allow 5 second tolerance
|
||||||
sendSuccessResponse("set_rtc_time",
|
sendSuccessResponse("set_rtc_time",
|
||||||
"RTC time and timezone updated successfully", context);
|
"RTC time and timezone updated successfully", context);
|
||||||
LOG_INFO("RTC time set with timezone: UTC %lu + %ld = local %lu",
|
LOG_INFO("RTC time set with timezone: UTC %lu + %ld = local %lu",
|
||||||
timestamp, totalOffset, localTimestamp);
|
timestamp, totalOffset, localTimestamp);
|
||||||
} else {
|
} else {
|
||||||
sendErrorResponse("set_rtc_time", "Failed to verify RTC time was set correctly", context);
|
sendErrorResponse("set_rtc_time", "Failed to verify RTC time was set correctly", context);
|
||||||
LOG_ERROR("RTC time verification failed - expected: %lu, got: %lu", timestamp, verifyTime);
|
LOG_ERROR("RTC time verification failed - expected: %lu, got: %lu", localTimestamp, verifyTime);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Legacy method: Use device's existing timezone config
|
// Legacy method: Use device's existing timezone config
|
||||||
|
|||||||
@@ -529,13 +529,19 @@ void ConfigManager::updateClockAlerts(JsonVariant doc) {
|
|||||||
clockConfig.alertRingInterval = doc["alertRingInterval"].as<uint16_t>();
|
clockConfig.alertRingInterval = doc["alertRingInterval"].as<uint16_t>();
|
||||||
}
|
}
|
||||||
if (doc.containsKey("hourBell")) {
|
if (doc.containsKey("hourBell")) {
|
||||||
clockConfig.hourBell = doc["hourBell"].as<uint8_t>();
|
uint8_t bellNum = doc["hourBell"].as<uint8_t>();
|
||||||
|
// Convert from 1-based (API) to 0-based (internal), or keep 255 (disabled)
|
||||||
|
clockConfig.hourBell = (bellNum == 255) ? 255 : bellNum - 1;
|
||||||
}
|
}
|
||||||
if (doc.containsKey("halfBell")) {
|
if (doc.containsKey("halfBell")) {
|
||||||
clockConfig.halfBell = doc["halfBell"].as<uint8_t>();
|
uint8_t bellNum = doc["halfBell"].as<uint8_t>();
|
||||||
|
// Convert from 1-based (API) to 0-based (internal), or keep 255 (disabled)
|
||||||
|
clockConfig.halfBell = (bellNum == 255) ? 255 : bellNum - 1;
|
||||||
}
|
}
|
||||||
if (doc.containsKey("quarterBell")) {
|
if (doc.containsKey("quarterBell")) {
|
||||||
clockConfig.quarterBell = doc["quarterBell"].as<uint8_t>();
|
uint8_t bellNum = doc["quarterBell"].as<uint8_t>();
|
||||||
|
// Convert from 1-based (API) to 0-based (internal), or keep 255 (disabled)
|
||||||
|
clockConfig.quarterBell = (bellNum == 255) ? 255 : bellNum - 1;
|
||||||
}
|
}
|
||||||
LOG_DEBUG("ConfigManager - Updated Clock alerts");
|
LOG_DEBUG("ConfigManager - Updated Clock alerts");
|
||||||
}
|
}
|
||||||
@@ -593,7 +599,7 @@ bool ConfigManager::loadClockConfig() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
StaticJsonDocument<512> doc;
|
StaticJsonDocument<1024> doc; // Increased size for all settings
|
||||||
DeserializationError error = deserializeJson(doc, file);
|
DeserializationError error = deserializeJson(doc, file);
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
@@ -602,12 +608,34 @@ bool ConfigManager::loadClockConfig() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clock enable/outputs
|
||||||
if (doc.containsKey("enabled")) clockConfig.enabled = doc["enabled"].as<bool>();
|
if (doc.containsKey("enabled")) clockConfig.enabled = doc["enabled"].as<bool>();
|
||||||
if (doc.containsKey("c1output")) clockConfig.c1output = doc["c1output"].as<uint8_t>();
|
if (doc.containsKey("c1output")) clockConfig.c1output = doc["c1output"].as<uint8_t>();
|
||||||
if (doc.containsKey("c2output")) clockConfig.c2output = doc["c2output"].as<uint8_t>();
|
if (doc.containsKey("c2output")) clockConfig.c2output = doc["c2output"].as<uint8_t>();
|
||||||
if (doc.containsKey("pulseDuration")) clockConfig.pulseDuration = doc["pulseDuration"].as<uint16_t>();
|
if (doc.containsKey("pulseDuration")) clockConfig.pulseDuration = doc["pulseDuration"].as<uint16_t>();
|
||||||
if (doc.containsKey("pauseDuration")) clockConfig.pauseDuration = doc["pauseDuration"].as<uint16_t>();
|
if (doc.containsKey("pauseDuration")) clockConfig.pauseDuration = doc["pauseDuration"].as<uint16_t>();
|
||||||
|
|
||||||
|
// Alert settings
|
||||||
|
if (doc.containsKey("alertType")) clockConfig.alertType = doc["alertType"].as<String>();
|
||||||
|
if (doc.containsKey("alertRingInterval")) clockConfig.alertRingInterval = doc["alertRingInterval"].as<uint16_t>();
|
||||||
|
if (doc.containsKey("hourBell")) clockConfig.hourBell = doc["hourBell"].as<uint8_t>();
|
||||||
|
if (doc.containsKey("halfBell")) clockConfig.halfBell = doc["halfBell"].as<uint8_t>();
|
||||||
|
if (doc.containsKey("quarterBell")) clockConfig.quarterBell = doc["quarterBell"].as<uint8_t>();
|
||||||
|
|
||||||
|
// Backlight settings
|
||||||
|
if (doc.containsKey("backlight")) clockConfig.backlight = doc["backlight"].as<bool>();
|
||||||
|
if (doc.containsKey("backlightOutput")) clockConfig.backlightOutput = doc["backlightOutput"].as<uint8_t>();
|
||||||
|
if (doc.containsKey("backlightOnTime")) clockConfig.backlightOnTime = doc["backlightOnTime"].as<String>();
|
||||||
|
if (doc.containsKey("backlightOffTime")) clockConfig.backlightOffTime = doc["backlightOffTime"].as<String>();
|
||||||
|
|
||||||
|
// Silence period settings
|
||||||
|
if (doc.containsKey("daytimeSilenceEnabled")) clockConfig.daytimeSilenceEnabled = doc["daytimeSilenceEnabled"].as<bool>();
|
||||||
|
if (doc.containsKey("daytimeSilenceOnTime")) clockConfig.daytimeSilenceOnTime = doc["daytimeSilenceOnTime"].as<String>();
|
||||||
|
if (doc.containsKey("daytimeSilenceOffTime")) clockConfig.daytimeSilenceOffTime = doc["daytimeSilenceOffTime"].as<String>();
|
||||||
|
if (doc.containsKey("nighttimeSilenceEnabled")) clockConfig.nighttimeSilenceEnabled = doc["nighttimeSilenceEnabled"].as<bool>();
|
||||||
|
if (doc.containsKey("nighttimeSilenceOnTime")) clockConfig.nighttimeSilenceOnTime = doc["nighttimeSilenceOnTime"].as<String>();
|
||||||
|
if (doc.containsKey("nighttimeSilenceOffTime")) clockConfig.nighttimeSilenceOffTime = doc["nighttimeSilenceOffTime"].as<String>();
|
||||||
|
|
||||||
LOG_DEBUG("ConfigManager - Clock config loaded");
|
LOG_DEBUG("ConfigManager - Clock config loaded");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -615,14 +643,37 @@ bool ConfigManager::loadClockConfig() {
|
|||||||
bool ConfigManager::saveClockConfig() {
|
bool ConfigManager::saveClockConfig() {
|
||||||
if (!ensureSDCard()) return false;
|
if (!ensureSDCard()) return false;
|
||||||
|
|
||||||
StaticJsonDocument<512> doc;
|
StaticJsonDocument<1024> doc; // Increased size for all settings
|
||||||
|
|
||||||
|
// Clock enable/outputs
|
||||||
doc["enabled"] = clockConfig.enabled;
|
doc["enabled"] = clockConfig.enabled;
|
||||||
doc["c1output"] = clockConfig.c1output;
|
doc["c1output"] = clockConfig.c1output;
|
||||||
doc["c2output"] = clockConfig.c2output;
|
doc["c2output"] = clockConfig.c2output;
|
||||||
doc["pulseDuration"] = clockConfig.pulseDuration;
|
doc["pulseDuration"] = clockConfig.pulseDuration;
|
||||||
doc["pauseDuration"] = clockConfig.pauseDuration;
|
doc["pauseDuration"] = clockConfig.pauseDuration;
|
||||||
|
|
||||||
char buffer[512];
|
// Alert settings
|
||||||
|
doc["alertType"] = clockConfig.alertType;
|
||||||
|
doc["alertRingInterval"] = clockConfig.alertRingInterval;
|
||||||
|
doc["hourBell"] = clockConfig.hourBell;
|
||||||
|
doc["halfBell"] = clockConfig.halfBell;
|
||||||
|
doc["quarterBell"] = clockConfig.quarterBell;
|
||||||
|
|
||||||
|
// Backlight settings
|
||||||
|
doc["backlight"] = clockConfig.backlight;
|
||||||
|
doc["backlightOutput"] = clockConfig.backlightOutput;
|
||||||
|
doc["backlightOnTime"] = clockConfig.backlightOnTime;
|
||||||
|
doc["backlightOffTime"] = clockConfig.backlightOffTime;
|
||||||
|
|
||||||
|
// Silence period settings
|
||||||
|
doc["daytimeSilenceEnabled"] = clockConfig.daytimeSilenceEnabled;
|
||||||
|
doc["daytimeSilenceOnTime"] = clockConfig.daytimeSilenceOnTime;
|
||||||
|
doc["daytimeSilenceOffTime"] = clockConfig.daytimeSilenceOffTime;
|
||||||
|
doc["nighttimeSilenceEnabled"] = clockConfig.nighttimeSilenceEnabled;
|
||||||
|
doc["nighttimeSilenceOnTime"] = clockConfig.nighttimeSilenceOnTime;
|
||||||
|
doc["nighttimeSilenceOffTime"] = clockConfig.nighttimeSilenceOffTime;
|
||||||
|
|
||||||
|
char buffer[1024];
|
||||||
size_t len = serializeJson(doc, buffer, sizeof(buffer));
|
size_t len = serializeJson(doc, buffer, sizeof(buffer));
|
||||||
|
|
||||||
if (len == 0 || len >= sizeof(buffer)) {
|
if (len == 0 || len >= sizeof(buffer)) {
|
||||||
|
|||||||
@@ -70,6 +70,8 @@ public:
|
|||||||
String apPass; // 🔐 AP is Open. No Password
|
String apPass; // 🔐 AP is Open. No Password
|
||||||
uint16_t discoveryPort = 32101; // 📡 Fixed discovery port
|
uint16_t discoveryPort = 32101; // 📡 Fixed discovery port
|
||||||
bool permanentAPMode = false; // 🔘 Permanent AP mode toggle (stored on SD)
|
bool permanentAPMode = false; // 🔘 Permanent AP mode toggle (stored on SD)
|
||||||
|
String defaultWifiSsid = "BellSystemsInfra"; // 📡 Default WiFi SSID to try on boot
|
||||||
|
String defaultWifiPsk = "v3sp3r_8998!"; // 🔐 Default WiFi password to try on boot
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -71,63 +71,97 @@ void Networking::begin() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ETHERNET DISABLED - WiFi only mode
|
||||||
// Start Ethernet hardware
|
// Start Ethernet hardware
|
||||||
auto& hwConfig = _configManager.getHardwareConfig();
|
// auto& hwConfig = _configManager.getHardwareConfig();
|
||||||
ETH.begin(hwConfig.ethPhyType, hwConfig.ethPhyAddr, hwConfig.ethPhyCs,
|
// ETH.begin(hwConfig.ethPhyType, hwConfig.ethPhyAddr, hwConfig.ethPhyCs,
|
||||||
hwConfig.ethPhyIrq, hwConfig.ethPhyRst, SPI);
|
// hwConfig.ethPhyIrq, hwConfig.ethPhyRst, SPI);
|
||||||
|
|
||||||
// Start connection sequence
|
// Start connection sequence - Skip Ethernet, go directly to WiFi
|
||||||
LOG_INFO("Starting network connection sequence...");
|
LOG_INFO("Starting WiFi connection (Ethernet disabled)...");
|
||||||
startEthernetConnection();
|
startWiFiConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Networking::startEthernetConnection() {
|
void Networking::startEthernetConnection() {
|
||||||
LOG_INFO("Attempting Ethernet connection...");
|
// ETHERNET DISABLED - Skip to WiFi immediately
|
||||||
setState(NetworkState::CONNECTING_ETHERNET);
|
LOG_DEBUG("Ethernet connection disabled - falling back to WiFi");
|
||||||
|
startWiFiConnection();
|
||||||
|
|
||||||
// Check if Ethernet hardware initialization failed
|
// Original Ethernet code (DISABLED):
|
||||||
if (!ETH.linkUp()) {
|
// LOG_INFO("Attempting Ethernet connection...");
|
||||||
LOG_WARNING("Ethernet hardware not detected or failed to initialize");
|
// setState(NetworkState::CONNECTING_ETHERNET);
|
||||||
LOG_INFO("Falling back to WiFi immediately");
|
//
|
||||||
startWiFiConnection();
|
// // Check if Ethernet hardware initialization failed
|
||||||
return;
|
// if (!ETH.linkUp()) {
|
||||||
}
|
// LOG_WARNING("Ethernet hardware not detected or failed to initialize");
|
||||||
|
// LOG_INFO("Falling back to WiFi immediately");
|
||||||
// Ethernet will auto-connect via events
|
// startWiFiConnection();
|
||||||
// Set timeout for Ethernet attempt (5 seconds)
|
// return;
|
||||||
_lastConnectionAttempt = millis();
|
// }
|
||||||
|
//
|
||||||
// Start reconnection timer to handle timeout
|
// // Ethernet will auto-connect via events
|
||||||
xTimerStart(_reconnectionTimer, 0);
|
// // Set timeout for Ethernet attempt (5 seconds)
|
||||||
|
// _lastConnectionAttempt = millis();
|
||||||
|
//
|
||||||
|
// // Start reconnection timer to handle timeout
|
||||||
|
// xTimerStart(_reconnectionTimer, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Networking::startWiFiConnection() {
|
void Networking::startWiFiConnection() {
|
||||||
LOG_INFO("Attempting WiFi connection...");
|
LOG_INFO("Attempting WiFi connection...");
|
||||||
setState(NetworkState::CONNECTING_WIFI);
|
setState(NetworkState::CONNECTING_WIFI);
|
||||||
|
|
||||||
if (!hasValidWiFiCredentials()) {
|
// ALWAYS try default credentials first (for bundled router deployment)
|
||||||
LOG_WARNING("No valid WiFi credentials found");
|
auto& netConfig = _configManager.getNetworkConfig();
|
||||||
if (!_bootSequenceComplete) {
|
|
||||||
// No credentials during boot - start portal
|
|
||||||
startWiFiPortal();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get and log saved credentials (for debugging)
|
LOG_INFO("Using DEFAULT WiFi credentials - SSID: %s", netConfig.defaultWifiSsid.c_str());
|
||||||
String savedSSID = _wifiManager->getWiFiSSID(true);
|
|
||||||
LOG_INFO("Using WiFiManager saved credentials - SSID: %s", savedSSID.c_str());
|
|
||||||
|
|
||||||
applyNetworkConfig(false); // false = WiFi config
|
applyNetworkConfig(false); // false = WiFi config
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
|
WiFi.begin(netConfig.defaultWifiSsid.c_str(), netConfig.defaultWifiPsk.c_str());
|
||||||
// Let WiFiManager handle credentials (uses saved SSID/password)
|
|
||||||
WiFi.begin();
|
|
||||||
|
|
||||||
_lastConnectionAttempt = millis();
|
_lastConnectionAttempt = millis();
|
||||||
|
|
||||||
// Start reconnection timer to handle timeout
|
|
||||||
xTimerStart(_reconnectionTimer, 0);
|
xTimerStart(_reconnectionTimer, 0);
|
||||||
|
|
||||||
|
// Original WiFiManager fallback code (DISABLED for fixed deployment):
|
||||||
|
// // First, try default credentials if this is the first boot attempt
|
||||||
|
// if (!_bootSequenceComplete && !hasValidWiFiCredentials()) {
|
||||||
|
// LOG_INFO("No saved credentials - trying default WiFi credentials");
|
||||||
|
// auto& netConfig = _configManager.getNetworkConfig();
|
||||||
|
//
|
||||||
|
// applyNetworkConfig(false); // false = WiFi config
|
||||||
|
// WiFi.mode(WIFI_STA);
|
||||||
|
// WiFi.begin(netConfig.defaultWifiSsid.c_str(), netConfig.defaultWifiPsk.c_str());
|
||||||
|
//
|
||||||
|
// _lastConnectionAttempt = millis();
|
||||||
|
// xTimerStart(_reconnectionTimer, 0);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Check if we have valid saved credentials
|
||||||
|
// if (!hasValidWiFiCredentials()) {
|
||||||
|
// LOG_WARNING("No valid WiFi credentials found");
|
||||||
|
// if (!_bootSequenceComplete) {
|
||||||
|
// // No credentials during boot - start portal
|
||||||
|
// startWiFiPortal();
|
||||||
|
// }
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Get and log saved credentials (for debugging)
|
||||||
|
// String savedSSID = _wifiManager->getWiFiSSID(true);
|
||||||
|
// LOG_INFO("Using WiFiManager saved credentials - SSID: %s", savedSSID.c_str());
|
||||||
|
//
|
||||||
|
// applyNetworkConfig(false); // false = WiFi config
|
||||||
|
// WiFi.mode(WIFI_STA);
|
||||||
|
//
|
||||||
|
// // Let WiFiManager handle credentials (uses saved SSID/password)
|
||||||
|
// WiFi.begin();
|
||||||
|
//
|
||||||
|
// _lastConnectionAttempt = millis();
|
||||||
|
//
|
||||||
|
// // Start reconnection timer to handle timeout
|
||||||
|
// xTimerStart(_reconnectionTimer, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Networking::startWiFiPortal() {
|
void Networking::startWiFiPortal() {
|
||||||
@@ -171,16 +205,17 @@ void Networking::handleReconnection() {
|
|||||||
|
|
||||||
LOG_DEBUG("Attempting reconnection...");
|
LOG_DEBUG("Attempting reconnection...");
|
||||||
|
|
||||||
|
// ETHERNET DISABLED - Skip Ethernet timeout checks
|
||||||
// Check for Ethernet timeout (fall back to WiFi)
|
// Check for Ethernet timeout (fall back to WiFi)
|
||||||
if (_state == NetworkState::CONNECTING_ETHERNET) {
|
// if (_state == NetworkState::CONNECTING_ETHERNET) {
|
||||||
unsigned long now = millis();
|
// unsigned long now = millis();
|
||||||
if (now - _lastConnectionAttempt > 5000) { // 5 second timeout
|
// if (now - _lastConnectionAttempt > 5000) { // 5 second timeout
|
||||||
LOG_INFO("Ethernet connection timeout - falling back to WiFi");
|
// LOG_INFO("Ethernet connection timeout - falling back to WiFi");
|
||||||
startWiFiConnection();
|
// startWiFiConnection();
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
return; // Still waiting for Ethernet
|
// return; // Still waiting for Ethernet
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Check for WiFi timeout
|
// Check for WiFi timeout
|
||||||
if (_state == NetworkState::CONNECTING_WIFI) {
|
if (_state == NetworkState::CONNECTING_WIFI) {
|
||||||
@@ -216,20 +251,15 @@ void Networking::handleReconnection() {
|
|||||||
return; // Still waiting for WiFi
|
return; // Still waiting for WiFi
|
||||||
}
|
}
|
||||||
|
|
||||||
// State is DISCONNECTED - decide what to try
|
// State is DISCONNECTED - WiFi only mode (Ethernet disabled)
|
||||||
if (_ethernetCableConnected) {
|
LOG_INFO("Disconnected - trying WiFi");
|
||||||
LOG_INFO("Ethernet cable detected - trying Ethernet");
|
if (hasValidWiFiCredentials()) {
|
||||||
startEthernetConnection();
|
startWiFiConnection();
|
||||||
|
} else if (!_bootSequenceComplete) {
|
||||||
|
// No credentials during boot - start portal
|
||||||
|
startWiFiPortal();
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("No Ethernet - trying WiFi");
|
LOG_WARNING("No WiFi credentials and boot sequence complete - waiting");
|
||||||
if (hasValidWiFiCredentials()) {
|
|
||||||
startWiFiConnection();
|
|
||||||
} else if (!_bootSequenceComplete) {
|
|
||||||
// No credentials during boot - start portal
|
|
||||||
startWiFiPortal();
|
|
||||||
} else {
|
|
||||||
LOG_WARNING("No WiFi credentials and boot sequence complete - waiting");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,8 +274,8 @@ bool Networking::isHealthy() const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check connection state
|
// Check connection state (Ethernet disabled, only check WiFi or AP)
|
||||||
if (_state != NetworkState::CONNECTED_ETHERNET && _state != NetworkState::CONNECTED_WIFI) {
|
if (_state != NetworkState::CONNECTED_WIFI && _state != NetworkState::AP_MODE_PERMANENT) {
|
||||||
LOG_DEBUG("Networking: Unhealthy - Not in connected state");
|
LOG_DEBUG("Networking: Unhealthy - Not in connected state");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -272,13 +302,14 @@ bool Networking::isHealthy() const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ETHERNET DISABLED - Removed Ethernet link check
|
||||||
// For Ethernet connections, check link status
|
// For Ethernet connections, check link status
|
||||||
if (_activeConnection == ConnectionType::ETHERNET) {
|
// if (_activeConnection == ConnectionType::ETHERNET) {
|
||||||
if (!ETH.linkUp()) {
|
// if (!ETH.linkUp()) {
|
||||||
LOG_DEBUG("Networking: Unhealthy - Ethernet link down");
|
// LOG_DEBUG("Networking: Unhealthy - Ethernet link down");
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -305,35 +336,43 @@ void Networking::notifyConnectionChange(bool connected) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event handlers
|
// Event handlers (ETHERNET DISABLED)
|
||||||
void Networking::onEthernetConnected() {
|
void Networking::onEthernetConnected() {
|
||||||
LOG_INFO("Ethernet connected successfully");
|
// ETHERNET DISABLED - This should never be called
|
||||||
setState(NetworkState::CONNECTED_ETHERNET);
|
LOG_WARNING("Ethernet event received but Ethernet is disabled - ignoring");
|
||||||
setActiveConnection(ConnectionType::ETHERNET);
|
|
||||||
|
|
||||||
// Stop WiFi if it was running
|
// Original code (DISABLED):
|
||||||
if (WiFi.getMode() != WIFI_OFF) {
|
// LOG_INFO("Ethernet connected successfully");
|
||||||
WiFi.disconnect(true);
|
// setState(NetworkState::CONNECTED_ETHERNET);
|
||||||
WiFi.mode(WIFI_OFF);
|
// setActiveConnection(ConnectionType::ETHERNET);
|
||||||
}
|
//
|
||||||
|
// // Stop WiFi if it was running
|
||||||
// Stop reconnection timer
|
// if (WiFi.getMode() != WIFI_OFF) {
|
||||||
xTimerStop(_reconnectionTimer, 0);
|
// WiFi.disconnect(true);
|
||||||
|
// WiFi.mode(WIFI_OFF);
|
||||||
notifyConnectionChange(true);
|
// }
|
||||||
|
//
|
||||||
|
// // Stop reconnection timer
|
||||||
|
// xTimerStop(_reconnectionTimer, 0);
|
||||||
|
//
|
||||||
|
// notifyConnectionChange(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Networking::onEthernetDisconnected() {
|
void Networking::onEthernetDisconnected() {
|
||||||
LOG_WARNING("Ethernet disconnected");
|
// ETHERNET DISABLED - This should never be called
|
||||||
|
LOG_WARNING("Ethernet disconnect event received but Ethernet is disabled - ignoring");
|
||||||
|
|
||||||
if (_activeConnection == ConnectionType::ETHERNET) {
|
// Original code (DISABLED):
|
||||||
setState(NetworkState::DISCONNECTED);
|
// LOG_WARNING("Ethernet disconnected");
|
||||||
setActiveConnection(ConnectionType::NONE);
|
//
|
||||||
notifyConnectionChange(false);
|
// if (_activeConnection == ConnectionType::ETHERNET) {
|
||||||
|
// setState(NetworkState::DISCONNECTED);
|
||||||
// Start reconnection attempts
|
// setActiveConnection(ConnectionType::NONE);
|
||||||
xTimerStart(_reconnectionTimer, 0);
|
// notifyConnectionChange(false);
|
||||||
}
|
//
|
||||||
|
// // Start reconnection attempts
|
||||||
|
// xTimerStart(_reconnectionTimer, 0);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void Networking::onWiFiConnected() {
|
void Networking::onWiFiConnected() {
|
||||||
@@ -367,35 +406,37 @@ void Networking::onWiFiDisconnected() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Networking::onEthernetCableChange(bool connected) {
|
void Networking::onEthernetCableChange(bool connected) {
|
||||||
_ethernetCableConnected = connected;
|
// ETHERNET DISABLED - Ignore cable events
|
||||||
LOG_INFO("Ethernet cable %s", connected ? "connected" : "disconnected");
|
LOG_DEBUG("Ethernet cable event ignored (Ethernet disabled)");
|
||||||
|
|
||||||
if (connected && _activeConnection != ConnectionType::ETHERNET) {
|
// Original code (DISABLED):
|
||||||
// Cable connected and we're not using Ethernet - try to connect
|
// _ethernetCableConnected = connected;
|
||||||
startEthernetConnection();
|
// LOG_INFO("Ethernet cable %s", connected ? "connected" : "disconnected");
|
||||||
}
|
//
|
||||||
|
// if (connected && _activeConnection != ConnectionType::ETHERNET) {
|
||||||
|
// // Cable connected and we're not using Ethernet - try to connect
|
||||||
|
// startEthernetConnection();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Utility methods
|
// Utility methods
|
||||||
void Networking::applyNetworkConfig(bool ethernet) {
|
void Networking::applyNetworkConfig(bool ethernet) {
|
||||||
auto& netConfig = _configManager.getNetworkConfig();
|
auto& netConfig = _configManager.getNetworkConfig();
|
||||||
|
|
||||||
|
// ETHERNET DISABLED - Only apply WiFi config
|
||||||
|
if (ethernet) {
|
||||||
|
LOG_WARNING("applyNetworkConfig called with ethernet=true but Ethernet is disabled");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (netConfig.useStaticIP) {
|
if (netConfig.useStaticIP) {
|
||||||
LOG_INFO("Applying static IP configuration");
|
LOG_INFO("Applying static IP configuration");
|
||||||
if (ethernet) {
|
WiFi.config(netConfig.ip, netConfig.gateway, netConfig.subnet, netConfig.dns1, netConfig.dns2);
|
||||||
ETH.config(netConfig.ip, netConfig.gateway, netConfig.subnet, netConfig.dns1, netConfig.dns2);
|
|
||||||
} else {
|
|
||||||
WiFi.config(netConfig.ip, netConfig.gateway, netConfig.subnet, netConfig.dns1, netConfig.dns2);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("Using DHCP configuration");
|
LOG_INFO("Using DHCP configuration");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ethernet) {
|
WiFi.setHostname(netConfig.hostname.c_str());
|
||||||
ETH.setHostname(netConfig.hostname.c_str());
|
|
||||||
} else {
|
|
||||||
WiFi.setHostname(netConfig.hostname.c_str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Networking::hasValidWiFiCredentials() {
|
bool Networking::hasValidWiFiCredentials() {
|
||||||
@@ -413,7 +454,9 @@ bool Networking::isConnected() const {
|
|||||||
String Networking::getLocalIP() const {
|
String Networking::getLocalIP() const {
|
||||||
switch (_activeConnection) {
|
switch (_activeConnection) {
|
||||||
case ConnectionType::ETHERNET:
|
case ConnectionType::ETHERNET:
|
||||||
return ETH.localIP().toString();
|
// ETHERNET DISABLED - Should never reach here
|
||||||
|
LOG_WARNING("getLocalIP called with ETHERNET type but Ethernet is disabled");
|
||||||
|
return "0.0.0.0";
|
||||||
case ConnectionType::WIFI:
|
case ConnectionType::WIFI:
|
||||||
return WiFi.localIP().toString();
|
return WiFi.localIP().toString();
|
||||||
case ConnectionType::AP:
|
case ConnectionType::AP:
|
||||||
@@ -426,7 +469,9 @@ String Networking::getLocalIP() const {
|
|||||||
String Networking::getGateway() const {
|
String Networking::getGateway() const {
|
||||||
switch (_activeConnection) {
|
switch (_activeConnection) {
|
||||||
case ConnectionType::ETHERNET:
|
case ConnectionType::ETHERNET:
|
||||||
return ETH.gatewayIP().toString();
|
// ETHERNET DISABLED - Should never reach here
|
||||||
|
LOG_WARNING("getGateway called with ETHERNET type but Ethernet is disabled");
|
||||||
|
return "0.0.0.0";
|
||||||
case ConnectionType::WIFI:
|
case ConnectionType::WIFI:
|
||||||
return WiFi.gatewayIP().toString();
|
return WiFi.gatewayIP().toString();
|
||||||
default:
|
default:
|
||||||
@@ -445,9 +490,9 @@ void Networking::forceReconnect() {
|
|||||||
WiFi.mode(WIFI_OFF);
|
WiFi.mode(WIFI_OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restart connection sequence
|
// Restart connection sequence - WiFi only (Ethernet disabled)
|
||||||
delay(1000);
|
delay(1000);
|
||||||
startEthernetConnection();
|
startWiFiConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Static callbacks
|
// Static callbacks
|
||||||
@@ -457,32 +502,16 @@ void Networking::networkEventHandler(arduino_event_id_t event, arduino_event_inf
|
|||||||
LOG_DEBUG("Network event: %d", event);
|
LOG_DEBUG("Network event: %d", event);
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
|
// ETHERNET EVENTS DISABLED - Ignored
|
||||||
case ARDUINO_EVENT_ETH_START:
|
case ARDUINO_EVENT_ETH_START:
|
||||||
LOG_DEBUG("ETH Started");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ARDUINO_EVENT_ETH_CONNECTED:
|
case ARDUINO_EVENT_ETH_CONNECTED:
|
||||||
LOG_DEBUG("ETH Cable Connected");
|
|
||||||
_instance->onEthernetCableChange(true);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ARDUINO_EVENT_ETH_GOT_IP:
|
case ARDUINO_EVENT_ETH_GOT_IP:
|
||||||
LOG_INFO("ETH Got IP: %s", ETH.localIP().toString().c_str());
|
|
||||||
_instance->applyNetworkConfig(true);
|
|
||||||
_instance->onEthernetConnected();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ARDUINO_EVENT_ETH_DISCONNECTED:
|
case ARDUINO_EVENT_ETH_DISCONNECTED:
|
||||||
LOG_WARNING("ETH Cable Disconnected");
|
|
||||||
_instance->onEthernetCableChange(false);
|
|
||||||
_instance->onEthernetDisconnected();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ARDUINO_EVENT_ETH_STOP:
|
case ARDUINO_EVENT_ETH_STOP:
|
||||||
LOG_INFO("ETH Stopped");
|
LOG_DEBUG("Ethernet event ignored (Ethernet disabled)");
|
||||||
_instance->onEthernetDisconnected();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// WiFi events (ACTIVE)
|
||||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
|
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
|
||||||
LOG_INFO("WiFi Got IP: %s", WiFi.localIP().toString().c_str());
|
LOG_INFO("WiFi Got IP: %s", WiFi.localIP().toString().c_str());
|
||||||
_instance->onWiFiConnected();
|
_instance->onWiFiConnected();
|
||||||
|
|||||||
@@ -64,19 +64,19 @@
|
|||||||
* 👨💻 AUTHOR: BellSystems bonamin
|
* 👨💻 AUTHOR: BellSystems bonamin
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define FW_VERSION "137"
|
#define FW_VERSION "138"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ═══════════════════════════════════════════════════════════════════════════════
|
* ═══════════════════════════════════════════════════════════════════════════════
|
||||||
* 📅 VERSION HISTORY:
|
* 📅 VERSION HISTORY:
|
||||||
|
* NOTE: Versions are now stored as integers (v1.3 = 130)
|
||||||
* ═══════════════════════════════════════════════════════════════════════════════
|
* ═══════════════════════════════════════════════════════════════════════════════
|
||||||
* v0.1 (100) - Vesper Launch Beta
|
* v0.1 (100) - Vesper Launch Beta
|
||||||
* v1.2 (120) - Added Log Level Configuration via App/MQTT
|
* v1.2 (120) - Added Log Level Configuration via App/MQTT
|
||||||
* v1.3 (130) - Added Telemetry Reports to App, Various Playback Fixes
|
* v1.3 (130) - Added Telemetry Reports to App, Various Playback Fixes
|
||||||
* v137 - Made OTA and MQTT delays Async
|
* v137 - Made OTA and MQTT delays Async
|
||||||
* ═══════════════════════════════════════════════════════════════════════════════
|
* v138 - Removed Ethernet, added default WiFi creds (Mikrotik AP) and fixed various Clock issues
|
||||||
* NOTE: Versions are now stored as integers (v1.3 = 130)
|
|
||||||
* ═══════════════════════════════════════════════════════════════════════════════
|
* ═══════════════════════════════════════════════════════════════════════════════
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user