mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 17:59:27 +02:00
Final tweaks, and 1F2 sending
This commit is contained in:
parent
a56ceb50dd
commit
055c933ee0
5 changed files with 51 additions and 14 deletions
|
@ -17,7 +17,7 @@
|
|||
//#define RENAULT_ZOE_BATTERY
|
||||
//#define SANTA_FE_PHEV_BATTERY
|
||||
//#define TESLA_MODEL_3_BATTERY
|
||||
#define TEST_FAKE_BATTERY
|
||||
//#define TEST_FAKE_BATTERY
|
||||
|
||||
/* Select inverter communication protocol. See Wiki for which to use with your inverter: https://github.com/dalathegreat/BYD-Battery-Emulator-For-Gen24/wiki */
|
||||
//#define BYD_CAN //Enable this line to emulate a "BYD Battery-Box Premium HVS" over CAN Bus
|
||||
|
@ -36,11 +36,11 @@
|
|||
//#define DUAL_CAN //Enable this line to activate an isolated secondary CAN Bus using add-on MCP2515 controller (Needed for FoxESS inverters)
|
||||
//#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 WEBSERVER //Enable this line to enable WiFi, and to run the webserver. See USER_SETTINGS.cpp for the Wifi settings.
|
||||
|
||||
/* Select charger used (Optional) */
|
||||
//#define CHEVYVOLT_CHARGER //Enable this line to control a Chevrolet Volt charger connected to battery - for example, when generator charging or using an inverter without a charging function.
|
||||
#define NISSANLEAF_CHARGER //Enable this line to control a Nissan LEAF PDM connected to battery - for example, when generator charging
|
||||
//#define NISSANLEAF_CHARGER //Enable this line to control a Nissan LEAF PDM connected to battery - for example, when generator charging
|
||||
|
||||
/* Battery limits: These are set in the USER_SETTINGS.cpp file, or later on via the Webserver */
|
||||
extern volatile uint16_t BATTERY_WH_MAX;
|
||||
|
|
|
@ -844,7 +844,10 @@ void send_can_leaf_battery() {
|
|||
break;
|
||||
}
|
||||
|
||||
//Only send this message when NISSANLEAF_CHARGER is not defined (otherwise it will collide!)
|
||||
#ifndef NISSANLEAF_CHARGER
|
||||
ESP32Can.CANWriteFrame(&LEAF_1F2); //Contains (CHG_STA_RQ == 1 == Normal Charge)
|
||||
#endif
|
||||
|
||||
mprun10r++;
|
||||
if (mprun10r > 19) { // 0x1F2 patter repeats after 20 messages,
|
||||
|
|
|
@ -27,9 +27,12 @@ static unsigned long previousMillis100ms = 0;
|
|||
|
||||
/* LEAF charger/battery parameters */
|
||||
enum OBC_MODES : uint8_t { IDLE_OR_QC = 1, FINISHED = 2, CHARGING_OR_INTERRUPTED = 4, IDLE1 = 8, IDLE2 = 9, PLUGGED_IN_WAITING_ON_TIMER };
|
||||
static uint8_t mprun100 = 0; //counter 0-3
|
||||
static uint8_t mprun10 = 0; //counter 0-3
|
||||
enum OBC_VOLTAGES : uint8_t { NO_SIGNAL = 0, AC110 = 1, AC230 = 2, ABNORMAL_WAVE = 3 };
|
||||
static uint16_t OBC_Charge_Power = 0; // Actual charger output
|
||||
static uint8_t mprun100 = 0; // Counter 0-3
|
||||
static uint8_t mprun10 = 0; // Counter 0-3
|
||||
static uint8_t OBC_Charge_Status = IDLE_OR_QC;
|
||||
static uint8_t OBC_Status_AC_Voltage = 0; //1=110V, 2=230V
|
||||
static uint8_t OBCpowerSetpoint = 0;
|
||||
static uint8_t OBCpower = 0;
|
||||
static bool PPStatus = false;
|
||||
|
@ -122,7 +125,7 @@ void receive_can_nissanleaf_charger(CAN_frame_t rx_frame) {
|
|||
case 0x679: // This message fires once when charging cable is plugged in
|
||||
OBCwakeup = true;
|
||||
charger_aux12V_enabled = true; //Not possible to turn off 12V charging
|
||||
// Startout with default values, so that charging can begin when user plugs in cable
|
||||
// Startout with default values, so that charging can begin right when user plugs in cable
|
||||
charger_HV_enabled = true;
|
||||
charger_setpoint_HV_IDC = 16; // Ampere
|
||||
charger_setpoint_HV_VDC = 400; // Target voltage
|
||||
|
@ -135,6 +138,19 @@ void receive_can_nissanleaf_charger(CAN_frame_t rx_frame) {
|
|||
else {
|
||||
PPStatus = false; //plug not inserted
|
||||
}
|
||||
OBC_Status_AC_Voltage = ((rx_frame.data.u8[3] & 0x18) >> 3);
|
||||
if(OBC_Status_AC_Voltage == AC110){
|
||||
charger_stat_ACvol = 110;
|
||||
}
|
||||
if(OBC_Status_AC_Voltage == AC230){
|
||||
charger_stat_ACvol = 230;
|
||||
}
|
||||
if(OBC_Status_AC_Voltage == ABNORMAL_WAVE){
|
||||
charger_stat_ACvol = 1;
|
||||
}
|
||||
|
||||
OBC_Charge_Power = ((rx_frame.data.u8[0] & 0x01) << 8) | (rx_frame.data.u8[1]);
|
||||
charger_stat_HVcur = OBC_Charge_Power;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -194,7 +210,9 @@ void send_can_nissanleaf_charger() {
|
|||
|
||||
// decrement charger power if volt setpoint is reached
|
||||
if (battery_voltage >= (CHARGER_SET_HV * 10)) {
|
||||
OBCpower--;
|
||||
if (OBCpower > 0x64){
|
||||
OBCpower--;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -207,8 +225,7 @@ void send_can_nissanleaf_charger() {
|
|||
LEAF_1F2.data.u8[6] = mprun10;
|
||||
LEAF_1F2.data.u8[7] = calculate_checksum_nibble(&LEAF_1F2);
|
||||
|
||||
// TODO
|
||||
ESP32Can.CANWriteFrame(&LEAF_1F2); // Logic needed to hijack so that the LEAF code does not send the static locked variant when charger is used! This is the only collision message
|
||||
ESP32Can.CANWriteFrame(&LEAF_1F2); // Sending of 1F2 message is halted in LEAF-BATTERY function incase charger is used!
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -524,6 +524,7 @@ String processor(const String& var) {
|
|||
content += "<span style='color: red;'>✕</span>";
|
||||
}
|
||||
content += "</h4>";
|
||||
#ifdef CHEVYVOLT_CHARGER
|
||||
float chgPwrDC = static_cast<float>(charger_stat_HVcur * charger_stat_HVvol);
|
||||
float chgPwrAC = static_cast<float>(charger_stat_ACcur * charger_stat_ACvol);
|
||||
float chgEff = chgPwrDC / chgPwrAC * 100;
|
||||
|
@ -536,13 +537,26 @@ String processor(const String& var) {
|
|||
|
||||
content += formatPowerValue("Charger Output Power", chgPwrDC, "", 1);
|
||||
content += "<h4 style='color: white;'>Charger Efficiency: " + String(chgEff) + "%</h4>";
|
||||
content += "<h4 style='color: white;'>Charger HVDC Output V: " + String(HVvol, 2) + "</h4>";
|
||||
content += "<h4 style='color: white;'>Charger HVDC Output I: " + String(HVcur, 2) + "</h4>";
|
||||
content += "<h4 style='color: white;'>Charger HVDC Output V: " + String(HVvol, 2) + " V</h4>";
|
||||
content += "<h4 style='color: white;'>Charger HVDC Output I: " + String(HVcur, 2) + " A</h4>";
|
||||
content += "<h4 style='color: white;'>Charger LVDC Output I: " + String(LVcur, 2) + "</h4>";
|
||||
content += "<h4 style='color: white;'>Charger LVDC Output V: " + String(LVvol, 2) + "</h4>";
|
||||
content += "<h4 style='color: white;'>Charger AC Input V: " + String(ACvol, 2) + "VAC</h4>";
|
||||
content += "<h4 style='color: white;'>Charger AC Input I: " + String(ACvol, 2) + "VAC</h4>";
|
||||
content += "<h4 style='color: white;'>Charger AC Input V: " + String(ACvol, 2) + " VAC</h4>";
|
||||
content += "<h4 style='color: white;'>Charger AC Input I: " + String(ACcur, 2) + " A</h4>";
|
||||
#endif
|
||||
#ifdef NISSANLEAF_CHARGER
|
||||
float chgPwrDC = static_cast<float>(charger_stat_HVcur*100);
|
||||
charger_stat_HVcur = chgPwrDC/(battery_voltage/10); // P/U=I
|
||||
charger_stat_HVvol = static_cast<float>(battery_voltage/10);
|
||||
float ACvol = charger_stat_ACvol;
|
||||
float HVvol = charger_stat_HVvol;
|
||||
float HVcur = charger_stat_HVcur;
|
||||
|
||||
content += formatPowerValue("Charger Output Power", chgPwrDC, "", 1);
|
||||
content += "<h4 style='color: white;'>Charger HVDC Output V: " + String(HVvol, 2) + " V</h4>";
|
||||
content += "<h4 style='color: white;'>Charger HVDC Output I: " + String(HVcur, 2) + " A</h4>";
|
||||
content += "<h4 style='color: white;'>Charger AC Input V: " + String(ACvol, 2) + " VAC</h4>";
|
||||
#endif
|
||||
// Close the block
|
||||
content += "</div>";
|
||||
#endif
|
||||
|
|
|
@ -44,6 +44,9 @@ extern float charger_stat_ACvol;
|
|||
extern float charger_stat_LVcur;
|
||||
extern float charger_stat_LVvol;
|
||||
|
||||
//LEAF charger
|
||||
extern uint16_t OBC_Charge_Power;
|
||||
|
||||
/**
|
||||
* @brief Initialization function for the webserver.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue