Skip to content

Commit

Permalink
fix battery voltage and current
Browse files Browse the repository at this point in the history
  • Loading branch information
Brett Christensen committed Feb 10, 2024
1 parent 3a8dc63 commit d3300f3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Software/src/devboard/mqtt/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static void publish_cell_voltages(void) {
// is the string content

// If cell voltages haven't been populated...
if (cellvoltages[0] == 0u) {
if (cellvoltages[0] == 0u / 1000) { //cell voltage is in mV and homeassistant expects V
return;
}

Expand Down Expand Up @@ -181,8 +181,9 @@ static void publish_common_info(void) {
" \"battery_voltage\": %d\n"
"}\n",
((float)SOC) / 100.0, ((float)StateOfHealth) / 100.0, ((float)((int16_t)temperature_min)) / 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);
((float)((int16_t)temperature_max)) / 10.0, ((float)((int16_t)stat_batt_power)),
((float)((int16_t)battery_current)) / 10.0, cell_max_voltage / 1000, cell_min_voltage / 1000,
battery_voltage / 10.0);
bool result = client.publish(state_topic, mqtt_msg, true);
}

Expand Down
2 changes: 2 additions & 0 deletions Software/src/devboard/mqtt/mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ extern uint16_t cell_max_voltage; //mV, 0-4350
extern uint16_t cell_min_voltage; //mV, 0-4350
extern uint16_t cellvoltages[120]; //mV 0-4350 per cell
extern uint8_t nof_cellvoltages; // Total number of cell voltages, set by each battery.
extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000)
extern uint16_t battery_current; //A+1, Goes thru convert2unsignedint16 function (5.0A = 50, -5.0A = 65485)

extern const char* mqtt_user;
extern const char* mqtt_password;
Expand Down

0 comments on commit d3300f3

Please sign in to comment.