mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 17:59:27 +02:00
precommit fixes
This commit is contained in:
parent
dff9788b96
commit
711aeded0c
11 changed files with 120 additions and 115 deletions
|
@ -21,8 +21,8 @@
|
||||||
#include "src/devboard/webserver/webserver.h"
|
#include "src/devboard/webserver/webserver.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Preferences settings; // Store user settings
|
Preferences settings; // Store user settings
|
||||||
const char* version_number = "5.2.0"; // The current software version, shown on webserver
|
const char* version_number = "5.2.0"; // The current software version, shown on webserver
|
||||||
// Interval settings
|
// Interval settings
|
||||||
int intervalUpdateValues = 4800; // Interval at which to update inverter values / Modbus registers
|
int intervalUpdateValues = 4800; // Interval at which to update inverter values / Modbus registers
|
||||||
const int interval10 = 10; // Interval for 10ms tasks
|
const int interval10 = 10; // Interval for 10ms tasks
|
||||||
|
@ -188,7 +188,7 @@ void loop() {
|
||||||
{
|
{
|
||||||
previousMillisUpdateVal = millis();
|
previousMillisUpdateVal = millis();
|
||||||
update_values(); // Update values heading towards inverter. Prepare for sending on CAN, or write directly to Modbus.
|
update_values(); // Update values heading towards inverter. Prepare for sending on CAN, or write directly to Modbus.
|
||||||
if(DUMMY_EVENT_ENABLED) {
|
if (DUMMY_EVENT_ENABLED) {
|
||||||
set_event(EVENT_DUMMY, (uint8_t)millis());
|
set_event(EVENT_DUMMY, (uint8_t)millis());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,5 +36,5 @@ const char* ssid = "REPLACE_WITH_YOUR_SSID"; // Maximum of 63 character
|
||||||
const char* password = "REPLACE_WITH_YOUR_PASSWORD"; // Minimum of 8 characters;
|
const char* password = "REPLACE_WITH_YOUR_PASSWORD"; // Minimum of 8 characters;
|
||||||
const char* ssidAP = "Battery Emulator"; // Maximum of 63 characters;
|
const char* ssidAP = "Battery Emulator"; // Maximum of 63 characters;
|
||||||
const char* passwordAP = "123456789"; // Minimum of 8 characters; set to NULL if you want the access point to be open
|
const char* passwordAP = "123456789"; // Minimum of 8 characters; set to NULL if you want the access point to be open
|
||||||
const uint8_t wifi_channel = 0; // set to 0 for automatic channel selection
|
const uint8_t wifi_channel = 0; // set to 0 for automatic channel selection
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
#define MQTT_PORT 1883
|
#define MQTT_PORT 1883
|
||||||
|
|
||||||
/* Event options*/
|
/* Event options*/
|
||||||
#define EVENTLOGGING //Enable this line to log events to the event log
|
#define EVENTLOGGING //Enable this line to log events to the event log
|
||||||
#define DUMMY_EVENT_ENABLED false //Enable this line to have a dummy event that gets logged to test the interface
|
#define DUMMY_EVENT_ENABLED false //Enable this line to have a dummy event that gets logged to test the interface
|
||||||
|
|
||||||
/* Select charger used (Optional) */
|
/* Select charger used (Optional) */
|
||||||
|
|
|
@ -266,8 +266,9 @@ void update_values_tesla_model_3_battery() { //This function maps all the value
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if BMS is in need of recalibration
|
//Check if BMS is in need of recalibration
|
||||||
if (nominal_full_pack_energy > 1 &&nominal_full_pack_energy < REASONABLE_ENERGYAMOUNT) {
|
if (nominal_full_pack_energy > 1 && nominal_full_pack_energy < REASONABLE_ENERGYAMOUNT) {
|
||||||
Serial.println("Warning: kWh remaining " + String(nominal_full_pack_energy) + " reported by battery not plausible. Battery needs cycling.");
|
Serial.println("Warning: kWh remaining " + String(nominal_full_pack_energy) +
|
||||||
|
" reported by battery not plausible. Battery needs cycling.");
|
||||||
set_event(EVENT_KWH_PLAUSIBILITY_ERROR, nominal_full_pack_energy);
|
set_event(EVENT_KWH_PLAUSIBILITY_ERROR, nominal_full_pack_energy);
|
||||||
LEDcolor = YELLOW;
|
LEDcolor = YELLOW;
|
||||||
} else if (nominal_full_pack_energy <= 1) {
|
} else if (nominal_full_pack_energy <= 1) {
|
||||||
|
|
|
@ -111,15 +111,24 @@ struct SensorConfig {
|
||||||
};
|
};
|
||||||
|
|
||||||
SensorConfig sensorConfigs[] = {
|
SensorConfig sensorConfigs[] = {
|
||||||
{"SOC", "homeassistant/sensor/battery-emulator/SOC/config", "Battery Emulator SOC", "{{ value_json.SOC }}", "%", "battery"},
|
{"SOC", "homeassistant/sensor/battery-emulator/SOC/config", "Battery Emulator SOC", "{{ value_json.SOC }}", "%",
|
||||||
{"state_of_health", "homeassistant/sensor/battery-emulator/state_of_health/config", "Battery Emulator State Of Health", "{{ value_json.state_of_health }}", "%", "battery"},
|
"battery"},
|
||||||
{"temperature_min", "homeassistant/sensor/battery-emulator/temperature_min/config", "Battery Emulator Temperature Min", "{{ value_json.temperature_min }}", "°C", "temperature"},
|
{"state_of_health", "homeassistant/sensor/battery-emulator/state_of_health/config",
|
||||||
{"temperature_max", "homeassistant/sensor/battery-emulator/temperature_max/config", "Battery Emulator Temperature Max", "{{ value_json.temperature_max }}", "°C", "temperature"},
|
"Battery Emulator State Of Health", "{{ value_json.state_of_health }}", "%", "battery"},
|
||||||
{"stat_batt_power", "homeassistant/sensor/battery-emulator/stat_batt_power/config", "Battery Emulator Stat Batt Power", "{{ value_json.stat_batt_power }}", "W", "power"},
|
{"temperature_min", "homeassistant/sensor/battery-emulator/temperature_min/config",
|
||||||
{"battery_current", "homeassistant/sensor/battery-emulator/battery_current/config", "Battery Emulator Battery Current", "{{ value_json.battery_current }}", "A", "current"},
|
"Battery Emulator Temperature Min", "{{ value_json.temperature_min }}", "°C", "temperature"},
|
||||||
{"cell_max_voltage", "homeassistant/sensor/battery-emulator/cell_max_voltage/config", "Battery Emulator Cell Max Voltage", "{{ value_json.cell_max_voltage }}", "V", "voltage"},
|
{"temperature_max", "homeassistant/sensor/battery-emulator/temperature_max/config",
|
||||||
{"cell_min_voltage", "homeassistant/sensor/battery-emulator/cell_min_voltage/config", "Battery Emulator Cell Min Voltage", "{{ value_json.cell_min_voltage }}", "V", "voltage"},
|
"Battery Emulator Temperature Max", "{{ value_json.temperature_max }}", "°C", "temperature"},
|
||||||
{"battery_voltage", "homeassistant/sensor/battery-emulator/battery_voltage/config", "Battery Emulator Battery Voltage", "{{ value_json.battery_voltage }}", "V", "voltage"},
|
{"stat_batt_power", "homeassistant/sensor/battery-emulator/stat_batt_power/config",
|
||||||
|
"Battery Emulator Stat Batt Power", "{{ value_json.stat_batt_power }}", "W", "power"},
|
||||||
|
{"battery_current", "homeassistant/sensor/battery-emulator/battery_current/config",
|
||||||
|
"Battery Emulator Battery Current", "{{ value_json.battery_current }}", "A", "current"},
|
||||||
|
{"cell_max_voltage", "homeassistant/sensor/battery-emulator/cell_max_voltage/config",
|
||||||
|
"Battery Emulator Cell Max Voltage", "{{ value_json.cell_max_voltage }}", "V", "voltage"},
|
||||||
|
{"cell_min_voltage", "homeassistant/sensor/battery-emulator/cell_min_voltage/config",
|
||||||
|
"Battery Emulator Cell Min Voltage", "{{ value_json.cell_min_voltage }}", "V", "voltage"},
|
||||||
|
{"battery_voltage", "homeassistant/sensor/battery-emulator/battery_voltage/config",
|
||||||
|
"Battery Emulator Battery Voltage", "{{ value_json.battery_voltage }}", "V", "voltage"},
|
||||||
};
|
};
|
||||||
|
|
||||||
static void publish_common_info(void) {
|
static void publish_common_info(void) {
|
||||||
|
@ -130,55 +139,50 @@ static void publish_common_info(void) {
|
||||||
for (int i = 0; i < sizeof(sensorConfigs) / sizeof(sensorConfigs[0]); i++) {
|
for (int i = 0; i < sizeof(sensorConfigs) / sizeof(sensorConfigs[0]); i++) {
|
||||||
SensorConfig& config = sensorConfigs[i];
|
SensorConfig& config = sensorConfigs[i];
|
||||||
snprintf(mqtt_msg, sizeof(mqtt_msg),
|
snprintf(mqtt_msg, sizeof(mqtt_msg),
|
||||||
"{"
|
"{"
|
||||||
"\"name\": \"%s\","
|
"\"name\": \"%s\","
|
||||||
"\"state_topic\": \"%s\","
|
"\"state_topic\": \"%s\","
|
||||||
"\"unique_id\": \"battery-emulator_%s\","
|
"\"unique_id\": \"battery-emulator_%s\","
|
||||||
"\"object_id\": \"sensor_battery_%s\","
|
"\"object_id\": \"sensor_battery_%s\","
|
||||||
"\"device\": {"
|
"\"device\": {"
|
||||||
"\"identifiers\": ["
|
"\"identifiers\": ["
|
||||||
"\"battery-emulator\""
|
"\"battery-emulator\""
|
||||||
"],"
|
"],"
|
||||||
"\"manufacturer\": \"DalaTech\","
|
"\"manufacturer\": \"DalaTech\","
|
||||||
"\"model\": \"BatteryEmulator\","
|
"\"model\": \"BatteryEmulator\","
|
||||||
"\"name\": \"BatteryEmulator\""
|
"\"name\": \"BatteryEmulator\""
|
||||||
"},"
|
"},"
|
||||||
"\"origin\": {"
|
"\"origin\": {"
|
||||||
"\"name\": \"BatteryEmulator\","
|
"\"name\": \"BatteryEmulator\","
|
||||||
"\"sw\": \"%s-mqtt\","
|
"\"sw\": \"%s-mqtt\","
|
||||||
"\"url\": \"https://github.com/dalathegreat/Battery-Emulator\""
|
"\"url\": \"https://github.com/dalathegreat/Battery-Emulator\""
|
||||||
"},"
|
"},"
|
||||||
"\"value_template\": \"%s\","
|
"\"value_template\": \"%s\","
|
||||||
"\"unit_of_measurement\": \"%s\","
|
"\"unit_of_measurement\": \"%s\","
|
||||||
"\"device_class\": \"%s\","
|
"\"device_class\": \"%s\","
|
||||||
"\"enabled_by_default\": true,"
|
"\"enabled_by_default\": true,"
|
||||||
"\"state_class\": \"measurement\""
|
"\"state_class\": \"measurement\""
|
||||||
"}",
|
"}",
|
||||||
config.name, state_topic, config.object_id, config.object_id, version_number, config.value_template, config.unit, config.device_class);
|
config.name, state_topic, config.object_id, config.object_id, version_number, config.value_template,
|
||||||
|
config.unit, config.device_class);
|
||||||
mqtt_publish_retain(config.topic);
|
mqtt_publish_retain(config.topic);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
snprintf(mqtt_msg, sizeof(mqtt_msg),
|
snprintf(mqtt_msg, sizeof(mqtt_msg),
|
||||||
"{\n"
|
"{\n"
|
||||||
" \"SOC\": %.3f,\n"
|
" \"SOC\": %.3f,\n"
|
||||||
" \"state_of_health\": %.3f,\n"
|
" \"state_of_health\": %.3f,\n"
|
||||||
" \"temperature_min\": %.3f,\n"
|
" \"temperature_min\": %.3f,\n"
|
||||||
" \"temperature_max\": %.3f,\n"
|
" \"temperature_max\": %.3f,\n"
|
||||||
" \"stat_batt_power\": %.3f,\n"
|
" \"stat_batt_power\": %.3f,\n"
|
||||||
" \"battery_current\": %.3f,\n"
|
" \"battery_current\": %.3f,\n"
|
||||||
" \"cell_max_voltage\": %d,\n"
|
" \"cell_max_voltage\": %d,\n"
|
||||||
" \"cell_min_voltage\": %d,\n"
|
" \"cell_min_voltage\": %d,\n"
|
||||||
" \"battery_voltage\": %d\n"
|
" \"battery_voltage\": %d\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
((float)SOC) / 100.0,
|
((float)SOC) / 100.0, ((float)StateOfHealth) / 100.0, ((float)((int16_t)temperature_min)) / 10.0,
|
||||||
((float)StateOfHealth) / 100.0,
|
((float)((int16_t)temperature_max)) / 10.0, ((float)((int16_t)stat_batt_power)) / 10.0,
|
||||||
((float)((int16_t)temperature_min)) / 10.0,
|
((float)((int16_t)battery_current)) / 10.0, cell_max_voltage, cell_min_voltage, battery_voltage / 10.0);
|
||||||
((float)((int16_t)temperature_max)) / 10.0,
|
|
||||||
((float)((int16_t)stat_batt_power)) / 10.0,
|
|
||||||
((float)((int16_t)battery_current)) / 10.0,
|
|
||||||
cell_max_voltage,
|
|
||||||
cell_min_voltage,
|
|
||||||
battery_voltage / 10.0);
|
|
||||||
bool result = client.publish(state_topic, mqtt_msg, true);
|
bool result = client.publish(state_topic, mqtt_msg, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
#define MQTT_MSG_BUFFER_SIZE (1024)
|
#define MQTT_MSG_BUFFER_SIZE (1024)
|
||||||
|
|
||||||
extern const char* version_number; // The current software version, used for mqtt
|
extern const char* version_number; // The current software version, used for mqtt
|
||||||
|
|
||||||
extern uint16_t SOC;
|
extern uint16_t SOC;
|
||||||
extern uint16_t StateOfHealth;
|
extern uint16_t StateOfHealth;
|
||||||
|
|
|
@ -39,7 +39,8 @@ void set_event(EVENTS_ENUM_TYPE event, uint8_t data) {
|
||||||
++entries[event].occurences;
|
++entries[event].occurences;
|
||||||
set_event_message(event);
|
set_event_message(event);
|
||||||
#ifdef DEBUG_VIA_USB
|
#ifdef DEBUG_VIA_USB
|
||||||
Serial.println("Set event: " + String(get_event_enum_string(event)) + ". Has occured " + String(entries[event].occurences) + " times");
|
Serial.println("Set event: " + String(get_event_enum_string(event)) + ". Has occured " +
|
||||||
|
String(entries[event].occurences) + " times");
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -93,9 +94,11 @@ const char* get_event_message(EVENTS_ENUM_TYPE event) {
|
||||||
case EVENT_BATTERY_CHG_DISCHG_STOP_REQ:
|
case EVENT_BATTERY_CHG_DISCHG_STOP_REQ:
|
||||||
return "ERROR: Battery raised caution indicator AND requested charge/discharge stop. Inspect battery status!";
|
return "ERROR: Battery raised caution indicator AND requested charge/discharge stop. Inspect battery status!";
|
||||||
case EVENT_LOW_SOH:
|
case EVENT_LOW_SOH:
|
||||||
return "ERROR: State of health critically low. Battery internal resistance too high to continue. Recycle battery.";
|
return "ERROR: State of health critically low. Battery internal resistance too high to continue. Recycle "
|
||||||
|
"battery.";
|
||||||
case EVENT_HVIL_FAILURE:
|
case EVENT_HVIL_FAILURE:
|
||||||
return "ERROR: Battery interlock loop broken. Check that high voltage connectors are seated. Battery will be disabled!";
|
return "ERROR: Battery interlock loop broken. Check that high voltage connectors are seated. Battery will be "
|
||||||
|
"disabled!";
|
||||||
case EVENT_INTERNAL_OPEN_FAULT:
|
case EVENT_INTERNAL_OPEN_FAULT:
|
||||||
return "ERROR: High voltage cable removed while battery running. Opening contactors!";
|
return "ERROR: High voltage cable removed while battery running. Opening contactors!";
|
||||||
case EVENT_CELL_UNDER_VOLTAGE:
|
case EVENT_CELL_UNDER_VOLTAGE:
|
||||||
|
@ -114,11 +117,11 @@ const char* get_event_message(EVENTS_ENUM_TYPE event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* get_event_enum_string(EVENTS_ENUM_TYPE event) {
|
const char* get_event_enum_string(EVENTS_ENUM_TYPE event) {
|
||||||
const char* fullString = EVENTS_ENUM_TYPE_STRING[event];
|
const char* fullString = EVENTS_ENUM_TYPE_STRING[event];
|
||||||
if (strncmp(fullString, "EVENT_", 6) == 0) {
|
if (strncmp(fullString, "EVENT_", 6) == 0) {
|
||||||
return fullString + 6; // Skip the first 6 characters
|
return fullString + 6; // Skip the first 6 characters
|
||||||
}
|
}
|
||||||
return fullString;
|
return fullString;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_event_message(EVENTS_ENUM_TYPE event) {
|
static void set_event_message(EVENTS_ENUM_TYPE event) {
|
||||||
|
|
|
@ -9,36 +9,32 @@ extern uint32_t time_seconds;
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define EVENTS_ENUM_TYPE(XX) \
|
#define EVENTS_ENUM_TYPE(XX) \
|
||||||
XX(EVENT_CAN_FAILURE) \
|
XX(EVENT_CAN_FAILURE) \
|
||||||
XX(EVENT_CAN_WARNING) \
|
XX(EVENT_CAN_WARNING) \
|
||||||
XX(EVENT_WATER_INGRESS) \
|
XX(EVENT_WATER_INGRESS) \
|
||||||
XX(EVENT_12V_LOW) \
|
XX(EVENT_12V_LOW) \
|
||||||
XX(EVENT_SOC_PLAUSIBILITY_ERROR) \
|
XX(EVENT_SOC_PLAUSIBILITY_ERROR) \
|
||||||
XX(EVENT_KWH_PLAUSIBILITY_ERROR) \
|
XX(EVENT_KWH_PLAUSIBILITY_ERROR) \
|
||||||
XX(EVENT_BATTERY_CHG_STOP_REQ) \
|
XX(EVENT_BATTERY_CHG_STOP_REQ) \
|
||||||
XX(EVENT_BATTERY_DISCHG_STOP_REQ) \
|
XX(EVENT_BATTERY_DISCHG_STOP_REQ) \
|
||||||
XX(EVENT_BATTERY_CHG_DISCHG_STOP_REQ) \
|
XX(EVENT_BATTERY_CHG_DISCHG_STOP_REQ) \
|
||||||
XX(EVENT_LOW_SOH) \
|
XX(EVENT_LOW_SOH) \
|
||||||
XX(EVENT_HVIL_FAILURE) \
|
XX(EVENT_HVIL_FAILURE) \
|
||||||
XX(EVENT_INTERNAL_OPEN_FAULT) \
|
XX(EVENT_INTERNAL_OPEN_FAULT) \
|
||||||
XX(EVENT_CELL_UNDER_VOLTAGE) \
|
XX(EVENT_CELL_UNDER_VOLTAGE) \
|
||||||
XX(EVENT_CELL_OVER_VOLTAGE) \
|
XX(EVENT_CELL_OVER_VOLTAGE) \
|
||||||
XX(EVENT_CELL_DEVIATION_HIGH) \
|
XX(EVENT_CELL_DEVIATION_HIGH) \
|
||||||
XX(EVENT_UNKNOWN_EVENT_SET) \
|
XX(EVENT_UNKNOWN_EVENT_SET) \
|
||||||
XX(EVENT_DUMMY) \
|
XX(EVENT_DUMMY) \
|
||||||
XX(EVENT_NOF_EVENTS)
|
XX(EVENT_NOF_EVENTS)
|
||||||
|
|
||||||
#define GENERATE_ENUM(ENUM) ENUM,
|
#define GENERATE_ENUM(ENUM) ENUM,
|
||||||
#define GENERATE_STRING(STRING) #STRING,
|
#define GENERATE_STRING(STRING) #STRING,
|
||||||
|
|
||||||
typedef enum {
|
typedef enum { EVENTS_ENUM_TYPE(GENERATE_ENUM) } EVENTS_ENUM_TYPE;
|
||||||
EVENTS_ENUM_TYPE(GENERATE_ENUM)
|
|
||||||
} EVENTS_ENUM_TYPE;
|
|
||||||
|
|
||||||
static const char *EVENTS_ENUM_TYPE_STRING[] = {
|
static const char* EVENTS_ENUM_TYPE_STRING[] = {EVENTS_ENUM_TYPE(GENERATE_STRING)};
|
||||||
EVENTS_ENUM_TYPE(GENERATE_STRING)
|
|
||||||
};
|
|
||||||
|
|
||||||
const char* get_event_enum_string(EVENTS_ENUM_TYPE event);
|
const char* get_event_enum_string(EVENTS_ENUM_TYPE event);
|
||||||
|
|
||||||
|
|
|
@ -37,20 +37,20 @@ const char index_html[] PROGMEM = R"rawliteral(
|
||||||
)rawliteral";
|
)rawliteral";
|
||||||
|
|
||||||
enum WifiState {
|
enum WifiState {
|
||||||
INIT, //before connecting first time
|
INIT, //before connecting first time
|
||||||
RECONNECTING, //we've connected before, but lost connection
|
RECONNECTING, //we've connected before, but lost connection
|
||||||
CONNECTED //we are connected
|
CONNECTED //we are connected
|
||||||
};
|
};
|
||||||
|
|
||||||
WifiState wifi_state = INIT;
|
WifiState wifi_state = INIT;
|
||||||
|
|
||||||
unsigned const long WIFI_MONITOR_INTERVAL_TIME = 15000;
|
unsigned const long WIFI_MONITOR_INTERVAL_TIME = 15000;
|
||||||
unsigned const long INIT_WIFI_CONNECT_TIMEOUT = 8000; // Timeout for initial WiFi connect in milliseconds
|
unsigned const long INIT_WIFI_CONNECT_TIMEOUT = 8000; // Timeout for initial WiFi connect in milliseconds
|
||||||
unsigned const long DEFAULT_WIFI_RECONNECT_INTERVAL = 1000; // Default WiFi reconnect interval in ms
|
unsigned const long DEFAULT_WIFI_RECONNECT_INTERVAL = 1000; // Default WiFi reconnect interval in ms
|
||||||
unsigned const long MAX_WIFI_RETRY_INTERVAL = 30000; // Maximum wifi retry interval in ms
|
unsigned const long MAX_WIFI_RETRY_INTERVAL = 30000; // Maximum wifi retry interval in ms
|
||||||
unsigned long last_wifi_monitor_time = millis(); //init millis so wifi monitor doesn't run immediately
|
unsigned long last_wifi_monitor_time = millis(); //init millis so wifi monitor doesn't run immediately
|
||||||
unsigned long wifi_reconnect_interval = DEFAULT_WIFI_RECONNECT_INTERVAL;
|
unsigned long wifi_reconnect_interval = DEFAULT_WIFI_RECONNECT_INTERVAL;
|
||||||
unsigned long last_wifi_attempt_time = millis(); //init millis so wifi monitor doesn't run immediately
|
unsigned long last_wifi_attempt_time = millis(); //init millis so wifi monitor doesn't run immediately
|
||||||
|
|
||||||
void init_webserver() {
|
void init_webserver() {
|
||||||
// Configure WiFi
|
// Configure WiFi
|
||||||
|
@ -76,9 +76,8 @@ void init_webserver() {
|
||||||
});
|
});
|
||||||
|
|
||||||
#ifdef EVENTLOGGING
|
#ifdef EVENTLOGGING
|
||||||
server.on("/events", HTTP_GET, [](AsyncWebServerRequest* request) {
|
server.on("/events", HTTP_GET,
|
||||||
request->send_P(200, "text/html", index_html, events_processor);
|
[](AsyncWebServerRequest* request) { request->send_P(200, "text/html", index_html, events_processor); });
|
||||||
});
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Route for editing Wh
|
// Route for editing Wh
|
||||||
|
@ -295,14 +294,14 @@ String getConnectResultString(wl_status_t status) {
|
||||||
|
|
||||||
void wifi_monitor() {
|
void wifi_monitor() {
|
||||||
unsigned long currentMillis = millis();
|
unsigned long currentMillis = millis();
|
||||||
if(currentMillis - last_wifi_monitor_time > WIFI_MONITOR_INTERVAL_TIME) {
|
if (currentMillis - last_wifi_monitor_time > WIFI_MONITOR_INTERVAL_TIME) {
|
||||||
last_wifi_monitor_time = currentMillis;
|
last_wifi_monitor_time = currentMillis;
|
||||||
wl_status_t status = WiFi.status();
|
wl_status_t status = WiFi.status();
|
||||||
if (status != WL_CONNECTED && status != WL_IDLE_STATUS) {
|
if (status != WL_CONNECTED && status != WL_IDLE_STATUS) {
|
||||||
Serial.println(getConnectResultString(status));
|
Serial.println(getConnectResultString(status));
|
||||||
if(wifi_state == INIT) { //we haven't been connected yet, try the init logic
|
if (wifi_state == INIT) { //we haven't been connected yet, try the init logic
|
||||||
init_WiFi_STA(ssid, password, wifi_channel);
|
init_WiFi_STA(ssid, password, wifi_channel);
|
||||||
} else { //we were connected before, try the reconnect logic
|
} else { //we were connected before, try the reconnect logic
|
||||||
if (currentMillis - last_wifi_attempt_time > wifi_reconnect_interval) {
|
if (currentMillis - last_wifi_attempt_time > wifi_reconnect_interval) {
|
||||||
last_wifi_attempt_time = currentMillis;
|
last_wifi_attempt_time = currentMillis;
|
||||||
Serial.println("WiFi not connected, trying to reconnect...");
|
Serial.println("WiFi not connected, trying to reconnect...");
|
||||||
|
@ -975,8 +974,10 @@ String events_processor(const String& var) {
|
||||||
content.reserve(5000);
|
content.reserve(5000);
|
||||||
// Page format
|
// Page format
|
||||||
content.concat(FPSTR(EVENTS_HTML_START));
|
content.concat(FPSTR(EVENTS_HTML_START));
|
||||||
for(int i = 0; i < EVENT_NOF_EVENTS; i++) {
|
for (int i = 0; i < EVENT_NOF_EVENTS; i++) {
|
||||||
Serial.println("Event: " + String(get_event_enum_string(static_cast<EVENTS_ENUM_TYPE>(i))) + " count: " + String(entries[i].occurences) + " seconds: " + String(entries[i].timestamp) + " data: " + String(entries[i].data));
|
Serial.println("Event: " + String(get_event_enum_string(static_cast<EVENTS_ENUM_TYPE>(i))) +
|
||||||
|
" count: " + String(entries[i].occurences) + " seconds: " + String(entries[i].timestamp) +
|
||||||
|
" data: " + String(entries[i].data));
|
||||||
if (entries[i].occurences > 0) {
|
if (entries[i].occurences > 0) {
|
||||||
content.concat("<div class='event'>");
|
content.concat("<div class='event'>");
|
||||||
content.concat("<div>" + String(get_event_enum_string(static_cast<EVENTS_ENUM_TYPE>(i))) + "</div>");
|
content.concat("<div>" + String(get_event_enum_string(static_cast<EVENTS_ENUM_TYPE>(i))) + "</div>");
|
||||||
|
@ -985,7 +986,7 @@ String events_processor(const String& var) {
|
||||||
content.concat("<div>" + String(entries[i].occurences) + "</div>");
|
content.concat("<div>" + String(entries[i].occurences) + "</div>");
|
||||||
content.concat("<div>" + String(entries[i].data) + "</div>");
|
content.concat("<div>" + String(entries[i].data) + "</div>");
|
||||||
content.concat("<div>" + String(get_event_message(static_cast<EVENTS_ENUM_TYPE>(i))) + "</div>");
|
content.concat("<div>" + String(get_event_message(static_cast<EVENTS_ENUM_TYPE>(i))) + "</div>");
|
||||||
content.concat("</div>"); // End of event row
|
content.concat("</div>"); // End of event row
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
content.concat(FPSTR(EVENTS_HTML_END));
|
content.concat(FPSTR(EVENTS_HTML_END));
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#include "../mqtt/mqtt.h"
|
#include "../mqtt/mqtt.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern const char* version_number; // The current software version, shown on webserver
|
extern const char* version_number; // The current software version, shown on webserver
|
||||||
extern uint16_t SOC; //SOC%, 0-100.00 (0-10000)
|
extern uint16_t SOC; //SOC%, 0-100.00 (0-10000)
|
||||||
extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000)
|
extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000)
|
||||||
extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000)
|
extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000)
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#define DUMMY_EVENT_ENABLED true
|
#define DUMMY_EVENT_ENABLED true
|
||||||
|
|
||||||
/* Helper functions */
|
/* Helper functions */
|
||||||
static char event_message[256]; // Declare the event_message variable
|
static char event_message[256]; // Declare the event_message variable
|
||||||
|
|
||||||
static void reset_event_msg(void) {
|
static void reset_event_msg(void) {
|
||||||
snprintf(event_message, sizeof(event_message), "");
|
snprintf(event_message, sizeof(event_message), "");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue