Add can-configuration to webui

This commit is contained in:
Daniel Öster 2024-08-05 22:14:23 +03:00
parent df626c3920
commit 28703453f9
5 changed files with 106 additions and 39 deletions

View file

@ -1,13 +1,36 @@
#include "USER_SETTINGS.h" #include "USER_SETTINGS.h"
#include <string> #include <string>
#include "src/devboard/hal/hal.h"
/* This file contains all the battery settings and limits */ /* This file contains all the battery settings and limits */
/* They can be defined here, or later on in the WebUI */ /* They can be defined here, or later on in the WebUI */
/* */ /* Select which CAN interface each component is connected to */
extern volatile uint8_t CAN_BATTERY; /*
extern volatile uint8_t CAN_BATTERY_DOUBLE; CAN_NATIVE = Native CAN port on the LilyGo & Stark hardware
extern volatile uint8_t CAN_INVERTER; CANFD_NATIVE = Native CANFD port on the Stark CMR hardware
CAN_ADDON_MCP2515 = Add-on CAN MCP2515 connected to GPIO pins
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?
.battery_double = CAN_ADDON_MCP2515, // Which CAN is your optional second battery connected to?
.inverter = CAN_NATIVE // Which CAN is your inverter connected to? (Not needed for RS485 inverters)
};
#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* 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
// MQTT
#ifdef MQTT
const char* mqtt_user = "REDACTED";
const char* mqtt_password = "REDACTED";
#endif // USE_MQTT
#endif // WEBSERVER
/* Charger settings (Optional, when using generator charging) */ /* Charger settings (Optional, when using generator charging) */
volatile float CHARGER_SET_HV = 384; // Reasonably appropriate 4.0v per cell charging of a 96s pack volatile float CHARGER_SET_HV = 384; // Reasonably appropriate 4.0v per cell charging of a 96s pack
@ -16,19 +39,3 @@ volatile float CHARGER_MIN_HV = 200; // Min permissible output (VDC) of cha
volatile float CHARGER_MAX_POWER = 3300; // Max power capable of charger, as a ceiling for validating config volatile float CHARGER_MAX_POWER = 3300; // Max power capable of charger, as a ceiling for validating config
volatile float CHARGER_MAX_A = 11.5; // Max current output (amps) of charger volatile float CHARGER_MAX_A = 11.5; // Max current output (amps) of charger
volatile float CHARGER_END_A = 1.0; // Current at which charging is considered complete volatile float CHARGER_END_A = 1.0; // Current at which charging is considered complete
#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* 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
// MQTT
#ifdef MQTT
const char* mqtt_user = "REDACTED";
const char* mqtt_password = "REDACTED";
#endif // USE_MQTT
#endif

View file

@ -17,7 +17,7 @@
//#define KIA_E_GMP_BATTERY //#define KIA_E_GMP_BATTERY
//#define KIA_HYUNDAI_HYBRID_BATTERY //#define KIA_HYUNDAI_HYBRID_BATTERY
//#define MG_5_BATTERY //#define MG_5_BATTERY
//#define NISSAN_LEAF_BATTERY #define NISSAN_LEAF_BATTERY
//#define PYLON_BATTERY //#define PYLON_BATTERY
//#define RENAULT_KANGOO_BATTERY //#define RENAULT_KANGOO_BATTERY
//#define RENAULT_ZOE_GEN1_BATTERY //#define RENAULT_ZOE_GEN1_BATTERY
@ -29,7 +29,7 @@
//#define DOUBLE_BATTERY //Enable this line if you use two identical batteries at the same time (requires DUAL_CAN setup) //#define DOUBLE_BATTERY //Enable this line if you use two identical batteries at the same time (requires DUAL_CAN setup)
/* Select inverter communication protocol. See Wiki for which to use with your inverter: https://github.com/dalathegreat/BYD-Battery-Emulator-For-Gen24/wiki */ /* 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 #define BYD_CAN //Enable this line to emulate a "BYD Battery-Box Premium HVS" over CAN Bus
//#define BYD_MODBUS //Enable this line to emulate a "BYD 11kWh HVM battery" over Modbus RTU //#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 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 PYLON_CAN //Enable this line to emulate a "Pylontech battery" over CAN bus
@ -69,7 +69,6 @@
//#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 settings */ /* Battery settings */
// Predefined total energy capacity of the battery in Watt-hours // Predefined total energy capacity of the battery in Watt-hours
#define BATTERY_WH_MAX 30000 #define BATTERY_WH_MAX 30000
// Increases battery life. If true will rescale SOC between the configured min/max-percentage // Increases battery life. If true will rescale SOC between the configured min/max-percentage
@ -83,10 +82,17 @@
// 300 = 30.0A , BYD CAN specific setting, Max discharge in Amp (Some inverters needs to be limited) // 300 = 30.0A , BYD CAN specific setting, Max discharge in Amp (Some inverters needs to be limited)
#define BATTERY_MAX_DISCHARGE_AMP 300 #define BATTERY_MAX_DISCHARGE_AMP 300
/* Do not change any code below this line unless you are sure what you are doing */
/* Only change battery specific settings in "USER_SETTINGS.h" */
typedef enum { CAN_NATIVE = 0, CAN_ADDON_MCP2515 = 1, CAN_ADDON_FD_MCP2518 = 2 } CAN_Interface;
typedef struct {
CAN_Interface battery;
CAN_Interface battery_double;
CAN_Interface inverter;
} CAN_Configuration;
extern volatile CAN_Configuration can_config;
extern volatile uint8_t AccessPointEnabled; extern volatile uint8_t AccessPointEnabled;
extern const uint8_t wifi_channel; extern const uint8_t wifi_channel;
/* Charger limits (Optional): Set in the USER_SETTINGS.cpp or later in the webserver */
extern volatile float charger_setpoint_HV_VDC; extern volatile float charger_setpoint_HV_VDC;
extern volatile float charger_setpoint_HV_IDC; extern volatile float charger_setpoint_HV_IDC;
extern volatile float charger_setpoint_HV_IDC_END; extern volatile float charger_setpoint_HV_IDC_END;
@ -99,4 +105,4 @@ extern volatile float CHARGER_END_A;
extern bool charger_HV_enabled; extern bool charger_HV_enabled;
extern bool charger_aux12V_enabled; extern bool charger_aux12V_enabled;
#endif #endif // __USER_SETTINGS_H__

View file

@ -3,6 +3,22 @@
#include "../../../USER_SETTINGS.h" #include "../../../USER_SETTINGS.h"
/* Enumeration for CAN interfaces
typedef enum {
CAN_NATIVE = 0,
CANFD_NATIVE = 1,
CAN_ADDON_MCP2515 = 2,
CAN_ADDON_FD_MCP2518 = 3
} CAN_Interface;
/* Struct to hold CAN assignments for components
typedef struct {
CAN_Interface battery;
CAN_Interface battery_double;
CAN_Interface inverter;
} CAN_Configuration;
*/
#if defined(HW_LILYGO) #if defined(HW_LILYGO)
#include "hw_lilygo.h" #include "hw_lilygo.h"
#elif defined(HW_STARK) #elif defined(HW_STARK)

View file

@ -19,21 +19,24 @@ String settings_processor(const String& var) {
"<h4 style='color: white;'>Password: ######## <span id='Password'></span> <button " "<h4 style='color: white;'>Password: ######## <span id='Password'></span> <button "
"onclick='editPassword()'>Edit</button></h4>"; "onclick='editPassword()'>Edit</button></h4>";
/* content += "<h4 style='color: white;'>Battery interface: <span id='Battery'>" +
If LilyGo used: String(getCANInterfaceName(can_config.battery)) + "</span></h4>";
Battery CAN channel: DISABLED / CAN / ADD-ON CAN MCP2515 / ADD-ON CAN-FD
Inverter CAN channel: DISABLED / CAN / ADD-ON CAN MCP2515 / ADD-ON CAN-FD
Battery#2 CAN channel: DISABLED / CAN / ADD-ON CAN MCP2515 / ADD-ON CAN-FD
If Stark board used
Battery CAN channel: DISABLED / CAN / CAN-FD
Inverter CAN channel: DISABLED / CAN / CAN-FD
Battery#2 CAN channel: DISABLED / CAN / CAN-FD
*/
content += #ifdef DOUBLE_BATTERY
"<h4 style='color: white;'>Password: ######## <span id='Password'></span> <button " content += "<h4 style='color: white;'>Battery #2 interface: <span id='Battery'>" +
"onclick='editPassword()'>Edit</button></h4>"; String(getCANInterfaceName(can_config.battery_double)) + "</span></h4>";
#else
content += "<h4 style='color: gray;'>Battery #2 interface: <span id='Battery'>" +
String(getCANInterfaceName(can_config.battery_double)) + "</span></h4>";
#endif // DOUBLE_BATTERY
#ifdef CAN_INVERTER_SELECTED
content += "<h4 style='color: white;'>Inverter interface: <span id='Inverter'>" +
String(getCANInterfaceName(can_config.inverter)) + "</span></h4>";
#endif //CAN_INVERTER_SELECTED
#ifdef MODBUS_INVERTER_SELECTED
content += "<h4 style='color: white;'>Inverter interface: RS485<span id='Inverter'></span></h4>";
#endif
// Close the block // Close the block
content += "</div>"; content += "</div>";
@ -210,3 +213,30 @@ String settings_processor(const String& var) {
} }
return String(); return String();
} }
const char* getCANInterfaceName(CAN_Interface interface) {
#ifdef HW_LILYGO
switch (interface) {
case CAN_NATIVE:
return "CAN";
case CAN_ADDON_MCP2515:
return "Add-on CAN via GPIO MCP2515";
case CAN_ADDON_FD_MCP2518:
return "Add-on CAN-FD via GPIO MCP2518";
default:
return "UNKNOWN";
}
#endif
#ifdef HW_STARK
switch (interface) {
case CAN_NATIVE:
return "CAN";
case CAN_ADDON_MCP2515:
return "CAN_ADDON_MCP2515";
case CAN_ADDON_FD_MCP2518:
return "CAN_ADDON_FD_MCP2518";
default:
return "UNKNOWN";
}
#endif
}

View file

@ -17,5 +17,13 @@ extern std::string password;
* @return String * @return String
*/ */
String settings_processor(const String& var); String settings_processor(const String& var);
/**
* @brief Maps the value to a string of characters
*
* @param[in] char
*
* @return String
*/
const char* getCANInterfaceName(CAN_Interface interface);
#endif #endif