mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-04 02:09:30 +02:00
Merge branch 'main' into mqtt-cleanup
This commit is contained in:
commit
ff18c2fc4a
60 changed files with 1371 additions and 1344 deletions
|
@ -37,7 +37,9 @@ static void publish_cell_voltages(void) {
|
|||
static JsonDocument doc;
|
||||
static const char* hostname = WiFi.getHostname();
|
||||
static String state_topic = String("battery-emulator_") + String(hostname) + "/spec_data";
|
||||
if (nof_cellvoltages == 0u) {
|
||||
|
||||
// If the cell voltage number isn't initialized...
|
||||
if (system_number_of_cells == 0u) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -45,7 +47,7 @@ static void publish_cell_voltages(void) {
|
|||
mqtt_first_transmission = false;
|
||||
String topic = "homeassistant/sensor/battery-emulator/cell_voltage";
|
||||
|
||||
for (int i = 0; i < nof_cellvoltages; i++) {
|
||||
for (int i = 0; i < system_number_of_cells; i++) {
|
||||
int cellNumber = i + 1;
|
||||
doc["name"] = "Battery Cell Voltage " + String(cellNumber);
|
||||
doc["object_id"] = "battery_voltage_cell" + String(cellNumber);
|
||||
|
@ -72,13 +74,13 @@ static void publish_cell_voltages(void) {
|
|||
doc.clear(); // clear after sending autoconfig
|
||||
} else {
|
||||
// If cell voltages haven't been populated...
|
||||
if (nof_cellvoltages == 0u) {
|
||||
if (system_number_of_cells == 0u) {
|
||||
return;
|
||||
}
|
||||
|
||||
JsonArray cell_voltages = doc["cell_voltages"].to<JsonArray>();
|
||||
for (size_t i = 0; i < nof_cellvoltages; ++i) {
|
||||
cell_voltages.add(((float)cellvoltages[i]) / 1000.0);
|
||||
for (size_t i = 0; i < system_number_of_cells; ++i) {
|
||||
cell_voltages.add(((float)system_cellvoltages_mV[i]) / 1000.0);
|
||||
}
|
||||
|
||||
serializeJson(doc, mqtt_msg, sizeof(mqtt_msg));
|
||||
|
@ -145,15 +147,16 @@ static void publish_common_info(void) {
|
|||
}
|
||||
doc.clear();
|
||||
} else {
|
||||
doc["SOC"] = ((float)SOC) / 100.0;
|
||||
doc["state_of_health"] = ((float)StateOfHealth) / 100.0;
|
||||
doc["temperature_min"] = ((float)((int16_t)temperature_min)) / 10.0;
|
||||
doc["temperature_max"] = ((float)((int16_t)temperature_max)) / 10.0;
|
||||
doc["stat_batt_power"] = ((float)((int16_t)stat_batt_power));
|
||||
doc["battery_current"] = ((float)((int16_t)battery_current)) / 10.0;
|
||||
doc["cell_max_voltage"] = ((float)cell_max_voltage) / 1000.0;
|
||||
doc["cell_min_voltage"] = ((float)cell_min_voltage) / 1000.0;
|
||||
doc["battery_voltage"] = ((float)battery_voltage) / 10.0;
|
||||
doc["SOC"] = ((float)system_scaled_SOC_pptt) / 100.0;
|
||||
doc["SOC_real"] = ((float)system_real_SOC_pptt) / 100.0;
|
||||
doc["state_of_health"] = ((float)system_SOH_pptt) / 100.0;
|
||||
doc["temperature_min"] = ((float)((int16_t)system_temperature_min_dC)) / 10.0;
|
||||
doc["temperature_max"] = ((float)((int16_t)system_temperature_max_dC)) / 10.0;
|
||||
doc["stat_batt_power"] = ((float)((int16_t)system_active_power_W));
|
||||
doc["battery_current"] = ((float)((int16_t)system_battery_current_dA)) / 10.0;
|
||||
doc["cell_max_voltage"] = ((float)system_cell_max_voltage_mV) / 1000.0;
|
||||
doc["cell_min_voltage"] = ((float)system_cell_min_voltage_mV) / 1000.0;
|
||||
doc["battery_voltage"] = ((float)system_battery_voltage_dV) / 10.0;
|
||||
|
||||
serializeJson(doc, mqtt_msg);
|
||||
if (!mqtt_publish(state_topic.c_str(), mqtt_msg, false)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue