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
|
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
||||||
|
@ -154,7 +163,8 @@ static void publish_common_info(void) {
|
||||||
"\"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 {
|
||||||
|
@ -170,15 +180,9 @@ static void publish_common_info(void) {
|
||||||
" \"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,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:
|
||||||
|
|
|
@ -32,13 +32,9 @@ extern uint32_t time_seconds;
|
||||||
#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);
|
||||||
|
|
||||||
|
|
|
@ -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,12 +294,12 @@ 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) {
|
||||||
|
@ -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>");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue