From 5388a4b5917f31faf1fc198712fe6c502a6ddd09 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 15 Aug 2024 19:40:52 +0300 Subject: [PATCH 01/17] Make eGMP use correct CAN struct --- Software/src/battery/KIA-E-GMP-BATTERY.cpp | 184 ++++++++++----------- 1 file changed, 91 insertions(+), 93 deletions(-) diff --git a/Software/src/battery/KIA-E-GMP-BATTERY.cpp b/Software/src/battery/KIA-E-GMP-BATTERY.cpp index e8f07f36..a157137b 100644 --- a/Software/src/battery/KIA-E-GMP-BATTERY.cpp +++ b/Software/src/battery/KIA-E-GMP-BATTERY.cpp @@ -19,7 +19,7 @@ static uint16_t SOC_Display = 0; static uint16_t batterySOH = 1000; static uint16_t CellVoltMax_mV = 3700; static uint16_t CellVoltMin_mV = 3700; -static uint16_t batteryVoltage = 0; +static uint16_t batteryVoltage = 6700; static int16_t leadAcidBatteryVoltage = 120; static int16_t batteryAmps = 0; static int16_t powerWatt = 0; @@ -53,10 +53,10 @@ CAN_frame EGMP_7E4_ack = { .ID = 0x7E4, .data = {0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; //Ack frame, correct PID is returned -void set_cell_voltages(CANFDMessage frame, int start, int length, int startCell) { +void set_cell_voltages(CAN_frame rx_frame, int start, int length, int startCell) { for (size_t i = 0; i < length; i++) { - if ((frame.data[start + i] * 20) > 1000) { - datalayer.battery.status.cell_voltages_mV[startCell + i] = (frame.data[start + i] * 20); + if ((rx_frame.data.u8[start + i] * 20) > 1000) { + datalayer.battery.status.cell_voltages_mV[startCell + i] = (rx_frame.data.u8[start + i] * 20); } } } @@ -180,170 +180,170 @@ void update_values_battery() { //This function maps all the values fetched via #endif } -void receive_canfd_battery(CANFDMessage frame) { +void receive_can_battery(CAN_frame rx_frame) { datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; - switch (frame.id) { + switch (rx_frame.ID) { case 0x7EC: // print_canfd_frame(frame); - switch (frame.data[0]) { + switch (rx_frame.data.u8[0]) { case 0x10: //"PID Header" // Serial.println ("Send ack"); - poll_data_pid = frame.data[4]; - // if (frame.data[4] == poll_data_pid) { + poll_data_pid = rx_frame.data.u8[4]; + // if (rx_frame.data.u8[4] == poll_data_pid) { transmit_can(&EGMP_7E4_ack, can_config.battery); //Send ack to BMS if the same frame is sent as polled // } break; case 0x21: //First frame in PID group if (poll_data_pid == 1) { - allowedChargePower = ((frame.data[3] << 8) + frame.data[4]); - allowedDischargePower = ((frame.data[5] << 8) + frame.data[6]); - SOC_BMS = frame.data[2] * 5; //100% = 200 ( 200 * 5 = 1000 ) + allowedChargePower = ((rx_frame.data.u8[3] << 8) + rx_frame.data.u8[4]); + allowedDischargePower = ((rx_frame.data.u8[5] << 8) + rx_frame.data.u8[6]); + SOC_BMS = rx_frame.data.u8[2] * 5; //100% = 200 ( 200 * 5 = 1000 ) } else if (poll_data_pid == 2) { // set cell voltages data, start bite, data length from start, start cell - set_cell_voltages(frame, 2, 6, 0); + set_cell_voltages(rx_frame, 2, 6, 0); } else if (poll_data_pid == 3) { - set_cell_voltages(frame, 2, 6, 32); + set_cell_voltages(rx_frame, 2, 6, 32); } else if (poll_data_pid == 4) { - set_cell_voltages(frame, 2, 6, 64); + set_cell_voltages(rx_frame, 2, 6, 64); } else if (poll_data_pid == 0x0A) { - set_cell_voltages(frame, 2, 6, 96); + set_cell_voltages(rx_frame, 2, 6, 96); } else if (poll_data_pid == 0x0B) { - set_cell_voltages(frame, 2, 6, 128); + set_cell_voltages(rx_frame, 2, 6, 128); } else if (poll_data_pid == 0x0C) { - set_cell_voltages(frame, 2, 6, 160); + set_cell_voltages(rx_frame, 2, 6, 160); } break; case 0x22: //Second datarow in PID group if (poll_data_pid == 1) { - batteryVoltage = (frame.data[3] << 8) + frame.data[4]; - batteryAmps = (frame.data[1] << 8) + frame.data[2]; - temperatureMax = frame.data[5]; - temperatureMin = frame.data[6]; - // temp1 = frame.data[7]; + batteryVoltage = (rx_frame.data.u8[3] << 8) + rx_frame.data.u8[4]; + batteryAmps = (rx_frame.data.u8[1] << 8) + rx_frame.data.u8[2]; + temperatureMax = rx_frame.data.u8[5]; + temperatureMin = rx_frame.data.u8[6]; + // temp1 = rx_frame.data.u8[7]; } else if (poll_data_pid == 2) { - set_cell_voltages(frame, 1, 7, 6); + set_cell_voltages(rx_frame, 1, 7, 6); } else if (poll_data_pid == 3) { - set_cell_voltages(frame, 1, 7, 38); + set_cell_voltages(rx_frame, 1, 7, 38); } else if (poll_data_pid == 4) { - set_cell_voltages(frame, 1, 7, 70); + set_cell_voltages(rx_frame, 1, 7, 70); } else if (poll_data_pid == 0x0A) { - set_cell_voltages(frame, 1, 7, 102); + set_cell_voltages(rx_frame, 1, 7, 102); } else if (poll_data_pid == 0x0B) { - set_cell_voltages(frame, 1, 7, 134); + set_cell_voltages(rx_frame, 1, 7, 134); } else if (poll_data_pid == 0x0C) { - set_cell_voltages(frame, 1, 7, 166); + set_cell_voltages(rx_frame, 1, 7, 166); } else if (poll_data_pid == 6) { - batteryManagementMode = frame.data[5]; + batteryManagementMode = rx_frame.data.u8[5]; } break; case 0x23: //Third datarow in PID group if (poll_data_pid == 1) { - temperature_water_inlet = frame.data[6]; - CellVoltMax_mV = (frame.data[7] * 20); //(volts *50) *20 =mV - // temp2 = frame.data[1]; - // temp3 = frame.data[2]; - // temp4 = frame.data[3]; + temperature_water_inlet = rx_frame.data.u8[6]; + CellVoltMax_mV = (rx_frame.data.u8[7] * 20); //(volts *50) *20 =mV + // temp2 = rx_frame.data.u8[1]; + // temp3 = rx_frame.data.u8[2]; + // temp4 = rx_frame.data.u8[3]; } else if (poll_data_pid == 2) { - set_cell_voltages(frame, 1, 7, 13); + set_cell_voltages(rx_frame, 1, 7, 13); } else if (poll_data_pid == 3) { - set_cell_voltages(frame, 1, 7, 45); + set_cell_voltages(rx_frame, 1, 7, 45); } else if (poll_data_pid == 4) { - set_cell_voltages(frame, 1, 7, 77); + set_cell_voltages(rx_frame, 1, 7, 77); } else if (poll_data_pid == 0x0A) { - set_cell_voltages(frame, 1, 7, 109); + set_cell_voltages(rx_frame, 1, 7, 109); } else if (poll_data_pid == 0x0B) { - set_cell_voltages(frame, 1, 7, 141); + set_cell_voltages(rx_frame, 1, 7, 141); } else if (poll_data_pid == 0x0C) { - set_cell_voltages(frame, 1, 7, 173); + set_cell_voltages(rx_frame, 1, 7, 173); } else if (poll_data_pid == 5) { - // ac = frame.data[3]; - // Vdiff = frame.data[4]; + // ac = rx_frame.data.u8[3]; + // Vdiff = rx_frame.data.u8[4]; - // airbag = frame.data[6]; - heatertemp = frame.data[7]; + // airbag = rx_frame.data.u8[6]; + heatertemp = rx_frame.data.u8[7]; } break; case 0x24: //Fourth datarow in PID group if (poll_data_pid == 1) { - CellVmaxNo = frame.data[1]; - CellVoltMin_mV = (frame.data[2] * 20); //(volts *50) *20 =mV - CellVminNo = frame.data[3]; - // fanMod = frame.data[4]; - // fanSpeed = frame.data[5]; - leadAcidBatteryVoltage = frame.data[6]; //12v Battery Volts - //cumulative_charge_current[0] = frame.data[7]; + CellVmaxNo = rx_frame.data.u8[1]; + CellVoltMin_mV = (rx_frame.data.u8[2] * 20); //(volts *50) *20 =mV + CellVminNo = rx_frame.data.u8[3]; + // fanMod = rx_frame.data.u8[4]; + // fanSpeed = rx_frame.data.u8[5]; + leadAcidBatteryVoltage = rx_frame.data.u8[6]; //12v Battery Volts + //cumulative_charge_current[0] = rx_frame.data.u8[7]; } else if (poll_data_pid == 2) { - set_cell_voltages(frame, 1, 7, 20); + set_cell_voltages(rx_frame, 1, 7, 20); } else if (poll_data_pid == 3) { - set_cell_voltages(frame, 1, 7, 52); + set_cell_voltages(rx_frame, 1, 7, 52); } else if (poll_data_pid == 4) { - set_cell_voltages(frame, 1, 7, 84); + set_cell_voltages(rx_frame, 1, 7, 84); } else if (poll_data_pid == 0x0A) { - set_cell_voltages(frame, 1, 7, 116); + set_cell_voltages(rx_frame, 1, 7, 116); } else if (poll_data_pid == 0x0B) { - set_cell_voltages(frame, 1, 7, 148); + set_cell_voltages(rx_frame, 1, 7, 148); } else if (poll_data_pid == 0x0C) { - set_cell_voltages(frame, 1, 7, 180); + set_cell_voltages(rx_frame, 1, 7, 180); } else if (poll_data_pid == 5) { - batterySOH = ((frame.data[2] << 8) + frame.data[3]); - // maxDetCell = frame.data[4]; - // minDet = (frame.data[5] << 8) + frame.data[6]; - // minDetCell = frame.data[7]; + batterySOH = ((rx_frame.data.u8[2] << 8) + rx_frame.data.u8[3]); + // maxDetCell = rx_frame.data.u8[4]; + // minDet = (rx_frame.data.u8[5] << 8) + rx_frame.data.u8[6]; + // minDetCell = rx_frame.data.u8[7]; } break; case 0x25: //Fifth datarow in PID group if (poll_data_pid == 1) { - //cumulative_charge_current[1] = frame.data[1]; - //cumulative_charge_current[2] = frame.data[2]; - //cumulative_charge_current[3] = frame.data[3]; - //cumulative_discharge_current[0] = frame.data[4]; - //cumulative_discharge_current[1] = frame.data[5]; - //cumulative_discharge_current[2] = frame.data[6]; - //cumulative_discharge_current[3] = frame.data[7]; + //cumulative_charge_current[1] = rx_frame.data.u8[1]; + //cumulative_charge_current[2] = rx_frame.data.u8[2]; + //cumulative_charge_current[3] = rx_frame.data.u8[3]; + //cumulative_discharge_current[0] = rx_frame.data.u8[4]; + //cumulative_discharge_current[1] = rx_frame.data.u8[5]; + //cumulative_discharge_current[2] = rx_frame.data.u8[6]; + //cumulative_discharge_current[3] = rx_frame.data.u8[7]; //set_cumulative_charge_current(); //set_cumulative_discharge_current(); } else if (poll_data_pid == 2) { - set_cell_voltages(frame, 1, 5, 27); + set_cell_voltages(rx_frame, 1, 5, 27); } else if (poll_data_pid == 3) { - set_cell_voltages(frame, 1, 5, 59); + set_cell_voltages(rx_frame, 1, 5, 59); } else if (poll_data_pid == 4) { - set_cell_voltages(frame, 1, 5, 91); + set_cell_voltages(rx_frame, 1, 5, 91); } else if (poll_data_pid == 0x0A) { - set_cell_voltages(frame, 1, 5, 123); + set_cell_voltages(rx_frame, 1, 5, 123); } else if (poll_data_pid == 0x0B) { - set_cell_voltages(frame, 1, 5, 155); + set_cell_voltages(rx_frame, 1, 5, 155); } else if (poll_data_pid == 0x0C) { - set_cell_voltages(frame, 1, 5, 187); + set_cell_voltages(rx_frame, 1, 5, 187); //set_cell_count(); } else if (poll_data_pid == 5) { // datalayer.battery.info.number_of_cells = 98; - SOC_Display = frame.data[1] * 5; + SOC_Display = rx_frame.data.u8[1] * 5; } break; case 0x26: //Sixth datarow in PID group if (poll_data_pid == 1) { - //cumulative_energy_charged[0] = frame.data[1]; - // cumulative_energy_charged[1] = frame.data[2]; - //cumulative_energy_charged[2] = frame.data[3]; - //cumulative_energy_charged[3] = frame.data[4]; - //cumulative_energy_discharged[0] = frame.data[5]; - //cumulative_energy_discharged[1] = frame.data[6]; - //cumulative_energy_discharged[2] = frame.data[7]; + //cumulative_energy_charged[0] = rx_frame.data.u8[1]; + // cumulative_energy_charged[1] = rx_frame.data.u8[2]; + //cumulative_energy_charged[2] = rx_frame.data.u8[3]; + //cumulative_energy_charged[3] = rx_frame.data.u8[4]; + //cumulative_energy_discharged[0] = rx_frame.data.u8[5]; + //cumulative_energy_discharged[1] = rx_frame.data.u8[6]; + //cumulative_energy_discharged[2] = rx_frame.data.u8[7]; // set_cumulative_energy_charged(); } break; case 0x27: //Seventh datarow in PID group if (poll_data_pid == 1) { - //cumulative_energy_discharged[3] = frame.data[1]; + //cumulative_energy_discharged[3] = rx_frame.data.u8[1]; - //opTimeBytes[0] = frame.data[2]; - //opTimeBytes[1] = frame.data[3]; - //opTimeBytes[2] = frame.data[4]; - //opTimeBytes[3] = frame.data[5]; + //opTimeBytes[0] = rx_frame.data.u8[2]; + //opTimeBytes[1] = rx_frame.data.u8[3]; + //opTimeBytes[2] = rx_frame.data.u8[4]; + //opTimeBytes[3] = rx_frame.data.u8[5]; - BMS_ign = frame.data[6]; - inverterVoltageFrameHigh = frame.data[7]; // BMS Capacitoir + BMS_ign = rx_frame.data.u8[6]; + inverterVoltageFrameHigh = rx_frame.data.u8[7]; // BMS Capacitoir // set_cumulative_energy_discharged(); // set_opTime(); @@ -351,7 +351,7 @@ void receive_canfd_battery(CANFDMessage frame) { break; case 0x28: //Eighth datarow in PID group if (poll_data_pid == 1) { - inverterVoltage = (inverterVoltageFrameHigh << 8) + frame.data[1]; // BMS Capacitoir + inverterVoltage = (inverterVoltageFrameHigh << 8) + rx_frame.data.u8[1]; // BMS Capacitoir } break; } @@ -361,8 +361,6 @@ void receive_canfd_battery(CANFDMessage frame) { } } -void receive_can_battery(CAN_frame frame) {} // Not used on CAN-FD battery, just included to compile - void send_can_battery() { unsigned long currentMillis = millis(); From 6d5f7aebc70565b7fe9c795ae27be8ca926947d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Fri, 16 Aug 2024 17:06:00 +0300 Subject: [PATCH 02/17] Add known sent IDs to receive function --- Software/src/battery/KIA-E-GMP-BATTERY.cpp | 52 +++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/Software/src/battery/KIA-E-GMP-BATTERY.cpp b/Software/src/battery/KIA-E-GMP-BATTERY.cpp index a157137b..d1857bce 100644 --- a/Software/src/battery/KIA-E-GMP-BATTERY.cpp +++ b/Software/src/battery/KIA-E-GMP-BATTERY.cpp @@ -181,8 +181,58 @@ void update_values_battery() { //This function maps all the values fetched via } void receive_can_battery(CAN_frame rx_frame) { - datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; switch (rx_frame.ID) { + case 0x055: + datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; + break; + case 0x150: + datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; + break; + case 0x1F5: + datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; + break; + case 0x215: + datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; + break; + case 0x21A: + datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; + break; + case 0x235: + datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; + break; + case 0x245: + datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; + break; + case 0x25A: + datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; + break; + case 0x275: + datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; + break; + case 0x2FA: + datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; + break; + case 0x325: + datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; + break; + case 0x330: + datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; + break; + case 0x335: + datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; + break; + case 0x360: + datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; + break; + case 0x365: + datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; + break; + case 0x3BA: + datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; + break; + case 0x3F5: + datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; + break; case 0x7EC: // print_canfd_frame(frame); switch (rx_frame.data.u8[0]) { From cd587cf8ca1ec050100d3b01072c2feb7264f53a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Tue, 20 Aug 2024 17:28:33 +0300 Subject: [PATCH 03/17] Add initial batch of CAN messages --- Software/src/battery/KIA-E-GMP-BATTERY.cpp | 197 ++++++++++++++++++++- 1 file changed, 190 insertions(+), 7 deletions(-) diff --git a/Software/src/battery/KIA-E-GMP-BATTERY.cpp b/Software/src/battery/KIA-E-GMP-BATTERY.cpp index d1857bce..c123e4c2 100644 --- a/Software/src/battery/KIA-E-GMP-BATTERY.cpp +++ b/Software/src/battery/KIA-E-GMP-BATTERY.cpp @@ -6,11 +6,31 @@ #include "KIA-E-GMP-BATTERY.h" /* Do not change code below unless you are sure what you are doing */ +static unsigned long previousMillis20ms = 0; // will store last time a 20ms CAN Message was send +static unsigned long previousMillis200ms = 0; // will store last time a 200ms CAN Message was send static unsigned long previousMillis500ms = 0; // will store last time a 500ms CAN Message was send #define MAX_CELL_VOLTAGE 4250 //Battery is put into emergency stop if one cell goes over this value #define MIN_CELL_VOLTAGE 2950 //Battery is put into emergency stop if one cell goes below this value +const unsigned char crc8_table[256] = + { // CRC8_SAE_J1850_ZER0 formula,0x1D Poly,initial value 0x3F,Final XOR value varies + 0x00, 0x1D, 0x3A, 0x27, 0x74, 0x69, 0x4E, 0x53, 0xE8, 0xF5, 0xD2, 0xCF, 0x9C, 0x81, 0xA6, 0xBB, 0xCD, 0xD0, + 0xF7, 0xEA, 0xB9, 0xA4, 0x83, 0x9E, 0x25, 0x38, 0x1F, 0x02, 0x51, 0x4C, 0x6B, 0x76, 0x87, 0x9A, 0xBD, 0xA0, + 0xF3, 0xEE, 0xC9, 0xD4, 0x6F, 0x72, 0x55, 0x48, 0x1B, 0x06, 0x21, 0x3C, 0x4A, 0x57, 0x70, 0x6D, 0x3E, 0x23, + 0x04, 0x19, 0xA2, 0xBF, 0x98, 0x85, 0xD6, 0xCB, 0xEC, 0xF1, 0x13, 0x0E, 0x29, 0x34, 0x67, 0x7A, 0x5D, 0x40, + 0xFB, 0xE6, 0xC1, 0xDC, 0x8F, 0x92, 0xB5, 0xA8, 0xDE, 0xC3, 0xE4, 0xF9, 0xAA, 0xB7, 0x90, 0x8D, 0x36, 0x2B, + 0x0C, 0x11, 0x42, 0x5F, 0x78, 0x65, 0x94, 0x89, 0xAE, 0xB3, 0xE0, 0xFD, 0xDA, 0xC7, 0x7C, 0x61, 0x46, 0x5B, + 0x08, 0x15, 0x32, 0x2F, 0x59, 0x44, 0x63, 0x7E, 0x2D, 0x30, 0x17, 0x0A, 0xB1, 0xAC, 0x8B, 0x96, 0xC5, 0xD8, + 0xFF, 0xE2, 0x26, 0x3B, 0x1C, 0x01, 0x52, 0x4F, 0x68, 0x75, 0xCE, 0xD3, 0xF4, 0xE9, 0xBA, 0xA7, 0x80, 0x9D, + 0xEB, 0xF6, 0xD1, 0xCC, 0x9F, 0x82, 0xA5, 0xB8, 0x03, 0x1E, 0x39, 0x24, 0x77, 0x6A, 0x4D, 0x50, 0xA1, 0xBC, + 0x9B, 0x86, 0xD5, 0xC8, 0xEF, 0xF2, 0x49, 0x54, 0x73, 0x6E, 0x3D, 0x20, 0x07, 0x1A, 0x6C, 0x71, 0x56, 0x4B, + 0x18, 0x05, 0x22, 0x3F, 0x84, 0x99, 0xBE, 0xA3, 0xF0, 0xED, 0xCA, 0xD7, 0x35, 0x28, 0x0F, 0x12, 0x41, 0x5C, + 0x7B, 0x66, 0xDD, 0xC0, 0xE7, 0xFA, 0xA9, 0xB4, 0x93, 0x8E, 0xF8, 0xE5, 0xC2, 0xDF, 0x8C, 0x91, 0xB6, 0xAB, + 0x10, 0x0D, 0x2A, 0x37, 0x64, 0x79, 0x5E, 0x43, 0xB2, 0xAF, 0x88, 0x95, 0xC6, 0xDB, 0xFC, 0xE1, 0x5A, 0x47, + 0x60, 0x7D, 0x2E, 0x33, 0x14, 0x09, 0x7F, 0x62, 0x45, 0x58, 0x0B, 0x16, 0x31, 0x2C, 0x97, 0x8A, 0xAD, 0xB0, + 0xE3, 0xFE, 0xD9, 0xC4}; + static uint16_t inverterVoltageFrameHigh = 0; static uint16_t inverterVoltage = 0; static uint16_t soc_calculated = 0; @@ -41,6 +61,99 @@ static int8_t temperature_water_inlet = 0; static int8_t powerRelayTemperature = 0; static int8_t heatertemp = 0; +static uint8_t ticks_200ms_counter = 0; +static uint8_t EGMP_1CF_counter = 0; + +CAN_frame EGMP_1CF = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x1CF, + .data = {0x56, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_3AA = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x3AA, + .data = {0xFF, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_4B4 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x4B4, + .data = {0x00, 0x00, 0xC0, 0x3F, 0x00, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_4B5 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x4B5, + .data = {0x08, 0x00, 0xF0, 0x07, 0x00, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_4B7 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x4B7, + .data = {0x08, 0x00, 0xF0, 0x07, 0x00, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_4CC = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x4CC, + .data = {0x08, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_4CE = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x4CE, + .data = {0x16, 0xCF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}}; +CAN_frame EGMP_4D8 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x4D8, + .data = {0x40, 0x10, 0xF0, 0xF0, 0x40, 0xF2, 0x1E, 0xCC}}; +CAN_frame EGMP_4DD = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x4DD, + .data = {0x3F, 0xFC, 0xFF, 0x00, 0x38, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_4E7 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x4E7, + .data = {0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00}}; +CAN_frame EGMP_4E9 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x4E9, + .data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_4EA = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x4EA, + .data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_4EB = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x4EB, + .data = {0x01, 0x50, 0x0B, 0x26, 0x00, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_4EC = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x4EC, + .data = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F}}; +CAN_frame EGMP_4ED = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x4ED, + .data = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F}}; +CAN_frame EGMP_4EE = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x4EE, + .data = {0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_4EF = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x4EF, + .data = {0x2B, 0xFE, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_641 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x641, + .data = {0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0xFF, 0xFF, 0xFF}}; CAN_frame EGMP_7E4 = {.FD = true, .ext_ID = false, .DLC = 8, @@ -61,6 +174,14 @@ void set_cell_voltages(CAN_frame rx_frame, int start, int length, int startCell) } } +static uint8_t calculateCRC(CAN_frame rx_frame, uint8_t length, uint8_t initial_value) { + uint8_t crc = initial_value; + for (uint8_t j = 1; j < length; j++) { //start at 1, since 0 is the CRC + crc = crc8_table[(crc ^ static_cast(rx_frame.data.u8[j])) % 256]; + } + return crc; +} + void update_values_battery() { //This function maps all the values fetched via CAN to the correct parameters used for modbus datalayer.battery.status.real_soc = (SOC_Display * 10); //increase SOC range from 0-100.0 -> 100.00 @@ -414,6 +535,72 @@ void receive_can_battery(CAN_frame rx_frame) { void send_can_battery() { unsigned long currentMillis = millis(); + + //Send 20ms CANFD message + if (currentMillis - previousMillis20ms >= INTERVAL_20_MS) { + previousMillis20ms = currentMillis; + + EGMP_1CF.data.u8[1] = (EGMP_1CF_counter % 15) * 0x10; + EGMP_1CF_counter++; + if (EGMP_1CF_counter > 0xE) { + EGMP_1CF_counter = 0; + } + EGMP_1CF.data.u8[0] = calculateCRC(EGMP_1CF, EGMP_1CF.DLC, 0x0A); // Set CRC bit, initial Value 0x0A + + transmit_can(&EGMP_1CF, can_config.battery); + } + + //Send 200ms CANFD message + if (currentMillis - previousMillis200ms >= INTERVAL_200_MS) { + previousMillis200ms = currentMillis; + + transmit_can(&EGMP_4B4, can_config.battery); + transmit_can(&EGMP_4B5, can_config.battery); + transmit_can(&EGMP_4B7, can_config.battery); + transmit_can(&EGMP_4CC, can_config.battery); + transmit_can(&EGMP_4CE, can_config.battery); + transmit_can(&EGMP_4D8, can_config.battery); + transmit_can(&EGMP_4DD, can_config.battery); + transmit_can(&EGMP_4E7, can_config.battery); + transmit_can(&EGMP_4E9, can_config.battery); + transmit_can(&EGMP_4EA, can_config.battery); + transmit_can(&EGMP_4EB, can_config.battery); + transmit_can(&EGMP_4EC, can_config.battery); + transmit_can(&EGMP_4ED, can_config.battery); + transmit_can(&EGMP_4EE, can_config.battery); + transmit_can(&EGMP_4EF, can_config.battery); + transmit_can(&EGMP_641, can_config.battery); + transmit_can(&EGMP_3AA, can_config.battery); + + if (ticks_200ms_counter < 254) { + ticks_200ms_counter++; + } + if (ticks_200ms_counter > 28) { + EGMP_4B4.data.u8[2] = 0; + EGMP_4B4.data.u8[3] = 0; + } + if (ticks_200ms_counter > 32) { + EGMP_4CE.data.u8[0] = 0x22; + EGMP_4CE.data.u8[1] = 0x41; + EGMP_4CE.data.u8[6] = 0x47; + EGMP_4CE.data.u8[7] = 0x1F; + } + if (ticks_200ms_counter > 43) { + EGMP_4EB.data.u8[2] = 0x0D; + EGMP_4EB.data.u8[3] = 0x3B; + } + if (ticks_200ms_counter > 46) { + EGMP_4EB.data.u8[2] = 0x0E; + EGMP_4EB.data.u8[3] = 0x00; + } + if (ticks_200ms_counter > 24) { + EGMP_4ED.data.u8[1] = 0x00; + EGMP_4ED.data.u8[2] = 0x00; + EGMP_4ED.data.u8[3] = 0x00; + EGMP_4ED.data.u8[4] = 0x00; + } + } + //Send 500ms CANFD message if (currentMillis - previousMillis500ms >= INTERVAL_500_MS) { @@ -424,13 +611,7 @@ void send_can_battery() { clear_event(EVENT_CAN_OVERRUN); } previousMillis500ms = currentMillis; - // Section added to close contractor - if (datalayer.battery.status.bms_status == ACTIVE) { - datalayer.system.status.battery_allows_contactor_closing = true; - } else { //datalayer.battery.status.bms_status == FAULT or inverter requested opening contactors - datalayer.system.status.battery_allows_contactor_closing = false; - } - // Section end + EGMP_7E4.data.u8[3] = KIA_7E4_COUNTER; transmit_can(&EGMP_7E4, can_config.battery); @@ -446,6 +627,8 @@ void setup_battery(void) { // Performs one time setup at startup Serial.println("Hyundai E-GMP (Electric Global Modular Platform) battery selected"); #endif + datalayer.system.status.battery_allows_contactor_closing = true; + datalayer.battery.info.number_of_cells = 192; // TODO: will vary depending on battery datalayer.battery.info.max_design_voltage_dV = From 00e44ccf9acfd66ae76dc3dd625c3edb857c0a4f Mon Sep 17 00:00:00 2001 From: Paul Brand Date: Sat, 24 Aug 2024 23:14:01 +0200 Subject: [PATCH 04/17] Makes MDNS optional by user setting Makes WIFI AP optional by user setting Tweaks ifdefs for double battery and charger settings Updates platformio platform packages --- Software/Software.ino | 28 ++++++++++++------- Software/USER_SETTINGS.cpp | 13 ++++++--- Software/USER_SETTINGS.h | 7 ++++- Software/src/devboard/webserver/webserver.cpp | 14 ++++++---- Software/src/devboard/webserver/webserver.h | 4 +++ platformio.ini | 4 +-- 6 files changed, 47 insertions(+), 23 deletions(-) diff --git a/Software/Software.ino b/Software/Software.ino index 2a711ec1..6c0f0030 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -26,9 +26,15 @@ #include "src/datalayer/datalayer.h" #ifdef WEBSERVER -#include #include "src/devboard/webserver/webserver.h" -#endif +#ifdef MDNSRESPONDER +#include +#endif // MDNSRESONDER +#else // WEBSERVER +#ifdef MDNSRESPONDER +#error WEBSERVER needs to be enabled for MDNSRESPONDER! +#endif // MDNSRSPONDER +#endif // WEBSERVER Preferences settings; // Store user settings // The current software version, shown on webserver @@ -167,7 +173,9 @@ void loop() { void connectivity_loop(void* task_time_us) { // Init init_webserver(); +#ifdef MDNSRESPONDER init_mDNS(); +#endif #ifdef MQTT init_mqtt(); #endif @@ -286,7 +294,7 @@ void core_loop(void* task_time_us) { } } -#ifdef WEBSERVER +#ifdef MDNSRESPONDER // Initialise mDNS void init_mDNS() { @@ -305,7 +313,7 @@ void init_mDNS() { MDNS.addService("battery_emulator", "tcp", 80); } } -#endif +#endif // MDNSRESPONDER // Initialization functions void init_serial() { @@ -928,19 +936,19 @@ void receive_can(CAN_frame* rx_frame, int interface) { if (interface == can_config.battery) { receive_can_battery(*rx_frame); } - if (interface == can_config.inverter) { #ifdef CAN_INVERTER_SELECTED + if (interface == can_config.inverter) { receive_can_inverter(*rx_frame); -#endif } - if (interface == can_config.battery_double) { +#endif #ifdef DOUBLE_BATTERY + if (interface == can_config.battery_double) { receive_can_battery2(*rx_frame); -#endif } - if (interface == can_config.charger) { +#endif #ifdef CHARGER_SELECTED + if (interface == can_config.charger) { receive_can_charger(*rx_frame); -#endif } +#endif } diff --git a/Software/USER_SETTINGS.cpp b/Software/USER_SETTINGS.cpp index 0171c248..71065018 100644 --- a/Software/USER_SETTINGS.cpp +++ b/Software/USER_SETTINGS.cpp @@ -14,17 +14,22 @@ CAN_ADDON_FD_MCP2518 = Add-on CAN-FD MCP2518 connected to GPIO pins volatile CAN_Configuration can_config = { .battery = CAN_NATIVE, // Which CAN is your battery connected to? .inverter = CAN_NATIVE, // Which CAN is your inverter connected to? (No need to configure incase you use RS485) +#ifdef DOUBLE_BATTERY .battery_double = CAN_ADDON_MCP2515, // (OPTIONAL) Which CAN is your second battery connected to? - .charger = CAN_NATIVE // (OPTIONAL) Which CAN is your charger connected to? +#endif +#ifdef CHARGER_SELECTED + .charger = CAN_NATIVE // (OPTIONAL) Which CAN is your charger connected to? +#endif }; #ifdef WEBSERVER -volatile uint8_t AccessPointEnabled = true; //Set to either true/false to enable direct wifi access point std::string ssid = "REPLACE_WITH_YOUR_SSID"; // Maximum of 63 characters; std::string 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, also used for device name on web interface +#ifdef WIFIAP 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 +#endif +const uint8_t wifi_channel = 0; // Set to 0 for automatic channel selection // MQTT #ifdef MQTT const char* mqtt_user = "REDACTED"; diff --git a/Software/USER_SETTINGS.h b/Software/USER_SETTINGS.h index 551054c7..5e82cd5a 100644 --- a/Software/USER_SETTINGS.h +++ b/Software/USER_SETTINGS.h @@ -54,6 +54,8 @@ //#define SERIAL_LINK_RECEIVER //Enable this line to receive battery data over RS485 pins from another Lilygo (This LilyGo interfaces with inverter) //#define SERIAL_LINK_TRANSMITTER //Enable this line to send battery data over RS485 pins to another Lilygo (This LilyGo interfaces with battery) #define WEBSERVER //Enable this line to enable WiFi, and to run the webserver. See USER_SETTINGS.cpp for the Wifi settings. +#define MDNSRESPONDER //Enable this line to enable MDNS, allows battery monitor te be found by .local address. Requires WEBSERVER to be enabled. +#define WIFIAP //Enable this line to make battery monitor create an wifi access point. When disabled make sure to hardcode wifi settings to make battery emulator connect to you home wifi. #define LOAD_SAVED_SETTINGS_ON_BOOT //Enable this line to read settings stored via the webserver on boot (overrides Wifi/battery settings set below) //#define FUNCTION_TIME_MEASUREMENT // Enable this to record execution times and present them in the web UI (WARNING, raises CPU load, do not use for production) @@ -89,11 +91,14 @@ typedef enum { CAN_NATIVE = 0, CANFD_NATIVE = 1, CAN_ADDON_MCP2515 = 2, CAN_ADDO typedef struct { CAN_Interface battery; CAN_Interface inverter; +#ifdef DOUBLE_BATTERY CAN_Interface battery_double; +#endif +#ifdef CHARGER_SELECTED CAN_Interface charger; +#endif } CAN_Configuration; extern volatile CAN_Configuration can_config; -extern volatile uint8_t AccessPointEnabled; extern const uint8_t wifi_channel; extern volatile float charger_setpoint_HV_VDC; extern volatile float charger_setpoint_HV_IDC; diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index 449f1638..b6a6c37b 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -37,12 +37,12 @@ unsigned long last_wifi_attempt_time = millis(); //init millis so wifi monitor void init_webserver() { // Configure WiFi - if (AccessPointEnabled) { - WiFi.mode(WIFI_AP_STA); // Simultaneous WiFi AP and Router connection - init_WiFi_AP(); - } else { - WiFi.mode(WIFI_STA); // Only Router connection - } +#ifdef WIFIAP + WiFi.mode(WIFI_AP_STA); // Simultaneous WiFi AP and Router connection + init_WiFi_AP(); +#else + WiFi.mode(WIFI_STA); // Only Router connection +#endif init_WiFi_STA(ssid.c_str(), password.c_str(), wifi_channel); String content = index_html; @@ -286,6 +286,7 @@ void init_webserver() { #endif } +#ifdef WIFIAP void init_WiFi_AP() { #ifdef DEBUG_VIA_USB Serial.println("Creating Access Point: " + String(ssidAP)); @@ -299,6 +300,7 @@ void init_WiFi_AP() { Serial.println(IP); #endif } +#endif String getConnectResultString(wl_status_t status) { switch (status) { diff --git a/Software/src/devboard/webserver/webserver.h b/Software/src/devboard/webserver/webserver.h index 93d17fde..8829e1c4 100644 --- a/Software/src/devboard/webserver/webserver.h +++ b/Software/src/devboard/webserver/webserver.h @@ -23,7 +23,9 @@ extern std::string ssid; extern std::string password; extern const uint8_t wifi_channel; extern const char* ssidAP; +#ifdef WIFI_AP extern const char* passwordAP; +#endif // Common charger parameters extern float charger_stat_HVcur; @@ -54,6 +56,7 @@ void init_webserver(); */ void wifi_monitor(); +#ifdef WIFI_AP /** * @brief Initialization function that creates a WiFi Access Point. * @@ -62,6 +65,7 @@ void wifi_monitor(); * @return void */ void init_WiFi_AP(); +#endif /** * @brief Initialization function that connects to an existing network. diff --git a/platformio.ini b/platformio.ini index fe1d94e3..f7cca324 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,8 +14,8 @@ src_dir = ./Software [env:esp32dev] platform = espressif32 platform_packages= - framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.2 - framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.2/esp32-arduino-libs-3.0.2.zip + framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.4 + framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.4/esp32-arduino-libs-3.0.4.zip board = esp32dev monitor_speed = 115200 monitor_filters = default, time, log2file From c10c1af359824ee95e396207852d96f484c58084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Mon, 26 Aug 2024 23:14:27 +0300 Subject: [PATCH 05/17] Add more CAN mappings --- Software/src/battery/KIA-E-GMP-BATTERY.cpp | 105 +++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/Software/src/battery/KIA-E-GMP-BATTERY.cpp b/Software/src/battery/KIA-E-GMP-BATTERY.cpp index c123e4c2..9469102f 100644 --- a/Software/src/battery/KIA-E-GMP-BATTERY.cpp +++ b/Software/src/battery/KIA-E-GMP-BATTERY.cpp @@ -7,6 +7,8 @@ /* Do not change code below unless you are sure what you are doing */ static unsigned long previousMillis20ms = 0; // will store last time a 20ms CAN Message was send +static unsigned long previousMillis30ms = 0; // will store last time a 30ms CAN Message was send +static unsigned long previousMillis100ms = 0; // will store last time a 100ms CAN Message was send static unsigned long previousMillis200ms = 0; // will store last time a 200ms CAN Message was send static unsigned long previousMillis500ms = 0; // will store last time a 500ms CAN Message was send @@ -63,6 +65,7 @@ static int8_t heatertemp = 0; static uint8_t ticks_200ms_counter = 0; static uint8_t EGMP_1CF_counter = 0; +static uint8_t EGMP_3XF_counter = 0; CAN_frame EGMP_1CF = {.FD = true, .ext_ID = false, @@ -74,6 +77,26 @@ CAN_frame EGMP_3AA = {.FD = true, .DLC = 8, .ID = 0x3AA, .data = {0xFF, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_3E0 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x3E0, + .data = {0xC3, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_3E1 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x3E1, + .data = {0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_36F = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x36F, + .data = {0x28, 0x31, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_37F = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x37F, + .data = {0x9B, 0x30, 0x52, 0x24, 0x41, 0x02, 0x00, 0x00}}; CAN_frame EGMP_4B4 = {.FD = true, .ext_ID = false, .DLC = 8, @@ -149,6 +172,31 @@ CAN_frame EGMP_4EF = {.FD = true, .DLC = 8, .ID = 0x4EF, .data = {0x2B, 0xFE, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_405 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x405, + .data = {0xE4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_410 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x410, + .data = {0xA6, 0x10, 0xFF, 0x3C, 0xFF, 0x7F, 0xFF, 0xFF}}; +CAN_frame EGMP_419 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x419, + .data = {0xC7, 0x90, 0xB9, 0xD2, 0x0D, 0x62, 0x7A, 0x00}}; +CAN_frame EGMP_422 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x422, + .data = {0x15, 0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_444 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x444, + .data = {0x96, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; CAN_frame EGMP_641 = {.FD = true, .ext_ID = false, .DLC = 8, @@ -550,6 +598,30 @@ void send_can_battery() { transmit_can(&EGMP_1CF, can_config.battery); } + //Send 30ms CANFD message + if (currentMillis - previousMillis30ms >= INTERVAL_30_MS) { + previousMillis30ms = currentMillis; + + transmit_can(&EGMP_419, can_config.battery); // TODO: Handle variations better + } + + //Send 100ms CANFD message + if (currentMillis - previousMillis100ms >= INTERVAL_100_MS) { + previousMillis100ms = currentMillis; + + EGMP_36F.data.u8[1] = ((EGMP_3XF_counter % 15) << 4) + 0x01; + EGMP_37F.data.u8[1] = ((EGMP_3XF_counter % 15) << 4); + EGMP_3XF_counter++; + if (EGMP_3XF_counter > 0xE) { + EGMP_3XF_counter = 0; + } + EGMP_36F.data.u8[0] = calculateCRC(EGMP_36F, EGMP_36F.DLC, 0x8A); // Set CRC bit, initial Value 0x8A + EGMP_37F.data.u8[0] = calculateCRC(EGMP_37F, EGMP_37F.DLC, 0x38); // Set CRC bit, initial Value 0x38 + + transmit_can(&EGMP_36F, can_config.battery); + transmit_can(&EGMP_37F, can_config.battery); + } + //Send 200ms CANFD message if (currentMillis - previousMillis200ms >= INTERVAL_200_MS) { previousMillis200ms = currentMillis; @@ -571,6 +643,12 @@ void send_can_battery() { transmit_can(&EGMP_4EF, can_config.battery); transmit_can(&EGMP_641, can_config.battery); transmit_can(&EGMP_3AA, can_config.battery); + transmit_can(&EGMP_3E0, can_config.battery); + transmit_can(&EGMP_3E1, can_config.battery); + transmit_can(&EGMP_422, can_config.battery); + transmit_can(&EGMP_444, can_config.battery); + transmit_can(&EGMP_405, can_config.battery); + transmit_can(&EGMP_410, can_config.battery); if (ticks_200ms_counter < 254) { ticks_200ms_counter++; @@ -599,6 +677,33 @@ void send_can_battery() { EGMP_4ED.data.u8[3] = 0x00; EGMP_4ED.data.u8[4] = 0x00; } + if (ticks_200ms_counter > 21) { + EGMP_3E1.data.u8[0] = 0x49; + EGMP_3E1.data.u8[1] = 0x10; + EGMP_3E1.data.u8[2] = 0x12; + EGMP_3E1.data.u8[3] = 0x15; + + EGMP_422.data.u8[0] = 0xEE; + EGMP_422.data.u8[1] = 0x20; + EGMP_422.data.u8[2] = 0x11; + EGMP_422.data.u8[6] = 0x04; + + EGMP_405.data.u8[0] = 0xD2; + EGMP_405.data.u8[1] = 0x10; + EGMP_405.data.u8[5] = 0x01; + } + if (ticks_200ms_counter > 12) { + EGMP_444.data.u8[0] = 0xEE; + EGMP_444.data.u8[1] = 0x30; + EGMP_444.data.u8[3] = 0x20; + if (ticks_200ms_counter > 12) { // TODO: Could be handled better + EGMP_444.data.u8[0] = 0xE4; + EGMP_444.data.u8[1] = 0x60; + EGMP_444.data.u8[2] = 0x25; + EGMP_444.data.u8[3] = 0x4E; + EGMP_444.data.u8[4] = 0x04; + } + } } //Send 500ms CANFD message From ce93284b514635314de04b7d0318c9b38a67a824 Mon Sep 17 00:00:00 2001 From: Paul Brand Date: Tue, 27 Aug 2024 13:47:33 +0200 Subject: [PATCH 06/17] Adds user setting for Home Assistant autodiscovery --- Software/USER_SETTINGS.cpp | 8 ++++---- Software/USER_SETTINGS.h | 3 +++ Software/src/devboard/mqtt/mqtt.cpp | 13 ++++++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Software/USER_SETTINGS.cpp b/Software/USER_SETTINGS.cpp index 71065018..d7817090 100644 --- a/Software/USER_SETTINGS.cpp +++ b/Software/USER_SETTINGS.cpp @@ -32,10 +32,10 @@ const char* passwordAP = "123456789"; // Minimum of 8 characters; set to NULL i const uint8_t wifi_channel = 0; // Set to 0 for automatic channel selection // MQTT #ifdef MQTT -const char* mqtt_user = "REDACTED"; -const char* mqtt_password = "REDACTED"; -#endif // USE_MQTT -#endif // WEBSERVER +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 /* Charger settings (Optional, when using generator charging) */ volatile float CHARGER_SET_HV = 384; // Reasonably appropriate 4.0v per cell charging of a 96s pack diff --git a/Software/USER_SETTINGS.h b/Software/USER_SETTINGS.h index 5e82cd5a..f60e1ea2 100644 --- a/Software/USER_SETTINGS.h +++ b/Software/USER_SETTINGS.h @@ -64,6 +64,9 @@ #define MQTT_SERVER "192.168.xxx.yyy" #define MQTT_PORT 1883 +/* Home Assistant options */ +#define HA_AUTODISCOVERY // Enable this line to send Home Assistant autodiscovery messages. If not enabled manual configuration of Home Assitant is required + /* Event options*/ #define DUMMY_EVENT_ENABLED false //Enable this line to have a dummy event that gets logged to test the interface diff --git a/Software/src/devboard/mqtt/mqtt.cpp b/Software/src/devboard/mqtt/mqtt.cpp index 67535cfd..5e4cdf17 100644 --- a/Software/src/devboard/mqtt/mqtt.cpp +++ b/Software/src/devboard/mqtt/mqtt.cpp @@ -31,7 +31,9 @@ static String generateCellVoltageAutoConfigTopic(int cell_number, const char* ho } static void publish_cell_voltages(void) { +#ifdef HA_AUTODISCOVERY static bool mqtt_first_transmission = true; +#endif static JsonDocument doc; static const char* hostname = WiFi.getHostname(); static String state_topic = String("battery-emulator_") + String(hostname) + "/spec_data"; @@ -40,7 +42,7 @@ static void publish_cell_voltages(void) { if (datalayer.battery.info.number_of_cells == 0u) { return; } - +#ifdef HA_AUTODISCOVERY if (mqtt_first_transmission == true) { mqtt_first_transmission = false; String topic = "homeassistant/sensor/battery-emulator/cell_voltage"; @@ -71,6 +73,7 @@ static void publish_cell_voltages(void) { } doc.clear(); // clear after sending autoconfig } else { +#endif // HA_AUTODISCOVERY // If cell voltages haven't been populated... if (datalayer.battery.info.number_of_cells == 0u || datalayer.battery.status.cell_voltages_mV[datalayer.battery.info.number_of_cells - 1] == 0u) { @@ -90,7 +93,9 @@ static void publish_cell_voltages(void) { #endif } doc.clear(); +#ifdef HA_AUTODISCOVERY } +#endif // HA_AUTODISCOVERY } struct SensorConfig { @@ -120,9 +125,12 @@ static String generateCommonInfoAutoConfigTopic(const char* object_id, const cha static void publish_common_info(void) { static JsonDocument doc; +#ifdef HA_AUTODISCOVERY static bool mqtt_first_transmission = true; +#endif // HA_AUTODISCOVERY static const char* hostname = WiFi.getHostname(); static String state_topic = String("battery-emulator_") + String(hostname) + "/info"; +#ifdef HA_AUTODISCOVERY if (mqtt_first_transmission == true) { mqtt_first_transmission = false; for (int i = 0; i < sizeof(sensorConfigs) / sizeof(sensorConfigs[0]); i++) { @@ -149,6 +157,7 @@ static void publish_common_info(void) { } doc.clear(); } else { +#endif // HA_AUTODISCOVERY doc["SOC"] = ((float)datalayer.battery.status.reported_soc) / 100.0; doc["SOC_real"] = ((float)datalayer.battery.status.real_soc) / 100.0; doc["state_of_health"] = ((float)datalayer.battery.status.soh_pptt) / 100.0; @@ -170,7 +179,9 @@ static void publish_common_info(void) { #endif } doc.clear(); +#ifdef HA_AUTODISCOVERY } +#endif // HA_AUTODISCOVERY } /* If we lose the connection, get it back */ From 7285c23b3e0feba417955d501b19bb74ba30cb1d Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Tue, 27 Aug 2024 12:11:19 +0000 Subject: [PATCH 07/17] Remove extra closing script tag --- Software/src/devboard/webserver/settings_html.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Software/src/devboard/webserver/settings_html.cpp b/Software/src/devboard/webserver/settings_html.cpp index 10a95f54..6a9b374b 100644 --- a/Software/src/devboard/webserver/settings_html.cpp +++ b/Software/src/devboard/webserver/settings_html.cpp @@ -155,7 +155,6 @@ String settings_processor(const String& var) { "XMLHttpRequest();xhr.onload=editComplete;xhr.onerror=editError;xhr.open('GET','/" "updateMaxDischargeA?value='+value,true);xhr.send();}else{alert('Invalid value. Please enter a value between 0 " "and 1000.0');}}}"; - content += ""; #ifdef TEST_FAKE_BATTERY content += From 573658e573beb5db81d931765a0be062d1b8aad3 Mon Sep 17 00:00:00 2001 From: Paul Brand Date: Tue, 27 Aug 2024 14:29:48 +0200 Subject: [PATCH 08/17] Restored functinality to disable WIFI AP mode with at runtime with a setting. Restored ifdefs for double battery and charger. --- Software/USER_SETTINGS.cpp | 11 +++-------- Software/USER_SETTINGS.h | 7 ++----- Software/src/devboard/webserver/webserver.cpp | 10 +++++++--- Software/src/devboard/webserver/webserver.h | 6 ++---- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/Software/USER_SETTINGS.cpp b/Software/USER_SETTINGS.cpp index d7817090..207d523c 100644 --- a/Software/USER_SETTINGS.cpp +++ b/Software/USER_SETTINGS.cpp @@ -14,22 +14,17 @@ CAN_ADDON_FD_MCP2518 = Add-on CAN-FD MCP2518 connected to GPIO pins volatile CAN_Configuration can_config = { .battery = CAN_NATIVE, // Which CAN is your battery connected to? .inverter = CAN_NATIVE, // Which CAN is your inverter connected to? (No need to configure incase you use RS485) -#ifdef DOUBLE_BATTERY .battery_double = CAN_ADDON_MCP2515, // (OPTIONAL) Which CAN is your second battery connected to? -#endif -#ifdef CHARGER_SELECTED - .charger = CAN_NATIVE // (OPTIONAL) Which CAN is your charger connected to? -#endif + .charger = CAN_NATIVE // (OPTIONAL) Which CAN is your charger connected to? }; #ifdef WEBSERVER +volatile uint8_t AccessPointEnabled = true; //Set to either true/false to enable direct wifi access point std::string ssid = "REPLACE_WITH_YOUR_SSID"; // Maximum of 63 characters; std::string password = "REPLACE_WITH_YOUR_PASSWORD"; // Minimum of 8 characters; const char* ssidAP = "Battery Emulator"; // Maximum of 63 characters, also used for device name on web interface -#ifdef WIFIAP const char* passwordAP = "123456789"; // Minimum of 8 characters; set to NULL if you want the access point to be open -#endif -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 // MQTT #ifdef MQTT const char* mqtt_user = "REDACTED"; // Set NULL for no username diff --git a/Software/USER_SETTINGS.h b/Software/USER_SETTINGS.h index f60e1ea2..b4a2e3a9 100644 --- a/Software/USER_SETTINGS.h +++ b/Software/USER_SETTINGS.h @@ -54,8 +54,8 @@ //#define SERIAL_LINK_RECEIVER //Enable this line to receive battery data over RS485 pins from another Lilygo (This LilyGo interfaces with inverter) //#define SERIAL_LINK_TRANSMITTER //Enable this line to send battery data over RS485 pins to another Lilygo (This LilyGo interfaces with battery) #define WEBSERVER //Enable this line to enable WiFi, and to run the webserver. See USER_SETTINGS.cpp for the Wifi settings. +#define WIFIAP //Disable this line to permanently disable WIFI AP mode (make sure to hardcode ssid and password of you home wifi network). When enabled WIFI AP can still be disabled by a setting in the future. #define MDNSRESPONDER //Enable this line to enable MDNS, allows battery monitor te be found by .local address. Requires WEBSERVER to be enabled. -#define WIFIAP //Enable this line to make battery monitor create an wifi access point. When disabled make sure to hardcode wifi settings to make battery emulator connect to you home wifi. #define LOAD_SAVED_SETTINGS_ON_BOOT //Enable this line to read settings stored via the webserver on boot (overrides Wifi/battery settings set below) //#define FUNCTION_TIME_MEASUREMENT // Enable this to record execution times and present them in the web UI (WARNING, raises CPU load, do not use for production) @@ -94,14 +94,11 @@ typedef enum { CAN_NATIVE = 0, CANFD_NATIVE = 1, CAN_ADDON_MCP2515 = 2, CAN_ADDO typedef struct { CAN_Interface battery; CAN_Interface inverter; -#ifdef DOUBLE_BATTERY CAN_Interface battery_double; -#endif -#ifdef CHARGER_SELECTED CAN_Interface charger; -#endif } CAN_Configuration; extern volatile CAN_Configuration can_config; +extern volatile uint8_t AccessPointEnabled; extern const uint8_t wifi_channel; extern volatile float charger_setpoint_HV_VDC; extern volatile float charger_setpoint_HV_IDC; diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index b6a6c37b..7e971c87 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -38,11 +38,15 @@ unsigned long last_wifi_attempt_time = millis(); //init millis so wifi monitor void init_webserver() { // Configure WiFi #ifdef WIFIAP - WiFi.mode(WIFI_AP_STA); // Simultaneous WiFi AP and Router connection - init_WiFi_AP(); + if (AccessPointEnabled) { + WiFi.mode(WIFI_AP_STA); // Simultaneous WiFi AP and Router connection + init_WiFi_AP(); + } else { + WiFi.mode(WIFI_STA); // Only Router connection + } #else WiFi.mode(WIFI_STA); // Only Router connection -#endif +#endif // WIFIAP init_WiFi_STA(ssid.c_str(), password.c_str(), wifi_channel); String content = index_html; diff --git a/Software/src/devboard/webserver/webserver.h b/Software/src/devboard/webserver/webserver.h index 8829e1c4..b2394d71 100644 --- a/Software/src/devboard/webserver/webserver.h +++ b/Software/src/devboard/webserver/webserver.h @@ -23,9 +23,7 @@ extern std::string ssid; extern std::string password; extern const uint8_t wifi_channel; extern const char* ssidAP; -#ifdef WIFI_AP extern const char* passwordAP; -#endif // Common charger parameters extern float charger_stat_HVcur; @@ -56,7 +54,7 @@ void init_webserver(); */ void wifi_monitor(); -#ifdef WIFI_AP +#ifdef WIFIAP /** * @brief Initialization function that creates a WiFi Access Point. * @@ -65,7 +63,7 @@ void wifi_monitor(); * @return void */ void init_WiFi_AP(); -#endif +#endif // WIFIAP /** * @brief Initialization function that connects to an existing network. From 2ddbb9d0d43c08d6ffe0c1a396167eeecc90c2b1 Mon Sep 17 00:00:00 2001 From: Paul Brand Date: Tue, 27 Aug 2024 14:39:20 +0200 Subject: [PATCH 09/17] Properly restore receive_can function --- Software/Software.ino | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Software/Software.ino b/Software/Software.ino index 6c0f0030..6edc2ebc 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -936,19 +936,19 @@ void receive_can(CAN_frame* rx_frame, int interface) { if (interface == can_config.battery) { receive_can_battery(*rx_frame); } -#ifdef CAN_INVERTER_SELECTED if (interface == can_config.inverter) { +#ifdef CAN_INVERTER_SELECTED receive_can_inverter(*rx_frame); - } #endif -#ifdef DOUBLE_BATTERY + } if (interface == can_config.battery_double) { +#ifdef DOUBLE_BATTERY receive_can_battery2(*rx_frame); - } #endif -#ifdef CHARGER_SELECTED + } if (interface == can_config.charger) { +#ifdef CHARGER_SELECTED receive_can_charger(*rx_frame); - } #endif + } } From feb726162fa11909eee4e6f896779d29d5d9b15b Mon Sep 17 00:00:00 2001 From: Paul Brand Date: Tue, 27 Aug 2024 22:16:03 +0200 Subject: [PATCH 10/17] Adds more code to HA_AUTODISCOVERY setting --- Software/src/devboard/mqtt/mqtt.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Software/src/devboard/mqtt/mqtt.cpp b/Software/src/devboard/mqtt/mqtt.cpp index 5e4cdf17..2c136243 100644 --- a/Software/src/devboard/mqtt/mqtt.cpp +++ b/Software/src/devboard/mqtt/mqtt.cpp @@ -25,10 +25,12 @@ static void publish_values(void) { publish_cell_voltages(); } +#ifdef HA_AUTODISCOVERY static String generateCellVoltageAutoConfigTopic(int cell_number, const char* hostname) { return String("homeassistant/sensor/battery-emulator_") + String(hostname) + "/cell_voltage" + String(cell_number) + "/config"; } +#endif // HA_AUTODISCOVERY static void publish_cell_voltages(void) { #ifdef HA_AUTODISCOVERY @@ -106,6 +108,7 @@ struct SensorConfig { const char* device_class; }; +#ifdef HA_AUTODISCOVERY SensorConfig sensorConfigs[] = { {"SOC", "Battery Emulator SOC (scaled)", "{{ value_json.SOC }}", "%", "battery"}, {"SOC_real", "Battery Emulator SOC (real)", "{{ value_json.SOC_real }}", "%", "battery"}, @@ -122,6 +125,7 @@ SensorConfig sensorConfigs[] = { static String generateCommonInfoAutoConfigTopic(const char* object_id, const char* hostname) { return String("homeassistant/sensor/battery-emulator_") + String(hostname) + "/" + String(object_id) + "/config"; } +#endif // HA_AUTODISCOVERY static void publish_common_info(void) { static JsonDocument doc; From ddb062398339faf40105d3c71bcd297279b88eed Mon Sep 17 00:00:00 2001 From: Paul Brand Date: Tue, 27 Aug 2024 22:24:24 +0200 Subject: [PATCH 11/17] Adds even more code to HA_AUTODISCOVERY setting Removes unused variable --- Software/src/devboard/mqtt/mqtt.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Software/src/devboard/mqtt/mqtt.cpp b/Software/src/devboard/mqtt/mqtt.cpp index 2c136243..6f4314f2 100644 --- a/Software/src/devboard/mqtt/mqtt.cpp +++ b/Software/src/devboard/mqtt/mqtt.cpp @@ -12,7 +12,6 @@ WiFiClient espClient; PubSubClient client(espClient); char mqtt_msg[MQTT_MSG_BUFFER_SIZE]; -int value = 0; static unsigned long previousMillisUpdateVal; MyTimer publish_global_timer(5000); @@ -100,6 +99,7 @@ static void publish_cell_voltages(void) { #endif // HA_AUTODISCOVERY } +#ifdef HA_AUTODISCOVER struct SensorConfig { const char* object_id; const char* name; @@ -108,7 +108,6 @@ struct SensorConfig { const char* device_class; }; -#ifdef HA_AUTODISCOVERY SensorConfig sensorConfigs[] = { {"SOC", "Battery Emulator SOC (scaled)", "{{ value_json.SOC }}", "%", "battery"}, {"SOC_real", "Battery Emulator SOC (real)", "{{ value_json.SOC_real }}", "%", "battery"}, From 775ee36d0b97863a67348acfbfe72b4c97f3502c Mon Sep 17 00:00:00 2001 From: Paul Brand Date: Wed, 28 Aug 2024 08:46:30 +0200 Subject: [PATCH 12/17] Fixes typo Adds #endif comments --- Software/src/devboard/mqtt/mqtt.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Software/src/devboard/mqtt/mqtt.cpp b/Software/src/devboard/mqtt/mqtt.cpp index 6f4314f2..87dcc413 100644 --- a/Software/src/devboard/mqtt/mqtt.cpp +++ b/Software/src/devboard/mqtt/mqtt.cpp @@ -34,7 +34,7 @@ static String generateCellVoltageAutoConfigTopic(int cell_number, const char* ho static void publish_cell_voltages(void) { #ifdef HA_AUTODISCOVERY static bool mqtt_first_transmission = true; -#endif +#endif // HA_AUTODISCOVERY static JsonDocument doc; static const char* hostname = WiFi.getHostname(); static String state_topic = String("battery-emulator_") + String(hostname) + "/spec_data"; @@ -91,7 +91,7 @@ static void publish_cell_voltages(void) { if (!mqtt_publish(state_topic.c_str(), mqtt_msg, false)) { #ifdef DEBUG_VIA_USB Serial.println("Cell voltage MQTT msg could not be sent"); -#endif +#endif // DEBUG_VIA_USB } doc.clear(); #ifdef HA_AUTODISCOVERY @@ -99,7 +99,7 @@ static void publish_cell_voltages(void) { #endif // HA_AUTODISCOVERY } -#ifdef HA_AUTODISCOVER +#ifdef HA_AUTODISCOVERY struct SensorConfig { const char* object_id; const char* name; @@ -179,7 +179,7 @@ static void publish_common_info(void) { if (!mqtt_publish(state_topic.c_str(), mqtt_msg, false)) { #ifdef DEBUG_VIA_USB Serial.println("Common info MQTT msg could not be sent"); -#endif +#endif // DEBUG_VIA_USB } doc.clear(); #ifdef HA_AUTODISCOVERY @@ -192,7 +192,7 @@ static void reconnect() { // attempt one reconnection #ifdef DEBUG_VIA_USB Serial.print("Attempting MQTT connection... "); -#endif +#endif // DEBUG_VIA_USB const char* hostname = WiFi.getHostname(); char clientId[64]; // Adjust the size as needed snprintf(clientId, sizeof(clientId), "LilyGoClient-%s", hostname); @@ -200,13 +200,13 @@ static void reconnect() { if (client.connect(clientId, mqtt_user, mqtt_password)) { #ifdef DEBUG_VIA_USB Serial.println("connected"); -#endif +#endif // DEBUG_VIA_USB } else { #ifdef DEBUG_VIA_USB Serial.print("failed, rc="); Serial.print(client.state()); Serial.println(" try again in 5 seconds"); -#endif +#endif // DEBUG_VIA_USB // Wait 5 seconds before retrying } } @@ -215,7 +215,7 @@ void init_mqtt(void) { client.setServer(MQTT_SERVER, MQTT_PORT); #ifdef DEBUG_VIA_USB Serial.println("MQTT initialized"); -#endif +#endif // DEBUG_VIA_USB previousMillisUpdateVal = millis(); reconnect(); From fb05db499fe6c9ebabe358f14a96aad3f1b59416 Mon Sep 17 00:00:00 2001 From: Paul Brand Date: Wed, 28 Aug 2024 08:58:12 +0200 Subject: [PATCH 13/17] Adds #endif comments in webserver.cpp --- Software/src/devboard/webserver/webserver.cpp | 102 +++++++++--------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index 7e971c87..e6867499 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -185,7 +185,7 @@ void init_webserver() { request->send(200, "text/plain", "Updated successfully"); }); -#endif +#endif // TEST_FAKE_BATTERY #if defined CHEVYVOLT_CHARGER || defined NISSANLEAF_CHARGER // Route for editing ChargerTargetV @@ -264,7 +264,7 @@ void init_webserver() { request->send(400, "text/plain", "Bad Request"); } }); -#endif +#endif // defined CHEVYVOLT_CHARGER || defined NISSANLEAF_CHARGER // Send a GET request to /update server.on("/debug", HTTP_GET, @@ -287,7 +287,7 @@ void init_webserver() { #ifdef MQTT // Init MQTT init_mqtt(); -#endif +#endif // MQTT } #ifdef WIFIAP @@ -295,16 +295,16 @@ void init_WiFi_AP() { #ifdef DEBUG_VIA_USB Serial.println("Creating Access Point: " + String(ssidAP)); Serial.println("With password: " + String(passwordAP)); -#endif +#endif // DEBUG_VIA_USB WiFi.softAP(ssidAP, passwordAP); IPAddress IP = WiFi.softAPIP(); #ifdef DEBUG_VIA_USB Serial.println("Access Point created."); Serial.print("IP address: "); Serial.println(IP); -#endif +#endif // DEBUG_VIA_USB } -#endif +#endif // WIFIAP String getConnectResultString(wl_status_t status) { switch (status) { @@ -337,7 +337,7 @@ void wifi_monitor() { if (status != WL_CONNECTED && status != WL_IDLE_STATUS) { #ifdef DEBUG_VIA_USB Serial.println(getConnectResultString(status)); -#endif +#endif // DEBUG_VIA_USB if (wifi_state == INIT) { //we haven't been connected yet, try the init logic init_WiFi_STA(ssid.c_str(), password.c_str(), wifi_channel); } else { //we were connected before, try the reconnect logic @@ -345,7 +345,7 @@ void wifi_monitor() { last_wifi_attempt_time = currentMillis; #ifdef DEBUG_VIA_USB Serial.println("WiFi not connected, trying to reconnect..."); -#endif +#endif // DEBUG_VIA_USB wifi_state = RECONNECTING; WiFi.reconnect(); wifi_reconnect_interval = min(wifi_reconnect_interval * 2, MAX_WIFI_RETRY_INTERVAL); @@ -361,7 +361,7 @@ void wifi_monitor() { Serial.print(" Signal Strength: " + String(WiFi.RSSI()) + " dBm"); Serial.println(" Channel: " + String(WiFi.channel())); Serial.println(" Hostname: " + String(WiFi.getHostname())); -#endif +#endif // DEBUG_VIA_USB } } @@ -379,7 +379,7 @@ void init_WiFi_STA(const char* ssid, const char* password, const uint8_t wifi_ch #ifdef DEBUG_VIA_USB Serial.print("Connecting to "); Serial.println(ssid); -#endif +#endif // DEBUG_VIA_USB WiFi.begin(ssid, password, wifi_channel); WiFi.setAutoReconnect(true); // Enable auto reconnect wl_status_t result = static_cast(WiFi.waitForConnectResult(INIT_WIFI_CONNECT_TIMEOUT)); @@ -414,10 +414,10 @@ String processor(const String& var) { // Show hardware used: #ifdef HW_LILYGO content += "

Hardware: LilyGo T-CAN485

"; -#endif +#endif // HW_LILYGO #ifdef HW_STARK content += "

Hardware: Stark CMR Module

"; -#endif +#endif // HW_STARK content += "

Uptime: " + uptime_formatter::getUptime() + "

"; #ifdef FUNCTION_TIME_MEASUREMENT // Load information @@ -437,7 +437,7 @@ String processor(const String& var) { content += "

CAN/serial RX function timing: " + String(datalayer.system.status.time_snap_comm_us) + " us

"; content += "

CAN TX function timing: " + String(datalayer.system.status.time_snap_cantx_us) + " us

"; content += "

OTA function timing: " + String(datalayer.system.status.time_snap_ota_us) + " us

"; -#endif +#endif // FUNCTION_TIME_MEASUREMENT wl_status_t status = WiFi.status(); // Display ssid of network connected to and, if connected to the WiFi, its own IP @@ -459,100 +459,100 @@ String processor(const String& var) { content += "

Inverter protocol: "; #ifdef BYD_CAN content += "BYD Battery-Box Premium HVS over CAN Bus"; -#endif +#endif // BYD_CAN #ifdef BYD_MODBUS content += "BYD 11kWh HVM battery over Modbus RTU"; -#endif +#endif // BYD_MODBUS #ifdef LUNA2000_MODBUS content += "Luna2000 battery over Modbus RTU"; -#endif +#endif // LUNA2000_MODBUS #ifdef PYLON_CAN content += "Pylontech battery over CAN bus"; -#endif +#endif // PYLON_CAN #ifdef SERIAL_LINK_TRANSMITTER content += "Serial link to another LilyGo board"; -#endif +#endif // SERIAL_LINK_TRANSMITTER #ifdef SMA_CAN content += "BYD Battery-Box H 8.9kWh, 7 mod over CAN bus"; -#endif +#endif // SMA_CAN #ifdef SOFAR_CAN content += "Sofar Energy Storage Inverter High Voltage BMS General Protocol (Extended Frame) over CAN bus"; -#endif +#endif // SOFAR_CAN #ifdef SOLAX_CAN content += "SolaX Triple Power LFP over CAN bus"; -#endif +#endif // SOLAX_CAN content += "

"; content += "

Battery protocol: "; #ifdef BMW_I3_BATTERY content += "BMW i3"; -#endif +#endif // BMW_I3_BATTERY #ifdef BYD_ATTO_3_BATTERY content += "BYD Atto 3"; -#endif +#endif // BYD_ATTO_3_BATTERY #ifdef CHADEMO_BATTERY content += "Chademo V2X mode"; -#endif +#endif // CHADEMO_BATTERY #ifdef IMIEV_CZERO_ION_BATTERY content += "I-Miev / C-Zero / Ion Triplet"; -#endif +#endif // IMIEV_CZERO_ION_BATTERY #ifdef JAGUAR_IPACE_BATTERY content += "Jaguar I-PACE"; -#endif +#endif // JAGUAR_IPACE_BATTERY #ifdef KIA_HYUNDAI_64_BATTERY content += "Kia/Hyundai 64kWh"; -#endif +#endif // KIA_HYUNDAI_64_BATTERY #ifdef KIA_E_GMP_BATTERY content += "Kia/Hyundai EGMP platform"; -#endif +#endif // KIA_E_GMP_BATTERY #ifdef KIA_HYUNDAI_HYBRID_BATTERY content += "Kia/Hyundai Hybrid"; -#endif +#endif // KIA_HYUNDAI_HYBRID_BATTERY #ifdef MG_5_BATTERY content += "MG 5"; -#endif +#endif // MG_5_BATTERY #ifdef NISSAN_LEAF_BATTERY content += "Nissan LEAF"; -#endif +#endif // NISSAN_LEAF_BATTERY #ifdef RENAULT_KANGOO_BATTERY content += "Renault Kangoo"; -#endif +#endif // RENAULT_KANGOO_BATTERY #ifdef RENAULT_ZOE_GEN1_BATTERY content += "Renault Zoe Gen1 22/40"; -#endif +#endif // RENAULT_ZOE_GEN1_BATTERY #ifdef RENAULT_ZOE_GEN2_BATTERY content += "Renault Zoe Gen2 50"; -#endif +#endif // RENAULT_ZOE_GEN2_BATTERY #ifdef SANTA_FE_PHEV_BATTERY content += "Santa Fe PHEV"; -#endif +#endif // SANTA_FE_PHEV_BATTERY #ifdef SERIAL_LINK_RECEIVER content += "Serial link to another LilyGo board"; -#endif +#endif // SERIAL_LINK_RECEIVER #ifdef TESLA_MODEL_3_BATTERY content += "Tesla Model S/3/X/Y"; -#endif +#endif // TESLA_MODEL_3_BATTERY #ifdef VOLVO_SPA_BATTERY content += "Volvo / Polestar 78kWh battery"; -#endif +#endif // VOLVO_SPA_BATTERY #ifdef TEST_FAKE_BATTERY content += "Fake battery for testing purposes"; -#endif +#endif // TEST_FAKE_BATTERY #ifdef DOUBLE_BATTERY content += " (Double battery)"; -#endif +#endif // DOUBLE_BATTERY content += "

"; #if defined CHEVYVOLT_CHARGER || defined NISSANLEAF_CHARGER content += "

Charger protocol: "; #ifdef CHEVYVOLT_CHARGER content += "Chevy Volt Gen1 Charger"; -#endif +#endif // CHEVYVOLT_CHARGER #ifdef NISSANLEAF_CHARGER content += "Nissan LEAF 2013-2024 PDM charger"; -#endif +#endif // NISSANLEAF_CHARGER content += "

"; -#endif +#endif // defined CHEVYVOLT_CHARGER || defined NISSANLEAF_CHARGER // Close the block content += ""; @@ -564,7 +564,7 @@ String processor(const String& var) { #else // Start a new block with a specific background color. Color changes depending on system status content += "
Charger LVDC Output V: " + String(LVvol, 2) + ""; content += "

Charger AC Input V: " + String(ACvol, 2) + " VAC

"; content += "

Charger AC Input I: " + String(ACcur, 2) + " A

"; -#endif +#endif // CHEVYVOLT_CHARGER #ifdef NISSANLEAF_CHARGER float chgPwrDC = static_cast(charger_stat_HVcur * 100); charger_stat_HVcur = chgPwrDC / (datalayer.battery.status.voltage_dV / 10); // P/U=I @@ -778,10 +778,10 @@ String processor(const String& var) { content += "

Charger HVDC Output V: " + String(HVvol, 2) + " V

"; content += "

Charger HVDC Output I: " + String(HVcur, 2) + " A

"; content += "

Charger AC Input V: " + String(ACvol, 2) + " VAC

"; -#endif +#endif // NISSANLEAF_CHARGER // Close the block content += "
"; -#endif +#endif // defined CHEVYVOLT_CHARGER || defined NISSANLEAF_CHARGER content += ""; content += " "; @@ -835,7 +835,7 @@ void onOTAProgress(size_t current, size_t final) { ota_progress_millis = millis(); #ifdef DEBUG_VIA_USB Serial.printf("OTA Progress Current: %u bytes, Final: %u bytes\n", current, final); -#endif +#endif // DEBUG_VIA_USB // Reset the "watchdog" ota_timeout_timer.reset(); } @@ -846,11 +846,11 @@ void onOTAEnd(bool success) { if (success) { #ifdef DEBUG_VIA_USB Serial.println("OTA update finished successfully!"); -#endif +#endif // DEBUG_VIA_USB } else { #ifdef DEBUG_VIA_USB Serial.println("There was an error during OTA update!"); -#endif +#endif // DEBUG_VIA_USB // If we fail without a timeout, try to restore CAN ESP32Can.CANInit(); From 43760af1fd4ac5591e354d339efc4093d5a20334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Thu, 29 Aug 2024 23:40:55 +0300 Subject: [PATCH 14/17] Add more messages from the logs --- Software/src/battery/KIA-E-GMP-BATTERY.cpp | 127 ++++++++++++++++++++- 1 file changed, 126 insertions(+), 1 deletion(-) diff --git a/Software/src/battery/KIA-E-GMP-BATTERY.cpp b/Software/src/battery/KIA-E-GMP-BATTERY.cpp index 9469102f..1f553511 100644 --- a/Software/src/battery/KIA-E-GMP-BATTERY.cpp +++ b/Software/src/battery/KIA-E-GMP-BATTERY.cpp @@ -11,6 +11,8 @@ static unsigned long previousMillis30ms = 0; // will store last time a 30ms CA static unsigned long previousMillis100ms = 0; // will store last time a 100ms CAN Message was send static unsigned long previousMillis200ms = 0; // will store last time a 200ms CAN Message was send static unsigned long previousMillis500ms = 0; // will store last time a 500ms CAN Message was send +static unsigned long previousMillis1s = 0; // will store last time a 1s CAN Message was send +static unsigned long previousMillis2s = 0; // will store last time a 2s CAN Message was send #define MAX_CELL_VOLTAGE 4250 //Battery is put into emergency stop if one cell goes over this value #define MIN_CELL_VOLTAGE 2950 //Battery is put into emergency stop if one cell goes below this value @@ -182,6 +184,71 @@ CAN_frame EGMP_410 = {.FD = true, .DLC = 8, .ID = 0x410, .data = {0xA6, 0x10, 0xFF, 0x3C, 0xFF, 0x7F, 0xFF, 0xFF}}; +CAN_frame EGMP_411 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x411, + .data = {0xEA, 0x22, 0x50, 0x51, 0x00, 0x00, 0x00, 0x40}}; +CAN_frame EGMP_412 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x412, + .data = {0xDC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_413 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x413, + .data = {0xB9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_414 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x414, + .data = {0xF0, 0x10, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_416 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x416, + .data = {0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_417 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x417, + .data = {0xC7, 0x10, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_418 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x418, + .data = {0x17, 0x20, 0x00, 0x00, 0x14, 0x0C, 0x00, 0x00}}; +CAN_frame EGMP_3C1 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x3C1, + .data = {0x59, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_3C2 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x3C2, + .data = {0x07, 0x00, 0x11, 0x40, 0x00, 0x00, 0x00, 0x00}}; +CAN_frame EGMP_4F0 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x4F0, + .data = {0x8A, 0x0A, 0x0D, 0x34, 0x60, 0x18, 0x12, 0xFC}}; +CAN_frame EGMP_4F2 = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x4F2, + .data = {0x0A, 0xC3, 0xD5, 0xFF, 0x0F, 0x21, 0x80, 0x2B}}; +CAN_frame EGMP_4FE = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x4FE, + .data = {0x69, 0x3F, 0x00, 0x04, 0xDF, 0x01, 0x4C, 0xA8}}; +CAN_frame EGMP_48F = {.FD = true, + .ext_ID = false, + .DLC = 8, + .ID = 0x48F, + .data = {0xAD, 0x10, 0x41, 0x00, 0x05, 0x00, 0x00, 0x00}}; CAN_frame EGMP_419 = {.FD = true, .ext_ID = false, .DLC = 8, @@ -649,14 +716,60 @@ void send_can_battery() { transmit_can(&EGMP_444, can_config.battery); transmit_can(&EGMP_405, can_config.battery); transmit_can(&EGMP_410, can_config.battery); + transmit_can(&EGMP_411, can_config.battery); + transmit_can(&EGMP_412, can_config.battery); + transmit_can(&EGMP_412, can_config.battery); + transmit_can(&EGMP_413, can_config.battery); + transmit_can(&EGMP_414, can_config.battery); + transmit_can(&EGMP_416, can_config.battery); + transmit_can(&EGMP_417, can_config.battery); + transmit_can(&EGMP_418, can_config.battery); + transmit_can(&EGMP_3C1, can_config.battery); + transmit_can(&EGMP_3C2, can_config.battery); + transmit_can(&EGMP_4F0, can_config.battery); //TODO: could be handled better + transmit_can(&EGMP_4F2, can_config.battery); //TODO: could be handled better if (ticks_200ms_counter < 254) { ticks_200ms_counter++; } + if (ticks_200ms_counter > 11) { + EGMP_412.data.u8[0] = 0x48; + EGMP_412.data.u8[1] = 0x10; + EGMP_412.data.u8[6] = 0x04; + + EGMP_418.data.u8[0] = 0xCE; + EGMP_418.data.u8[1] = 0x30; + EGMP_418.data.u8[4] = 0x14; + EGMP_418.data.u8[5] = 0x4C; + if (ticks_200ms_counter > 39) { + EGMP_412.data.u8[0] = 0xB3; + EGMP_412.data.u8[1] = 0x20; + EGMP_412.data.u8[6] = 0x00; + + EGMP_418.data.u8[0] = 0xA6; + EGMP_418.data.u8[1] = 0x40; + EGMP_418.data.u8[5] = 0x0C; + } + } + if (ticks_200ms_counter > 20) { + EGMP_413.data.u8[0] = 0xF5; + EGMP_413.data.u8[1] = 0x10; + EGMP_413.data.u8[3] = 0x41; + } if (ticks_200ms_counter > 28) { EGMP_4B4.data.u8[2] = 0; EGMP_4B4.data.u8[3] = 0; } + if (ticks_200ms_counter > 26) { + EGMP_411.data.u8[0] = 0x9E; + EGMP_411.data.u8[1] = 0x32; + EGMP_411.data.u8[7] = 0x50; + + EGMP_417.data.u8[0] = 0x9E; + EGMP_417.data.u8[1] = 0x20; + EGMP_417.data.u8[4] = 0x04; + EGMP_417.data.u8[5] = 0x01; + } if (ticks_200ms_counter > 32) { EGMP_4CE.data.u8[0] = 0x22; EGMP_4CE.data.u8[1] = 0x41; @@ -696,7 +809,7 @@ void send_can_battery() { EGMP_444.data.u8[0] = 0xEE; EGMP_444.data.u8[1] = 0x30; EGMP_444.data.u8[3] = 0x20; - if (ticks_200ms_counter > 12) { // TODO: Could be handled better + if (ticks_200ms_counter > 23) { // TODO: Could be handled better EGMP_444.data.u8[0] = 0xE4; EGMP_444.data.u8[1] = 0x60; EGMP_444.data.u8[2] = 0x25; @@ -725,6 +838,18 @@ void send_can_battery() { KIA_7E4_COUNTER = 0x01; } } + //Send 1s CANFD message + if (currentMillis - previousMillis1s >= INTERVAL_1_S) { + previousMillis1s = currentMillis; + + transmit_can(&EGMP_48F, can_config.battery); + } + //Send 2s CANFD message + if (currentMillis - previousMillis2s >= INTERVAL_2_S) { + previousMillis2s = currentMillis; + + transmit_can(&EGMP_4FE, can_config.battery); + } } void setup_battery(void) { // Performs one time setup at startup From 73d4d0777ffa517b115e254c1914494e94655c94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Fri, 30 Aug 2024 12:21:59 +0300 Subject: [PATCH 15/17] Remove unused LUNA library --- .github/workflows/compile-all-batteries.yml | 1 - .../workflows/compile-all-combinations.yml | 1 - .github/workflows/compile-all-inverters.yml | 1 - Software/USER_SETTINGS.h | 1 - Software/src/devboard/webserver/webserver.cpp | 3 - Software/src/inverter/INVERTERS.h | 4 -- Software/src/inverter/LUNA2000-MODBUS.cpp | 61 ------------------- Software/src/inverter/LUNA2000-MODBUS.h | 13 ---- 8 files changed, 85 deletions(-) delete mode 100644 Software/src/inverter/LUNA2000-MODBUS.cpp delete mode 100644 Software/src/inverter/LUNA2000-MODBUS.h diff --git a/.github/workflows/compile-all-batteries.yml b/.github/workflows/compile-all-batteries.yml index f740f480..dd3db498 100644 --- a/.github/workflows/compile-all-batteries.yml +++ b/.github/workflows/compile-all-batteries.yml @@ -53,7 +53,6 @@ jobs: inverter: - BYD_CAN # - BYD_MODBUS -# - LUNA2000_MODBUS # - PYLON_CAN # - SMA_CAN # - SMA_TRIPOWER_CAN diff --git a/.github/workflows/compile-all-combinations.yml b/.github/workflows/compile-all-combinations.yml index 799023fe..b4262f29 100644 --- a/.github/workflows/compile-all-combinations.yml +++ b/.github/workflows/compile-all-combinations.yml @@ -55,7 +55,6 @@ jobs: - BYD_CAN - BYD_SMA - BYD_MODBUS - - LUNA2000_MODBUS - PYLON_CAN - SMA_CAN - SMA_TRIPOWER_CAN diff --git a/.github/workflows/compile-all-inverters.yml b/.github/workflows/compile-all-inverters.yml index d12c7c7e..616536f6 100644 --- a/.github/workflows/compile-all-inverters.yml +++ b/.github/workflows/compile-all-inverters.yml @@ -45,7 +45,6 @@ jobs: - BYD_CAN - BYD_SMA - BYD_MODBUS - - LUNA2000_MODBUS - PYLON_CAN - SMA_CAN - SMA_TRIPOWER_CAN diff --git a/Software/USER_SETTINGS.h b/Software/USER_SETTINGS.h index 67ea352f..3b8cd1ed 100644 --- a/Software/USER_SETTINGS.h +++ b/Software/USER_SETTINGS.h @@ -32,7 +32,6 @@ //#define BYD_CAN //Enable this line to emulate a "BYD Battery-Box Premium HVS" over CAN Bus //#define BYD_SMA //Enable this line to emulate a SMA compatible "BYD Battery-Box HVS 10.2KW battery" over CAN bus //#define BYD_MODBUS //Enable this line to emulate a "BYD 11kWh HVM battery" over Modbus RTU -//#define LUNA2000_MODBUS //Enable this line to emulate a "Luna2000 battery" over Modbus RTU //#define PYLON_CAN //Enable this line to emulate a "Pylontech battery" over CAN bus //#define SMA_CAN //Enable this line to emulate a "BYD Battery-Box H 8.9kWh, 7 mod" over CAN bus //#define SMA_TRIPOWER_CAN //Enable this line to emulate a "SMA Home Storage battery" over CAN bus diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index 449f1638..f86b3e65 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -457,9 +457,6 @@ String processor(const String& var) { #ifdef BYD_MODBUS content += "BYD 11kWh HVM battery over Modbus RTU"; #endif -#ifdef LUNA2000_MODBUS - content += "Luna2000 battery over Modbus RTU"; -#endif #ifdef PYLON_CAN content += "Pylontech battery over CAN bus"; #endif diff --git a/Software/src/inverter/INVERTERS.h b/Software/src/inverter/INVERTERS.h index c448697e..6aafc3e5 100644 --- a/Software/src/inverter/INVERTERS.h +++ b/Software/src/inverter/INVERTERS.h @@ -15,10 +15,6 @@ #include "BYD-SMA.h" #endif -#ifdef LUNA2000_MODBUS -#include "LUNA2000-MODBUS.h" -#endif - #ifdef PYLON_CAN #include "PYLON-CAN.h" #endif diff --git a/Software/src/inverter/LUNA2000-MODBUS.cpp b/Software/src/inverter/LUNA2000-MODBUS.cpp deleted file mode 100644 index 889daa0b..00000000 --- a/Software/src/inverter/LUNA2000-MODBUS.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "../include.h" -#ifdef LUNA2000_MODBUS -#include "../datalayer/datalayer.h" -#include "LUNA2000-MODBUS.h" - -void update_modbus_registers_inverter() { - handle_update_data_modbus32051(); - handle_update_data_modbus39500(); -} - -void handle_update_data_modbus32051() { - // Store the data into the array - static uint16_t system_data[9]; - system_data[0] = 1; - system_data[1] = 534; //Goes between 534-498 depending on SOC - system_data[2] = 110; //Goes between 110- -107 [NOTE, SIGNED VALUE] - system_data[3] = 0; //Goes between 0 and -1 [NOTE, SIGNED VALUE] - system_data[4] = 616; //Goes between 616- -520 [NOTE, SIGNED VALUE] - system_data[5] = datalayer.battery.status.temperature_max_dC; //Temperature max? - system_data[6] = datalayer.battery.status.temperature_min_dC; //Temperature min? - system_data[7] = (datalayer.battery.status.reported_soc / 100); //SOC 0-100%, no decimals - system_data[8] = 98; //Always 98 in logs - static uint16_t i = 2051; - memcpy(&mbPV[i], system_data, sizeof(system_data)); -} - -void handle_update_data_modbus39500() { - // Store the data into the array - static uint16_t system_data[26]; - system_data[0] = 0; - system_data[1] = datalayer.battery.info.total_capacity_Wh; //Capacity? 5000 with 5kWh battery - system_data[2] = 0; - system_data[3] = datalayer.battery.info.total_capacity_Wh; //Capacity? 5000 with 5kWh battery - system_data[4] = 0; - system_data[5] = 2500; //??? - system_data[6] = 0; - system_data[7] = 2500; //??? - system_data[8] = (datalayer.battery.status.reported_soc / 100); //SOC 0-100%, no decimals - system_data[9] = - 1; //Running status, equiv to register 37762, 0 = Offline, 1 = Standby,2 = Running, 3 = Fault, 4 = sleep mode - system_data[10] = datalayer.battery.status.voltage_dV; //Battery bus voltage (766.5V = 7665) - system_data[11] = 9; //TODO: GOES LOWER WITH LOW SOC - system_data[12] = 0; - system_data[13] = 699; //TODO: GOES LOWER WITH LOW SOC - system_data[14] = 1; //Always 1 in logs - system_data[15] = 18; //Always 18 in logs - system_data[16] = 8066; //TODO: GOES HIGHER WITH LOW SOC (max allowed charge W?) - system_data[17] = 17; - system_data[18] = 44027; //TODO: GOES LOWER WITH LOW SOC - system_data[19] = 0; - system_data[20] = 435; //Always 435 in logs - system_data[21] = 0; - system_data[22] = 0; - system_data[23] = 0; - system_data[24] = (datalayer.battery.status.reported_soc / 10); //SOC 0-100.0%, 1x decimal - system_data[25] = 0; - system_data[26] = 1; //Always 1 in logs - static uint16_t i = 9500; - memcpy(&mbPV[i], system_data, sizeof(system_data)); -} -#endif diff --git a/Software/src/inverter/LUNA2000-MODBUS.h b/Software/src/inverter/LUNA2000-MODBUS.h deleted file mode 100644 index 5f994aee..00000000 --- a/Software/src/inverter/LUNA2000-MODBUS.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef LUNA2000_MODBUS_H -#define LUNA2000_MODBUS_H -#include "../include.h" - -#define MODBUS_INVERTER_SELECTED - -#define MB_RTU_NUM_VALUES 30000 - -extern uint16_t mbPV[MB_RTU_NUM_VALUES]; - -void handle_update_data_modbus32051(); -void handle_update_data_modbus39500(); -#endif From 2c98596f862c746e0d82c54227c89782792de537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Sat, 31 Aug 2024 16:49:44 +0300 Subject: [PATCH 16/17] Update Software version tag --- Software/Software.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Software/Software.ino b/Software/Software.ino index d9f47601..11cf06bd 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -38,7 +38,7 @@ Preferences settings; // Store user settings // The current software version, shown on webserver -const char* version_number = "7.1.dev"; +const char* version_number = "7.1.0"; // Interval settings uint16_t intervalUpdateValues = INTERVAL_5_S; // Interval at which to update inverter values / Modbus registers From 587159c5f2d49c65beb2e2f79417fb19c5264991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Sat, 31 Aug 2024 17:05:03 +0300 Subject: [PATCH 17/17] Update software version tag to signal dev --- Software/Software.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Software/Software.ino b/Software/Software.ino index 11cf06bd..6fec76fa 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -38,7 +38,7 @@ Preferences settings; // Store user settings // The current software version, shown on webserver -const char* version_number = "7.1.0"; +const char* version_number = "7.2.dev"; // Interval settings uint16_t intervalUpdateValues = INTERVAL_5_S; // Interval at which to update inverter values / Modbus registers