mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-05 10:49:42 +02:00
pre-commit fixes
This commit is contained in:
parent
ae475c3b24
commit
3a5e39171f
3 changed files with 43 additions and 50 deletions
|
@ -37,16 +37,16 @@ IPAddress gateway(192, 168, 10, 1);
|
|||
IPAddress subnet(255, 255, 255, 0);
|
||||
#endif
|
||||
#ifdef WEBSERVER
|
||||
const char* http_username = "admin"; // username to webserver authentication;
|
||||
const char* http_username = "admin"; // username to webserver authentication;
|
||||
const char* http_password = "admin"; // password to webserver authentication;
|
||||
|
||||
// MQTT
|
||||
#ifdef MQTT
|
||||
const char* mqtt_user = "REDACTED"; // Set NULL for no username
|
||||
const char* mqtt_user = "REDACTED"; // Set NULL for no username
|
||||
const char* mqtt_password = "REDACTED"; // Set NULL for no password
|
||||
#endif // USE_MQTT
|
||||
#endif // WEBSERVER
|
||||
#endif // WIFI
|
||||
#endif // USE_MQTT
|
||||
#endif // WEBSERVER
|
||||
#endif // WIFI
|
||||
|
||||
/* Charger settings (Optional, when using generator charging) */
|
||||
volatile float CHARGER_SET_HV = 384; // Reasonably appropriate 4.0v per cell charging of a 96s pack
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
#include "../../include.h"
|
||||
#include "../utils/events.h"
|
||||
|
||||
|
||||
// Configuration Parameters
|
||||
static const uint16_t WIFI_CHECK_INTERVAL = 5000; // 5 seconds
|
||||
static const uint16_t INIT_WIFI_FULL_RECONNECT_INTERVAL = 10000; // 10 seconds
|
||||
static const uint16_t MAX_WIFI_FULL_RECONNECT_INTERVAL = 60000; // 60 seconds
|
||||
static const uint16_t STEP_WIFI_FULL_RECONNECT_INTERVAL = 5000; // 5 seconds
|
||||
static const uint16_t MAX_RECONNECT_ATTEMPTS = 3; // Maximum number of reconnect attempts before forcing a full connection
|
||||
static const uint16_t WIFI_CHECK_INTERVAL = 5000; // 5 seconds
|
||||
static const uint16_t INIT_WIFI_FULL_RECONNECT_INTERVAL = 10000; // 10 seconds
|
||||
static const uint16_t MAX_WIFI_FULL_RECONNECT_INTERVAL = 60000; // 60 seconds
|
||||
static const uint16_t STEP_WIFI_FULL_RECONNECT_INTERVAL = 5000; // 5 seconds
|
||||
static const uint16_t MAX_RECONNECT_ATTEMPTS =
|
||||
3; // Maximum number of reconnect attempts before forcing a full connection
|
||||
|
||||
// State variables
|
||||
static unsigned long lastReconnectAttempt = 0;
|
||||
|
@ -35,8 +35,8 @@ void init_WiFi() {
|
|||
WiFi.setAutoReconnect(true);
|
||||
|
||||
#ifdef WIFICONFIG
|
||||
// Set static IP
|
||||
WiFi.config(local_IP, gateway, subnet);
|
||||
// Set static IP
|
||||
WiFi.config(local_IP, gateway, subnet);
|
||||
#endif
|
||||
|
||||
// Initialize Wi-Fi event handlers
|
||||
|
@ -46,43 +46,41 @@ void init_WiFi() {
|
|||
|
||||
// Start Wi-Fi connection
|
||||
connectToWiFi();
|
||||
|
||||
}
|
||||
|
||||
// Task to monitor Wi-Fi status and handle reconnections
|
||||
void wifi_monitor() {
|
||||
unsigned long currentMillis = millis();
|
||||
unsigned long currentMillis = millis();
|
||||
|
||||
// Check if it's time to monitor the Wi-Fi status
|
||||
if (currentMillis - lastWiFiCheck > WIFI_CHECK_INTERVAL) {
|
||||
lastWiFiCheck = currentMillis;
|
||||
// Check if it's time to monitor the Wi-Fi status
|
||||
if (currentMillis - lastWiFiCheck > WIFI_CHECK_INTERVAL) {
|
||||
lastWiFiCheck = currentMillis;
|
||||
|
||||
wl_status_t status = WiFi.status();
|
||||
if (status != WL_CONNECTED ) {
|
||||
Serial.println("Wi-Fi not connected, attempting to reconnect...");
|
||||
wl_status_t status = WiFi.status();
|
||||
if (status != WL_CONNECTED) {
|
||||
Serial.println("Wi-Fi not connected, attempting to reconnect...");
|
||||
|
||||
// Try WiFi.reconnect() if it was successfully connected at least once
|
||||
if (hasConnectedBefore) {
|
||||
if (WiFi.reconnect()) {
|
||||
Serial.println("Wi-Fi reconnect attempt...");
|
||||
reconnectAttempts = 0; // Reset the attempt counter on successful reconnect
|
||||
} else {
|
||||
reconnectAttempts++;
|
||||
if (reconnectAttempts >= MAX_RECONNECT_ATTEMPTS) {
|
||||
Serial.println("Failed to reconnect multiple times, forcing a full connection attempt...");
|
||||
FullReconnectToWiFi();
|
||||
}
|
||||
}
|
||||
// Try WiFi.reconnect() if it was successfully connected at least once
|
||||
if (hasConnectedBefore) {
|
||||
if (WiFi.reconnect()) {
|
||||
Serial.println("Wi-Fi reconnect attempt...");
|
||||
reconnectAttempts = 0; // Reset the attempt counter on successful reconnect
|
||||
} else {
|
||||
// If no previous connection, force a full connection attempt
|
||||
if (currentMillis - lastReconnectAttempt > current_full_reconnect_interval) {
|
||||
Serial.println("No previous OK connection, force a full connection attempt...");
|
||||
reconnectAttempts++;
|
||||
if (reconnectAttempts >= MAX_RECONNECT_ATTEMPTS) {
|
||||
Serial.println("Failed to reconnect multiple times, forcing a full connection attempt...");
|
||||
FullReconnectToWiFi();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If no previous connection, force a full connection attempt
|
||||
if (currentMillis - lastReconnectAttempt > current_full_reconnect_interval) {
|
||||
Serial.println("No previous OK connection, force a full connection attempt...");
|
||||
FullReconnectToWiFi();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Function to force a full reconnect to Wi-Fi
|
||||
|
@ -102,7 +100,7 @@ static void FullReconnectToWiFi() {
|
|||
static void connectToWiFi() {
|
||||
if (WiFi.status() != WL_CONNECTED) {
|
||||
Serial.println("Connecting to Wi-Fi...");
|
||||
WiFi.begin( ssid.c_str(), password.c_str(),wifi_channel);
|
||||
WiFi.begin(ssid.c_str(), password.c_str(), wifi_channel);
|
||||
} else {
|
||||
Serial.println("Wi-Fi already connected.");
|
||||
}
|
||||
|
@ -118,7 +116,6 @@ static void onWifiConnect(WiFiEvent_t event, WiFiEventInfo_t info) {
|
|||
reconnectAttempts = 0; // Reset the attempt counter
|
||||
current_full_reconnect_interval = INIT_WIFI_FULL_RECONNECT_INTERVAL; // Reset the full reconnect interval
|
||||
clear_event(EVENT_WIFI_CONNECT);
|
||||
|
||||
}
|
||||
|
||||
// Event handler for Wi-Fi Got IP
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
#define WIFI_H
|
||||
|
||||
#include <WiFi.h>
|
||||
#include "../../include.h"
|
||||
#include <string>
|
||||
#include "../../include.h"
|
||||
|
||||
extern std::string ssid;
|
||||
extern std::string password;
|
||||
|
@ -11,7 +11,6 @@ extern const uint8_t wifi_channel;
|
|||
extern const char* ssidAP;
|
||||
extern const char* passwordAP;
|
||||
|
||||
|
||||
void init_WiFi();
|
||||
void wifi_monitor();
|
||||
static void connectToWiFi();
|
||||
|
@ -20,8 +19,6 @@ static void onWifiConnect(WiFiEvent_t event, WiFiEventInfo_t info);
|
|||
static void onWifiDisconnect(WiFiEvent_t event, WiFiEventInfo_t info);
|
||||
static void onWifiGotIP(WiFiEvent_t event, WiFiEventInfo_t info);
|
||||
|
||||
|
||||
|
||||
#ifdef WIFIAP
|
||||
void init_WiFi_AP();
|
||||
#endif // WIFIAP
|
||||
|
@ -29,7 +26,6 @@ void init_WiFi_AP();
|
|||
#ifdef MDNSRESPONDER
|
||||
// Initialise mDNS
|
||||
void init_mDNS();
|
||||
#endif // MDNSRESPONDER
|
||||
|
||||
#endif // MDNSRESPONDER
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue